1 /* 2 * The pitch class models the pitch of a note in a manner that will facilitate the Chromesthetic processing of the pitch. A pitch object will have five properties: 3 * -String name | ABC notation pitch name 4 * - SPainter painter | the painting agent 5 * - Note note | a note that will be set to the pitch corresponding to the ABC notation pitch name 6 * -SRectangle box | an SRectangle object that will chromesthetically represent the pitch 7 * -Color color | the color associated with the pitch for the presumed chromesthete. 8 * */ 9 10 package chromesthesia0; 11 12 import note.SNote; 13 import painter.SPainter; 14 import shapes.SRectangle; 15 16 import java.awt.*; 17 18 public class Pitch { 19 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 } 48 else if ( abcPitchClassName.equals("C,") ) { 49 note.lp(7); 50 } 51 else if ( abcPitchClassName.equals("c") ) { 52 note.rp(7); 53 } 54 else if ( abcPitchClassName.equals("D") ) { 55 note.rp(1); 56 } 57 else if ( abcPitchClassName.equals("D,") ) { 58 note.lp(6); 59 } 60 else if ( abcPitchClassName.equals("d")) { 61 note.rp(8); 62 } 63 else if ( abcPitchClassName.equals("E")) { 64 note.rp(2); 65 } 66 else if ( abcPitchClassName.equals("E,")) { 67 note.lp(5); 68 } 69 else if ( abcPitchClassName.equals("e")) { 70 note.rp(9); 71 } 72 return note; 73 } 74 75 private Color getPitchClassColor(String letter) { 76 if ( letter.equals("C") ) { 77 return Color.blue; 78 } 79 else if ( letter.equals("D")) { 80 return Color.green; 81 } 82 else if ( letter.equals("E")) { 83 return new Color(127, 0,127); 84 } 85 else { 86 return Color.black; 87 } 88 } 89 90 public void play(String d) { 91 painter.setColor(color); 92 painter.paint(box); 93 painter.setColor(randomColor()); 94 painter.draw(box); 95 if ( d.equals("1")) { 96 note.play(); 97 } 98 } 99 100 private static Color randomColor() { 101 int rv = (int)(Math.random()*256); 102 int gv = (int)(Math.random()*256); 103 int bv = (int)(Math.random()*256); 104 return new Color(rv, gv, bv); 105 } 106 107 } 108