1 package chromesthesia2; 2 3 /* 4 * The Pitch class models the pitch of a note in a manner that will facilitate 5 * the chromesthetic processing of the pitch. A Pitch object will have five 6 * properties: 7 * -String name | ABC notation pitch name 8 * -SPainter painter | the painting agent 9 * -Note note | a note that will be set to the pitch corresponding to the 10 * ABC notation pitch name 11 * -SRectangle box | an SRectangle object that will chromesthetically 12 * represent the pitch 13 * -Color color | the color associated with thte pitch for the presumed 14 * chromesthete 15 */ 16 17 import java.awt.Color; 18 import note.SNote; 19 import painter.SPainter; 20 import shapes.SRectangle; 21 22 public class Pitch { 23 24 // INSTANCE VARIABLES 25 private String abcName; 26 private SPainter painter; 27 private SRectangle box; 28 private SNote note; 29 private Color color; 30 31 public Pitch(String abcName, SPainter painter) 32 { 33 this.abcName = abcName; 34 this.painter = painter; 35 this.box = new SRectangle(painter.painterHeight-50, painter.painterWidth-50); 36 this.note = createNoteForThisPitch(abcName); 37 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 38 } 39 40 public String toString(){ 41 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 42 } 43 44 private SNote createNoteForThisPitch(String abcPitchClassName) 45 { 46 SNote note = new SNote(); 47 if (abcPitchClassName.equals("C")){ 48 // nothing to do 49 } 50 else if (abcPitchClassName.equals("C,")){ 51 note.lp(7); 52 } 53 else if (abcPitchClassName.equals("c")){ 54 note.rp(7); 55 } 56 else if (abcPitchClassName.equals("D")){ 57 note.rp(1); 58 } 59 else if (abcPitchClassName.equals("D,")){ 60 note.lp(6); 61 } 62 else if (abcPitchClassName.equals("d")){ 63 note.rp(8); 64 } 65 else if (abcPitchClassName.equals("E")){ 66 note.rp(2); 67 } 68 else if (abcPitchClassName.equals("E,")){ 69 note.lp(5); 70 } 71 else if (abcPitchClassName.equals("e")){ 72 note.rp(9); 73 } 74 else if(abcPitchClassName.equals("F")) 75 { 76 note.rp(3); 77 } 78 else if(abcPitchClassName.equals("F,")) 79 { 80 note.lp(4); 81 } 82 else if(abcPitchClassName.equals("f")) 83 { 84 note.rp(10); 85 } 86 else if(abcPitchClassName.equals("G")) 87 { 88 note.rp(4); 89 } 90 else if(abcPitchClassName.equals("G,")) 91 { 92 note.lp(3); 93 } 94 else if(abcPitchClassName.equals("g")) 95 { 96 note.rp(11); 97 } 98 else if(abcPitchClassName.equals("A")) 99 { 100 note.rp(5); 101 } 102 else if(abcPitchClassName.equals("A,")) 103 { 104 note.lp(2); 105 } 106 else if(abcPitchClassName.equals("a")) 107 { 108 note.rp(12); 109 } 110 else if(abcPitchClassName.equals("B")) 111 { 112 note.rp(6); 113 } 114 else if(abcPitchClassName.equals("B,")) 115 { 116 note.lp(1); 117 } 118 else if(abcPitchClassName.equals("b")) 119 { 120 note.rp(13); 121 } 122 return note; 123 } 124 125 private Color getPitchClassColor(String letter) 126 { 127 if (letter.equals("C")) 128 { 129 return new Color(127,0,127); 130 } 131 else if (letter.equals("D")) 132 { 133 return new Color(255,255,0); 134 } 135 else if (letter.equals("E")) 136 { 137 return new Color(255, 0, 0); 138 } 139 else if(letter.equals("F")){ 140 return new Color(255,127,0); 141 } 142 else if(letter.equals("G")){ 143 return new Color(0,255,255); 144 } 145 else if(letter.equals("A")) 146 { 147 return new Color(0,0,255); 148 } 149 else if(letter.equals("B")) 150 { 151 return new Color(0,255,0); 152 } 153 else 154 { 155 return color.BLACK; 156 } 157 } 158 159 public void play(String d) 160 { 161 painter.setColor(color); 162 painter.paint(box); 163 painter.setColor(randomColor()); 164 painter.draw(box); 165 if(d.equals("1")) 166 { 167 note.play(); 168 } 169 else if (d.equals("2")) 170 { 171 note.x2(); note.play(); note.s2(); 172 } 173 else if(d.equals("3")) 174 { 175 note.x3(); note.play(); note.s3(); 176 } 177 else if(d.equals("1/3")) 178 { 179 note.s3(); note.play(); note.x3(); 180 } 181 else if (d.equals("1/2")) 182 { 183 note.s2(); note.play(); note.x2(); 184 } 185 else if (d.equals("2/3")) 186 { 187 note.x2(); note.s3(); note.play(); note.x3(); note.s2(); 188 } 189 190 } 191 192 private static Color randomColor() 193 { 194 int rv = (int)(Math.random()*256); 195 int gv = (int)(Math.random()*256); 196 int bv = (int)(Math.random()*256); 197 return new Color(rv,gv,bv); 198 } 199 200 public String abcName() { 201 return abcName; 202 } 203 } 204