From 31ab9fccd609ac6a0c25819d0b7e685298b4047b Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Sun, 25 May 2025 01:56:52 +0300 Subject: Stabilise the channels logic --- src/adlmidi_midiplay.hpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/adlmidi_midiplay.hpp') diff --git a/src/adlmidi_midiplay.hpp b/src/adlmidi_midiplay.hpp index e5058b9..bcd76a1 100644 --- a/src/adlmidi_midiplay.hpp +++ b/src/adlmidi_midiplay.hpp @@ -235,11 +235,16 @@ public: Phys *phys_find(unsigned chip_chan) { Phys *ph = NULL; + for(unsigned i = 0; i < chip_channels_count && !ph; ++i) + { if(chip_channels[i].chip_chan == chip_chan) ph = &chip_channels[i]; + } + return ph; } + Phys *phys_find_or_create(uint16_t chip_chan) { Phys *ph = phys_find(chip_chan); @@ -251,20 +256,23 @@ public: } return ph; } + Phys *phys_ensure_find_or_create(uint16_t chip_chan) { Phys *ph = phys_find_or_create(chip_chan); assert(ph); return ph; } + void phys_erase_at(const Phys *ph) { intptr_t pos = ph - chip_channels; - assert(pos < static_cast(chip_channels_count)); + assert(pos >= 0 && pos < static_cast(chip_channels_count)); for(intptr_t i = pos + 1; i < static_cast(chip_channels_count); ++i) chip_channels[i - 1] = chip_channels[i]; --chip_channels_count; } + void phys_erase(unsigned chip_chan) { Phys *ph = phys_find(chip_chan); @@ -285,6 +293,24 @@ public: typedef pl_list::iterator notes_iterator; typedef pl_list::const_iterator const_notes_iterator; + void clear_all_phys_users(unsigned chip_chan) + { + for(pl_list::iterator it = activenotes.begin(); it != activenotes.end(); ) + { + NoteInfo::Phys *p = it->value.phys_find(chip_chan); + if(p) + { + it->value.phys_erase_at(p); + if(it->value.chip_channels_count == 0) + it = activenotes.erase(it); + else + ++it; + } + else + ++it; + } + } + notes_iterator find_activenote(unsigned note) { return activenotes.find_if(NoteInfo::FindPredicate(note)); -- cgit v1.2.3