From bcd3f8f33a492885b8e4803a246b16d69146d2fb Mon Sep 17 00:00:00 2001 From: Francois Best Date: Wed, 21 May 2014 08:30:15 +0200 Subject: [PATCH] Low, High and Last playing modes. --- .../MIDI_SimpleSynth/MIDI_SimpleSynth.ino | 9 ++- res/Examples/MIDI_SimpleSynth/noteList.h | 65 +++++++++++++++++-- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino b/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino index c44c441..205611a 100644 --- a/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino +++ b/res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino @@ -41,8 +41,13 @@ void handleNotesChanged() } else { + // Possible playing modes: + // Mono Low: use midiNotes.getLow + // Mono High: use midiNotes.getHigh + // Mono Last: use midiNotes.getLast + byte currentNote = 0; - if (midiNotes.getTail(currentNote)) + if (midiNotes.getLast(currentNote)) { tone(sAudioOutPin, sNotePitches[currentNote]); pulseGate(); // Retrigger envelopes. Remove for legato effect. @@ -67,7 +72,7 @@ void handleNoteOff(byte inChannel, byte inNote, byte inVelocity) // ----------------------------------------------------------------------------- void setup() -{ +{ pinMode(sGatePin, OUTPUT); pinMode(sAudioOutPin, OUTPUT); MIDI.setHandleNoteOn(handleNoteOn); diff --git a/res/Examples/MIDI_SimpleSynth/noteList.h b/res/Examples/MIDI_SimpleSynth/noteList.h index 6d5885c..c5b5190 100644 --- a/res/Examples/MIDI_SimpleSynth/noteList.h +++ b/res/Examples/MIDI_SimpleSynth/noteList.h @@ -65,7 +65,9 @@ public: public: inline bool get(byte inIndex, byte& outPitch) const; - inline bool getTail(byte& outPitch) const; + inline bool getLast(byte& outPitch) const; + inline bool getHigh(byte& outPitch) const; + inline bool getLow(byte& outPitch) const; public: inline bool empty() const; @@ -257,14 +259,65 @@ inline bool MidiNoteList::get(byte inIndex, byte& outPitch) const } template -inline bool MidiNoteList::getTail(byte& outPitch) const +inline bool MidiNoteList::getLast(byte& outPitch) const { - if (mTail) + if (!mTail) { - outPitch = mTail->note.pitch; - return true; + return false; } - return false; + + outPitch = mTail->note.pitch; + return true; +} + +template +inline bool MidiNoteList::getHigh(byte& outPitch) const +{ + if (!mTail) + { + return false; + } + + outPitch = 0; + const Cell* it = mTail; + for (byte i = 0; i < mSize; ++i) + { + if (it->note.pitch > outPitch) + { + outPitch = it->note.pitch; + } + + if (it->prev) + { + it = it->prev; + } + } + return true; +} + +template +inline bool MidiNoteList::getLow(byte& outPitch) const +{ + if (!mTail) + { + return false; + } + + outPitch = 0xff; + const Cell* it = mTail; + for (byte i = 0; i < mSize; ++i) + { + if (it->note.pitch < outPitch) + { + outPitch = it->note.pitch; + } + + if (it->prev) + { + it = it->prev; + } + } + return true; } // -----------------------------------------------------------------------------