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