1 package Chromes; 2 3 import java.awt.Color; 4 import note.SNote; 5 import painter.SPainter; 6 import shapes.SRectangle; 7 8 public class Pitch { 9 10 // INSTANCE VARIABLES 11 private String abcName; 12 private SPainter painter; 13 private SRectangle box; 14 private SNote note; 15 private Color color; 16 17 public Pitch(String abcName, SPainter painter) { 18 this.abcName = abcName; 19 this.painter = painter; 20 this.box = new SRectangle(painter.painterHeight-50,painter.painterWidth-50); 21 this.note = createNoteForThisPitch(abcName); 22 this.color = getPitchClassColor(abcName.substring(0,1).toUpperCase()); 23 } 24 25 public String toString() { 26 return "[ " + abcName + " | " + note.degree() + " | " + color + " ]"; 27 } 28 29 public String abcName() { 30 return abcName; 31 } 32 33 private SNote createNoteForThisPitch(String abcPitchClassName) { 34 SNote note = new SNote(); 35 if ( abcPitchClassName.equals("C") ) { 36 37 // nothing to do 38 } else if ( abcPitchClassName.equals("C,") ) { 39 note.lp(7); 40 } else if ( abcPitchClassName.equals("c") ) { 41 note.rp(7); 42 } else if ( abcPitchClassName.equals("D") ) { 43 note.rp(1); 44 } else if ( abcPitchClassName.equals("D,") ) { 45 note.lp(6); 46 } else if ( abcPitchClassName.equals("d") ) { 47 note.rp(8); 48 } else if ( abcPitchClassName.equals("E") ) { 49 note.rp(2); 50 } else if ( abcPitchClassName.equals("E,") ) { 51 note.lp(5); 52 } else if ( abcPitchClassName.equals("e") ) { 53 note.rp(9); 54 } 55 return note; 56 } 57 58 private Color getPitchClassColor(String letter) { 59 if ( letter.equals("C") ) { 60 return Color.BLUE; 61 } else if ( letter.equals("D") ) { 62 return Color.GREEN; 63 } else if ( letter.equals("E") ) { 64 return new Color(127,0,127); 65 } else { 66 return Color.BLACK; 67 } 68 } 69 70 public void play(String d) { 71 painter.setColor(color); 72 painter.paint(box); 73 painter.setColor(randomColor()); 74 painter.draw(box); 75 if ( d.equals("1") ) { 76 note.play(); 77 } 78 } 79 80 private static Color randomColor() { 81 int rv = (int)(Math.random()*256); 82 int gv = (int)(Math.random()*256); 83 int bv = (int)(Math.random()*256); 84 return new Color(rv,gv,bv); 85 } 86 } 87