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 chromesthesia0; 16 import java.awt.Color; 17 import note.SNote; 18 import painter.SPainter; 19 import shapes.SRectangle; 20 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 public Pitch(String abcName, SPainter painter) { 29 this.abcName = abcName; 30 this.painter = painter; 31 this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50); 32 this.note = createNoteForThisPitch(abcName); 33 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 34 } 35 public String toString() { 36 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 37 } 38 public String abcName() { 39 return abcName; 40 } 41 private SNote createNoteForThisPitch(String abcPitchClassName) { 42 SNote note = new SNote(); 43 if ( abcPitchClassName.equals("C") ) { 44 // nothing to do 45 } else if ( abcPitchClassName.equals("C,") ) { 46 note.lp(7); 47 } else if ( abcPitchClassName.equals("c") ) { 48 note.rp(7); 49 } else if ( abcPitchClassName.equals("D") ) { 50 note.rp(1); 51 } else if ( abcPitchClassName.equals("D,") ) { 52 note.lp(6); 53 } else if ( abcPitchClassName.equals("d") ) { 54 note.rp(8); 55 } else if ( abcPitchClassName.equals("E") ) { 56 note.rp(2); 57 } else if ( abcPitchClassName.equals("E,") ) { 58 note.lp(5); 59 } else if ( abcPitchClassName.equals("e") ) { 60 note.rp(9); 61 } 62 return note; 63 } 64 private Color getPitchClassColor(String letter) { 65 if ( letter.equals("C") ) { 66 return Color.BLUE; 67 } else if ( letter.equals("D") ) { 68 return Color.GREEN; 69 } else if ( letter.equals("E") ) { 70 return new Color(127,0,127); 71 } else { 72 return Color.BLACK; 73 } 74 } 75 public void play(String d) { 76 painter.setColor(color); 77 painter.paint(box); 78 painter.setColor(randomColor()); 79 painter.draw(box); 80 if ( d.equals("1") ) { 81 note.play(); 82 } 83 } 84 private static Color randomColor() { 85 int rv = (int)(Math.random()*256); 86 int gv = (int)(Math.random()*256); 87 int bv = (int)(Math.random()*256); 88 return new Color(rv,gv,bv); 89 } 90 }