Pitch.java
1    package chromesthesia2;
2    
3    import java.awt.Color;
4    import note.SNote;
5    import painter.SPainter;
6    import shapes.SRectangle;
7    public class Pitch {
8        //instance variables
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 toSting(){
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           }else if(abcPitchClassName.equals("C,")){
32               note.lp(7);
33           }else if(abcPitchClassName.equals("c")) {
34               note.rp(7);
35           }else if(abcPitchClassName.equals("D")) {
36               note.rp(1);
37           }else if(abcPitchClassName.equals("D,")) {
38               note.lp(6);
39           }else if(abcPitchClassName.equals("d")) {
40               note.rp(8);
41           }else if(abcPitchClassName.equals("E")) {
42               note.rp(2);
43           }else if(abcPitchClassName.equals("E,")) {
44               note.lp(5);
45           }else if(abcPitchClassName.equals("e")) {
46               note.rp(9);
47           }else if(abcPitchClassName.equals("F")) {
48               note.rp(2);
49           }else if(abcPitchClassName.equals("F,")) {
50               note.lp(5);
51           }else if(abcPitchClassName.equals("f")) {
52               note.rp(9);
53           }else if(abcPitchClassName.equals("G")) {
54               note.rp(2);
55           }else if(abcPitchClassName.equals("G,")) {
56               note.lp(5);
57           }else if(abcPitchClassName.equals("g")) {
58               note.rp(9);
59           }else if(abcPitchClassName.equals("A")) {
60               note.rp(2);
61           }else if(abcPitchClassName.equals("A,")) {
62               note.lp(5);
63           }else if(abcPitchClassName.equals("a")) {
64               note.rp(9);
65           }else if(abcPitchClassName.equals("B")) {
66               note.rp(2);
67           }else if(abcPitchClassName.equals("B,")) {
68               note.lp(5);
69           }else if(abcPitchClassName.equals("b")) {
70               note.rp(9);
71           }
72           return note;
73       }
74       private Color getPitchClassColor(String letter){
75           if(letter.equals("C")){
76               return new Color(127,0,127);
77           }else if (letter.equals("D")){
78               return new Color(255,255,0);
79           }else if (letter.equals("E")){
80               return new Color(255,0,0);
81           }else if (letter.equals("F")){
82               return new Color(255,127,0);
83           }else if (letter.equals("G")){
84               return new Color(0,225,225);
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{
90               return Color.BLACK;
91           }
92       }
93       public void play(String d){
94           painter.setColor(color);
95           painter.paint(box);
96           painter.setColor(randomColor());
97           painter.draw(box);
98           if(d.equals("1")){
99               note.play();
100          }else if (d.equals("1/2")){
101              note.s2();
102              note.play();
103              note.x2();
104          }else if (d.equals("2")){
105              note.x2();
106              note.play();
107              note.s2();
108          }else if (d.equals("3")){
109              note.x3();
110              note.play();
111              note.s3();
112          }else if (d.equals("1/3")){
113              note.s3();
114              note.play();
115              note.x3();
116          }else if (d.equals("2/3")){
117              note.s3();
118              note.x2();
119              note.play();
120              note.s2();
121              note.x3();
122          }
123      }
124      private static Color randomColor(){
125          int rv=(int)(Math.random()*256);
126          int gv=(int)(Math.random()*256);
127          int bv=(int)(Math.random()*256);
128          return new Color(rv,gv,bv);
129      }
130  }
131