1 2 package chromesthesia2; 3 4 import java.awt.Color; 5 import note.SNote; 6 import painter.SPainter; 7 import shapes.SRectangle; 8 9 public class Pitch { 10 // INSTANCE VARIABLES 11 private String abcName; 12 private SPainter painter; 13 private SRectangle box; 14 private SNote note; 15 private Color color; 16 17 public Pitch(String abcName, SPainter painter) 18 {this.abcName = abcName; 19 this.painter = painter; 20 this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50); 21 this.note = createNoteForThisPitch(abcName); 22 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 23 } 24 25 public String toString() 26 { 27 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 28 } 29 30 public String abcName() { 31 return abcName; 32 } 33 private SNote createNoteForThisPitch(String abcPitchClassName) { 34 SNote note = new SNote(); 35 if ( abcPitchClassName.equals("C") ) { 36 // nothing to do 37 } else if ( abcPitchClassName.equals("C,") ) { 38 note.lp(7); } else if ( abcPitchClassName.equals("c") ) { 39 note.rp(7);} else if ( abcPitchClassName.equals("D") ) { 40 note.rp(1);} else if ( abcPitchClassName.equals("D,") ) { 41 note.lp(6);} else if ( abcPitchClassName.equals("d") ) { 42 note.rp(8);} else if ( abcPitchClassName.equals("E") ) { 43 note.rp(2);} else if ( abcPitchClassName.equals("E,") ) { 44 note.lp(5);} else if ( abcPitchClassName.equals("e") ) { 45 note.rp(9);} else if ( abcPitchClassName.equals("F") ) { 46 note.rp(3);} else if ( abcPitchClassName.equals("F,") ) { 47 note.lp(6);} else if ( abcPitchClassName.equals("f") ) { 48 note.rp(10);} else if ( abcPitchClassName.equals("G") ) { 49 note.rp(4);} else if ( abcPitchClassName.equals("G,") ) { 50 note.lp(3);} else if ( abcPitchClassName.equals("g") ) { 51 note.rp(11);} else if ( abcPitchClassName.equals("A") ) { 52 note.rp(5);}else if ( abcPitchClassName.equals("A,") ) { 53 note.lp(2);} else if ( abcPitchClassName.equals("a") ) { 54 note.rp(12);} else if ( abcPitchClassName.equals("B") ) { 55 note.rp(5);} else if ( abcPitchClassName.equals("B,") ) { 56 note.lp(1);} else if ( abcPitchClassName.equals("b") ) { 57 note.rp(13);} return note; 58 } 59 private Color getPitchClassColor(String letter) { 60 if ( letter.equals("C") ) { 61 return new Color(127,0,127); 62 } else if ( letter.equals("D") ) { 63 return new Color(255,255,0); 64 } else if ( letter.equals("E") ) { 65 return new Color(255,0,0); 66 } else if ( letter.equals("F")) { 67 return new Color(255, 127, 0); 68 } else if ( letter.equals("G")) { 69 return new Color(0,255,255); 70 } else if ( letter.equals("A")){ 71 return new Color(0,0,255); 72 } else if ( letter.equals("B")) { 73 return new Color(0,255,0); 74 } 75 else { 76 return Color.BLACK; 77 } 78 } 79 80 public void play(String d) { 81 painter.setColor(color); 82 painter.paint(box); 83 painter.setColor(randomColor()); 84 painter.draw(box); 85 if ( d.equals("1") ) { 86 note.play(); 87 }else if (d.equals("2")){ 88 note.x2(); 89 note.play(); 90 note.s2(); 91 }else if (d.equals("1/2")) { 92 note.s2(); 93 note.play(); 94 note.x2(); 95 }else if (d.equals("3")) { 96 note.x3(); 97 note.play(); 98 note.s3(); 99 }else if (d.equals("1/3")) { 100 note.s3(); 101 note.play(); 102 note.x3(); 103 }else if (d.equals("2/3")) { 104 note.s3(); 105 note.x2(); 106 note.play(); 107 note.x3(); 108 note.s2(); 109 } 110 111 } 112 113 private static Color randomColor() { 114 int rv = (int)(Math.random()*256); 115 int gv = (int)(Math.random()*256); 116 int bv = (int)(Math.random()*256); 117 return new Color(rv,gv,bv); 118 } 119 }