X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooKeyboard.java;h=7031c40711c1831c50802947fe01cf186066b1e2;hb=a8b0b5e27d120df964c5b6d8554a6207951b00d0;hp=90ed18fd4acf3d582b7569f08f16c23b25fc4ebc;hpb=e49990e17bff158ad638a16ba4aa616673b94627;p=moosique.git diff --git a/MooKeyboard.java b/MooKeyboard.java index 90ed18f..7031c40 100644 --- a/MooKeyboard.java +++ b/MooKeyboard.java @@ -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. @@ -47,8 +56,10 @@ public class MooKeyboard extends KeyAdapter { * Sets the octave of the lower part of the keyboard (default = 4) * @param n the octave to start at */ - public void setOctave(int n) { - startNote = n * 12; + public static void setOctave(int n) { + if (startNote == 0 || startNote == 108) return; + startNote += n*12; + makeKeyboardMapping(); } /** Maps keycodes (array indices) to MIDI note numbers using the following layout: @@ -58,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; @@ -92,4 +103,4 @@ public class MooKeyboard extends KeyAdapter { keyToNote[48] = startNote + 27; keyToNote[80] = startNote + 28; } -} \ No newline at end of file +}