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