Fixed gate logic.

This commit is contained in:
Francois Best 2014-05-21 08:55:12 +02:00
parent 532b0d3843
commit 7980d5f881
1 changed files with 25 additions and 26 deletions

View File

@ -18,12 +18,12 @@ MidiNoteList<sMaxNumNotes> midiNotes;
// -----------------------------------------------------------------------------
void handleGateChanged(bool inGateActive)
inline void handleGateChanged(bool inGateActive)
{
digitalWrite(sGatePin, inGateActive ? HIGH : LOW);
}
void pulseGate()
inline void pulseGate()
{
handleGateChanged(false);
delay(1);
@ -32,15 +32,11 @@ void pulseGate()
// -----------------------------------------------------------------------------
void handleNotesChanged()
void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
{
if (midiNotes.empty())
{
handleGateChanged(false);
noTone(sAudioOutPin);
}
else
{
const bool firstNote = midiNotes.empty();
midiNotes.add(MidiNote(inNote, inVelocity));
// Possible playing modes:
// Mono Low: use midiNotes.getLow
// Mono High: use midiNotes.getHigh
@ -50,23 +46,26 @@ void handleNotesChanged()
if (midiNotes.getLast(currentNote))
{
tone(sAudioOutPin, sNotePitches[currentNote]);
if (firstNote)
{
handleGateChanged(true);
}
else
{
pulseGate(); // Retrigger envelopes. Remove for legato effect.
}
}
}
// -----------------------------------------------------------------------------
void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
{
midiNotes.add(MidiNote(inNote, inVelocity));
handleNotesChanged();
}
void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
{
midiNotes.remove(inNote);
handleNotesChanged();
if (midiNotes.empty())
{
handleGateChanged(false);
noTone(sAudioOutPin);
}
}
// -----------------------------------------------------------------------------