/home/sjenks/NetBeansProjects/CS1/src/chromesthesia2/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 chromesthesia2;
 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        }else if (abcPitchClassName.equals("F")){
 68            note.rp(3);
 69        } else if (abcPitchClassName.equals("F,")){
 70            note.lp(4);
 71        }else if (abcPitchClassName.equals("f")){
 72            note.rp(10);
 73        }else if (abcPitchClassName.equals("G")){
 74            note.rp(4);
 75        } else if (abcPitchClassName.equals("G,")){
 76            note.lp(3);
 77        }else if (abcPitchClassName.equals("g")){
 78            note.rp(11);
 79        }else if (abcPitchClassName.equals("A")){
 80            note.rp(5);
 81        } else if (abcPitchClassName.equals("A,")){
 82            note.lp(2);
 83        }else if (abcPitchClassName.equals("a")){
 84            note.rp(12);
 85        }else if (abcPitchClassName.equals("B")){
 86            note.rp(6);
 87        } else if (abcPitchClassName.equals("B,")){
 88            note.lp(1);
 89        }else if (abcPitchClassName.equals("b")){
 90            note.rp(13);
 91        }
 92        return note;
 93     }
 94 
 95     private Color getPitchClassColor(String letter) {
 96         if ( letter.equals ("C")){
 97             return new Color(0,255,0);
 98         }else if (letter.equals ("D")){
 99             return new Color(255,255,0);
100         }else if (letter.equals ("E")){
101             return new Color(255,255,0);
102         }else if (letter.equals ("F")){
103             return new Color(25,127,0);
104         }else if (letter.equals ("G")){
105             return new Color(0,255,255);
106         }else if (letter.equals ("A")){
107             return new Color(0,0,255);
108         }else if (letter.equals ("B")){
109             return new Color(0,255,0);
110         }else { 
111             return Color.BLACK;
112         }
113     }
114     
115     public void play ( String d) {
116         painter.setColor (color);
117         painter.paint(box);
118         painter.setColor(randomColor());
119         painter.draw (box);
120         if ( d.equals("1")){
121             note.play();
122         }else if (d.equals("2")){
123             note.x2();
124             note.play();
125             note.s2();
126         }else if (d.equals("1/2")){
127             note.s2();
128             note.play();
129             note.x2();          
130         } else if (d.equals("3")){
131             note.x3();
132             note.play();
133             note.s3();
134         }else if (d.equals("1/3")){
135             note.s3();
136             note.play();
137             note.x3();
138         }else if (d.equals("2/3")){
139             note.x2();
140             note.s3();
141             note.play();
142             note.s2();
143             note.x3();
144         }
145     }
146     
147     private static Color randomColor(){
148         int rv = (int) (Math.random()*256);
149         int gv = (int) (Math.random()*256);
150         int bv = (int) (Math.random()*256);
151         return new Color (rv,gv,bv);
152     }
153 }
154