X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooKeyboard.java;h=ce110b254c46b1dd0f214654b63ad9fe401887d9;hb=2875ce498e9bf83ed635156599dd29a3c3b379de;hp=0ebfa63f063dd6f0cec8aeda527594d63156e0bd;hpb=4ac3b6210979ea78dceb609a0501cb0265d00065;p=moosique.git diff --git a/MooKeyboard.java b/MooKeyboard.java index 0ebfa63..ce110b2 100644 --- a/MooKeyboard.java +++ b/MooKeyboard.java @@ -1,7 +1,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. * * @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) { @@ -28,7 +28,7 @@ public class MooKeyboard extends KeyAdapter { } } - /* + /** * Plays the appropriate MIDI NoteOff event. */ public void keyReleased(KeyEvent e) { @@ -43,7 +43,15 @@ public class MooKeyboard extends KeyAdapter { } } - /* 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 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 +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;