Creating a velocity limiting knob, can someone show me how this should look?
-
Hey all,
I'm trying to create a knob that as you turn it down will limit the maximum velocity that gets fed into my sampler. I'm trying to use message.setVelocity like so:
message.setVelocity(range, 1 - 127)
But I'm not sure how to:
A. use this to limit the velocity depending on the value of the knob.
B. Tie this to a knob, I understand this shouldn't be used in the interface script, would you put this in a control callback or in onNoteon in the MIDI script processor?Has anyone got an example of this so I can see how/where it would be used?
Thanks all!
-
@LozPetts What you need is:
- a midi script processor in the sampler.
- add a knob to this script processor's interface, and set its max property to 127, step to 1, etc...
- add a knob to the main interface, and set its max property to 127, step to 1, etc...
- link the interface's knob to the midi script proc' knob, either via the properties panel or by script.
- In the sampler's midi script
onInit
, reference the knob likeconst var maxVelKnb = Content.getComponent("maxVelKnb");
- in the
onNoteOn
callback, set the velocity usingMath.min()
I leave to you what two parameters to put inside
Math.min()
.
Hint: it'll be something about the knob and the current message velocity -
@ustk You absolute star, thanks for that! This is where I am, I think I might be pretty close but I'm getting 'Unknown Function "min"' errors, which seems odd consider HISE filled it in for me so I KNOW the function is written correctly at least.
function onNoteOn() { math.min(message.getVelocity(), MaxVelKnob(getValue())); Console.print("Velocity: " + Message.getVelocity()); };
I'm using math.min to compare the two numbers (the velocity played and the velocity stated by the knob), and pick the lowest one. Then (as I've only loaded in one sample across the keyboard as I haven't had the sample session yet), I've got it to print the velocity so I can confirm it's working.
-
@LozPetts Whenever you get a unknown function error it means either the thing on the left side of the
.
doesn't have a function with that name, or the thing on the left side of the.
doesn't exist. In your case it's the latter - check your spelling (HISE script is case sensitive). -
@d-healey D'oh. Thank you!
That's got it printing the velocity okay, no more errors - still not limiting the velocity when I play with my knob though... -
@LozPetts said in Creating a velocity limiting knob, can someone show me how this should look?:
play with my knob though
:face_with_raised_eyebrow:
I don't see in your script where you're changing the velocity.
-
@LozPetts like @d-healey says, and adding that:
MaxVelKnob(getValue())
is not how to get the value, but you’re close:
https://docs.hise.audio/scripting/scripting-api/scriptslider/index.html#getvalue -
@d-healey That would help. Face palmed pretty hard there.
Just in case it helps anyone in future!
function onNoteOn() { //Velocity Limiter Knob Message.setVelocity(Math.min(Message.getVelocity(), MaxVelKnob.getValue())); Console.print("Velocity: " + Message.getVelocity()); };
-
@LozPetts PS you both rock - thank you so much for your help.