PaulS:
Perhaps you should explain more about this weird data structure.
Don’t say I didn’t warm you… haha.
Maybe it will help with finding a good solution though, and perhaps someone could show me how to optimise it.
I don’t know what you know about the MIDI protocol, but it’s 3 byte messages. We’ll ignore the first one, as it’s not relevant here, but after this, essentially they are “Parameter number”, followed by “value”.
A 2D array saves the “patch” - that is, arrays of all the “values”, the 3rd bytes.
This is indexed by another array, 20 or so long, holding the CC numbers.
So to load a patch, you cycle through an array of all the parameter numbers, looking at the patches array:
1st dimension = the patch number
2nd dimension = indexed by the value of the parameters array.
EG: Sending cutoff frequency (parameter number 45) for patch 3 would look like this:
SendSysEx(1, ccNum[14], patches[3][ccNum[14]]);
]
14? Because 45 is at position 14 in the array, although this is arbitrary - I will never need to send just one parameter, only all of them.
Here's the parameter numbers, if you'd find that relevant:
[code]
byte ccNum[] = {11 , 42, 5,40, 43, 46, 48, 47, 49, 50, 51, 52, 53, 44, 45};
The problem is that the patches array is 20 (number of patches) x 50 - because parameter numbers range from 1 - 50, even though there is only 20 or so of them, and I’m using them to index each patch. This is obviously a little pointless, as if I work out how to write them to EEPROM i’ll be writing a bunch of zeros or NULLs or whatever.
void loadPatch() {
for (int i = 0; i < sizeof(ccNum); i++) {
if (ccNum[i] != 0) {
SendSysEx(1, ccNum[i], patches[currentPatch][ccNum[i]]);
// SendSysEx(1, ccNum[i],100);
}
}
}
void SendSysEx(int Chan, byte Par, byte Value) {
Serial1.write(176); // for example Cutoff Synt
Serial1.write(Par); // for example Cutoff Synt
Serial1.write(Value); // for example Cutoff Synt
}
Above is the basic function used to load patches. I hope I’ve made it clear in the way I’ve gone about this!
Thanks and best wishes!