diff options
author | Vitaly Novichkov <Wohlstand@users.noreply.github.com> | 2018-04-16 22:37:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-16 22:37:23 +0300 |
commit | f87aa4d29c638d77501ec9474d213262238b9d1d (patch) | |
tree | 0bb91b6ab803d23305bf462a7a192119c0d9fe2a /src/adlmidi_private.hpp | |
parent | b3ea5157f09b30e17fc434f7bc86861a794c9abb (diff) | |
parent | 2678f0c510cf6814698f8c773e7808946047d5d0 (diff) | |
download | libADLMIDI-f87aa4d29c638d77501ec9474d213262238b9d1d.tar.gz libADLMIDI-f87aa4d29c638d77501ec9474d213262238b9d1d.tar.bz2 libADLMIDI-f87aa4d29c638d77501ec9474d213262238b9d1d.zip |
Merge pull request #67 from jpcima/hard-realtime
transform the note map into a fixed array
Diffstat (limited to 'src/adlmidi_private.hpp')
-rw-r--r-- | src/adlmidi_private.hpp | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index b60c7c0..08c22c0 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -606,6 +606,8 @@ public: bool is_xg_percussion; struct NoteInfo { + uint8_t note; + bool active; // Current pressure uint8_t vol; char ____padding[1]; @@ -636,10 +638,73 @@ public: // List of OPL3 channels it is currently occupying. std::map<uint16_t /*adlchn*/, Phys> phys; }; - typedef std::map<uint8_t, NoteInfo> activenotemap_t; - typedef activenotemap_t::iterator activenoteiterator; char ____padding2[5]; - activenotemap_t activenotes; + NoteInfo activenotes[128]; + + struct activenoteiterator + { + explicit activenoteiterator(NoteInfo *info = 0) + : ptr(info) {} + activenoteiterator &operator++() + { + if(ptr->note == 127) + ptr = 0; + else + for(++ptr; ptr && !ptr->active;) + ptr = (ptr->note == 127) ? 0 : (ptr + 1); + return *this; + }; + activenoteiterator operator++(int) + { + activenoteiterator pos = *this; + ++*this; + return pos; + } + NoteInfo &operator*() const + { return *ptr; } + NoteInfo *operator->() const + { return ptr; } + bool operator==(activenoteiterator other) const + { return ptr == other.ptr; } + bool operator!=(activenoteiterator other) const + { return ptr != other.ptr; } + operator NoteInfo *() const + { return ptr; } + private: + NoteInfo *ptr; + }; + + activenoteiterator activenotes_begin() + { + activenoteiterator it(activenotes); + return (it->active) ? it : ++it; + } + + activenoteiterator activenotes_find(uint8_t note) + { + return activenoteiterator( + activenotes[note].active ? &activenotes[note] : 0); + } + + std::pair<activenoteiterator, bool> activenotes_insert(uint8_t note) + { + NoteInfo &info = activenotes[note]; + bool inserted = !info.active; + if(inserted) info.active = true; + return std::pair<activenoteiterator, bool>(activenoteiterator(&info), inserted); + } + + void activenotes_erase(activenoteiterator pos) + { + if(pos) + pos->active = false; + } + + bool activenotes_empty() + { + return !activenotes_begin(); + } + void reset() { resetAllControllers(); |