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