diff options
author | JP Cimalando <jpcima@users.noreply.github.com> | 2018-04-18 16:18:37 +0200 |
---|---|---|
committer | JP Cimalando <jpcima@users.noreply.github.com> | 2018-04-18 17:17:28 +0200 |
commit | 26388a7cd07a365e4256b0308c3aa87772accd41 (patch) | |
tree | 92de37a1755d6de96853835269221ae2d5f656f5 /src/adlmidi_private.hpp | |
parent | f87aa4d29c638d77501ec9474d213262238b9d1d (diff) | |
download | libADLMIDI-26388a7cd07a365e4256b0308c3aa87772accd41.tar.gz libADLMIDI-26388a7cd07a365e4256b0308c3aa87772accd41.tar.bz2 libADLMIDI-26388a7cd07a365e4256b0308c3aa87772accd41.zip |
reformulated phys code into original map semantics
Diffstat (limited to 'src/adlmidi_private.hpp')
-rw-r--r-- | src/adlmidi_private.hpp | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 08c22c0..69a833c 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -87,6 +87,7 @@ typedef int32_t ssize_t; #include <cmath> #include <cstdarg> #include <cstdio> +#include <cassert> #if !(defined(__APPLE__) && defined(__GLIBCXX__)) #include <cinttypes> //PRId32, PRIu32, etc. #else @@ -618,13 +619,25 @@ public: size_t midiins; // Index to physical adlib data structure, adlins[] size_t insmeta; + enum + { + MaxNumPhysChans = 2, + MaxNumPhysItemCount = MaxNumPhysChans, + }; struct Phys { + //! Destination chip channel + uint16_t chip_chan; //! ins, inde to adl[] size_t insId; //! Is this voice must be detunable? bool pseudo4op; + void assign(const Phys &oth) + { + insId = oth.insId; + pseudo4op = oth.pseudo4op; + } bool operator==(const Phys &oth) const { return (insId == oth.insId) && (pseudo4op == oth.pseudo4op); @@ -634,9 +647,50 @@ public: return !operator==(oth); } }; - typedef std::map<uint16_t, Phys> PhysMap; - // List of OPL3 channels it is currently occupying. - std::map<uint16_t /*adlchn*/, Phys> phys; + //! List of OPL3 channels it is currently occupying. + Phys chip_channels[MaxNumPhysItemCount]; + //! Count of used channels. + unsigned chip_channels_count; + // + 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(unsigned chip_chan) + { + Phys *ph = phys_find(chip_chan); + if(!ph) { + if(chip_channels_count < MaxNumPhysItemCount) { + ph = &chip_channels[chip_channels_count++]; + ph->chip_chan = chip_chan; + } + } + return ph; + } + Phys *phys_ensure_find_or_create(unsigned chip_chan) + { + Phys *ph = phys_find_or_create(chip_chan); + assert(ph); + return ph; + } + void phys_erase_at(const Phys *ph) + { + unsigned pos = ph - chip_channels; + assert(pos < chip_channels_count); + for(unsigned i = pos + 1; i < 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); + if(ph) + phys_erase_at(ph); + } }; char ____padding2[5]; NoteInfo activenotes[128]; @@ -686,6 +740,13 @@ public: activenotes[note].active ? &activenotes[note] : 0); } + activenoteiterator activenotes_ensure_find(uint8_t note) + { + activenoteiterator it = activenotes_find(note); + assert(it); + return it; + } + std::pair<activenoteiterator, bool> activenotes_insert(uint8_t note) { NoteInfo &info = activenotes[note]; |