Change Slider Value via MIDI + Velocity
-
@trillbilly did you actually mean this:
inline function cAnimation(index) { slider.setValue(index); }
-
It is still not functioning.
Now I've got this in on onInit:
const var slider = Content.getComponent("slider"); const var keySwitchesC = [24, 36, 48, 60, 72, 84, 96, 108, 120]; //Cs inline function cAnimation(index) { slider.setValue(index); }
And this in my onNoteOn:
function onNoteOn() { //slider.setValue(Message.getVelocity()); if (keySwitchesC.indexOf(Message.getNoteNumber())) { cAnimation(keySwitchesC.indexOf(Message.getNoteNumber()())); } }
-
@Lindon @aaronventure @d-healey
Here is a minimal snippet. It's basically everything mentioned above.
HiseSnippet 1221.3oc0W0uSabDD+NaeU3Ksnjpzp9mqh5eXjbAeDJgJTULXfHTiAKNBsRUUnk6Fauh6185cqAbihTdz5iPeTxaP6r2c125fCww0ToZI9XmcmY9MeOtSrvCRRDwFlUOcXDXX94VtC4x9s5SYbiC2yvbYq1zDIDSxHs6vHZRB3aXZV9EJBlUqXj94cOeWZ.k6AEjLLNSv7fWxBYxBpcZ9SrffCn9vorPsWuQyC8D7Vh.w.DOksZXDQ8tj1CNhpdVIKCyOaeelTD6JoRHwvrxtB+gt8EWyyd+YrD1EAf5figKJnLxGHB7UHVQ0nUeVfemQ1chggoUmBuP4LuvisZy7YioW3MdX5EjBNz8GlklDdkm.dN5vqgF7lBjL0fTkLH8HKWuXVjr3FEddf0gbL3zkhtccnj8ViR8JY0RfufKWMjdIbPLdXLG01rQi5D7WqrssM55Sjjqnwjj.lOFu+QxHN6AxVhvHAGOT6IYW+jI44RXn60LoWeHoEx4ut9F0IOcy5jM1Rof5jmsdcxVHse.o4z.I5rdieaaxZq0Jw1lwCXbfzc.2SxDbh2NbVHU8u0Xbe3lUreMgPrwexw1pIf7LZv.H+9ssei8XtE7iDR3XdMjM6pqs16yRaz6gIUJq5LHP3wjCqsBJhp1UUZf0kTS2ZVMUEG2UmOkBNZP3EPLx4JY785r+n9ng+OEIoj01YR4MJ6spMZVjaYXc6lYYypcgxPSDpXZrHHPoPkTduqUUjS+lbFqwSQacLpiJc7CwzzIy8s9v495kldYoXZOTvOjyjGGA7OTAqQddopNIGU3SkoUIKmWk3l5bLXXwvRVYdJiTDiHyLsayqNbOpjNRFn3PUDAwRlB8l6AWgMtxp7pZsGjboTDk9175.CS6OtFuon4leygiO71yZhdQWIxVxXh+44Mw1rQtr+.z6oFx78CfNhDlJNTHhiadMyW1eLglPy9.qW+h9ruk1Ljdit7MtcWErelveP.UNYSNUm87KTZUuyhp6AGQyPcTtv57MqP7QVcTUUSGiklBFw.88AFymW7EV62sK3IK.XEqC9k6mgC5pe4L0+.KWrAZ5f6Tk+0omI+L8Jf7BfCwJmmycL69ul0Y2Qy7r6i8jn5OMlxShDISHXWHjcJVEknS7UI3zI32OQEM0o2RPim5Uu64GfF4T4wkJGDmlVrSnX.WNQZP46ZGBm4bGhJ2W6PTY1RSta38+fBeyRct0tnODSiCiBf84WgCzPJJL9kX23tzAAxQTmLutsfKh5K3LO8f9I.1rsWOHVG6S0f1QJwkNKn73lm.A.UOA9aa9RLwiFi9IXN8ENexq+M0302XkAWhpXj7uItsvSyVJC11Vi1EIEve03ijwliyGGsXugSoovQO5cENsVwTQXdOvicADLYfAajkqyTYjN0O8KSrnBWKjYVkmoYVK7vz7O+Zw.kSDCjLdu1Tr9D2UwB2E1EGg3AHR3bHPsIoYI0XfryMFs+lKv8SO723m7KcTmMyuzYzk+mniPpWr3bursQUkvKkRAsad5WdsJ9snwyDmwagZ0X0FF31cry87Tt6uC8OSmm0mCdd5bvyFyAOe+bvylyAOOaN3Yq6jG0L3cFHEYeQMLf1ty9Y8FL2mqZTjl0a7OvzVD4e
-
@trillbilly Do you see the error in the console?
-
@d-healey I messed up on naming the slider in the snippet. I have corrected it. Still does not work with the corrected slider names.
-
@trillbilly What error do you see? (Slider name seems fine to me btw)
-
@d-healey Ahh, I see what you are mentioning now. I was equating it to the wrongly named slider.
Now I see the issue is this line
cAnimation(keySwitchesC.indexOf(Message.getNoteNumber()()));
Where am I going wrong?
I've tried replacing it with
slider.setValue(Message.getVelocity());
But again, it reacts to all keys and not only C.
-
-
@d-healey Boobs!
-
@aaronventure @d-healey
I need a dunce cap and a beer because I am blind to this. Maybe I should continue banging my head on the keyboard until it works, I've done that a time or 2. -
-
@aaronventure @d-healey Yes, the boobs remark makes sense now. Now it is working on just the C but seems to be limited.
I have the slider set to min 0 - max 127 with steps 1.0.
With the new code, it doesn't surpass 3.
Should I be setting the slider up differently in this sense or am I missing something else.
-
@trillbilly You are passing the index of the array, based on the note you play. So if you play note 24 the knob will be set to 0, if you play 36 the knob will be set to 1, etc.
-
@d-healey Thanks. Now Im super confused how to now make it follow the velocity modulator. I will continue tinkering with it.
If you have time for a snippet or anything it would be super appreciated.
-
@trillbilly If you want your knob to have the same value as the incoming velocity then you have that in my first response. If you only want to respond to certain notes then use an if statement to check if the incoming note is in your array before you set the knob's value.
-
@d-healey yes, I've put
slider.setValue(Message.getVelocity());
within the IF statement in the onNoteOn like so:
if (keySwitchesC.indexOf(Message.getNoteNumber())) { cAnimation(keySwitchesC.indexOf(Message.getNoteNumber())); slider.setValue(Message.getVelocity()); }
But is apparently incorrect as it then changes to all keys again instead of just C.
I will keep plugging away.
-
@trillbilly said in Change Slider Value via MIDI + Velocity:
if (keySwitchesC.indexOf(Message.getNoteNumber()))
.indexOf
will return the index in the array. It doesn't check for true or false. Use.contains()
instead. -
@trillbilly I have a custom GPT that i fed with HISE source and hise docs and told it a bit about hise.
nothing fancy. it still makes a lot of mistakes as it forgets this isn't exactly javascript., but I guess I should upload more code examples.
I entered your post in there https://forum.hise.audio//post/75262 hoping that maybe the magical talking computer will do a better job of explaining it to you than we did
and this is what i got
The issue you're encountering seems to stem from a couple of misunderstandings about how to check if a note is in your
keySwitchesC
array and how to properly use thecAnimation
function. Here's a breakdown of what needs to be fixed:- Checking for Key Presses: You are using
Message.getVelocity()
to check if a key is in yourkeySwitchesC
array, butMessage.getVelocity()
returns the velocity of the note being played, not its pitch. You should useMessage.getNoteNumber()
to check if the played note's pitch matches any of the Cs in your array. - Using
indexOf
Properly: TheindexOf
method returns-1
if the element is not found in the array. Any other returned value (i.e.,0
or above) means the element was found. Therefore, you need to check if the result ofindexOf
is not equal to-1
to confirm the presence of the note number in your array. - The
cAnimation
Function: YourcAnimation
function seems to be designed to set the slider's value, but it's missing thevalue
parameter. You need to decide what value you want to set the slider to when a C note is pressed. Since the function takes anindex
, you might want to use this index or the note number itself to determine the slider's value.
Here's a corrected version of your script:
const var slider = Content.getComponent("slider"); const var keySwitchesC = [24, 36, 48, 60, 72, 84, 96, 108, 120]; // Cs inline function cAnimation(value) { slider.setValue(value); } function onNoteOn() { var noteNumber = Message.getNoteNumber(); // Get the note number var index = keySwitchesC.indexOf(noteNumber); // Find the index of the note in the array if (index != -1) // Check if the note is a C { // Decide what value you want to set. For example, setting the slider to the note's velocity: var velocity = Message.getVelocity(); cAnimation(velocity); // Call the animation function with the determined value } }
In this revised version, the script correctly identifies when a C note is played by checking its note number against the
keySwitchesC
array. When a match is found, it uses the note's velocity (or any other logic you define) as the value for thecAnimation
function to set the slider's value. This approach ensures that the animation only happens for the specified C notes.Obviously declaring variables inside the realtime callbacks is a nono so once I reminded it about it, I got
const var slider = Content.getComponent("slider"); const var keySwitchesC = [24, 36, 48, 60, 72, 84, 96, 108, 120]; // C notes // Use 'reg' for variables involved in real-time callbacks reg noteNumber = -1; reg index = -1; reg velocity = 0; inline function cAnimation(value) { slider.setValue(value); } function onNoteOn() { noteNumber = Message.getNoteNumber(); // Use the 'reg' variable index = keySwitchesC.indexOf(noteNumber); // Update the 'reg' variable based on the note number if (index != -1) // Check if the note is a C { velocity = Message.getVelocity(); // Use the 'reg' variable for velocity cAnimation(velocity); // Call the animation function with the velocity } }
and when paste this, it sets slider to the value of velocity whenever the note is C.
Also, a much simpler way to check for C is
if ((Message.getNoteNumber() % 12) == 0)
.And if you ask the GPT about it, it'll tell you the same thing:
Yes, indeed! Since you're dealing with MIDI note numbers where middle C is 60, and each octave >spans 12 notes, you can simplify the process of checking for C notes by leveraging this pattern. >Here's how you can do it:
const var slider = Content.getComponent("slider"); reg noteNumber = 0; reg velocity = 0; function onNoteOn() { noteNumber = Message.getNoteNumber(); // Check if the note is a C (where middle C is 60) if (noteNumber % 12 == 0) { velocity = Message.getVelocity(); slider.setValue(velocity); } }
In this version of the script:
- We calculate the difference between the note number and 60, representing middle C.
- We then use the modulo operator
%
to check if this difference is a multiple of 12, indicating >that the note is a C. - If the condition is met, we proceed with setting the slider value based on the note's velocity.
This approach simplifies the code by removing the need for a separate array to store C notes and directly computes whether the note is a C using arithmetic operations.
And do a much better job of explaining these very simple snippets, mentioning all the important things so even at the base level of skill you should be able to understand.
- Checking for Key Presses: You are using
-
@aaronventure said in Change Slider Value via MIDI + Velocity:
will do a better job of explaining it to you than we did
I was intentionally vague to try and make him work it out for himself :)
-
@d-healey it seems the
.contains
may have done the trick. And yes, I appreciate you allowing me to work it through,@aaronventure Thats cool what you did with GPT. I've only ever tried to use it once or twice with HISE and got lost faster than without it.