How To Link Keyboard Keys to Buttons
-
Hello I currently am trying to make a drum machine style plugin.
I have 16 buttons I assigned as pads with a custom pad Image I imported.
When I click the pads it triggers the samples in my sampler which is great. The pads light up and everything. However, when I hit the keys on the keyboard, the pads are not linked to the keys. I want the pads to light up as well and be triggered when I hit the keys on the keyboard not just when I click with a mouse, here is the code of my interface so far that I put in the editor to achieve this,
Content.makeFrontInterface(900, 600); // ===== Config ===== const var NUM_PADS = 16; const var BASE_NOTE = 60; // Your C3 maps to MIDI 60 // ===== State ===== reg eventIds = []; const var btnTrigger = []; reg suppressBtnCallback = false; // ===== Helper ===== inline function setPadLit(index, on) { if (index < 0 || index >= NUM_PADS || !btnTrigger[index]) return; suppressBtnCallback = true; // don't re-trigger UI callback btnTrigger[index].setValue(on ? 1 : 0); // visually light/unlight suppressBtnCallback = false; } // ===== UI Callback ===== inline function onBtnTriggerControl(component, value) { if (suppressBtnCallback) return; // ignore programmatic changes local index = btnTrigger.indexOf(component); if (index == -1) return; if (value) eventIds[index] = Synth.playNote(BASE_NOTE + index, 64); else if (eventIds[index] != 0) Synth.noteOffByEventId(eventIds[index]); } // ===== Wire up the 16 buttons ===== var i; for (i = 0; i < NUM_PADS; i++) { btnTrigger[i] = Content.getComponent("Button" + i); // Capital B if (btnTrigger[i]) btnTrigger[i].setControlCallback(onBtnTriggerControl); } // ===== MIDI → UI mirroring ===== function onNoteOn() { local idx = Message.getNoteNumber() - BASE_NOTE; // 60 -> index 0 setPadLit(idx, true); } function onNoteOff() { local idx = Message.getNoteNumber() - BASE_NOTE; setPadLit(idx, false); }to my knowledge, and for the past 6 hours of failing at coding with chat gpt, the interface doesn't recognize midi? how can I go about linking the buttons to the keys?
-
@weezycarter said in How To Link Keyboard Keys to Buttons:
I have 16 buttons I assigned as pads with a custom pad Image I imported.
Use a panel instead of buttons.
@weezycarter said in How To Link Keyboard Keys to Buttons:
reg eventIds = [];
Should probably be a const, and perhaps a midi list instead of an array
@weezycarter said in How To Link Keyboard Keys to Buttons:
the past 6 hours of failing at coding with chat gpt,
Better to spend 6 hours reading the docs
@weezycarter said in How To Link Keyboard Keys to Buttons:
function onNoteOn()
{
local idx = Message.getNoteNumber() - BASE_NOTE; // 60 -> index 0
setPadLit(idx, true);
}Is this inside your
on initcallback? -
@d-healey This code is inside my interface on the oninit tab
-
@weezycarter The HISE script editor provides a drop down to switch between the major callbacks.

You need to put your
onNoteOnandonNoteOffcode within the correct callbacks, rather than in theonInitcallback. -
@d-healey THANK YOU! IT WORKS PERFECT!