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