]> ruin.nu Git - moosique.git/blobdiff - MooKeyboard.java
no message
[moosique.git] / MooKeyboard.java
index 2a2bd9ead52f0797785de9e127154f2d6a965a11..7031c40711c1831c50802947fe01cf186066b1e2 100644 (file)
@@ -9,9 +9,18 @@ import java.awt.event.*;
  
 public class MooKeyboard extends KeyAdapter {
 
-       private boolean[] isOn = new boolean[120];
-       private static int startNote = 48;
-       private static final int[] keyToNote = new int[120];
+       private boolean[] isOn;
+       private static int startNote;
+       private static int[] keyToNote;
+
+       /**
+        * Sets up the synthesizer emulation.
+        */
+       public MooKeyboard() {
+               isOn = new boolean[120];
+               keyToNote = new int[120];
+               setOctave(4);
+       }
 
        /**
         * Plays the appropriate MIDI NoteOn event.
@@ -23,7 +32,6 @@ 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;
                }
@@ -39,7 +47,6 @@ public class MooKeyboard extends KeyAdapter {
                        // Sends the NoteOff event.
                        Moosique.getActiveChannel().noteOff(noteNumber);
                        isOn[noteNumber] = false;
-                       System.out.println("NoteOFF");
                } catch (ArrayIndexOutOfBoundsException x) {
                        return;
                }
@@ -50,7 +57,9 @@ public class MooKeyboard extends KeyAdapter {
         * @param n     the octave to start at
         */
        public static void setOctave(int n) {
-               startNote = n * 12;
+               if (startNote == 0 || startNote == 108) return;
+               startNote += n*12;
+               makeKeyboardMapping();
        }
 
        /** Maps keycodes (array indices) to MIDI note numbers using the following layout:
@@ -60,7 +69,7 @@ public class MooKeyboard extends KeyAdapter {
         *  s d   g h j   l     =>  # #   # # #   #
         * z x c v b n m , .    => c d e f g a b c d
         */
-       static {
+       private static void makeKeyboardMapping() {
                keyToNote[KeyEvent.VK_Q] = startNote;
                keyToNote[83] = startNote + 1;
                keyToNote[88] = startNote + 2;