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/midimapparser.cc | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/midimapparser.cc') diff --git a/src/midimapparser.cc b/src/midimapparser.cc index 363e1d5..20ccc77 100644 --- a/src/midimapparser.cc +++ b/src/midimapparser.cc @@ -29,6 +29,8 @@ #include #include +#include + bool MidiMapParser::parseFile(const std::string& filename) { pugi::xml_document doc; @@ -42,16 +44,42 @@ bool MidiMapParser::parseFile(const std::string& filename) pugi::xml_node midimap_node = doc.child("midimap"); for(pugi::xml_node map_node : midimap_node.children("map")) { - constexpr int bad_value = 10000; - auto note = map_node.attribute("note").as_int(bad_value); - auto instr = map_node.attribute("instr").as_string(); - if(std::string(instr) == "" || note == bad_value) + constexpr int default_int = 10000; + auto note = map_node.attribute("note").as_int(default_int); + auto cc = map_node.attribute("cc").as_int(default_int); + auto instr = std::string(map_node.attribute("instr").as_string()); + auto control_str = std::string(map_node.attribute("control").as_string()); + auto control = (control_str == "openness" ? InstrumentStateKind::Openness : + InstrumentStateKind::NoneOrAny); + + bool is_conflict = (note != default_int && cc != default_int); + bool is_note_play_instrument = + (!is_conflict && instr != "" && note != default_int); + bool is_cc_control = + (!is_conflict && instr != "" && control != InstrumentStateKind::NoneOrAny && cc != default_int); + + if (is_note_play_instrument) { - continue; + MidimapEntry entry( + MapFrom::Note, + note, + MapTo::PlayInstrument, + instr, + InstrumentStateKind::NoneOrAny + ); + midimap.push_back(entry); + } + else if (is_cc_control) + { + MidimapEntry entry( + MapFrom::CC, + cc, + MapTo::InstrumentState, + instr, + control + ); + midimap.push_back(entry); } - - MidimapEntry entry{note, instr}; - midimap.push_back(entry); } return true; -- cgit v1.2.3