Low, High and Last playing modes.

This commit is contained in:
Francois Best 2014-05-21 08:30:15 +02:00
parent 5454bd46bc
commit bcd3f8f33a
2 changed files with 66 additions and 8 deletions

View File

@ -41,8 +41,13 @@ void handleNotesChanged()
} }
else else
{ {
// Possible playing modes:
// Mono Low: use midiNotes.getLow
// Mono High: use midiNotes.getHigh
// Mono Last: use midiNotes.getLast
byte currentNote = 0; byte currentNote = 0;
if (midiNotes.getTail(currentNote)) if (midiNotes.getLast(currentNote))
{ {
tone(sAudioOutPin, sNotePitches[currentNote]); tone(sAudioOutPin, sNotePitches[currentNote]);
pulseGate(); // Retrigger envelopes. Remove for legato effect. pulseGate(); // Retrigger envelopes. Remove for legato effect.
@ -67,7 +72,7 @@ void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void setup() void setup()
{ {
pinMode(sGatePin, OUTPUT); pinMode(sGatePin, OUTPUT);
pinMode(sAudioOutPin, OUTPUT); pinMode(sAudioOutPin, OUTPUT);
MIDI.setHandleNoteOn(handleNoteOn); MIDI.setHandleNoteOn(handleNoteOn);

View File

@ -65,7 +65,9 @@ public:
public: public:
inline bool get(byte inIndex, byte& outPitch) const; 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: public:
inline bool empty() const; inline bool empty() const;
@ -257,14 +259,65 @@ inline bool MidiNoteList<Size>::get(byte inIndex, byte& outPitch) const
} }
template<byte Size> template<byte Size>
inline bool MidiNoteList<Size>::getTail(byte& outPitch) const inline bool MidiNoteList<Size>::getLast(byte& outPitch) const
{ {
if (mTail) if (!mTail)
{ {
outPitch = mTail->note.pitch; return false;
return true;
} }
return false;
outPitch = mTail->note.pitch;
return true;
}
template<byte Size>
inline bool MidiNoteList<Size>::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<byte Size>
inline bool MidiNoteList<Size>::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;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------