Pitch.java
1    /* 
2     *The Pitch class models the pitch of a note in a manner that will facilitate 
3     * the 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     * ABC 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   package chromesthesia0;
15   import java.awt.Color;
16   import note.SNote;
17   import painter.SPainter;
18   import shapes.SRectangle;
19   
20   public class Pitch {
21       private String abcName;
22       private SPainter painter;
23       private SRectangle box;
24       private SNote note;
25       private Color color;
26   
27       public Pitch(String abcName, SPainter painter){
28           this.abcName = abcName;
29           this.painter = painter;
30           this.box = new SRectangle(painter.painterHeight-50, painter.painterWidth-50);
31           this.note = createNoteForThisPitch(abcName);
32           this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase());
33       }
34       public String toString(){
35           return "[" +  abcName + " | " + note.degree() + " | " + color + "]";
36       }
37       public String abcName(){
38           return abcName;
39       }
40       public SNote createNoteForThisPitch(String abcPitchClassName){
41           SNote note = new SNote();
42           if ( abcPitchClassName.equals("C")){
43               //nothing to do
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           }
61           return note;
62       }
63       private Color getPitchClassColor(String letter){
64           if ( letter.equals("C")){
65               return Color.BLUE;
66           }else if (letter.equals("D")){
67               return Color.GREEN;
68           }else if ( letter.equals("E")){
69               return new Color(127,0,127);
70           }else{
71               return Color.BLACK;
72           }
73       }
74       public void play(String d){
75           painter.setColor(color);
76           painter.paint(box);
77           painter.setColor(randomColor());
78           painter.draw(box);
79           if ( d.equals("1")){
80               note.play();
81           }
82       }
83       private static Color randomColor(){
84           int rv = (int)(Math.random()*256);
85           int gv = (int)(Math.random()*256);
86           int bv = (int)(Math.random()*256);
87           return new Color(rv,gv,bv);
88       }
89   }
90