/home/kchan2/NetBeansProjects/CS1/src/chromesthesia2/Pitch.java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package chromesthesia2;
16
17 import java.awt.Color;
18 import note.SNote;
19 import painter.SPainter;
20 import shapes.SRectangle;
21
22
23
24 @author
25
26 public class Pitch {
27
28
29 private String abcName;
30 private SPainter painter;
31 private SRectangle box;
32 private SNote note;
33 private Color color;
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 } else if (abcPitchClassName.equals("F")) {
72 note.rp(3);
73 } else if (abcPitchClassName.equals("F,")) {
74 note.lp(4);
75 } else if (abcPitchClassName.equals("f")) {
76 note.rp(10);
77 } else if (abcPitchClassName.equals("G")) {
78 note.rp(4);
79 } else if (abcPitchClassName.equals("G,")) {
80 note.lp(3);
81 } else if (abcPitchClassName.equals("g")) {
82 note.rp(11);
83 } else if (abcPitchClassName.equals("A")) {
84 note.rp(5);
85 } else if (abcPitchClassName.equals("A,")) {
86 note.lp(2);
87 } else if (abcPitchClassName.equals("a")) {
88 note.rp(12);
89 } else if (abcPitchClassName.equals("B")) {
90 note.rp(6);
91 } else if (abcPitchClassName.equals("B,")) {
92 note.lp(1);
93 } else if (abcPitchClassName.equals("b")) {
94 note.rp(13);
95 }
96 return note;
97 }
98
99 private Color getPitchClassColor(String letter) {
100 if ( letter.equals("C") ) {
101 return new Color(0,0,255);
102 } else if ( letter.equals("D") ) {
103 return new Color(0,255,0);
104 } else if ( letter.equals("E") ) {
105 return new Color(127,0,127);
106 } else if ( letter.equals("F") ) {
107 return new Color(255,255,0);
108 } else if ( letter.equals("G") ) {
109 return new Color(255,0,0);
110 } else if ( letter.equals("A") ) {
111 return new Color(255,127,0);
112 } else if ( letter.equals("B") ) {
113 return new Color(0,255,255);
114 } else {
115 return Color.BLACK;
116 }
117 }
118
119 public void play(String d) {
120 painter.setColor(color);
121 painter.paint(box);
122 painter.setColor(randomColor());
123 painter.draw(box);
124 if ( d.equals("1") ) {
125 note.play();
126 } else if ( d.equals("2") ) {
127 note.x2(); note.play(); note.s2();
128 } else if ( d.equals("1/2") ) {
129 note.s2(); note.play(); note.x2();
130 } else if ( d.equals("3") ) {
131 note.x3(); note.play(); note.s3();
132 } else if ( d.equals("1/3") ) {
133 note.s3(); note.play(); note.x3();
134 } else if ( d.equals("2/3") ) {
135 note.s3(); note.x2(); note.play(); note.s2(); note.x3();
136 }
137 }
138
139 private Color randomColor() {
140 int rv = (int)(Math.random()*256);
141 int gv = (int)(Math.random()*256);
142 int bv = (int)(Math.random()*256);
143 return new Color(rv,gv,bv);
144 }
145 }
146