X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooKeyboard.java;fp=MooKeyboard.java;h=29ffeecd6207ea2b5ac1348178478528ca4c4a65;hp=ef4785e67c5081e343983c06d411800dab2e1d1c;hb=c31857b9fcb119f0d4c12b96222f66340b3dcc56;hpb=4526e51b70110f7272b0c2a3a5f207657d690029 diff --git a/MooKeyboard.java b/MooKeyboard.java index ef4785e..29ffeec 100644 --- a/MooKeyboard.java +++ b/MooKeyboard.java @@ -9,14 +9,17 @@ import java.awt.event.*; public class MooKeyboard extends KeyAdapter { - private boolean[] isOn; private static int startNote; private static int[] keyToNote = new int[120]; + private boolean[] isOn; + private boolean recording; + private MooTrackTitle title; /** * Sets up the synthesizer emulation. */ - public MooKeyboard() { + public MooKeyboard(MooTrackTitle mtt) { + title = mtt; isOn = new boolean[120]; } @@ -34,9 +37,17 @@ public class MooKeyboard extends KeyAdapter { // Retrieves the notenumber from the conversion array. int noteNumber = keyToNote[e.getKeyCode()]; // 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); + if (!isOn[noteNumber] && noteNumber > 0) { + if (recording) { + ShortMessage msg = new ShortMessage(); + msg.setMessage(ShortMessage.NOTE_ON, title.getChannel(), noteNumber, 100); + Moosique.getSequencer().getReceiver().send(msg, -1); + } else { + Moosique.getActiveChannel().noteOn(noteNumber, 127); + } + } isOn[noteNumber] = true; - } catch (ArrayIndexOutOfBoundsException x) { + } catch (Exception x) { return; } } @@ -51,16 +62,36 @@ public class MooKeyboard extends KeyAdapter { // Retrieves the notenumber from the conversion array. int noteNumber = keyToNote[e.getKeyCode()]; // Sends the NoteOff event. - Moosique.getActiveChannel().noteOff(noteNumber); + if (recording) { + ShortMessage msg = new ShortMessage(); + msg.setMessage(ShortMessage.NOTE_OFF, title.getChannel(), noteNumber, 0); + Moosique.getSequencer().getReceiver().send(msg, -1); + } else { + Moosique.getActiveChannel().noteOff(noteNumber); + } isOn[noteNumber] = false; - } catch (ArrayIndexOutOfBoundsException x) { + } catch (Exception x) { return; } } } /** - * Sets the octave of the lower part of the keyboard (default = 4) + * Prepares the keyboard for recording on the current channel. + */ + public void recordEnable() { + recording = true; + } + + /** + * Disables recording and returns to keyjazz mode. + */ + public void recordDisable() { + recording = false; + } + + /** + * 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) { @@ -69,7 +100,7 @@ public class MooKeyboard extends KeyAdapter { } /** - * Increases or decreases the octave of the lower part of the keyboard (default = 4) + * Increases or decreases the octave of the lower part of the keyboard (default = 4). * @param increase true for increase, false for decrease */ public static void setRelativeOctave(boolean increase) {