1 package chromesthesia1; 2 3 import java.awt.Color; 4 import note.SNote; 5 import painter.SPainter; 6 import shapes.SRectangle; 7 8 public class Pitchv1 { 9 private String abcName; 10 private SPainter painter; 11 private SRectangle box; 12 private SNote note; 13 private Color color; 14 public Pitchv1(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 } else if ( abcPitchClassName.equals("F") ) { 47 note.rp(3); 48 } else if ( abcPitchClassName.equals("F,") ) { 49 note.lp(4); 50 } else if ( abcPitchClassName.equals("f") ) { 51 note.rp(10); 52 } else if ( abcPitchClassName.equals("G") ) { 53 note.rp(4); 54 } else if ( abcPitchClassName.equals("G,") ) { 55 note.lp(3); 56 } else if ( abcPitchClassName.equals("g") ) { 57 note.rp(11); 58 } else if ( abcPitchClassName.equals("A") ) { 59 note.rp(5); 60 } else if ( abcPitchClassName.equals("A,") ) { 61 note.lp(2); 62 } else if ( abcPitchClassName.equals("a") ) { 63 note.rp(12); 64 } else if ( abcPitchClassName.equals("B") ) { 65 note.rp(6); 66 } else if ( abcPitchClassName.equals("B,") ) { 67 note.lp(1); 68 } else if ( abcPitchClassName.equals("b") ) { 69 note.rp(13); 70 } 71 return note; 72 } 73 private Color getPitchClassColor(String letter) { 74 if ( letter.equals("C") ) { 75 return Color.BLUE; 76 } else if ( letter.equals("D") ) { 77 return Color.GREEN; 78 } else if ( letter.equals("E") ) { 79 return new Color(127,0,127); 80 } else if ( letter.equals("F") ) { 81 return new Color(127,127,0); 82 } else if ( letter.equals("G") ) { 83 return new Color(0,127,127); 84 } else if ( letter.equals("A") ) { 85 return new Color(127,127,127); 86 } else if ( letter.equals("B") ) { 87 return Color.RED; 88 } else { 89 return Color.BLACK; 90 } 91 } 92 public void play(String d) { 93 painter.setColor(color); 94 painter.paint(box); 95 painter.setColor(randomColor()); 96 painter.draw(box); 97 if ( d.equals("1") ) { 98 note.play(); 99 } 100 } 101 private static Color randomColor() { 102 int rv = (int)(Math.random()*256); 103 int gv = (int)(Math.random()*256); 104 int bv = (int)(Math.random()*256); 105 return new Color(rv,gv,bv); 106 } 107 }