/Users/lyon/j4p/src/sound/soundDemo/Key.java

1    /** 
2     * Created by IntelliJ IDEA. 
3     * User: dlyon 
4     * Date: Oct 1, 2003 
5     * Time: 1:08:41 PM 
6     * To change this template use Options | File Templates. 
7     */ 
8    package sound.soundDemo; 
9     
10   import java.awt.*; 
11    
12   public class Key extends Rectangle { 
13    
14       int kNum; 
15       private MidiSynth midiSynth; 
16       int noteState = midiSynth.OFF; 
17    
18       public Key(MidiSynth midiSynth, int x, int y, int width, int height, int num) { 
19           super(x, y, width, height); 
20           this.midiSynth = midiSynth; 
21    
22           kNum = num; 
23       } 
24    
25       public boolean isNoteOn() { 
26           return noteState == midiSynth.ON; 
27       } 
28    
29       public void on() { 
30           setNoteState(midiSynth.ON); 
31           midiSynth.cc.channel.noteOn(kNum, midiSynth.cc.velocity); 
32           if (midiSynth.record) { 
33               midiSynth.createShortEvent(midiSynth.NOTEON, kNum); 
34           } 
35       } 
36    
37       public void off() { 
38           setNoteState(midiSynth.OFF); 
39           midiSynth.cc.channel.noteOff(kNum, midiSynth.cc.velocity); 
40           if (midiSynth.record) { 
41               midiSynth.createShortEvent(midiSynth.NOTEOFF, kNum); 
42           } 
43       } 
44    
45       public void setNoteState(int state) { 
46           noteState = state; 
47       } 
48   } // End class Key 
49