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