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 properties: 
4    * - String name | ABC notation pitch name 
5    * - SPainter painter | the painting agent 
6    * - Note note | a note that will be set to the pitch corresponding to the ABC notation pitch name 
7    * - SRectangle box | an SRectangle object that will chromesthetically represent the pitch 
8    * - Color color | the color associated with the pitch for the presumed chromesthete 
9     */
10   package chromesthesia0;
11   
12   import note.SNote;
13   import painter.SPainter;
14   import shapes.SRectangle;
15   
16   import java.awt.*;
17   
18   public class Pitch {
19   
20       //INSTANCE VARIABLES
21       private String abcName;
22       private SPainter painter;
23       private SRectangle box;
24       private SNote note;
25       private Color color;
26   
27       public Pitch(String abcName, SPainter painter) {
28           this.abcName = abcName;
29           this.painter = painter;
30           this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50);
31           this.note = createNoteForThisPitch(abcName);
32           this.color = getPitchClassColor(abcName.substring(0, 1).toUpperCase());
33       }
34   
35       public String toString() {
36           return "[ " + abcName + " | " + note.degree() + " | " + color + " ]";
37       }
38   
39       public String abcName() {
40           return abcName;
41       }
42   
43       private SNote createNoteForThisPitch(String abcPitchClassName) {
44           SNote note = new SNote();
45           if (abcPitchClassName.equals("C")) {
46               //nothing to do
47           } else if (abcPitchClassName.equals("C,")) {
48               note.lp(7);
49           } else if (abcPitchClassName.equals("c")) {
50               note.rp(7);
51           } else if (abcPitchClassName.equals("D")) {
52               note.rp(1);
53           } else if (abcPitchClassName.equals("D,")) {
54               note.lp(6);
55           } else if (abcPitchClassName.equals("d")) {
56               note.rp(8);
57           } else if (abcPitchClassName.equals("E")) {
58               note.rp(2);
59           } else if (abcPitchClassName.equals("E,")) {
60               note.lp(5);
61           } else if (abcPitchClassName.equals("e")) {
62               note.rp(9);
63           }
64           return note;
65       }
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 {
73               return Color.BLACK;
74           }
75       }
76   
77       public void play(String d){
78           painter.setColor(color);
79           painter.paint(box);
80           painter.setColor(randomColor());
81           painter.draw(box);
82           if(d.equals("1")){
83               note.play();
84           }
85       }
86       private static Color randomColor(){
87           int rv = (int)(Math.random()*256);
88           int gv = (int)(Math.random()*256);
89           int bv = (int)(Math.random()*256);
90           return new Color(rv,gv,bv);
91       }
92   }