Pitch.java
1    /*The Pitch class models the pitch of a note in a manner that will facilitate 
2    the chromesthetic processing of the pitch. A Pitch object will have five properties: 
3    -String name | ABC notation pitch name 
4    -SPainter painter |the painting agent 
5    -Note note | a note that will be set to the pitch corresponding to the ABC notation pitch name 
6    -SRectangle box | an SRectangle object that will chromesthetically represent the pitch 
7    -Color color | the color associated with the pitch for the presumed chromesthete 
8     */
9    package chromesthesia0;
10   
11   import java.awt.Color;
12   import note.SNote;
13   import painter.SPainter;
14   import shapes.SRectangle;
15   
16   public class Pitch {
17       //Instance Variables
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       public String toString(){
32           return "[" + abcName + "|" + note.degree() + "|" + color + "]";
33       }
34       public String abcName(){
35           return abcName;
36       }
37       private SNote createNoteForThisPitch(String abcPitchClassName){
38           SNote note = new SNote();
39           if ( abcPitchClassName.equals("C")){
40               //nothing to do
41           }else if ( abcPitchClassName.equals("C,")){
42               note.lp(7);
43           }else if ( abcPitchClassName.equals("c")) {
44               note.rp(7);
45           }else if ( abcPitchClassName.equals("D")) {
46               note.rp(1);
47           }else if ( abcPitchClassName.equals("D,")) {
48               note.lp(6);
49           }else if ( abcPitchClassName.equals("d")) {
50               note.rp(8);
51           }else if ( abcPitchClassName.equals("E")) {
52               note.rp(2);
53           }else if ( abcPitchClassName.equals("E,")) {
54               note.lp(5);
55           }else if ( abcPitchClassName.equals("e")) {
56               note.rp(9);
57           }
58           return note;
59       }
60       private Color getPitchClassColor(String letter){
61           if (letter.equals("C")) {
62               return Color.BLUE;
63           }else if (letter.equals("D")){
64               return Color.GREEN;
65           }else if (letter.equals("E")){
66               return new Color(127,0,127);
67           }else{
68               return Color.BLACK;
69           }
70       }
71       public void play(String d) {
72           painter.setColor(color);
73           painter.paint(box);
74           painter.setColor(randomColor());
75           painter.draw(box);
76           if (d.equals("1")) {
77               note.play();
78           }
79       }
80       private static Color randomColor(){
81           int rv =(int)(Math.random()*256);
82           int gv =(int)(Math.random()*256);
83           int bv =(int)(Math.random()*256);
84           return new Color(rv,gv,bv);
85       }
86   }
87