1 package chromesthesia2; 2 3 import java.awt.Color; 4 import note.SNote; 5 import painter.SPainter; 6 import shapes.SRectangle; 7 8 public class Pitchv2 { 9 private String abcName; 10 private SPainter painter; 11 private SRectangle box; 12 private SNote note; 13 private Color color; 14 public Pitchv2(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 new Color(127,0,127); 76 } else if ( letter.equals("D") ) { 77 return new Color(255,255,0); 78 } else if ( letter.equals("E") ) { 79 return new Color(255,0,0); 80 } else if ( letter.equals("F") ) { 81 return new Color(255,127,0); 82 } else if ( letter.equals("G") ) { 83 return new Color(0,255,255); 84 } else if ( letter.equals("A") ) { 85 return new Color(0,0,255); 86 } else if ( letter.equals("B") ) { 87 return new Color(0,255,0); 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 } else if ( d.equals("2")) { 100 note.x2(); 101 note.play(); 102 note.s2(); 103 } else if ( d.equals("1/2")) { 104 note.s2(); 105 note.play(); 106 note.x2(); 107 } else if (d.equals("3")){ 108 note.x3(); 109 note.play(); 110 note.s3(); 111 } else if (d.equals("1/3")){ 112 note.s3(); 113 note.play(); 114 note.x3(); 115 } else if (d.equals("2/3")){ 116 note.x2(); 117 note.s3(); 118 note.play(); 119 note.x3(); 120 note.s2(); 121 } 122 } 123 private static Color randomColor() { 124 int rv = (int)(Math.random()*256); 125 int gv = (int)(Math.random()*256); 126 int bv = (int)(Math.random()*256); 127 return new Color(rv,gv,bv); 128 } 129 } 130