Pitch.java
1    package chromesthesia0;
2    import java.awt.Color;
3    import note.SNote;
4    import painter.SPainter;
5    import shapes.SRectangle;
6    //This is the most basic Pitch Program, it is Pitch Program 0.
7    //This program works with the Basic Chromesthesia Program...0
8    public class Pitch {
9        private String abcName;
10       private SPainter painter;
11       private SRectangle box;
12       private SNote note;
13       private Color color;
14   
15       public Pitch(String abcName, SPainter painter) {
16           this.abcName = abcName;
17           this.painter = painter;
18           this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50);
19           this.note = createNoteForThisPitch(abcName);
20           this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase());
21       }
22       public String toString() {
23           return "[ " + abcName + " | " + note.degree() + " | " + color + " ]";
24       }
25       public String abcName() {
26           return abcName;
27       }
28       private SNote createNoteForThisPitch(String abcPitchClassName) {
29           SNote note = new SNote();
30           if (abcPitchClassName.equals("C") ) {
31               //nothing will be done
32           } else if (abcPitchClassName.equals("C,") ) {
33               note.lp(7);
34           } else if (abcPitchClassName.equals("c") ) {
35               note.rp(7);
36           } else if (abcPitchClassName.equals("D") ) {
37               note.rp(1);
38           } else if (abcPitchClassName.equals("D,") ) {
39               note.lp(6);
40           } else if (abcPitchClassName.equals("d") ) {
41               note.rp(8);
42           } else if (abcPitchClassName.equals("E") ) {
43               note.rp(2);
44           } else if (abcPitchClassName.equals("E,") ) {
45               note.lp(5);
46           } else if (abcPitchClassName.equals("e") ) {
47               note.rp(9);
48           }
49   
50           return note;
51       }
52       private Color getPitchClassColor(String letter) {
53           if (letter.equals("C") ) {
54               return Color.BLUE;
55           } else if (letter.equals("D") ) {
56               return Color.GREEN;
57           } else if (letter.equals("E") ) {
58               return new Color(127,0,127);
59           } else {
60               return Color.BLACK;
61           }
62       }
63       public void play(String d) {
64           painter.setColor(color);
65           painter.paint(box);
66           painter.setColor(randomColor());
67           painter.draw(box);
68           if (d.equals("1") ) {
69               note.play();
70           }
71       }
72   
73       private Color randomColor() {
74           int rv = (int) (Math.random()*256);
75           int gv = (int) (Math.random()*256);
76           int bv = (int) (Math.random()*256);
77           return new Color(rv,gv,bv);
78       }
79   }
80