Although the approaches by @GoToLoop and @eightohnine are equally valid I prefer the former because it is more concise although I would remove the static
keyword because it has no benefit in this context i.e. a basic Processing sketch.
@eightohnine does show clearly the structure of a 2D array - a 2D array is a 1D array of 1D arrays and we can extend that to a 3D array is a 1D array of 2D arrays
The following sketch combines some of the features of previous posts but also uses method / function overloading to improve flexibility in accessing chords and notes. Just in case you don’t know function overloading is where you have two or more functions with the same name but with different parameters. When you call the function the compiler looks ate the parameters you pass and selects the matching function for you.
final byte[][][] CHORD_BANKS = {
{ // bank 0
{ 40, 45, 50, 55, 59, 64 }, // open strings 0
{ 40, 47, 52, 56, 59, 64 }, // E major 1
{ 41, 48, 53, 57, 60, 65 }, // F major 2
{ 43, 47, 50, 55, 59, 67 }, // G major 3
{ 33, 45, 52, 57, 61, 64 }, // A major 4
{ 35, 47, 54, 59, 63, 66 }, // B major 5
{ 36, 48, 52, 55, 60, 64 }, // C major 6
{ 38, 38, 50, 57, 62, 66 } // D major 7
},
{ // bank 1
{ 40, 45, 50, 55, 59, 64 }, // open strings 0
{ 40, 47, 52, 56, 59, 64 }, // E major 1
{ 41, 48, 53, 57, 60, 65 }, // F major 2
{ 43, 47, 50, 55, 59, 67 }, // G major 3
{ 33, 45, 52, 57, 61, 64 }, // A major 4
{ 35, 47, 54, 59, 63, 66 }, // B major 5
{ 36, 48, 52, 55, 60, 64 }, // C major 6
{ 38, 38, 50, 57, 62, 66 } // D major 7
},
{ // bank 2
{ 40, 45, 50, 55, 59, 64 }, // open strings 0
{ 40, 47, 52, 56, 59, 64 }, // E major 1
{ 41, 48, 53, 57, 60, 65 }, // F major 2
{ 43, 47, 50, 55, 59, 67 }, // G major 3
{ 33, 45, 52, 57, 61, 64 }, // A major 4
{ 35, 47, 54, 59, 63, 66 }, // B major 5
{ 36, 48, 52, 55, 60, 64 }, // C major 6
{ 38, 38, 50, 57, 62, 66 } // D major 7
}
};
void setup() {
byte[][] bank = getBank(2);
byte[] chord = getChord(bank, 3);
printBank(bank);
printChord(chord);
println("Note : " + getNote(0, 3, 2));
}
byte[][] getBank(int bankNbr) {
return CHORD_BANKS[bankNbr];
}
byte[] getChord(byte[][] bank, int chord) {
return bank[chord];
}
byte[] getChord(int bankNbr, int chord) {
return CHORD_BANKS[bankNbr][chord];
}
byte getNote( byte[] chord, int n) {
return chord[n];
}
byte getNote(int bankNbr, int chord, int n) {
return CHORD_BANKS[bankNbr][chord][n];
}
void printBank(byte[][] bank) {
println("Bank : ");
for (int chordIdx = 0; chordIdx < bank.length; chordIdx++) {
byte[] chord = bank[chordIdx];
print("Chord: " + chordIdx + " Notes: " );
for (int noteIdx = 0; noteIdx < chord.length; noteIdx++) {
print(" " + chord[noteIdx]);
}
println();
}
}
void printBank(int bankNbr) {
println("Bank munber : " + bankNbr);
byte[][] bank = CHORD_BANKS[bankNbr];
for (int chordIdx = 0; chordIdx < bank.length; chordIdx++) {
byte[] chord = bank[chordIdx];
print("Chord: " + chordIdx + " Notes: " );
for (int noteIdx = 0; noteIdx < chord.length; noteIdx++) {
print(" " + chord[noteIdx]);
}
println();
}
}
void printChord(byte[] chord) {
println("Chord : ");
print(" Notes: " );
for (int noteIdx = 0; noteIdx < chord.length; noteIdx++) {
print(" " + chord[noteIdx]);
}
println();
}
void printChord(int bankNbr, int chordNbr) {
println("Bank munber : " + bankNbr + " Chord number : " + chordNbr);
byte[] chord = CHORD_BANKS[bankNbr][chordNbr];
print(" Notes: " );
for (int noteIdx = 0; noteIdx < chord.length; noteIdx++) {
print(" " + chord[noteIdx]);
}
println();
}