1 /* 2 * The pitch class models the pitch of a note in a manner that will facilitate the Chromesthetic processing of the pitch. A pitch object will have five properties: 3 * -String name | ABC notation pitch name 4 * - SPainter painter | the painting agent 5 * - Note note | a note that will be set to the pitch corresponding to the ABC notation pitch name 6 * -SRectangle box | an SRectangle object that will chromesthetically represent the pitch 7 * -Color color | the color associated with the pitch for the presumed chromesthete. 8 * */ 9 10 package chromesthesia2; 11 12 import note.SNote; 13 import painter.SPainter; 14 import shapes.SRectangle; 15 16 import java.awt.*; 17 18 public class Pitch { 19 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 } 48 // Notes A, A, and a 49 else if ( abcPitchClassName.equals("A")){ 50 note.rp(5); 51 } 52 else if ( abcPitchClassName.equals("A,")) { 53 note.lp(1); 54 } 55 else if ( abcPitchClassName.equals("a")) { 56 note.rp(1); 57 } 58 59 // Notes B, B, and b 60 else if ( abcPitchClassName.equals("B")){ 61 note.rp(6); 62 } 63 else if ( abcPitchClassName.equals("B,")) { 64 note.lp(2); 65 } 66 else if ( abcPitchClassName.equals("b")) { 67 note.rp(2); 68 } 69 70 71 else if ( abcPitchClassName.equals("C,") ) { 72 note.lp(3); 73 } 74 else if ( abcPitchClassName.equals("c") ) { 75 note.rp(3); 76 } 77 78 else if ( abcPitchClassName.equals("D") ) { 79 note.rp(1); 80 } 81 else if ( abcPitchClassName.equals("D,") ) { 82 note.lp(4); 83 } 84 else if ( abcPitchClassName.equals("d")) { 85 note.rp(4); 86 } 87 88 else if ( abcPitchClassName.equals("E")) { 89 note.rp(2); 90 } 91 else if ( abcPitchClassName.equals("E,")) { 92 note.lp(5); 93 } 94 else if ( abcPitchClassName.equals("e")) { 95 note.rp(5); 96 } 97 98 // Notes F F, and f 99 else if ( abcPitchClassName.equals("F")){ 100 note.rp(3); 101 } 102 else if ( abcPitchClassName.equals("F,")) { 103 note.lp(6); 104 } 105 else if ( abcPitchClassName.equals("f")) { 106 note.rp(6); 107 } 108 109 // Notes G, G, and g 110 else if ( abcPitchClassName.equals("G")){ 111 note.rp(4); 112 } 113 else if ( abcPitchClassName.equals("G,")) { 114 note.lp(7); 115 } 116 else if ( abcPitchClassName.equals("g")) { 117 note.rp(7); 118 } 119 120 return note; 121 } 122 123 private Color getPitchClassColor(String letter) { 124 if ( letter.equals("A") ) { 125 return new Color(0, 0,255); 126 } 127 else if ( letter.equals("B")) { 128 return new Color(0, 255,0); 129 } 130 else if (letter.equals("C") || letter.equals("C,") || letter.equals("c")) { 131 return new Color(127, 0,127); 132 } 133 else if (letter.equals("D") || letter.equals("D,") || letter.equals("d")) { 134 return new Color(255, 255, 0); 135 } 136 else if (letter.equals("E") || letter.equals("E,") || letter.equals("e")) { 137 return new Color(255, 0, 0); 138 } 139 else if (letter.equals("F") || letter.equals("F,") || letter.equals("f")) { 140 return new Color(255, 127, 0); 141 } 142 else if ( letter.equals("G") || letter.equals("G,") || letter.equals("g")) { 143 return new Color(0, 255,255); 144 } 145 else { 146 return Color.black; 147 } 148 } 149 150 public void play(String d) { 151 painter.setColor(color); 152 painter.paint(box); 153 painter.setColor(randomColor()); 154 painter.draw(box); 155 if ( d.equals("1")) { 156 note.play(); 157 } 158 else if (d.equals("2")) { 159 note.x2(); 160 note.play(); 161 note.s2(); 162 } 163 else if (d.equals("1/2")) { 164 note.s2(); 165 note.play(); 166 note.x2(); 167 } 168 else if (d.equals("3")) { 169 note.x3(); 170 note.play(); 171 note.s3(); 172 } 173 else if (d.equals("1/3")) { 174 note.s3(); 175 note.play(); 176 note.x3(); 177 } 178 else if (d.equals("2/3")) { 179 note.s5(); 180 note.play(); 181 note.x5(); 182 } 183 } 184 185 private static Color randomColor() { 186 int rv = (int)(Math.random()*256); 187 int gv = (int)(Math.random()*256); 188 int bv = (int)(Math.random()*256); 189 return new Color(rv, gv, bv); 190 } 191 192 } 193 // END Pitch2