| /home/jfernan6/NetBeansProjects/CSX/src/chromesthesia0/Pitch.java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package chromesthesia0;
15
16 import java.awt.Color;
17 import note.SNote;
18 import painter.SPainter;
19 import shapes.SRectangle;
20
21
22
23 @author
24
25 public class Pitch {
26
27
28 private String abcName;
29 private SPainter painter;
30 private SRectangle box;
31 private SNote note;
32 private Color color;
33
34
35 public Pitch(String abcName, SPainter painter) {
36 this.abcName = abcName;
37 this.painter = painter;
38 this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50);
39 this.note = createNoteForThisPitch(abcName);
40 this.color = getPitchClassColor(abcName.substring(0, 1).toUpperCase());
41 }
42
43 public String toString() {
44 return "[" + abcName + "|" + note.degree() + "|" + color + "]";
45 }
46
47 public String abcName() {
48 return abcName;
49 }
50
51 private SNote createNoteForThisPitch(String abcPitchClassName) {
52 SNote note = new SNote();
53 if (abcPitchClassName.equals("C")) {
54
55 } else if (abcPitchClassName.equals("C,")) {
56 note.lp(7);
57 } else if (abcPitchClassName.equals("c")) {
58 note.rp(7);
59 } else if (abcPitchClassName.equals("D")) {
60 note.rp(1);
61 } else if (abcPitchClassName.equals("D,")) {
62 note.lp(6);
63 } else if (abcPitchClassName.equals("d")) {
64 note.rp(8);
65 } else if (abcPitchClassName.equals("E")) {
66 note.rp(2);
67 } else if (abcPitchClassName.equals("E,")) {
68 note.lp(5);
69 } else if (abcPitchClassName.equals("e")) {
70 note.rp(9);
71 }
72 return note;
73 }
74
75 private Color getPitchClassColor(String letter) {
76 if (letter.equals("C")) {
77 return Color.BLUE;
78 } else if (letter.equals("D")) {
79 return Color.GREEN;
80 } else if (letter.equals("E")) {
81 return new Color(127, 0, 127);
82 } else {
83 return Color.BLACK;
84 }
85 }
86
87 public void play(String d) {
88 painter.setColor(color);
89 painter.paint(box);
90 painter.setColor(randomColor());
91 painter.draw(box);
92 if (d.equals("1")) {
93 note.play();
94 }
95 }
96
97 private Color randomColor() {
98 int rv = (int) (Math.random() * 256);
99 int gv = (int) (Math.random() * 256);
100 int bv = (int) (Math.random() * 256);
101 return new Color(rv, gv, bv);
102 }
103
104 }
105