I previously built a midi to control voltage converter and used an array to keep track of which keys were being pressed and in which order. When a note is released, it's corresponding element is changed to zero and then I used a subroutine to reorganize the array so the zeros are at the end.

```
unsigned int pitchVoltage[6] = {0};
for (int i = 0; i < 6; i++) {
if (pitchVoltage[i] == voltage) {
pitchVoltage[i] = 0;
removeZeros(pitchVoltage, sizeof(pitchVoltage) / sizeof(pitchVoltage[0]));
}
}
void removeZeros(int array[], size_t length) {
if (array != nullptr && length > 0) {
for (size_t i = 0; i < length; i++) {
if (array[i] == 0) {
for (size_t j = i + 1; j < length; j++) {
if (array[j] != 0) {
array[i] = array[j];
array[j] = 0;
break;
}
}
}
}
}
}
```

this works, but admittedly I found the "remove zeros" subroutine online and only have a superficial understanding of what is happening.

Currently, Im adapting my single channel midi to cv device to be a two channel one and have changed the single line array into a 2d one to keep track of which notes are being held on each of the two respective midi channels. Ive (attempted to) modify the "remove zeros" subroutine to accommodation the two levels of the array like so:

```
unsigned int pitchVoltage[2][6] {0};
for (int i = 0; i < 6; i++) {
if (pitchVoltage[x][i] == voltage) {
pitchVoltage[x][i] = 0;
removeZeros( pitchVoltage[x], sizeof(pitchVoltage[x]) / sizeof(pitchVoltage[x][0]));
}
}
void removeZeros(int array[], size_t length) {
if (array != nullptr && length > 0) {
for (size_t i = 0; i < length; i++) {
if (array[i] == 0) {
for (size_t j = i + 1; j < length; j++) {
if (array[j] != 0) {
array[i] = array[j];
array[j] = 0;
break;
}
}
}
}
}
}
```

this seems to be working, but only for the first level of the array, when x=0. When x=1, it does not work.

Any ideas of what is the issue, or how to solve it, or even a better way of how to do this whole process?

Thanks