]> ruin.nu Git - moosique.git/blobdiff - MooKeyboard.java
no message
[moosique.git] / MooKeyboard.java
index 0ebfa63f063dd6f0cec8aeda527594d63156e0bd..2a2bd9ead52f0797785de9e127154f2d6a965a11 100644 (file)
@@ -1,8 +1,8 @@
 import javax.sound.midi.*;
 import java.awt.event.*;
 
-/*
- * Functional representation of a MIDI note, which contains two MIDI events, note on and note off.
+/**
+ * A keyboard listener emulating a synthesizer.
  * 
  * @author  Einar Pehrson
  */
@@ -10,10 +10,10 @@ import java.awt.event.*;
 public class MooKeyboard extends KeyAdapter {
 
        private boolean[] isOn = new boolean[120];
-       private static final int startNote = 48;
+       private static int startNote = 48;
        private static final int[] keyToNote = new int[120];
 
-       /*
+       /**
         * Plays the appropriate MIDI NoteOn event.
         */
        public void keyPressed(KeyEvent e) {
@@ -23,12 +23,13 @@ public class MooKeyboard extends KeyAdapter {
                        // If note is not already on and the key is mapped to a note, sends the NoteOn event.
                        if (!isOn[noteNumber] && noteNumber > 0) Moosique.getActiveChannel().noteOn(noteNumber, 127);
                        isOn[noteNumber] = true;
+                       System.out.println("NoteON");
                } catch (ArrayIndexOutOfBoundsException x) {
                        return;
                }
        }
        
-       /*
+       /**
         * Plays the appropriate MIDI NoteOff event.
         */
        public void keyReleased(KeyEvent e) {
@@ -38,12 +39,21 @@ public class MooKeyboard extends KeyAdapter {
                        // Sends the NoteOff event.
                        Moosique.getActiveChannel().noteOff(noteNumber);
                        isOn[noteNumber] = false;
+                       System.out.println("NoteOFF");
                } catch (ArrayIndexOutOfBoundsException x) {
                        return;
                }
        }
 
-       /* Maps keycodes (array indices) to MIDI note numbers using the following layout:
+       /**
+        * Sets the octave of the lower part of the keyboard (default = 4)
+        * @param n     the octave to start at
+        */
+       public static void setOctave(int n) {
+               startNote = n * 12;
+       }
+
+       /** Maps keycodes (array indices) to MIDI note numbers using the following layout:
         *
         *  2 3   5 6 7   9 0   =>  # #   # # #   # #
         * q w e r t y u i o p  => c d e f g a b c d e
@@ -51,7 +61,7 @@ public class MooKeyboard extends KeyAdapter {
         * z x c v b n m , .    => c d e f g a b c d
         */
        static {
-               keyToNote[90] = startNote;
+               keyToNote[KeyEvent.VK_Q] = startNote;
                keyToNote[83] = startNote + 1;
                keyToNote[88] = startNote + 2;
                keyToNote[68] = startNote + 3;
@@ -84,4 +94,4 @@ public class MooKeyboard extends KeyAdapter {
                keyToNote[48] = startNote + 27;
                keyToNote[80] = startNote + 28;
        }
-}
\ No newline at end of file
+}