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 chromesthesia1; 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 Color.BLUE; 76 }else if (letter.equals("D")) { 77 return Color.GREEN; 78 }else if (letter.equals("E")) { 79 return new Color(127, 0, 127); 80 }else if (letter.equals("F")) { 81 return Color.RED; 82 }else if (letter.equals("G")) { 83 return Color.YELLOW; 84 }else if (letter.equals("A")) { 85 return Color.CYAN; 86 }else if (letter.equals("B")){ 87 return Color.ORANGE; 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 } 100 } 101 102 private Color randomColor() { 103 int rv = (int)(Math.random() * 256); 104 int gv = (int)(Math.random() * 256); 105 int bv = (int)(Math.random() * 256); 106 return new Color(rv,gv,bv); 107 } 108 109 }