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