1 2 3 package chromesthesia2; 4 5 //import com.sun.org.apache.regexp.internal.RE; 6 import note.SNote; 7 import painter.SPainter; 8 import shapes.SRectangle; 9 //import sun.dc.pr.PRError; 10 //import sun.java2d.pipe.SpanIterator; 11 //import sun.tools.jconsole.ProxyClient; 12 13 import java.awt.*; 14 15 public class Pitch { 16 //INSTANCE VARIABLES 17 private String abcName; 18 private SPainter painter; 19 private SRectangle box; 20 private SNote note; 21 private Color color; 22 23 public Pitch(String abcName, SPainter painter) { 24 this.abcName = abcName; 25 this.painter = painter; 26 this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50); 27 this.note = createNoteForThisPitch(abcName); 28 this.color = getPitchClassColor(abcName.substring(0, 1).toUpperCase()); 29 30 } 31 32 public String toString() { 33 return "[" + abcName + "|" + note.degree() + "|" + color + "]"; 34 } 35 36 private SNote createNoteForThisPitch(String abcPitchClassName) { 37 SNote note = new SNote(); 38 if (abcPitchClassName.equals("C")) { 39 //nothing to do 40 } else if (abcPitchClassName.equals("C,")) { 41 note.lp(7); 42 } else if (abcPitchClassName.equals("c")) { 43 note.rp(7); 44 } else if (abcPitchClassName.equals("D")) { 45 note.rp(1); 46 } else if (abcPitchClassName.equals("D,")) { 47 note.lp(6); 48 } else if (abcPitchClassName.equals("d")) { 49 note.rp(8); 50 } else if (abcPitchClassName.equals("E")) { 51 note.rp(2); 52 } else if (abcPitchClassName.equals("E,")) { 53 note.lp(5); 54 } else if (abcPitchClassName.equals("e")) { 55 note.rp(9); 56 } else if (abcPitchClassName.equals("F")) { 57 note.rp(3); 58 } else if (abcPitchClassName.equals("F,")) { 59 note.lp(4); 60 } else if (abcPitchClassName.equals("f")) { 61 note.rp(10); 62 } else if (abcPitchClassName.equals("G")) { 63 note.rp(5); 64 } else if (abcPitchClassName.equals("G,")) { 65 note.lp(3); 66 } else if (abcPitchClassName.equals("g")) { 67 note.rp(11); 68 } else if (abcPitchClassName.equals("A")) { 69 note.rp(6); 70 } else if (abcPitchClassName.equals("A,")) { 71 note.lp(2); 72 } else if (abcPitchClassName.equals("a")) { 73 note.rp(12); 74 } else if (abcPitchClassName.equals("B")) { 75 note.rp(7); 76 } else if (abcPitchClassName.equals("B,")) { 77 note.lp(1); 78 } else if (abcPitchClassName.equals("b")) { 79 note.rp(13); 80 81 } 82 return note; 83 } 84 85 86 private Color getPitchClassColor(String letter) { 87 if (letter.equals("C")) { 88 return new Color(127, 0, 127); 89 } else if (letter.equals("D")) { 90 return new Color(255, 255, 0); 91 } else if (letter.equals("E")) { 92 return new Color(255, 0, 0); 93 } else { if (letter.equals("F")) { 94 return new Color(255, 127, 0); 95 } else if (letter.equals("G")) { 96 return new Color(0, 255, 255); 97 } else if (letter.equals("A")) { 98 return new Color(0, 0, 255); 99 } else if (letter.equals("B")) { 100 return new Color(0, 255, 0); 101 } else { 102 return Color.BLACK; 103 } 104 } 105 } 106 public void play(String d) { 107 painter.setColor(color); 108 painter.paint(box); 109 painter.setColor(randomColor()); 110 painter.draw(box); 111 if (d.equals("1")) { 112 note.play(); 113 } else if (d.equals("2")) { //changes made for 2 and 1/2 114 note.x2();note.play(); note.s2(); 115 } else if (d.equals("1/2")) { 116 note.s2();note.play();note.x2(); 117 }else if (d.equals("3")) { 118 note.x3();note.play();note.s3(); 119 }else if (d.equals("1/3")) { 120 note.s3(); note.play();note.x3(); 121 }else if (d.equals("2/3")) { 122 note.x2(); note.play();note.s2(); 123 } 124 } 125 private static Color randomColor() { 126 int rv = (int) (Math.random() * 256); 127 int gv = (int) (Math.random() * 256); 128 int bv = (int) (Math.random() * 256); 129 return new Color(rv, gv, bv); 130 } 131 132 public Object abcName() { 133 return abcName; 134 } 135 136 137 } 138 139