MidiKeys maxNotes is sometimes non-zero
Closed this issue · 9 comments
In MidiKeys.cpp, line 75
for(int i=0; i<this->maxNotes; ++i){ gates[i].unLink(); values[i].unLink(); }
The problem is
this->maxNotes
is never initialized to zero
so gates[i].unLink();
throws a EXC_BAD_ACCESS
occasionally
ah yes, they're in the wrong order, it's initialized in line 80
fixing this now, thank you very much for catching it!
Ah! setPolyMode
was fine before. All that is needed is maxNotes = 0;
in the constructor. The error was that this->maxNotes
was initially some garbage value, not zero.
I'm sorry for not being more clear before.
ah ok, it shouln't give EXC_BAD_ACCESS
with the changes, but setting maxNotes=0
in the costructor should be done anyway, doing it now
ah sorry, i just saw that setPolyMode(8, 1) is called in the constructor, initializing the notes to 8 the correct way with the new setPolyMode()
can you test it ? this issue should be solved by the last changes
The reason this->maxNotes = maxNotes
was done after the fact was so that unLink()
could be called on all gates
and values
using the old this->maxNotes
value.
I believe your changes do prevent EXC_BAD_ACCESS
... but the new version of setPolyMode()
leaves some of gates
and values
linked (in the case of decreasing maxNotes
). I don't know if this causes any issues or not, but it could possibly lead to unintended behavior.
ah yes, so this could be better, as it should link everything anyway in the successive lines
void pdsp::midi::Keys::setPolyMode(int maxNotes, int unisonVoices ){
this->maxNotes = maxNotes;
for( auto & gate : gates ){
gate.unLink();
}
for( auto & value : values ){
value.unLink();
}
// ...
i pushed the changes, let me know if something is still wrong
Looks awesome! Would be great to see the same in setMonoMode()
as well.
done!