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 chromesthesia1; 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 else if ( abcPitchClassName.equals("C,") ) { 49 note.lp(7); 50 } 51 else if ( abcPitchClassName.equals("c") ) { 52 note.rp(7); 53 } 54 else if ( abcPitchClassName.equals("D") ) { 55 note.rp(1); 56 } 57 else if ( abcPitchClassName.equals("D,") ) { 58 note.lp(6); 59 } 60 else if ( abcPitchClassName.equals("d")) { 61 note.rp(8); 62 } 63 else if ( abcPitchClassName.equals("E")) { 64 note.rp(2); 65 } 66 else if ( abcPitchClassName.equals("E,")) { 67 note.lp(5); 68 } 69 else if ( abcPitchClassName.equals("e")) { 70 note.rp(9); 71 } 72 73 // Notes F F, and f 74 else if ( abcPitchClassName.equals("F")){ 75 note.rp(2); 76 } 77 else if ( abcPitchClassName.equals("F,")) { 78 note.lp(5); 79 } 80 else if ( abcPitchClassName.equals("f")) { 81 note.rp(10); 82 } 83 84 // Notes G, G, and g 85 else if ( abcPitchClassName.equals("G")){ 86 note.rp(4); 87 } 88 else if ( abcPitchClassName.equals("G,")) { 89 note.lp(6); 90 } 91 else if ( abcPitchClassName.equals("g")) { 92 note.rp(7); 93 } 94 95 // Notes A, A, and a 96 else if ( abcPitchClassName.equals("A")){ 97 note.rp(4); 98 } 99 else if ( abcPitchClassName.equals("A,")) { 100 note.lp(3); 101 } 102 else if ( abcPitchClassName.equals("a")) { 103 note.rp(7); 104 } 105 106 // Notes B, B, and b 107 else if ( abcPitchClassName.equals("B")){ 108 note.rp(5); 109 } 110 else if ( abcPitchClassName.equals("B,")) { 111 note.lp(4); 112 } 113 else if ( abcPitchClassName.equals("b")) { 114 note.rp(6); 115 } 116 117 return note; 118 } 119 120 private Color getPitchClassColor(String letter) { 121 if ( letter.equals("C") ) { 122 return Color.blue; 123 } 124 else if ( letter.equals("D")) { 125 return Color.green; 126 } 127 else if (letter.equals("F") || letter.equals("F,") || letter.equals("f")) { 128 return new Color(200, 60,5); 129 } 130 else if (letter.equals("G") || letter.equals("G,") || letter.equals("g")) { 131 return new Color(105, 147, 211); 132 } 133 else if (letter.equals("A") || letter.equals("A,") || letter.equals("a")) { 134 return new Color(59, 211, 44); 135 } 136 else if (letter.equals("B") || letter.equals("B,") || letter.equals("b")) { 137 return new Color(211, 0, 163); 138 } 139 else if ( letter.equals("E")) { 140 return new Color(127, 0,127); 141 } 142 else { 143 return Color.black; 144 } 145 } 146 147 public void play(String d) { 148 painter.setColor(color); 149 painter.paint(box); 150 painter.setColor(randomColor()); 151 painter.draw(box); 152 if ( d.equals("1")) { 153 note.play(); 154 } 155 } 156 157 private static Color randomColor() { 158 int rv = (int)(Math.random()*256); 159 int gv = (int)(Math.random()*256); 160 int bv = (int)(Math.random()*256); 161 return new Color(rv, gv, bv); 162 } 163 164 } 165 // END Pitch2