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