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 133 9 * ABC notation pitch name 10 * - SRectangle box | an SRectangle object that will chromesthetically 11 * represent the pitch 12 * - Color color | the color associated with the pitch for the presumed 13 * chromesthete 14 */ 15 package chromesthesia2; 16 17 import note.SNote; 18 import painter.SPainter; 19 import shapes.SRectangle; 20 21 import java.awt.*; 22 23 public class Pitch { 24 // INSTANCE VARIABLES 25 private String abcName; 26 private SPainter painter; 27 private SRectangle box; 28 private SNote note; 29 private Color color; 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 public String toString() { 38 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 39 } 40 public String abcName() { 41 return abcName; 42 } 43 private SNote createNoteForThisPitch(String abcPitchClassName) { 44 SNote note = new SNote(); 45 if ( abcPitchClassName.equals("C") ) { 46 // nothing to do 47 } else if ( abcPitchClassName.equals("C,") ) { 48 note.lp(7); 49 } else if ( abcPitchClassName.equals("c") ) { 50 note.rp(7); 51 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 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 66 } else if ( abcPitchClassName.equals("F") ) { 67 note.rp(3); 68 } else if ( abcPitchClassName.equals("F,") ) { 69 note.lp(4); 70 } else if ( abcPitchClassName.equals("f") ) { 71 note.rp(10); 72 73 } else if ( abcPitchClassName.equals("G") ) { 74 note.rp(4); 75 } else if ( abcPitchClassName.equals("G,") ) { 76 note.lp(3); 77 } else if ( abcPitchClassName.equals("g") ) { 78 note.rp(11); 79 80 } else if ( abcPitchClassName.equals("A") ) { 81 note.rp(5); 82 } else if ( abcPitchClassName.equals("A,") ) { 83 note.lp(2); 84 } else if ( abcPitchClassName.equals("a") ) { 85 note.rp(12); 86 87 } else if ( abcPitchClassName.equals("B") ) { 88 note.rp(6); 89 } else if ( abcPitchClassName.equals("B,") ) { 90 note.lp(1); 91 } else if ( abcPitchClassName.equals("b") ) { 92 note.rp(13); 93 } 94 95 return note; 96 } 97 private Color getPitchClassColor(String letter) { 98 if ( letter.equals("C") ) { 99 return new Color(127,0,127); 100 } else if ( letter.equals("D") ) { 101 return new Color(255,255,0); 102 } else if ( letter.equals("E") ) { 103 return new Color(255,0,0); 104 } else if ( letter.equals("F") ) { 105 return new Color(255,127,0); 106 } else if ( letter.equals("G") ) { 107 return new Color(0,255,255); 108 } else if ( letter.equals("A") ) { 109 return new Color(0,0,255); 110 } else if ( letter.equals("B") ) { 111 return new Color(0,255,0); 112 } else { 113 return Color.BLACK; 114 } 115 } 116 117 public void play(String d) { 118 painter.setColor(color); 119 painter.paint(box); 120 painter.setColor(randomColor()); 121 painter.draw(box); 122 if ( d.equals("1") ) { 123 note.play(); 124 } else if ( d.equals("2") ) { 125 note.x2(); 126 note.play(); 127 note.s2(); 128 } else if ( d.equals("1/2") ) { 129 note.s2(); 130 note.play(); 131 note.x2(); 132 } else if ( d.equals("1/3") ) { 133 note.s3(); 134 note.play(); 135 note.x3(); 136 } else if ( d.equals("3") ) { 137 note.x3(); 138 note.play(); 139 note.s3(); 140 } 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 }