From 9157f847ca9a750b48d384fae4b3fa944db825f1 Mon Sep 17 00:00:00 2001 From: Francois Best Date: Wed, 21 May 2014 09:01:29 +0200 Subject: [PATCH] Fix the fix. --- .../MIDI_SimpleSynth/MIDI_SimpleSynth.ino | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino b/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino index 205611a..0b6f560 100644 --- a/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino +++ b/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino @@ -18,12 +18,12 @@ MidiNoteList 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,7 +32,7 @@ void pulseGate() // ----------------------------------------------------------------------------- -void handleNotesChanged() +void handleNotesChanged(bool isFirstNote = false) { if (midiNotes.empty()) { @@ -50,7 +50,15 @@ void handleNotesChanged() if (midiNotes.getLast(currentNote)) { tone(sAudioOutPin, sNotePitches[currentNote]); - pulseGate(); // Retrigger envelopes. Remove for legato effect. + + if (isFirstNote) + { + handleGateChanged(true); + } + else + { + pulseGate(); // Retrigger envelopes. Remove for legato effect. + } } } } @@ -59,8 +67,9 @@ void handleNotesChanged() void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) { + const bool firstNote = midiNotes.empty(); midiNotes.add(MidiNote(inNote, inVelocity)); - handleNotesChanged(); + handleNotesChanged(firstNote); } void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)