Pitch2.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     * -SPainter painter | the painting agent 
7     * -Note note | a note that will be set to the pitch corresponding to the 
8     * ABC 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 chromesthesia2;
16   
17   import java.awt.Color;
18   import note.SNote;
19   import painter.SPainter;
20   import shapes.SRectangle;
21   
22   public class Pitch2 {
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 Pitch2(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               //nothing to do
51           } else if (abcPitchClassName.equals("C,")) {
52               note.lp(7);
53           } else if (abcPitchClassName.equals("c")) {
54               note.rp(7);
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           } else if (abcPitchClassName.equals("E")) {
62               note.rp(2);
63           } else if (abcPitchClassName.equals("E,")) {
64               note.lp(5);
65           } else if (abcPitchClassName.equals("e")) {
66               note.rp(9);
67           }
68           return note;
69       }
70   
71       private Color getPitchClassColor(String letter) {
72           if (letter.equals("C")) {
73               return new Color(127, 0, 127);
74           } else if (letter.equals("D")) {
75               return new Color(255, 255, 0);
76           } else if (letter.equals("E")) {
77               return new Color(255, 0, 0);
78           } else if (letter.equals("F")) {
79               return new Color(255, 127, 0);
80           } else if (letter.equals("A")) {
81               return new Color(0, 0, 255);
82           } else if (letter.equals("G")) {
83               return new Color(0, 255, 255);
84           } else if (letter.equals("B")) {
85               return new Color(0, 255, 0);
86           } else {
87               return Color.BLACK;
88           }
89       }
90   
91       public void play(String d) {
92           painter.setColor(color);
93           painter.paint(box);
94           painter.setColor(randomColor());
95           painter.draw(box);
96           if (d.equals("1")) {
97               note.play();
98           } else if (d.equals("2")) {
99               note.x2();
100              note.play();
101              note.s2();
102          } else if (d.equals("1/2")) {
103              note.s2();
104              note.play();
105              note.x2();
106          } else if (d.equals("3")) {
107              note.s3(0);
108              note.play();
109              note.x3();
110           } else if (d.equals("1/3")) {
111              note.s3();
112              note.play();
113              note.x3();
114          } else if (d.equals("2/3"));
115              note.s3();
116              note.x2();
117              note.play();
118              note.s2();
119              note.x3();
120          }
121  
122  
123  
124      private static Color randomColor(){
125          int rv = (int)(Math.random()*256);
126          int gv = (int)(Math.random()*256);
127          int bv = (int)(Math.random()*256);
128          return new Color(rv,gv,bv);
129      }
130  }