/home/sjenks/NetBeansProjects/CS1/src/chromesthesia0/Pitch.java
  1 /*
  2  * The Pitch class models the pitch of a note in a manner that will faciliate 
  3  * the chromesthetic processing of the pitch. A Pitch object will have five 
  4  * properties:
  5  * - String name | ABC notaion pitch name
  6  * - Note note | a note that will be set to the pitch coresponding to the 
  7  *   ABC notation pitch name
  8  * - SRectangle box | an SRectangle object that will chromesthetically
  9  *   represent the pitch
 10  * - Color color | the color associated with the pitch for the presumed chromesthete
 11  */
 12 package chromesthesia0;
 13 import java.awt.Color;
 14 import note.SNote;
 15 import painter.SPainter;
 16 import shapes.SRectangle;
 17 
 18 /**
 19  *
 20  * @author sjenks
 21  */
 22 class Pitch {
 23     // INSTANCE VARIABLES
 24     private String abcName;
 25     private SPainter painter;
 26     private SRectangle box;
 27     private SNote note;
 28     private Color color;
 29     
 30     public Pitch (String abcName, SPainter painter){
 31         this.abcName = abcName;
 32         this.painter = painter;
 33         this.box = new SRectangle( painter.painterHeight-50, painter.painterWidth-50);
 34         this.note = createNoteForThisPitch(abcName);
 35         this.color = getPitchClassColor(abcName.substring (0,1).toUpperCase());
 36         
 37     }
 38     
 39     public String toString (){
 40         return "[ " + abcName + " | " + note.degree() + " | " + color + " ]";
 41     }
 42     
 43     public String abcName(){
 44         return abcName;
 45     }
 46 
 47     private SNote createNoteForThisPitch(String abcPitchClassName) {
 48        SNote note = new SNote();
 49        if (abcPitchClassName.equals("C")){
 50            //nothing to do
 51        } else if (abcPitchClassName.equals("C,")){
 52            note.lp(7);
 53        }else if (abcPitchClassName.equals("c")){
 54            note.rp(7);
 55        }else if (abcPitchClassName.equals("D")){
 56            note.rp(1);
 57        } else if (abcPitchClassName.equals("D,")){
 58            note.lp(6);
 59        }else if (abcPitchClassName.equals("d")){
 60            note.rp(8);
 61        }else if (abcPitchClassName.equals("E")){
 62            note.rp(2);
 63        } else if (abcPitchClassName.equals("E,")){
 64            note.lp(5);
 65        }else if (abcPitchClassName.equals("e")){
 66            note.rp(9);
 67        }
 68        return note;
 69     }
 70 
 71     private Color getPitchClassColor(String letter) {
 72         if ( letter.equals ("C")){
 73             return Color.BLUE;
 74         }else if (letter.equals ("D")){
 75             return Color.GREEN;
 76         }else if (letter.equals ("E")){
 77             return new Color(127,0,127);
 78         }else { 
 79             return Color.BLACK;
 80         }
 81     }
 82     
 83     public void play ( String d) {
 84         painter.setColor (color);
 85         painter.paint(box);
 86         painter.setColor(randomColor());
 87         painter.draw (box);
 88         if ( d.equals ("1")){
 89             note.play();
 90         }
 91     }
 92     
 93     private static Color randomColor(){
 94         int rv = (int) (Math.random()*256);
 95         int gv = (int) (Math.random()*256);
 96         int bv = (int) (Math.random()*256);
 97         return new Color (rv,gv,bv);
 98     }
 99 }
100