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