aboutsummaryrefslogtreecommitdiff
path: root/src/adlmidi_midiplay.hpp
diff options
context:
space:
mode:
authorJP Cimalando <jpcima@users.noreply.github.com>2018-11-10 19:05:27 +0100
committerJP Cimalando <jpcima@users.noreply.github.com>2018-11-10 19:05:27 +0100
commit63ae4b909946eca9be11f2c5b0f0dc08ae706597 (patch)
tree9b6faf206e83d30a0e1a38dd56565f7c3b9f4609 /src/adlmidi_midiplay.hpp
parent298160f0154a05030681a208a247e2ed309f89db (diff)
downloadlibADLMIDI-63ae4b909946eca9be11f2c5b0f0dc08ae706597.tar.gz
libADLMIDI-63ae4b909946eca9be11f2c5b0f0dc08ae706597.tar.bz2
libADLMIDI-63ae4b909946eca9be11f2c5b0f0dc08ae706597.zip
converted activenotes to generic list
Diffstat (limited to 'src/adlmidi_midiplay.hpp')
-rw-r--r--src/adlmidi_midiplay.hpp105
1 files changed, 28 insertions, 77 deletions
diff --git a/src/adlmidi_midiplay.hpp b/src/adlmidi_midiplay.hpp
index d16d851..f7dc0fa 100644
--- a/src/adlmidi_midiplay.hpp
+++ b/src/adlmidi_midiplay.hpp
@@ -140,8 +140,6 @@ public:
{
//! Note number
uint8_t note;
- //! Is note active
- bool active;
//! Current pressure
uint8_t vol;
//! Note vibrato (a part of Note Aftertouch feature)
@@ -166,6 +164,15 @@ public:
MaxNumPhysItemCount = MaxNumPhysChans
};
+ struct FindPredicate
+ {
+ explicit FindPredicate(unsigned note)
+ : note(note) {}
+ bool operator()(const NoteInfo &ni) const
+ { return ni.note == note; }
+ unsigned note;
+ };
+
/**
* @brief Reference to currently using chip channel
*/
@@ -245,87 +252,31 @@ public:
unsigned gliding_note_count;
//! Active notes in the channel
- NoteInfo activenotes[128];
-
- struct activenoteiterator
- {
- explicit activenoteiterator(NoteInfo *info = NULL)
- : ptr(info) {}
- activenoteiterator &operator++()
- {
- if(ptr->note == 127)
- ptr = NULL;
- else
- for(++ptr; ptr && !ptr->active;)
- ptr = (ptr->note == 127) ? NULL : (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;
- }
+ pl_list<NoteInfo> activenotes;
+ typedef typename pl_list<NoteInfo>::iterator notes_iterator;
+ typedef typename pl_list<NoteInfo>::const_iterator const_notes_iterator;
- activenoteiterator activenotes_find(uint8_t note)
+ notes_iterator find_activenote(unsigned note)
{
- assert(note < 128);
- return activenoteiterator(
- activenotes[note].active ? &activenotes[note] : NULL);
+ return activenotes.find_if(NoteInfo::FindPredicate(note));
}
- activenoteiterator activenotes_ensure_find(uint8_t note)
+ notes_iterator ensure_find_activenote(unsigned note)
{
- activenoteiterator it = activenotes_find(note);
- assert(it);
+ notes_iterator it = find_activenote(note);
+ assert(!it.is_end());
return it;
}
- std::pair<activenoteiterator, bool> activenotes_insert(uint8_t note)
- {
- assert(note < 128);
- 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 activenotes_clear()
+ notes_iterator find_or_create_activenote(unsigned note)
{
- for(uint8_t i = 0; i < 128; ++i) {
- activenotes[i].note = i;
- activenotes[i].active = false;
+ notes_iterator it = find_activenote(note);
+ if(it.is_end()) {
+ NoteInfo ni;
+ ni.note = note;
+ it = activenotes.insert(activenotes.end(), ni);
}
+ return it;
}
/**
@@ -391,8 +342,8 @@ public:
}
MIDIchannel()
+ : activenotes(128)
{
- activenotes_clear();
gliding_note_count = 0;
reset();
}
@@ -432,7 +383,7 @@ public:
struct FindPredicate
{
- FindPredicate(Location loc)
+ explicit FindPredicate(Location loc)
: loc(loc) {}
bool operator()(const LocationData &ld) const
{ return ld.loc == loc; }
@@ -907,7 +858,7 @@ private:
* @param select_adlchn Specify chip channel, or -1 - all chip channels used by the note
*/
void noteUpdate(size_t midCh,
- MIDIchannel::activenoteiterator i,
+ MIDIchannel::notes_iterator i,
unsigned props_mask,
int32_t select_adlchn = -1);
@@ -943,7 +894,7 @@ private:
void killOrEvacuate(
size_t from_channel,
AdlChannel::users_iterator j,
- MIDIchannel::activenoteiterator i);
+ MIDIchannel::notes_iterator i);
/**
* @brief Off all notes and silence sound