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