/home/jfernan6/NetBeansProjects/CSX/src/chromesthesia1/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    *   chromesthete
 13    */
 14   package chromesthesia1;
 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           }
 95           return note;
 96       }
 97   
 98       private Color getPitchClassColor(String letter) {
 99           if (letter.equals("C")) {
100              return Color.BLUE;
101          } else if (letter.equals("D")) {
102              return Color.GREEN;
103         } else if (letter.equals("E")) {
104              return new Color(40, 0, 10);
105          } else if (letter.equals("F")) {
106              return Color.RED;
107          } else if (letter.equals("G")) {
108              return new Color(194, 22, 98);
109          } else if (letter.equals("A")) {
110              return new Color(103, 0, 103);
111          } else if (letter.equals("B")) {
112              return new Color(230, 66, 230);
113          } else {
114              return Color.BLACK;
115          }
116      }
117  
118      public void play(String d) {
119          painter.setColor(color);
120          painter.paint(box);
121          painter.setColor(randomColor());
122          painter.draw(box);
123          if (d.equals("1")) {
124              note.play();
125         }
126      }
127  
128      private Color randomColor() {
129          int rv = (int) (Math.random() * 256);
130          int gv = (int) (Math.random() * 256);
131          int bv = (int) (Math.random() * 256);
132          return new Color(rv, gv, bv);
133      }
134  
135  }
136