/Users/lyon/j4p/src/sound/musica/KeyProcessor.java

1    package sound.musica; 
2     
3    /* 
4     * Open Source Software by http://www.Docjava.com 
5     * programmer: D. Lyon 
6     * e-mail: lyon@docjava.com 
7     * Date: Apr 30, 2002 
8     * Time: 3:40:56 PM 
9     */ 
10    
11   import sound.*; 
12   import sound.Scales; 
13   import sound.Utils; 
14    
15   import java.awt.event.KeyEvent; 
16   import java.awt.event.KeyListener; 
17    
18   public class KeyProcessor 
19           implements KeyListener { 
20       int scale[] = sound.Scales.getScale( 
21               Scales.CHROMATIC, 23, 64); 
22    
23       PetriNodes pn = SongReader.initMarkov(20); 
24       KeyMap km = new KeyMap(); 
25    
26    
27       public void keyPressed(KeyEvent 
28               e) { 
29           int c = e.getKeyChar(); 
30    
31           Utils.noteOn(km.getNoteNumber(c), 127); 
32       } 
33    
34       public void keyTyped(KeyEvent 
35               e) { 
36           /* 
37            int c = e.getKeyChar(); 
38            System.out.println("key="+c); 
39            if (e.isAltDown()) { 
40                (pn.getNode(c % 9)).play(); 
41                return; 
42            } 
43    
44            if (e.isShiftDown()) 
45                Utils.play(SongReader.getNextNote()); 
46            else 
47                Utils.play(scale[c % scale.length], -1); 
48           */ 
49       } 
50    
51       public void keyReleased(KeyEvent 
52               e) { 
53           int c = e.getKeyChar(); 
54           System.out.println("key released:" + c); 
55           Utils.noteOff(km.getNoteNumber(c)); 
56       } 
57   } 
58