Pitch.java
1    /* 
2     *The Pitch class models the pitch of a note in a manner that will facilitate 
3     * teh chromesthetic processing of the pitch. A Pitch object will have five 
4     * properties: 
5     * -String name | ABC notation pitch name 
6     * -SPainter painter | the painting agent 
7     * -Note note | a note that will be set to the pitch corresponding to the 
8     * ABD notation pitch name 
9     * -SRectangle box | an SRectangle object that will chromesthetically 
10    * represent the pitch 
11    * -Color color | the color associated with the pitch for the presumed 
12    * chromesthete 
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   public class Pitch {
23   
24       //INSTANCE VARIABLES
25       private String abcName;
26       private SPainter painter;
27       private SRectangle box;
28       private SNote note;
29       private Color color;
30   
31       public Pitch(String abdName, SPainter painter) {
32           this.abcName = abdName;
33           this.painter = painter;
34           this.box = new SRectangle(painter.painterHeight-50, painter.painterWidth-50);
35           this.note = createNoteForThisPitch(abdName);
36           this.color = getPitchClassColor(abdName.substring(0,1).toUpperCase());
37       }
38   
39       public String toString() {
40           return "[" + abcName + "|" + note.degree() + "|" + color + "]";
41       }
42   
43       public String abcName() {
44           return abcName;
45       }
46   
47       private SNote createNoteForThisPitch(String abcPitchClassName) {
48           SNote note = new SNote();
49           if( abcPitchClassName.equals("C")) {
50               //nothing to do
51           }else if (abcPitchClassName.equals("C,")) {
52               note.lp(7);
53           }else if (abcPitchClassName.equals("c")) {
54               note.rp(7);
55           }else if (abcPitchClassName.equals("D")) {
56               note.rp(1);
57           }else if (abcPitchClassName.equals("D,")) {
58               note.lp(6);
59           }else if (abcPitchClassName.equals("d")) {
60               note.rp(8);
61           }else if (abcPitchClassName.equals("E")) {
62               note.rp(2);
63           }else if (abcPitchClassName.equals("E,")) {
64               note.lp(5);
65           }else if (abcPitchClassName.equals("e")) {
66               note.rp(9);
67               //ADDED NOTES
68           }else if ( abcPitchClassName.equals("F")) {
69               note.rp();
70           }else if (abcPitchClassName.equals("F,")) {
71               note.lp();
72           }else if (abcPitchClassName.equals("f")) {
73               note.rp();
74           }else if (abcPitchClassName.equals("G")) {
75               note.rp();
76           }else if (abcPitchClassName.equals("G,")) {
77               note.lp();
78           }else if (abcPitchClassName.equals("g")) {
79               note.rp();
80           }else if (abcPitchClassName.equals("A")) {
81               note.rp();
82           }else if (abcPitchClassName.equals("A,")) {
83               note.lp();
84           }else if (abcPitchClassName.equals("a")) {
85               note.rp();
86           }else if (abcPitchClassName.equals("B")) {
87               note.rp();
88           }else if (abcPitchClassName.equals("B,")) {
89               note.lp();
90           }else if (abcPitchClassName.equals("b")) {
91               note.rp();
92           }
93           return note;
94       }
95   
96       private Color getPitchClassColor (String letter) {
97           if( letter.equals("C")) {
98               return new Color(127,0,127);
99           }else if (letter.equals("D")){
100              return new Color(255,255,0);
101          }else if (letter.equals("E")) {
102              return new Color(255,0,0);
103          }else if (letter.equals("F")){
104              return new Color(255,127,0);
105          }else if (letter.equals("G")) {
106              return new Color(0,255,255);
107          }else if (letter.equals("A")){
108              return new Color(0,0,255);
109          }else if (letter.equals("B")) {
110              return new Color(0,255,0);
111          }else {
112              return Color.BLACK;
113          }
114      }
115  
116      public void play(String d) {
117          painter.setColor(color);
118          painter.paint(box);
119          painter.setColor(randomColor());
120          painter.draw(box);
121          if (d.equals("1")) {
122              note.play();
123          } else if (d.equals("2")) {
124              note.x2();
125              note.play();
126              note.s2();
127          }else if (d.equals("1/2")){
128              note.s2();
129              note.play();
130              note.x2();
131          }else if (d.equals("3")) {
132              note.x3();
133              note.play();
134              note.s3();
135              //FIX THE LENGTHS AT WHICH THESE NOTES WILL PLAY
136          }else if (d.equals("1/3")) {
137              note.s3();
138              note.play();
139              note.x3();
140          }else if (d.equals("2/3")) {
141              note.s3();
142              note.play();
143              note.play();
144              note.x3();
145  
146  
147  
148          }
149  
150      }
151  
152      private static Color randomColor() {
153          int rv = (int)(Math.random()*256);
154          int gv = (int)(Math.random()*256);
155          int bv = (int)(Math.random()*256);
156          return new Color(rv,gv,bv);
157      }
158  }
159  
160