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