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