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    - 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   
16   package chromesthesia0;
17   
18   import java.awt.Color;
19   import note.SNote;
20   import painter.SPainter;
21   import shapes.SRectangle;
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       public String toString() {
39           return "[" + abcName + " | " + note.degree() + " | " + color + " ]";
40       }
41       public String abcName() {
42           return abcName;
43       }
44       private SNote createNoteForThisPitch(String abcPitchClassName) {
45           SNote note = new SNote();
46           if (abcPitchClassName.equals("C")) {
47               //nothing to do
48           } else if (abcPitchClassName.equals("C,")) {
49               note.lp(7);
50           } else if (abcPitchClassName.equals("c")) {
51               note.rp(7);
52           } else if (abcPitchClassName.equals("D")) {
53               note.rp(1);
54           } else if (abcPitchClassName.equals("D,")) {
55               note.lp(6);
56           } else if (abcPitchClassName.equals("d")) {
57               note.rp(8);
58           }else if (abcPitchClassName.equals("E")) {
59               note.rp(2);
60           }else if(abcPitchClassName.equals("E,")) {
61               note.lp(5);
62           }else if (abcPitchClassName.equals("e")){
63               note.rp(9);
64           }
65           return note;
66       }
67       private Color getPitchClassColor(String letter){
68           if ( letter.equals("C")) {
69               return Color.BLUE;
70           }else if (letter.equals("D")) {
71               return Color.GREEN;
72           }else if (letter.equals("E")) {
73               return new Color(127, 0, 127);
74           }else{
75               return Color.BLACK;
76           }
77       }
78       public void play(String d){
79           painter.setColor(color);
80           painter.paint(box);
81           painter.setColor(randomColor());
82           painter.draw(box);
83           if (d.equals("1")){
84               note.play();
85           }
86       }
87   
88       private Color randomColor() {
89           int rv = (int)(Math.random() * 256);
90           int gv = (int)(Math.random() * 256);
91           int bv = (int)(Math.random() * 256);
92           return new Color(rv,gv,bv);
93       }
94   
95   }
96   
97   
98   
99