/home/jfernan6/NetBeansProjects/CSX/src/chromesthesia2/Pitch.java
  1   /*
  2    * The Pitch class models pitch of a note in a manner that will facilitate
  3    * the chromesthetic processing of the pitch. 
  4    * A Pitch object will have five properties:
  5    * - String name | ABC notation pitch name
  6    * - SPainter painter | the painting agent
  7    * - Note note | a note that will be set to the pitch corresponding to the ABC 
  8    *   notation pitch name
  9    * - SRectangle box | an SRectangle object that will chromesthetically 
 10    *   represent the pitch
 11    * - Color color | the color associated with the pitch for the presumed 
 12    * chromesthesia.
 13    */
 14   package chromesthesia2;
 15  
 16   import java.awt.Color;
 17   import note.SNote;
 18   import painter.SPainter;
 19   import shapes.SRectangle;
 20   
 21   /**
 22    *
 23    * @author jfernan6
 24    */
 25  public class Pitch {
 26   
 27       // INSTANCE VARIABLES
 28       private String abcName;
 29       private SPainter painter;
 30       private SRectangle box;
 31       private SNote note;
 32       private Color color;
 33   
 34      public Pitch(String abcName, SPainter painter) {
 35           this.abcName = abcName;
 36           this.painter = painter;
 37           this.box = new SRectangle(painter.painterHeight - 50, painter.painterWidth - 50);
 38           this.note = createNoteForThisPitch(abcName);
 39           this.color = getPitchClassColor(abcName.substring(0, 1).toUpperCase());
 40       }
 41   
 42       public String toString() {
 43           return "[" + abcName + "|" + note.degree() + "|" + color + "]";
 44       }
 45   
 46       public String abcName() {
 47           return abcName;
 48       }
 49   
 50       private SNote createNoteForThisPitch(String abcPitchClassName) {
 51           SNote note = new SNote();
 52           if (abcPitchClassName.equals("C")) {
 53              // nothing to do
 54           } else if (abcPitchClassName.equals("C,")) {
 55               note.lp(7);
 56           } else if (abcPitchClassName.equals("c")) {
 57               note.rp(7);
 58           } else if (abcPitchClassName.equals("D")) {
 59               note.rp(1);
 60           } else if (abcPitchClassName.equals("D,")) {
 61               note.lp(6);
 62           } else if (abcPitchClassName.equals("d")) {
 63               note.rp(8);
 64           } else if (abcPitchClassName.equals("E")) {
 65               note.rp(2);
 66           } else if (abcPitchClassName.equals("E,")) {
 67              note.lp(5);
 68           } else if (abcPitchClassName.equals("e")) {
 69               note.rp(9);
 70           } else if (abcPitchClassName.equals("F")) {
 71               note.rp(3);
 72           } else if (abcPitchClassName.equals("F,")) {
 73               note.lp(6);
 74           } else if (abcPitchClassName.equals("f")) {
 75               note.rp(2);
 76           } else if (abcPitchClassName.equals("G")) {
 77               note.rp(8);
 78           } else if (abcPitchClassName.equals("G,")) {
 79               note.lp(3);
 80           } else if (abcPitchClassName.equals("g")) {
 81               note.rp(3);
 82           } else if (abcPitchClassName.equals("A")) {
 83               note.rp(2);
 84           } else if (abcPitchClassName.equals("A,")) {
 85               note.lp(5);
 86           } else if (abcPitchClassName.equals("a")) {
 87               note.rp(9);
 88           } else if (abcPitchClassName.equals("B")) {
 89               note.rp(6);
 90           } else if (abcPitchClassName.equals("B,")) {
 91               note.lp(6);
 92           } else if (abcPitchClassName.equals("b")) {
 93               note.rp(2);
 94           } else if (abcPitchClassName.equals("H")) {
 95               note.rp(2);
 96           } else if (abcPitchClassName.equals("H,")) {
 97               note.lp(4);
 98           } else if (abcPitchClassName.equals("h")) {
 99               note.rp(5);
100          } else if (abcPitchClassName.equals("I")) {
101              note.rp(1);
102          } else if (abcPitchClassName.equals("I,")) {
103              note.lp(1);
104          } else if (abcPitchClassName.equals("i")) {
105              note.rp(1);
106          }         return note;
107      }
108  
109      private Color getPitchClassColor(String letter) {
110          if (letter.equals("C")) {
111              return new Color(127,0,127);
112          } else if (letter.equals("D")) {
113              return new Color(255, 255, 0);
114          } else if (letter.equals("E")) {
115              return new Color(255, 0, 0);
116          } else if (letter.equals("F")) {
117              return new Color(255, 127, 0);
118         } else if (letter.equals("G")) {
119              return new Color(0, 255, 255);
120          } else if (letter.equals("A")) {
121              return new Color(0, 0, 255);
122          } else if (letter.equals("B")) {
123              return new Color(0, 127, 255);
124          } else if (letter.equals("H")) {
125              return new Color(0, 127, 127);
126          } else if (letter.equals("I")) {
127              return new Color(127, 0, 0);
128          } else {
129              return Color.BLACK;
130          }
131      }
132  
133      public void play(String d) {
134         painter.setColor(color);
135          painter.paint(box);
136          painter.setColor(randomColor());
137          painter.draw(box);
138          if (d.equals("1")) {
139              note.play();
140          } else if (d.equals("2")){
141              note.x2();
142              note.play();
143              note.s2();
144          } else if (d.equals("1/2")) {
145              note.s2();
146              note.play();
147              note.x2();
148          } else if (d.equals("3")) {
149              note.x3();
150              note.play();
151              note.s3();
152          } else if (d.equals("1/3")) {
153              note.s3();
154              note.play();
155              note.x3();
156          } else if (d.equals("2/3")) {
157              note.s3();
158              note.x2();
159              note.play();
160              note.s2();
161              note.x3();       
162          }
163      }
164  
165      private Color randomColor() {
166          int rv = (int) (Math.random() * 256);
167          int gv = (int) (Math.random() * 256);
168          int bv = (int) (Math.random() * 256);
169          return new Color(rv, gv, bv);
170      }
171  
172  }
173