Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Created March 25, 2022 20:58
Show Gist options
  • Save rchrd2/f640472bf81616efabd3a58f1dd8a55e to your computer and use it in GitHub Desktop.
Save rchrd2/f640472bf81616efabd3a58f1dd8a55e to your computer and use it in GitHub Desktop.
Processing sketch to convert midi sustain pedal to a bass drum midi note trigger
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus
int NOTE_NUMBER = 36;
int NOTE_VELOCITY = 50;
int NOTE_CHANNEL = 9;
String MIDI_DEVICE_IN = "GO:KEYS";
String MIDI_DEVICE_OUT = "GO:KEYS";
boolean DEBUG = false;
void setup() {
size(400, 400);
background(0);
fill(255);
textAlign(CENTER);
text("Midi sustain pedal to bass drum trigger", width/2,height/2);
MidiBus.list();
myBus = new MidiBus(this, MIDI_DEVICE_IN, MIDI_DEVICE_OUT);
}
void draw() {
delay(2000);
}
void controllerChange(int channel, int number, int value) {
if (DEBUG) {
println();
println("Controller Change:");
println("Channel:"+channel);
println("Number:"+number);
println("Value:"+value);
}
if (number == 64 && value > 0) {
myBus.sendNoteOn(NOTE_CHANNEL, NOTE_NUMBER, NOTE_VELOCITY);
delay(100);
myBus.sendNoteOff(NOTE_CHANNEL, NOTE_NUMBER, NOTE_VELOCITY);
}
}
void noteOn(int channel, int pitch, int velocity) {
if (DEBUG) {
println();
println("Note On:");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
}
void noteOff(int channel, int pitch, int velocity) {
if (DEBUG) {
println();
println("Note Off:");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
}
void delay(int time) {
int current = millis();
while (millis () < current+time) Thread.yield();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment