From faaaf5d328429fd2c3f38131f7a874d056761f3f Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Sun, 28 Jul 2024 09:24:01 +0200 Subject: Openness development --- src/midimapper.cc | 65 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 9 deletions(-) (limited to 'src/midimapper.cc') diff --git a/src/midimapper.cc b/src/midimapper.cc index 345ce2f..b4de580 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -26,25 +26,72 @@ */ #include "midimapper.h" -std::vector MidiMapper::lookup(int note_id) +#include + +MidimapEntry::MidimapEntry(MapFrom from_kind, + int from_id, + MapTo to_kind, + std::string instrument_name, + InstrumentStateKind maybe_instrument_state_kind + ) : + from_kind(from_kind) + , from_id(from_id) + , to_kind(to_kind) + , instrument_name(instrument_name) + , maybe_instrument_state_kind(maybe_instrument_state_kind) +{} + +MidimapEntry::MidimapEntry(const MidimapEntry& other) +{ + *this = other; +} + +MidimapEntry &MidimapEntry::operator=(const MidimapEntry& other) { - std::vector instruments; + from_kind = other.from_kind; + from_id = other.from_id; + to_kind = other.to_kind; + instrument_name = other.instrument_name; + maybe_instrument_state_kind = other.maybe_instrument_state_kind; + + return *this; +} + +int MidiMapper::lookup_instrument(std::string name) { + const std::lock_guard guard(mutex); + auto instrmap_it = instrmap.find(name); + if(instrmap_it != instrmap.end()) + { + return instrmap_it->second; + } + return -1; +} + +std::vector MidiMapper::lookup( + int from_id, + MapFrom from_kind, + MapTo to_kind, + InstrumentStateKind state_kind) +{ + std::vector rval; const std::lock_guard guard(mutex); for(const auto& map_entry : midimap) { - if(map_entry.note_id == note_id) + bool match = true; + match = match && (from_id == -1 || from_id == map_entry.from_id); + match = match && (from_kind == MapFrom::NoneOrAny || from_kind == map_entry.from_kind); + match = match && (to_kind == MapTo::NoneOrAny || to_kind == map_entry.to_kind); + match = match && (state_kind == InstrumentStateKind::NoneOrAny || state_kind == map_entry.maybe_instrument_state_kind); + + if(match) { - auto instrmap_it = instrmap.find(map_entry.instrument_name); - if(instrmap_it != instrmap.end()) - { - instruments.push_back(instrmap_it->second); - } + rval.push_back(map_entry); } } - return instruments; + return rval; } void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap) -- cgit v1.2.3