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