Currently, when parameterMap.set() is called, it also triggers the parameterMap.onChange() . This makes bidirectional Electra-device communication very tricky because you can get feedback loops.
So far I tried having isReceiving and isSending flags and checking these flags, but even with calling midi.flush() before setting and checking, this seems unreliable, likely because handling of messages is asynchronous. Another issue is that such flags are not per control, so to do it well I’d have to write a table of controls and changing state, and that would still not solve the issue fully. Also when many changes come in, or go out, the CPU load is significant.
Suggested: add an extra parameter ignoreChange that defaults to false: parameterMap.set(deviceId, parameterType, parameterNumber, midiValue, ignoreChange = false) , that if set to true does not propagate the change to the parameterMap.onChange handler.
Well, I like the flexibility because there are some cases when i am doing internal manipulation of values in the parameterMap and sometimes I want them sent to the device and sometimes not or sometimes I’ll intercept the triggered parameterNumber/value and send some other things.
So, inside the onChange(), I can code the exceptions as necessary.
yes, it’s ugly coding sometimes, but dealing with old gear and system exclusive messages is ugly by nature. lol
yeah, there was a good idea behind that: make sure that when parameterMap entry is updated, it always sends the data out and fires all functions. Later, I realized the idea has these drawbacks. Anyways, to keep things backward compatible I am going to add a few new methods to make more flexible.