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