Dear SC Community,
I want to calculate the derivation of incoming OSC Data to use them as a modulator for my synth. I tried to afford that using an array. Unfortunately, the code is not repeated, as I intented to and I dont know how to implement it correctly. Does anyone have a quick solution or a hint for me?
var z, d;
z = Array.with(0,0); //Derivation of OSC_data
d = z - z;
Thank you in advance!
I think the problem is that you reallocate a new array z every time you receive the OSC_data msg.
You should probably move the z = Array.with line outside the OSCdef.
Thank you for your reply!
Unfortunately it does not work. The array always gives out the exact same values in both positions.
This makes sense because your code is setting z = msg, and z = z. So both entries in the array are identical. And later when you subtract one from the other you end up with d == 0.
It would be helpful to know what the OSC data stream looks to help find a way to proceed.
- Put the new value into z.
- Put z into z – now, what is z at this point? Is it the old value (what you expected) or the new value (which you just put in).
You should copy the old value first, before overwriting it.
Next you’ll find that you’re getting the inverse derivative, because you’re doing old - new, where the derivative would be new - old.
Last, a note for forum usage: it helps people to read your code more accurately if you use markdown style for formatting: Code markup: Correct style
I understand it now, thank you very much for your help and reply.
I got it working now.
//an OSC listener that sends set messages
z = Array.with(0,0);
d = z - z;
Thank you very much!