1 2 /* 3 * The Pitch class models the pitch of a note in a manner that will facilitate 4 * the chromesthetic processing of the pitch. A Pitch object will have five 5 * properties: 6 * - String name | ABC notation pitch name 7 * - SPainter painter | the painting agent 8 * - Note note | a note that will be set to the pitch corresponding to the 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 16 package chromesthesia0; 17 18 19 import java.awt.Color; 20 import note.SNote; 21 import painter.SPainter; 22 import shapes.SRectangle; 23 24 public class Pitch { 25 26 //instance variables 27 28 private String abcName; 29 private SPainter painter; 30 private SRectangle box; 31 private SNote note; 32 private Color color; 33 34 public Pitch(String abcName, SPainter painter){ 35 this.abcName = abcName; 36 this.painter = painter; 37 this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50); 38 this.note = createNoteForThisPitch(abcName); 39 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 40 } 41 42 public String toString(){ 43 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 44 } 45 46 public String abcName(){ 47 return abcName; 48 } 49 50 private SNote createNoteForThisPitch(String abcPitchClassName){ 51 SNote note = new SNote(); 52 if( abcPitchClassName.equals("C") ) { 53 // nothing to do 54 } else if ( abcPitchClassName.equals("C,") ) { 55 note.lp(7); 56 } else if ( abcPitchClassName.equals("c") ) { 57 note.rp(7); 58 } else if ( abcPitchClassName.equals("D") ) { 59 note.rp(1); 60 } else if ( abcPitchClassName.equals("D,") ) { 61 note.lp(6); 62 } else if ( abcPitchClassName.equals("d") ) { 63 note.rp(8); 64 } else if ( abcPitchClassName.equals("E") ) { 65 note.rp(2); 66 } else if ( abcPitchClassName.equals("E,") ) { 67 note.lp(5); 68 } else if ( abcPitchClassName.equals("e") ) { 69 note.rp(9); 70 } 71 return note; 72 } 73 private Color getPitchClassColor(String letter) { 74 if ( letter.equals("C") ) { 75 return Color.BLUE; 76 } else if ( letter.equals("D") ) { 77 return Color.GREEN; 78 } else if ( letter.equals("E") ) { 79 return new Color(127,0,127); 80 } else { 81 return Color.BLACK; 82 } 83 } 84 public void play(String d) { 85 painter.setColor(color); 86 painter.paint(box); 87 painter.setColor(randomColor()); 88 painter.draw(box); 89 if ( d.equals("1") ) { 90 note.play(); 91 } } 92 private static Color randomColor() { 93 int rv = (int)(Math.random()*256); 94 int gv = (int)(Math.random()*256); 95 int bv = (int)(Math.random()*256); 96 return new Color(rv,gv,bv); 97 } 98 } 99 100 101