From 624aafbc9cde2b9e83c7c278e44f19ab9e3bc9fc Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Thu, 25 Jul 2024 09:09:35 +0200 Subject: Support curve maps in midi map file --- src/midimapper.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'src/midimapper.cc') diff --git a/src/midimapper.cc b/src/midimapper.cc index 345ce2f..8b44dde 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -25,26 +25,64 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "midimapper.h" +#include -std::vector MidiMapper::lookup(int note_id) +#include + +MidimapEntry::MidimapEntry(int note_id, + std::string instrument_name, + CurveMap *maybe_curve_map) : + note_id(note_id) + , instrument_name(instrument_name) +{ + if (maybe_curve_map) + { + this->maybe_curve_map = std::make_unique(*maybe_curve_map); + } +} + +MidimapEntry::MidimapEntry(const MidimapEntry& other) +{ + *this = other; +} + +MidimapEntry &MidimapEntry::operator=(const MidimapEntry& other) +{ + note_id = other.note_id; + instrument_name = other.instrument_name; + if (other.maybe_curve_map) + { + maybe_curve_map = std::make_unique(*other.maybe_curve_map); + } + + 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 note_id) { - std::vector instruments; + std::vector rval; const std::lock_guard guard(mutex); for(const auto& map_entry : midimap) { - if(map_entry.note_id == note_id) + if(note_id == map_entry.note_id) { - 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