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