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 note.SNote; 17 import painter.SPainter; 18 import shapes.SRectangle; 19 20 import java.awt.*; 21 public class Pitch { 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 abdName, SPainter painter) { 30 this.abcName = abdName; 31 this.painter = painter; 32 this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50); 33 this.note = createNoteForThisPitch(abdName); 34 this.color = getPitchClassColor(abdName.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 //ADDED NOTES 66 } else if (abcPitchClassName.equals("F")) { 67 note.rp(1); 68 } else if (abcPitchClassName.equals("F,")) { 69 note.lp(6); 70 } else if (abcPitchClassName.equals("f")) { 71 note.rp(3); 72 } else if (abcPitchClassName.equals("G")) { 73 note.rp(6); 74 } else if (abcPitchClassName.equals("G,")) { 75 note.lp(2); 76 } else if (abcPitchClassName.equals("g")) { 77 note.rp(7); 78 } else if (abcPitchClassName.equals("A")) { 79 note.rp(4); 80 } else if (abcPitchClassName.equals("A,")) { 81 note.lp(7); 82 } else if (abcPitchClassName.equals("a")) { 83 note.rp(2); 84 } else if (abcPitchClassName.equals("B")) { 85 note.rp(5); 86 } else if (abcPitchClassName.equals("B,")) { 87 note.lp(7); 88 } else if (abcPitchClassName.equals("b")) { 89 note.rp(2); 90 } 91 return note; 92 } 93 private Color getPitchClassColor (String letter){ 94 if (letter.equals("C")) { 95 return new Color(255, 255, 0); 96 } else if (letter.equals("D")) { 97 return new Color(255, 0, 255); 98 } else if (letter.equals("E")) { 99 return new Color(0, 255, 255); 100 } else if (letter.equals("F")) { 101 return new Color(255, 0, 0); 102 } else if (letter.equals("G")) { 103 return new Color(0, 255, 0); 104 } else if (letter.equals("A")) { 105 return new Color(0, 0, 255); 106 } else if (letter.equals("B")) { 107 return new Color(69, 69, 69); 108 } else { 109 return Color.BLACK; 110 } 111 } 112 public void play (String d){ 113 painter.setColor(color); 114 painter.paint(box); 115 painter.setColor(randomColor()); 116 painter.draw(box); 117 if (d.equals("1")) { 118 note.play(); 119 } else if (d.equals("2")) { 120 note.x2(); 121 note.play(); 122 note.s2(); 123 } else if (d.equals("1/2")) { 124 note.s2(); 125 note.play(); 126 note.x2(); 127 } else if (d.equals("3")) { 128 note.x3(); 129 note.play(); 130 note.s3(); 131 //FIX THE LENGTHS AT WHICH THESE NOTES WILL PLAY 132 } else if (d.equals("1/3")) { 133 note.s3(); 134 note.play(); 135 note.x3(); 136 } else if (d.equals("2/3")) { 137 note.s3(); 138 note.play(); 139 note.play(); 140 note.x3(); 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