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 Pitch { 9 10 private String abcName; 11 private SPainter painter; 12 private SRectangle box; 13 private SNote note; 14 private Color color; 15 16 public Pitch(String abcName, SPainter painter){ 17 18 this.abcName = abcName; 19 this.painter = painter; 20 this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50); 21 this.note = createNoteForThisPitch(abcName); 22 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 23 24 } 25 26 public String toString(){ 27 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 28 } 29 30 public String abcName(){ 31 return abcName; 32 } 33 34 private SNote createNoteForThisPitch(String abcPitchClassName){ 35 36 SNote note = new SNote(); 37 38 if (abcPitchClassName.equals("C")) { 39 40 } else if (abcPitchClassName.equals("C,")){ 41 note.lp(7); 42 } else if (abcPitchClassName.equals("c")){ 43 note.rp(7); 44 } 45 46 else if (abcPitchClassName.equals("D")){ 47 note.rp(1); 48 } else if (abcPitchClassName.equals("D,")){ 49 note.lp(6); 50 } else if (abcPitchClassName.equals("d")){ 51 note.rp(8); 52 } 53 54 else if (abcPitchClassName.equals("E")){ 55 note.rp(2); 56 } else if (abcPitchClassName.equals("E,")){ 57 note.lp(5); 58 } else if (abcPitchClassName.equals("e")){ 59 note.rp(9); 60 } 61 62 else if (abcPitchClassName.equals("F")){ 63 note.rp(3); 64 } else if (abcPitchClassName.equals("F,")){ 65 note.lp(4); 66 } else if (abcPitchClassName.equals("f")){ 67 note.rp(10); 68 } 69 70 else if (abcPitchClassName.equals("G")){ 71 note.rp(4); 72 } else if (abcPitchClassName.equals("G,")){ 73 note.lp(3); 74 } else if (abcPitchClassName.equals("g")){ 75 note.rp(11); 76 } 77 78 else if (abcPitchClassName.equals("A")){ 79 note.rp(5); 80 } else if (abcPitchClassName.equals("A,")){ 81 note.lp(2); 82 } else if (abcPitchClassName.equals("a")){ 83 note.rp(12); 84 } 85 86 else if (abcPitchClassName.equals("B")){ 87 note.rp(6); 88 } else if (abcPitchClassName.equals("B,")){ 89 note.lp(1); 90 } else if (abcPitchClassName.equals("b")){ 91 note.rp(13); 92 } 93 94 return note; 95 96 } 97 98 private Color getPitchClassColor(String letter) { 99 100 if (letter.equals("C")) { 101 return new Color(127, 0, 127); 102 } else if (letter.equals("D")) { 103 return new Color(255, 255, 0); 104 } else if (letter.equals("E")) { 105 return new Color(255, 0, 0); 106 } else if (letter.equals("F")) { 107 return new Color(255, 127, 0); 108 } else if (letter.equals("G")) { 109 return new Color(0, 255, 255); 110 } else if (letter.equals("A")) { 111 return new Color(0, 0, 255); 112 } else if (letter.equals("B")) { 113 return new Color(0, 255, 0); 114 } 115 116 else { 117 return Color.BLACK; 118 } 119 } 120 121 public void play(String d){ 122 123 painter.setColor(color); 124 painter.paint(box); 125 painter.setColor(randomColor()); 126 painter.draw(box); 127 if (d.equals("1")){ 128 note.play(); 129 } else if (d.equals("2")){ 130 note.x2(); 131 note.play(); 132 note.s2(); 133 } else if (d.equals("3")){ 134 note.x3(); 135 note.play(); 136 note.s3(); 137 } else if (d.equals("1/3")){ 138 note.s3(); 139 note.play(); 140 note.x3(); 141 } else if (d.equals("1/2")){ 142 note.s2(); 143 note.play(); 144 note.x2(); 145 } else if (d.equals("2/3")){ 146 note.s3(); 147 note.x2(); 148 note.play(); 149 note.s2(); 150 note.x3(); 151 } 152 153 } 154 155 private static Color randomColor(){ 156 157 int rv = (int)(Math.random()*256); 158 int gv = (int)(Math.random()*256); 159 int bv = (int)(Math.random()*256); 160 161 return new Color(rv,gv,bv); 162 163 } 164 165 } 166