package chromesthesia1; import java.awt.Color; import note.SNote; import painter.SPainter; import shapes.SRectangle; public class Pitch { //INSTANCE VARIABLES private String abcName; private SPainter painter; private SRectangle box; private SNote note; private Color color; public Pitch(String abdName, SPainter painter) { this.abcName = abdName; this.painter = painter; this.box = new SRectangle(painter.painterHeight-50, painter.painterWidth-50); this.note = createNoteForThisPitch(abdName); this.color = getPitchClassColor(abdName.substring(0,1).toUpperCase()); } public String toString() { return "[" + abcName + "|" + note.degree() + "|" + color + "]"; } public String abcName() { return abcName; } private SNote createNoteForThisPitch(String abcPitchClassName) { SNote note = new SNote(); if( abcPitchClassName.equals("C")) { //nothing to do }else if (abcPitchClassName.equals("C,")) { note.lp(7); }else if (abcPitchClassName.equals("c")) { note.rp(7); }else if (abcPitchClassName.equals("D")) { note.rp(1); }else if (abcPitchClassName.equals("D,")) { note.lp(6); }else if (abcPitchClassName.equals("d")) { note.rp(8); }else if (abcPitchClassName.equals("E")) { note.rp(2); }else if (abcPitchClassName.equals("E,")) { note.lp(5); }else if (abcPitchClassName.equals("e")) { note.rp(9); //ADDED NOTES }else if ( abcPitchClassName.equals("F")) { note.rp(); }else if (abcPitchClassName.equals("F,")) { note.lp(); }else if (abcPitchClassName.equals("f")) { note.rp(); }else if (abcPitchClassName.equals("G")) { note.rp(); }else if (abcPitchClassName.equals("G,")) { note.lp(); }else if (abcPitchClassName.equals("g")) { note.rp(); }else if (abcPitchClassName.equals("A")) { note.rp(); }else if (abcPitchClassName.equals("A,")) { note.lp(); }else if (abcPitchClassName.equals("a")) { note.rp(); }else if (abcPitchClassName.equals("B")) { note.rp(); }else if (abcPitchClassName.equals("B,")) { note.lp(); }else if (abcPitchClassName.equals("b")) { note.rp(); } return note; } private Color getPitchClassColor (String letter) { if( letter.equals("C")) { return Color.BLUE; }else if (letter.equals("D")){ return Color.GREEN; }else if (letter.equals("E")) { return Color.MAGENTA; }else if (letter.equals("F")){ return Color.ORANGE; }else if (letter.equals("G")) { return Color.CYAN; }else if (letter.equals("A")){ return Color.YELLOW; }else if (letter.equals("B")) { return Color.RED; }else { return Color.BLACK; } } public void play(String d) { painter.setColor(color); painter.paint(box); painter.setColor(randomColor()); painter.draw(box); if (d.equals("1")) { note.play(); } } private static Color randomColor() { int rv = (int)(Math.random()*256); int gv = (int)(Math.random()*256); int bv = (int)(Math.random()*256); return new Color(rv,gv,bv); } }