1 /* 2 * The pitch class models the pitch of a note in a manner that will facilitate 3 * the chromesthetic processing of the pitch. 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 to the ABC notation pitch name 7 * - SRectangle box | 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 note.SNote; 14 import painter.SPainter; 15 import shapes.SRectangle; 16 17 import java.awt.*; 18 19 public class Pitch { 20 //INSTANCE VARIABLES 21 private String abcName; 22 private SPainter painter; 23 private SRectangle box; 24 private SNote note; 25 private Color color; 26 27 public Pitch(String abcName, SPainter painter) { 28 this.abcName = abcName; 29 this.painter = painter; 30 this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50); 31 this.note = createNoteForThisPitch(abcName); 32 this.color = getPitchClassColor(abcName.substring(0, 1).toUpperCase()); 33 } 34 35 public String toString() { 36 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 37 } 38 39 public String abcName() { 40 return abcName; 41 } 42 43 private SNote createNoteForThisPitch(String abcPitchClassName) { 44 SNote note = new SNote(); 45 if (abcPitchClassName.equals("C")) { 46 //nothing to do 47 } else if (abcPitchClassName.equals("C,")) { 48 note.lp(7); 49 } else if (abcPitchClassName.equals("c")) { 50 note.rp(7); 51 } else if (abcPitchClassName.equals("D")) { 52 note.rp(1); 53 } else if (abcPitchClassName.equals("D,")) { 54 note.lp(6); 55 } else if (abcPitchClassName.equals("d")) { 56 note.rp(8); 57 } else if (abcPitchClassName.equals("E")) { 58 note.rp(2); 59 } else if (abcPitchClassName.equals("E,")) { 60 note.lp(5); 61 } else if (abcPitchClassName.equals("e")) { 62 note.rp(9); 63 } else if (abcPitchClassName.equals("F")) { 64 note.rp(3); 65 } else if (abcPitchClassName.equals("F,")) { 66 note.lp(4); 67 } else if (abcPitchClassName.equals("f")) { 68 note.rp(10); 69 } else if (abcPitchClassName.equals("G")) { 70 note.rp(4); 71 } else if (abcPitchClassName.equals("G,")) { 72 note.lp(3); 73 } else if (abcPitchClassName.equals("g")) { 74 note.rp(11); 75 } else if (abcPitchClassName.equals("A")) { 76 note.lp(2); 77 } else if (abcPitchClassName.equals("A,")) { 78 note.lp(9); 79 } else if (abcPitchClassName.equals("a")) { 80 note.rp(5); 81 } else if (abcPitchClassName.equals("B")) { 82 note.lp(1); 83 } else if (abcPitchClassName.equals("B,")) { 84 note.lp(8); 85 } else if (abcPitchClassName.equals("b")) { 86 note.rp(6); 87 } 88 return note; 89 } 90 91 private Color getPitchClassColor(String letter) { 92 if (letter.equals("C")) { 93 return new Color(127, 0, 127); 94 } else if (letter.equals("D")) { 95 return new Color(255, 255, 0); 96 } else if (letter.equals("E")) { 97 return new Color(255, 0, 0); 98 } else if (letter.equals("F")) { 99 return new Color(255, 127, 0); 100 } else if (letter.equals("G")) { 101 return new Color(0, 255, 255); 102 } else if (letter.equals("A")) { 103 return new Color(0, 0, 255); 104 } else if (letter.equals("B")) { 105 return new Color(0, 255, 0); 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 } 150