From 60bc095f2f431b4e6421307fc7ab62c6cc9ce0c2 Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Thu, 24 Jan 2019 11:29:29 +0100 Subject: cache the extended note count per channel --- src/adlmidi_midiplay.hpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/adlmidi_midiplay.hpp') 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 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(); } }; -- cgit v1.2.3