Pitch.java
1    package chromesthesia2;
2    
3    import java.awt.Color;
4    import note.SNote;
5    import painter.SPainter;
6    import shapes.SRectangle;
7    //Look at the comments for Chromesthesia2... from there you can assume this program helps that program function.
8    //Sorry just got tired of saying it... ,-,
9    public class Pitch {
10       private String abcName;
11       private SPainter painter;
12       private SRectangle box;
13       private SNote note;
14       private Color color;
15   
16       public Pitch(String abcName, SPainter painter) {
17           this.abcName = abcName;
18           this.painter = painter;
19           this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50);
20           this.note = createNoteForThisPitch(abcName);
21           this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase());
22       }
23       public String toString() {
24           return "[ " + abcName + " | " + note.degree() + " | " + color + " ]";
25       }
26       public String abcName() {
27           return abcName;
28       }
29       private SNote createNoteForThisPitch(String abcPitchClassName) {
30           SNote note = new SNote();
31           if (abcPitchClassName.equals("C") ) {
32               //nothing will be done
33           } else if (abcPitchClassName.equals("C,") ) {
34               note.lp(7);
35           } else if (abcPitchClassName.equals("c") ) {
36               note.rp(7);
37           } else if (abcPitchClassName.equals("D") ) {
38               note.rp(1);
39           } else if (abcPitchClassName.equals("D,") ) {
40               note.lp(6);
41           } else if (abcPitchClassName.equals("d") ) {
42               note.rp(8);
43           } else if (abcPitchClassName.equals("E") ) {
44               note.rp(2);
45           } else if (abcPitchClassName.equals("E,") ) {
46               note.lp(5);
47           } else if (abcPitchClassName.equals("e") ) {
48               note.rp(9);
49           } else if (abcPitchClassName.equals("F") ) {
50               note.rp(3);
51           } else if (abcPitchClassName.equals("F,") ) {
52               note.lp(4);
53           } else if (abcPitchClassName.equals("f") ) {
54               note.rp(10);
55           } else if (abcPitchClassName.equals("G") ) {
56               note.rp(4);
57           } else if (abcPitchClassName.equals("G,") ) {
58               note.lp(3);
59           } else if (abcPitchClassName.equals("g") ) {
60               note.rp(11);
61           } else if (abcPitchClassName.equals("A") ) {
62               note.rp(5);
63           } else if (abcPitchClassName.equals("A,") ) {
64               note.lp(2);
65           } else if (abcPitchClassName.equals("a") ) {
66               note.rp(12);
67           } else if (abcPitchClassName.equals("B") ) {
68               note.rp(6);
69           } else if (abcPitchClassName.equals("B,") ) {
70               note.lp(1);
71           } else if (abcPitchClassName.equals("b") ) {
72               note.rp(13);
73           }
74   
75   
76           return note;
77       }
78       private Color getPitchClassColor(String letter) {
79           if (letter.equals("C") ) {
80               return new Color (127,0,127);
81           } else if (letter.equals("D") ) {
82               return new Color (255,255,0);
83           } else if (letter.equals("E") ) {
84               return new Color(255,0,0);
85           } else if (letter.equals("A") ) {
86               return new Color(0,0,255);
87           } else if (letter.equals("B") ) {
88               return new Color(0,255,0);
89           } else if (letter.equals("F")) {
90               return new Color(255,127,0);
91           } else if (letter.equals("G")) {
92               return new Color(0,255,255);
93           } else {
94               return Color.BLACK;
95           }
96       }
97       public void play(String d) {
98           painter.setColor(color);
99           painter.paint(box);
100          painter.setColor(randomColor());
101          painter.draw(box);
102          if (d.equals("1") ) {
103              note.play();
104          } else if (d.equals("2") ) {
105              note.x2(); note.play();
106              note.s2();
107          } else if (d.equals("1/2") ) {
108              note.s2(); note.play();
109              note.x2();
110          } else if (d.equals("3") ) {
111              note.x3(); note.play();
112              note.s3();
113          } else if (d.equals("1/3")) {
114              note.s3(); note.play();
115              note.x3();
116          } else if (d.equals("2/3")) {
117              note.s3(); note.x2();
118              note.play();
119              note.s2(); note.x3();
120          }
121      }
122  
123      private Color randomColor() {
124          int rv = (int) (Math.random()*256);
125          int gv = (int) (Math.random()*256);
126          int bv = (int) (Math.random()*256);
127          return new Color(rv,gv,bv);
128      }
129  }
130