X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooKeyboard.java;h=11f45fce02f35f580548b8cd337cf5ec606de678;hb=83ec11f99e143607d057db2a68c262ca9672e524;hp=67664dfb1298db17435907fb07b81f4aec17dd1b;hpb=d7666fadd2f8baca8a03cacae836f2563fe4dd5d;p=moosique.git diff --git a/MooKeyboard.java b/MooKeyboard.java index 67664df..11f45fc 100644 --- a/MooKeyboard.java +++ b/MooKeyboard.java @@ -2,7 +2,7 @@ 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,7 +10,7 @@ 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]; /** @@ -43,6 +43,14 @@ 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 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 => # # # # # # # @@ -51,7 +59,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;