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