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