diff options
author | JP Cimalando <jpcima@users.noreply.github.com> | 2018-04-18 17:19:28 +0200 |
---|---|---|
committer | JP Cimalando <jpcima@users.noreply.github.com> | 2018-04-18 17:19:28 +0200 |
commit | 9a4d104c76cacf92ce109fb56750cd7ec1f58def (patch) | |
tree | 3eae66c1e86655f81ba6bc65cedcc016256ff9af /src/adlmidi_private.hpp | |
parent | 985f08d9ab40ffa6367261281660e6c3e5b0720f (diff) | |
parent | 26388a7cd07a365e4256b0308c3aa87772accd41 (diff) | |
download | libADLMIDI-9a4d104c76cacf92ce109fb56750cd7ec1f58def.tar.gz libADLMIDI-9a4d104c76cacf92ce109fb56750cd7ec1f58def.tar.bz2 libADLMIDI-9a4d104c76cacf92ce109fb56750cd7ec1f58def.zip |
Merge remote-tracking branch 'origin/hard-realtime-phys2' into HEAD
Diffstat (limited to 'src/adlmidi_private.hpp')
-rw-r--r-- | src/adlmidi_private.hpp | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 6391f2a..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 @@ -620,17 +621,23 @@ public: size_t insmeta; enum { - MaxNumPhysChans = 2 + MaxNumPhysChans = 2, + MaxNumPhysItemCount = MaxNumPhysChans, }; struct Phys { - //! Destinition chip channel + //! 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); @@ -641,9 +648,49 @@ public: } }; //! List of OPL3 channels it is currently occupying. - Phys chip_channels[MaxNumPhysChans]; + Phys chip_channels[MaxNumPhysItemCount]; //! Count of used channels. - size_t chip_channels_max; + 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]; @@ -693,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]; |