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