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