diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/adlmidi_midiplay.cpp | 26 | ||||
-rw-r--r-- | src/adlmidi_midiplay.hpp | 20 |
2 files changed, 39 insertions, 7 deletions
diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 6261181..f8bd0a2 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -269,15 +269,23 @@ void MIDIplay::TickIterators(double s) for(size_t c = 0, n = m_midiChannels.size(); c < n; ++c) { MIDIchannel &ch = m_midiChannels[c]; + if(ch.extended_note_count == 0) + continue; + for(MIDIchannel::notes_iterator inext = ch.activenotes.begin(); !inext.is_end();) { MIDIchannel::notes_iterator i(inext++); MIDIchannel::NoteInfo &ni = i->value; + double ttl = ni.ttl; - if(ttl > 0) + if(ttl <= 0) + continue; + + ni.ttl = ttl = ttl - s; + if(ttl <= 0) { - ni.ttl = ttl = ttl - s; - if(ni.isOnExtendedLifeTime && ttl <= 0) + --ch.extended_note_count; + if(ni.isOnExtendedLifeTime) { noteUpdate(c, i, Upd_Off); ni.isOnExtendedLifeTime = false; @@ -608,7 +616,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity) ni.isPercussion = isPercussion; ni.isBlank = isBlankNote; ni.isOnExtendedLifeTime = false; - ni.ttl = isPercussion ? drum_note_min_time : 0; + ni.ttl = 0; ni.ains = ains; ni.chip_channels_count = 0; @@ -628,6 +636,13 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity) ++midiChan.gliding_note_count; } + // Enable life time extension on percussion note + if (isPercussion) + { + ni.ttl = drum_note_min_time; + ++midiChan.extended_note_count; + } + for(unsigned ccount = 0; ccount < MIDIchannel::NoteInfo::MaxNumPhysChans; ++ccount) { int32_t c = adlchannel[ccount]; @@ -1369,8 +1384,7 @@ void MIDIplay::noteUpdate(size_t midCh, if(info.chip_channels_count == 0) { - if(info.glideRate != HUGE_VAL) - --m_midiChannels[midCh].gliding_note_count; + m_midiChannels[midCh].cleanupNote(i); m_midiChannels[midCh].activenotes.erase(i); } } diff --git a/src/adlmidi_midiplay.hpp b/src/adlmidi_midiplay.hpp index d3e5ea4..d7d8022 100644 --- a/src/adlmidi_midiplay.hpp +++ b/src/adlmidi_midiplay.hpp @@ -254,6 +254,8 @@ public: char _padding2[5]; //! Count of gliding notes in this channel unsigned gliding_note_count; + //! Count of notes having a TTL countdown in this channel + unsigned extended_note_count; //! Active notes in the channel pl_list<NoteInfo> activenotes; @@ -275,7 +277,10 @@ public: notes_iterator find_or_create_activenote(unsigned note) { notes_iterator it = find_activenote(note); - if(it.is_end()) { + if(!it.is_end()) + cleanupNote(it); + else + { NoteInfo ni; ni.note = note; it = activenotes.insert(activenotes.end(), ni); @@ -352,10 +357,23 @@ public: bendsense = cent * (1.0 / (128 * 8192)); } + /** + * @brief Clean up the state of the active note before removal + */ + void cleanupNote(notes_iterator i) + { + NoteInfo &info = i->value; + if(info.glideRate != HUGE_VAL) + --gliding_note_count; + if(info.ttl > 0) + --extended_note_count; + } + MIDIchannel() : activenotes(128) { gliding_note_count = 0; + extended_note_count = 0; reset(); } }; |