edit: I figured it out... using the method I mentioned at the end of this post, Arrays within Arrays.
I am trying to simplify some code and i'm not sure how to go about it.
I basically have 4 buttons, and I currently have some code to continuously check if any of the 4 buttons are pressed. When any button is pressed, I want to execute a set of commands, but with different arguments depending on which button was pressed.
More specifically, I am trying to make buttons that send 3 MIDI messages using the following commands:
noteOn(0, x, 100)
noteOn(0, y, 100)
noteOn(0, z, 100)
So each button will send a different x/y/z value. My initial thought was to create arrays that contain the chord values:
chord1[] = {48, 55, 68}
chord2[] = {57, 68, 79}
then change the commands to something like
noteOn(0, chord1[0], 100)
noteOn(0, chord1[1], 100)
noteOn(0, chord1[2], 100)
but that would still require me to write an addition if/elseif statement for querying which button is pressed in the first place so we know which chord array to use.
I need some kind of trick to identify which button is pressed and pick the appropriate values without making repetitive code. I'm SURE there is an answer to this, I just can't think of it!
Thanks for the help
edit: additional thought just came to mind. What if I make an array of arrays?
allChords[4][3] = { {48, 49 50}, //chord 1
{51, 52, 53}, //chord 2
{54, 55, 56}, //chord 3
{57, 58, 59}}; //chord 4
then run the variable in noteOn as
noteOn{0, allChords[i][0], 100}
noteOn{0, allChords[i][1], 100}
noteOn{0, allChords[i][2], 100}
So when i = 0, which is button 1, it will pull the array from the allChords array that contains the proper 3 note values for button 1, then it should split the 3 values into the 3 midi commands... I think that makes sense. And I believe you can make an array of arrays... I hope! ![]()