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