1 package chromesthesia0; 2 3 import java.awt.Color; 4 import note.SNote; 5 import painter.SPainter; 6 import shapes.SRectangle; 7 8 public class Pitchv0 { 9 private String abcName; 10 private SPainter painter; 11 private SRectangle box; 12 private SNote note; 13 private Color color; 14 public Pitchv0(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 } else if ( abcPitchClassName.equals("C,") ) { 31 note.lp(7); 32 } else if ( abcPitchClassName.equals("c") ) { 33 note.rp(7); 34 } else if ( abcPitchClassName.equals("D") ) { 35 note.rp(1); 36 } else if ( abcPitchClassName.equals("D,") ) { 37 note.lp(6); 38 } else if ( abcPitchClassName.equals("d") ) { 39 note.rp(8); 40 } else if ( abcPitchClassName.equals("E") ) { 41 note.rp(2); 42 } else if ( abcPitchClassName.equals("E,") ) { 43 note.lp(5); 44 } else if ( abcPitchClassName.equals("e") ) { 45 note.rp(9); 46 } 47 return note; 48 } 49 private Color getPitchClassColor(String letter) { 50 if ( letter.equals("C") ) { 51 return Color.BLUE; 52 } else if ( letter.equals("D") ) { 53 return Color.GREEN; 54 } else if ( letter.equals("E") ) { 55 return new Color(127,0,127); 56 } else { 57 return Color.BLACK; 58 } 59 } 60 public void play(String d) { 61 painter.setColor(color); 62 painter.paint(box); 63 painter.setColor(randomColor()); 64 painter.draw(box); 65 if ( d.equals("1") ) { 66 note.play(); 67 } 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 }