asb2m10 / dexed

DX7 FM multi plaform/multi format plugin
GNU General Public License v3.0
2.85k stars 244 forks source link

Usage of loop-var in for-loop dexed/Source/PluginProcessor.cpp:340? #83

Closed dcoredump closed 7 years ago

dcoredump commented 7 years ago

Hi Pascal,

I am not sure, but I think I found a bug in dexed/Source/PluginProcessor.cpp:340 It seems for me that there is a loop which does nothing special:

int note = currentNote;
for (int i=0; i<MAX_ACTIVE_NOTES; i++) {
    if (!voices[note].keydown) {
        currentNote = (note + 1) % MAX_ACTIVE_NOTES;
        lfo.keydown();  // TODO: should only do this if # keys down was 0
        voices[note].midi_note = pitch;
        voices[note].sustained = sustain;
        voices[note].keydown = true;
        voices[note].dx7_note->init(data, pitch, velo, feedback_bitdepth);
        if ( data[136] )
            voices[note].dx7_note->oscSync();
        break;
    }
note = (note + 1) % MAX_ACTIVE_NOTES;

The loop variable is "i" but this var is never referenced inside the for-loop. I think every access to the voices-array must be done with 'i' instead of 'note' - like this?

int note = currentNote;
for (int i=0; i<MAX_ACTIVE_NOTES; i++) {
    if (!voices[i].keydown) {
        currentNote = (note + 1) % MAX_ACTIVE_NOTES;
        lfo.keydown();  // TODO: should only do this if # keys down was 0
        voices[i].midi_note = pitch;
        voices[i].sustained = sustain;
        voices[i].keydown = true;
        voices[i].dx7_note->init(data, pitch, velo, feedback_bitdepth);
        if ( data[136] )
            voices[i].dx7_note->oscSync();
        break;
    }
note = (note + 1) % MAX_ACTIVE_NOTES;

Regards, Holger

dcoredump commented 7 years ago

Hmmmm, after thinking a little bit longer about this I think I am wrong - sorry.