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