Pitch.java
1    package Chromesthesia2;
2    
3    import note.SNote;
4    import painter.SPainter;
5    import shapes.SRectangle;
6    import java.awt.*;
7    
8    public class Pitch {
9    
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   
24       public String toString() {
25           return "[ " + abcName + " | " + note.degree() + " | " + color + " ]";
26       }
27   
28       public String abcName() {
29           return abcName;
30       }
31   
32       private SNote createNoteForThisPitch(String abcPitchClassName) {
33           SNote note = new SNote();
34           if ( abcPitchClassName.equals("C") ) {
35               //idk
36           } else if ( abcPitchClassName.equals("C,") ) {
37               note.lp(7);
38           } else if ( abcPitchClassName.equals("c") ) {
39               note.rp(7);
40           } else if ( abcPitchClassName.equals("D") ) {
41               note.rp(1);
42           } else if ( abcPitchClassName.equals("D,") ) {
43               note.lp(6);
44           } else if ( abcPitchClassName.equals("d") ) {
45               note.rp(8);
46           } else if ( abcPitchClassName.equals("E") ) {
47               note.rp(2);
48           } else if ( abcPitchClassName.equals("E,") ) {
49               note.lp(5);
50           } else if ( abcPitchClassName.equals("e") ) {
51               note.rp(9);
52           } else if ( abcPitchClassName.equals("F") ) {
53               note.rp(3);
54           } else if ( abcPitchClassName.equals("F,") ) {
55               note.lp(4);
56           } else if ( abcPitchClassName.equals("f") ) {
57               note.rp(10);
58           } else if ( abcPitchClassName.equals("G") ) {
59               note.rp(4);
60           } else if ( abcPitchClassName.equals("G,") ) {
61               note.lp(3);
62           } else if ( abcPitchClassName.equals("g") ) {
63               note.rp(11);
64           } else if ( abcPitchClassName.equals("A") ) {
65               note.rp(5);
66           } else if ( abcPitchClassName.equals("A,") ) {
67               note.lp(2);
68           } else if ( abcPitchClassName.equals("a") ) {
69               note.rp(12);
70           } else if ( abcPitchClassName.equals("B") ) {
71               note.rp(6);
72           } else if ( abcPitchClassName.equals("B,") ) {
73               note.lp(1);
74           } else if ( abcPitchClassName.equals("b") ) {
75               note.rp(13);
76           }return note;
77       }
78   
79       private Color getPitchClassColor(String letter) {
80           if ( letter.equals("C") ) {
81               return new Color(127,0,127);
82           } else if ( letter.equals("D") ) {
83               return new Color(225,255,0);
84           } else if ( letter.equals("E") ) {
85               return new Color(255, 0, 0);
86           } else if (letter.equals("F")) {
87               return new Color(255, 127, 0);
88           } else if (letter.equals("G")) {
89               return new Color(0, 255, 255);
90           }else if (letter.equals("A")) {
91               return new Color(0, 0, 225);
92           }else if (letter.equals("B")){
93               return new Color(0,255,0);
94           } else {
95               return Color.BLACK;
96           }
97       }
98   
99       public void play(String d) {
100          painter.setColor(color);
101          painter.paint(box);
102          painter.setColor(randomColor());
103          painter.draw(box);
104          if ( d.equals("1") ) {
105              note.play();
106          }
107          else if (d.equals("2")) {
108              note.x2(); note.play(); note.s2();
109          }
110          else if(d.equals("1/2")) {
111              note.s2(); note.play(); note.x2();
112          }
113          else if(d.equals("3")) {
114              note.x3(); note.play(); note.s3();
115          }
116          else if(d.equals("1/3")) {
117              note.s3(); note.play(); note.x3();
118          }
119          else if(d.equals("2/3")) {
120              note.s3(); note.x2(); note.play(); note.x3(); note.s2();
121          }
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  }