Pitch.java
1    package chromesthesia1;
2    import java.awt.Color;
3    import note.SNote;
4    import painter.SPainter;
5    import shapes.SRectangle;
6    //This pitch program works with the second Chromesthesia Program in folder chromesthesia1.
7    //This is what I would call the Pitch1 program.
8    //This program is set up to understand letters A B C D E F G
9    //YadaYadaYada... basically just functions with Chromesthesia1-.-.
10   public class Pitch {
11       private String abcName;
12       private SPainter painter;
13       private SRectangle box;
14       private SNote note;
15       private Color color;
16   
17       public Pitch(String abcName, SPainter painter) {
18           this.abcName = abcName;
19           this.painter = painter;
20           this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50);
21           this.note = createNoteForThisPitch(abcName);
22           this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase());
23       }
24       public String toString() {
25           return "[ " + abcName + " | " + note.degree() + " | " + color + " ]";
26       }
27       public String abcName() {
28           return abcName;
29       }
30       private SNote createNoteForThisPitch(String abcPitchClassName) {
31           SNote note = new SNote();
32           if (abcPitchClassName.equals("C") ) {
33               //nothing will be done
34           } else if (abcPitchClassName.equals("C,") ) {
35               note.lp(7);
36           } else if (abcPitchClassName.equals("c") ) {
37               note.rp(7);
38           } else if (abcPitchClassName.equals("D") ) {
39               note.rp(1);
40           } else if (abcPitchClassName.equals("D,") ) {
41               note.lp(6);
42           } else if (abcPitchClassName.equals("d") ) {
43               note.rp(8);
44           } else if (abcPitchClassName.equals("E") ) {
45               note.rp(2);
46           } else if (abcPitchClassName.equals("E,") ) {
47               note.lp(5);
48           } else if (abcPitchClassName.equals("e") ) {
49               note.rp(9);
50           } else if (abcPitchClassName.equals("F") ) {
51               note.rp(3);
52           } else if (abcPitchClassName.equals("F,") ) {
53               note.lp(4);
54           } else if (abcPitchClassName.equals("f") ) {
55               note.rp(10);
56           } else if (abcPitchClassName.equals("G") ) {
57               note.rp(4);
58           } else if (abcPitchClassName.equals("G,") ) {
59               note.lp(3);
60           } else if (abcPitchClassName.equals("g") ) {
61               note.rp(11);
62           } else if (abcPitchClassName.equals("A") ) {
63               note.rp(5);
64           } else if (abcPitchClassName.equals("A,") ) {
65               note.lp(2);
66           } else if (abcPitchClassName.equals("a") ) {
67               note.rp(12);
68           } else if (abcPitchClassName.equals("B") ) {
69               note.rp(6);
70           } else if (abcPitchClassName.equals("B,") ) {
71               note.lp(1);
72           } else if (abcPitchClassName.equals("b") ) {
73               note.rp(13);
74           }
75   
76   
77           return note;
78       }
79       private Color getPitchClassColor(String letter) {
80           if (letter.equals("C") ) {
81               return Color.BLUE;
82           } else if (letter.equals("D") ) {
83               return Color.GREEN;
84           } else if (letter.equals("E") ) {
85               return new Color(127,0,127);
86           } else if (letter.equals("A") ) {
87               return Color.CYAN;
88           } else if (letter.equals("B") ) {
89               return Color.ORANGE;
90           } else if (letter.equals("F")) {
91               return  Color.PINK;
92           } else if (letter.equals("G")) {
93               return Color.RED;
94           } else {
95               return Color.BLACK;
96           }
97       }
98       public void play(String d) {
99           painter.setColor(color);
100          painter.paint(box);
101          painter.setColor(randomColor());
102          painter.draw(box);
103          if (d.equals("1") ) {
104              note.play();
105          }
106      }
107  
108      private Color randomColor() {
109          int rv = (int) (Math.random()*256);
110          int gv = (int) (Math.random()*256);
111          int bv = (int) (Math.random()*256);
112          return new Color(rv,gv,bv);
113      }
114  }