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