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 * ABD 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 12 * chromesthete 13 */ 14 15 package chromesthesia2; 16 import java.awt.Color; 17 import note.SNote; 18 import painter.SPainter; 19 import shapes.SRectangle; 20 public class Pitch { 21 //INSTANCE VARIABLES 22 private String abcName; 23 private SPainter painter; 24 private SRectangle box; 25 private SNote note; 26 private Color color; 27 28 public Pitch(String abdName, SPainter painter) { 29 this.abcName = abdName; 30 this.painter = painter; 31 this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50); 32 this.note = createNoteForThisPitch(abdName); 33 this.color = getPitchClassColor(abdName.substring(0, 1).toUpperCase()); 34 } 35 36 public String toString() { 37 return "[" + abcName + "|" + note.degree() + "|" + color + "]"; 38 } 39 40 public String abcName() { 41 return abcName; 42 } 43 44 private SNote createNoteForThisPitch(String abcPitchClassName) { 45 SNote note = new SNote(); 46 if (abcPitchClassName.equals("C")) { 47 //nothing to do 48 } else if (abcPitchClassName.equals("C,")) { 49 note.lp(7); 50 } else if (abcPitchClassName.equals("c")) { 51 note.rp(7); 52 } else if (abcPitchClassName.equals("D")) { 53 note.rp(1); 54 } else if (abcPitchClassName.equals("D,")) { 55 note.lp(6); 56 } else if (abcPitchClassName.equals("d")) { 57 note.rp(8); 58 } else if (abcPitchClassName.equals("E")) { 59 note.rp(2); 60 } else if (abcPitchClassName.equals("E,")) { 61 note.lp(5); 62 } else if (abcPitchClassName.equals("e")) { 63 note.rp(9); 64 //ADDED NOTES 65 } else if (abcPitchClassName.equals("F")) { 66 note.rp(1); 67 } else if (abcPitchClassName.equals("F,")) { 68 note.lp(6); 69 } else if (abcPitchClassName.equals("f")) { 70 note.rp(3); 71 } else if (abcPitchClassName.equals("G")) { 72 note.rp(6); 73 } else if (abcPitchClassName.equals("G,")) { 74 note.lp(2); 75 } else if (abcPitchClassName.equals("g")) { 76 note.rp(7); 77 } else if (abcPitchClassName.equals("A")) { 78 note.rp(4); 79 } else if (abcPitchClassName.equals("A,")) { 80 note.lp(7); 81 } else if (abcPitchClassName.equals("a")) { 82 note.rp(2); 83 } else if (abcPitchClassName.equals("B")) { 84 note.rp(5); 85 } else if (abcPitchClassName.equals("B,")) { 86 note.lp(7); 87 } else if (abcPitchClassName.equals("b")) { 88 note.rp(2); 89 } 90 return note; 91 } 92 private Color getPitchClassColor (String letter){ 93 if (letter.equals("C")) { 94 return new Color(255, 255, 0); 95 } else if (letter.equals("D")) { 96 return new Color(255, 0, 255); 97 } else if (letter.equals("E")) { 98 return new Color(0, 255, 255); 99 } else if (letter.equals("F")) { 100 return new Color(255, 0, 0); 101 } else if (letter.equals("G")) { 102 return new Color(0, 255, 0); 103 } else if (letter.equals("A")) { 104 return new Color(0, 0, 255); 105 } else if (letter.equals("B")) { 106 return new Color(69, 69, 69); 107 } else { 108 return Color.BLACK; 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 //FIX THE LENGTHS AT WHICH THESE NOTES WILL PLAY 131 } else if (d.equals("1/3")) { 132 note.s3(); 133 note.play(); 134 note.x3(); 135 } else if (d.equals("2/3")) { 136 note.s3(); 137 note.play(); 138 note.play(); 139 note.x3(); 140 } 141 } 142 private static Color randomColor () { 143 int rv = (int) (Math.random() * 256); 144 int gv = (int) (Math.random() * 256); 145 int bv = (int) (Math.random() * 256); 146 return new Color(rv, gv, bv); 147 } 148 }