Control velocity from each incoming midi note with a Knob / Slider?
-
I know it is possible to link a button to incoming each midi note.
Can the same be accomplished with a Knob for each note?
( controlling the velocity while the note is being pressed )
I often do this in Max/Msp, PureData.Thanks I hope :)
-
@Rognvald Do you want the knob to set the velocity or the velocity to set the knob value?
-
@d-healey Ahh, the Knob to control the Velocity
-
Ok let's say your knob is called
knbVelocityand you have a reference to it inonInitconst knbVelocity = Content.getComponent("knbVelocity");In the
onNoteOncallback you can use the knob's value to set the Message's velocity.Message.setVelocity(knbVelocity.getValue());Ideally this should be done using two MIDI processors. The Interface script should be deferred - which means you won't be able to use
setVelocitythere. A second MIDI processor should be used for setting the velocity, and the knob on the GUI should be connected the knob of the second MIDI processor. -
@d-healey Ok thanks for all this info, I will have a blast and see what comes out :)
-
@d-healey I am currently using this code for buttons to midi. Is there any way to insert this velocity function or would I also need to put this code on the second Midi Processor? Little confused but I am sure it can work.
onInt
const Buttons = Content.getAllComponents("Button"); // this list will save the played note eventIds reg eventIds = Engine.createMidiList(); // this played keys will trigger the buttons reg keysThatTrigger = [48, 49, 50, 51]; // this notes will sound reg triggeredNotes = [48, 49, 50, 51]; inline function onButtonsControl(component, value) { local index = Buttons.indexOf(component); if (value) eventIds.setValue(triggeredNotes[index], Synth.playNote(triggeredNotes[index], 60)); else Synth.noteOffByEventId(eventIds.getValue(triggeredNotes[index])); }; for (b in Buttons) b.setControlCallback(onButtonsControl);onNoteOn
function onNoteOn() { Message.ignoreEvent(true); if (keysThatTrigger.contains(Message.getNoteNumber())) { local index = keysThatTrigger.indexOf(Message.getNoteNumber()); Buttons[index].setValue(true); Buttons[index].changed(); } }onNoteOff
function onNoteOff() { if (keysThatTrigger.contains(Message.getNoteNumber())) { local index = keysThatTrigger.indexOf(Message.getNoteNumber()); Buttons[index].setValue(false); Buttons[index].changed(); } } -
@Rognvald You can put it all in the interface MIDI processor if you want to keep things simple - just avoid doing any UI stuff in the MIDI callbacks.
// This sort of thing should be avoided in a non-deferred script. Buttons[index].setValue(true); Buttons[index].changed();However the ideal situation is you separate UI logic from MIDI processing by using separate processors for individual tasks.
You can add the velocity code I described above alongside your current script.
Those
regvariables you have should most likely beconst. Rule of thumb is if the values are fixed (or it's an array or object) use aconst. If the value is going to be dynamic then use areg.