I noticed in juce::MidiMessage that there is a function for getting the controller value, but there isn’t one for setting it. Is there a reason for this? If not, would you mind adding a method for it?
MidiMessage is an immutable class, it doesn’t have any “setter” methods at all.
Aren’t setTimeStamp (double newTimestamp), setChannel (int newChannelNumber), setNoteNumber (int newNoteNumber) and setVelocity (float newVelocity) “setter” methods?
Oh, fair point! Ok, well all the actual midi data in there is immutable!
I’m not really seeing how the midi data is immutable. In the setter functions for velocity, note number etc. you are directly manipulating the data, and there is even a function in MidiMessage to get the raw midi data.
Ok, it’s been a while since I looked at those methods… Let me retreat a bit, and say it should be immutable (and mostly is)! Certainly I’m not going to add any more setter methods, and may at some point remove some of the ones that are there.
Ok if that is the case then what would be the best way of changing MidiMessage controller values in real time with something like a slider? Repeatedly delete the event and add a new one using MidiMessage::controllerEvent()? Or access the raw data with MidiMessage::getRawData()
And I’m just curious, why should the midi data be immutable?
Just create a new object and use operator=, they’re very lightweight.
I’d say that as a rule of thumb, it’s always best to use immutable classes where possible. It’s a more functional style of programming.
And BTW, never do that. I’m surprised that the array returned isn’t const… I think it should be, and I might change that.
Thanks for the suggestion! I will do that.