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 chromesthesia0;
16   
17      import java.awt.Color;
18      import note.SNote;
19      import painter.SPainter;
20      import shapes.SRectangle;
21      public class Pitch {
22          //INSTANCE VARIABLES
23          private String abcName;
24          private SPainter painter;
25          private SRectangle box;
26          private SNote note;
27          private Color color;
28          public Pitch(String abdName, SPainter painter) {
29              this.abcName = abdName;
30              this.painter = painter;
31              this.box = new SRectangle(painter.painterHeight-50, painter.painterWidth-50);
32              this.note = createNoteForThisPitch(abdName);
33              this.color = getPitchClassColor(abdName.substring(0,1).toUpperCase());
34          }
35          public String toString() {
36              return "[" + abcName + "|" + note.degree() + "|" + color + "]";
37          }
38   
39          public String abcName() {
40              return abcName;
41          }
42          private SNote createNoteForThisPitch(String abcPitchClassName) {
43              SNote note = new SNote();
44              if( abcPitchClassName.equals("C")) {
45                  //nothing to do
46              }else if (abcPitchClassName.equals("C,")) {
47                  note.lp(7);
48              }else if (abcPitchClassName.equals("c")) {
49                  note.rp(7);
50              }else if (abcPitchClassName.equals("D")) {
51                  note.rp(1);
52              }else if (abcPitchClassName.equals("D,")) {
53                  note.lp(6);
54              }else if (abcPitchClassName.equals("d")) {
55                  note.rp(8);
56              }else if (abcPitchClassName.equals("E")) {
57                  note.rp(2);
58              }else if (abcPitchClassName.equals("E,")) {
59                  note.lp(5);
60              }else if (abcPitchClassName.equals("e")) {
61                  note.rp(9);
62              }
63              return note;
64          }
65          private Color getPitchClassColor (String letter) {
66              if( letter.equals("C")) {
67                  return Color.BLUE;
68              }else if (letter.equals("D")){
69                  return Color.GREEN;
70              }else if (letter.equals("E")) {
71                  return new Color(14,120,169);
72              }else {
73                  return Color.BLACK;
74              }
75          }
76          public void play(String d) {
77              painter.setColor(color);
78              painter.paint(box);
79              painter.setColor(randomColor());
80              painter.draw(box);
81              if (d.equals("1")) {
82                  note.play();
83              }
84          }
85          private static Color randomColor() {
86              int rv = (int)(Math.random()*256);
87              int gv = (int)(Math.random()*256);
88              int bv = (int)(Math.random()*256);
89              return new Color(rv,gv,bv);
90          }
91      }