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