Professional Documents
Culture Documents
Sustain
Sustain
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import javax.sound.sampled.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
/***
* Author: Dois Koh
* Date: 27th October 2015
*
* Gets your microphone signal and you can go do whatever you want with it.
* Right now, it takes signals from my Cherub WTB-004 Keyboard Sustain Pedal,
plugged into
* my microphone jack, and converts it into key presses (holds down V when
depressed,
* releases V when released)
*/
public class PedalToKeyboard {
try {
// Initialize robot for later use
robot = new Robot();
int numBytesRead = 0;
short previousShort = 0;
ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN).asShortBuffer().get(shorts);
previousShort = s;
}
}
/***
* The action to perform when the pedal is depressed
*/
public static void PedalPressedAction() {
pedalPressed = true;
robot.keyPress(KeyEvent.VK_V);
}
/***
* The action to perform when the pedal is released
*/
public static void PedalReleasedAction(){
pedalPressed = false;
robot.keyRelease(KeyEvent.VK_V);
}
}