1 /* 2 * The pitch class models the pitch of a note in a manner that will 3 * facilitate the chromesthetic processing of the pitch. 4 * A Pitch object will have: 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 ABC notation pitch name 8 * + SRectangle box | an SRectangle object the will chromesthetically represent the pitch 9 * + Color color | the color associated with the pitch for the presumed chromesthete 10 */ 11 12 package chromesthesia0; 13 14 import java.awt.Color; 15 import note.SNote; 16 import painter.SPainter; 17 import shapes.SRectangle; 18 19 public class Pitch { 20 21 //INSTANCE VARIABLES 22 private String abcName; 23 private SPainter painter; 24 private SRectangle box; 25 private SNote note; 26 private Color color; 27 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 36 public String toString() { 37 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 38 } 39 40 public String abcName() { 41 return abcName; 42 } 43 44 private SNote createNoteForThisPitch(String abcPitchClassName) { 45 SNote note = new SNote(); 46 if (abcPitchClassName.equals("C")) { 47 //NOTHING TO DO... 48 } else if (abcPitchClassName.equals("C,")) { 49 note.lp(7); 50 } else if (abcPitchClassName.equals("c")) { 51 note.rp(7); 52 } else if (abcPitchClassName.equals("D")) { 53 note.rp(1); 54 } else if (abcPitchClassName.equals("D,")) { 55 note.lp(6); 56 } else if (abcPitchClassName.equals("d")) { 57 note.rp(8); 58 } else if (abcPitchClassName.equals("E")) { 59 note.rp(2); 60 } else if (abcPitchClassName.equals("E,")) { 61 note.lp(5); 62 } else if (abcPitchClassName.equals("e")){ 63 note.rp(9); 64 } 65 return note; 66 } 67 68 private Color getPitchClassColor(String letter) { 69 if (letter.equals("C")) { 70 return Color.BLUE; 71 } else if (letter.equals("D")) { 72 return Color.GREEN; 73 } else if (letter.equals("E")) { 74 return new Color (127, 0, 127); 75 } else { 76 return Color.BLACK; 77 } 78 } 79 80 public void play(String d) { 81 painter.setColor(color); 82 painter.paint(box); 83 painter.setColor(randomColor()); 84 painter.draw(box); 85 if (d.equals("1")) { 86 note.play(); 87 } 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 }