Matching to Arrays

I got answer previously about matching in context to constraints but still not clear as the definition is backwards ie case use then the definition

What am I doing wrong here?
Am initiating an a ‘non’ sequential array, which should access the same as writing it on the callback line? Just like the literal example in the docs

(The first commented line does not compile)

You can’t use variables for the “Matching” argument. You would need to list out the integers again. This ability would also be on my wish list.

1 Like

Thanks
Yeah thats all I was asking in the beginning…
Im somewhat lazy;

It is not an argument - it is a constraint on the callback.

The purpose of the matching constraint was to optimize a critical piece of performance (remember, we’re doing real-time systems here, not writing a payroll program where having your paycheck take an extra 20 ms to calculate does no harm!)

I’m not going to get too technical here but suffice it to say that when these callbacks are being “built”, the appropriate callback can be called pretty much instantly because the association between the CC number and the actual callback is known at compile time.

But now, consider the consequences of allowing it to be a variable

  1. You would have to update the associations of bytes to control message callbacks every time that variable changed — imagine the cost of assigning that variable through a widget or whenever you played a note

  2. The runtime cost would become significant because everything would have be locked while those updates were being reconfigured to prevent race conditions … imagine for example that you try to change that variable from two widgets…

  3. Even if you were to ignore the costs, consider the consequences to the semantics/ You could now have multiple callbacks for the same CC message. Which one should be executed? The first one…the second one…all of them (and in what order?) Then sometimes one of them would get called, at other times, it wouldn’t ---- trust me — your code is going to get very contorted trying to deal with these combinations.

1 Like

Thanks for the explanation
Python deals with this all real-time for Live remote scripts but appreciate Gpscript is an appropriate tool I appreciate all the hard work that has gone into it
Good to know though and will just workaround it

I would consider the definitions as constants though and never really reassigned but then the can of worms for those who reassign :wink:
Cheers David

So does GP Script — the constraint mechanism is an optimization that lets you do some things faster than real time — there is nothing to stop you from testing the CC number in a single callback and calling the appropriate function based on the result.

1 Like

Thanks