1 package chromesthesia0; 2 3 import note.SNote; 4 import painter.SPainter; 5 import shapes.SRectangle; 6 7 import java.awt.*; 8 9 public class Pitch { 10 11 private String abcName; 12 private SPainter painter; 13 private SRectangle box; 14 private SNote note; 15 private Color color; 16 17 public Pitch(String abcName, SPainter painter) { 18 this.abcName = abcName; 19 this.painter = painter; 20 this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50); 21 this.note = createNoteForThisPitch(abcName); 22 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 23 } 24 25 public String toString() { 26 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 27 } 28 29 public String abcName() { return abcName; } 30 31 private SNote createNoteForThisPitch(String abcPitchClassName) { 32 SNote note = new SNote(); 33 if ( abcPitchClassName.equals("C")) { 34 // nothing to do 35 } else if ( abcPitchClassName.equals("C,")) { 36 note.lp(7); 37 } else if ( abcPitchClassName.equals("c")) { 38 note.rp(7); 39 } else if ( abcPitchClassName.equals("D")) { 40 note.rp(1); 41 } else if ( abcPitchClassName.equals("D,")) { 42 note.lp(6); 43 } else if ( abcPitchClassName.equals("d")) { 44 note.rp(8); 45 } else if ( abcPitchClassName.equals("E")) { 46 note.rp(2); 47 } else if ( abcPitchClassName.equals("E,")) { 48 note.lp(5); 49 } else if ( abcPitchClassName.equals("e")) { 50 note.rp(9); 51 } 52 return note; 53 } 54 55 private Color getPitchClassColor(String letter) { 56 if (letter.equals("C")) { 57 return Color.BLUE; 58 } else if (letter.equals("D")) { 59 return Color.GREEN; 60 } else if (letter.equals("E")) { 61 return new Color(127,0,127); 62 } else { 63 return Color.BLACK; 64 } 65 } 66 67 public void play(String d) { 68 painter.setColor(color); 69 painter.paint(box); 70 painter.setColor(randomColor()); 71 painter.draw(box); 72 if(d.equals("1")) { 73 note.play(); 74 } 75 } 76 77 private static Color randomColor() { 78 int rv = (int)(Math.random()*256); 79 int gv = (int)(Math.random()*256); 80 int bv = (int)(Math.random()*256); 81 return new Color(rv,gv,bv); 82 } 83 84 } 85