Pitch.java
1    /* 
2    2     *The Pitch class models the pitch of a note in a manner that will facilitate 
3    3     * teh chromesthetic processing of the pitch. A Pitch object will have five 
4    4     * properties: 
5    5     * -String name | ABC notation pitch name 
6    6     * -SPainter painter | the painting agent 
7    7     * -Note note | a note that will be set to the pitch corresponding to the 
8    8     * ABD notation pitch name 
9    9     * -SRectangle box | an SRectangle object that will chromesthetically 
10   10    * represent the pitch 
11   11    * -Color color | the color associated with the pitch for the presumed 
12   12    * chromesthete 
13   13    */
14   package chromesthesia1;
15   
16   import note.SNote;
17   import painter.SPainter;
18   import shapes.SRectangle;
19   
20   import java.awt.*;
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       public String abcName() {
43           return abcName;
44       }
45       private SNote createNoteForThisPitch(String abcPitchClassName) {
46           SNote note = new SNote();
47           if( abcPitchClassName.equals("C")) {
48               //nothing to do
49           }else if (abcPitchClassName.equals("C,")) {
50               note.lp(7);
51           }else if (abcPitchClassName.equals("c")) {
52               note.rp(7);
53           }else if (abcPitchClassName.equals("D")) {
54               note.rp(1);
55           }else if (abcPitchClassName.equals("D,")) {
56               note.lp(6);
57           }else if (abcPitchClassName.equals("d")) {
58               note.rp(8);
59           }else if (abcPitchClassName.equals("E")) {
60                  note.rp(2);
61           }else if (abcPitchClassName.equals("E,")) {
62               note.lp(5);
63           }else if (abcPitchClassName.equals("e")) {
64               note.rp(9);
65               //ADDED NOTES
66           }else if ( abcPitchClassName.equals("F")) {
67               note.rp();
68           }else if (abcPitchClassName.equals("F,")) {
69               note.lp();
70           }else if (abcPitchClassName.equals("f")) {
71               note.rp();
72           }else if (abcPitchClassName.equals("G")) {
73               note.rp();
74           }else if (abcPitchClassName.equals("G,")) {
75               note.lp();
76           }else if (abcPitchClassName.equals("g")) {
77               note.rp();
78           }else if (abcPitchClassName.equals("A")) {
79               note.rp();
80           }else if (abcPitchClassName.equals("A,")) {
81               note.lp();
82           }else if (abcPitchClassName.equals("a")) {
83               note.rp();
84           }else if (abcPitchClassName.equals("B")) {
85               note.rp();
86           }else if (abcPitchClassName.equals("B,")) {
87               note.lp();
88           }else if (abcPitchClassName.equals("b")) {
89               note.rp();
90           }
91           return note;
92       }
93       private Color getPitchClassColor (String letter) {
94           if( letter.equals("C")) {
95               return Color.BLUE;
96           }else if (letter.equals("D")){
97               return Color.GREEN;
98           }else if (letter.equals("E")) {
99               return Color.MAGENTA;
100          }else if (letter.equals("F")){
101              return Color.ORANGE;
102          }else if (letter.equals("G")) {
103              return Color.CYAN;
104          }else if (letter.equals("A")){
105              return Color.YELLOW;
106          }else if (letter.equals("B")) {
107              return Color.RED;
108          }else {
109              return Color.BLACK;
110          }
111      }
112      public void play(String d) {
113          painter.setColor(color);
114          painter.paint(box);
115          painter.setColor(randomColor());
116          painter.draw(box);
117          if (d.equals("1")) {
118              note.play();
119          }
120      }
121      private static Color randomColor() {
122          int rv = (int)(Math.random()*256);
123          int gv = (int)(Math.random()*256);
124          int bv = (int)(Math.random()*256);
125          return new Color(rv,gv,bv);
126      }
127  }
128  
129