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