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