diff options
author | Nils Brederlow <62596379+dingodoppelt@users.noreply.github.com> | 2022-02-03 20:57:53 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-02-03 20:57:53 +0100 |
commit | 76d649620c321d94cf8fcbe8ee5f006ffd191b14 (patch) | |
tree | fbff2cbb76b620845eaf5b192ef928b0f95e0897 /src | |
parent | 235ad6fbbce2e0ae9e06db960a5ba3b099936ace (diff) |
Add feature CC to note to midimap
Diffstat (limited to 'src')
-rw-r--r-- | src/audioinputenginemidi.cc | 19 | ||||
-rw-r--r-- | src/midimapparser.cc | 14 | ||||
-rw-r--r-- | src/midimapparser.h | 1 | ||||
-rw-r--r-- | src/midimapper.cc | 20 | ||||
-rw-r--r-- | src/midimapper.h | 11 |
5 files changed, 61 insertions, 4 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc index 69aeeb6..c4041e3 100644 --- a/src/audioinputenginemidi.cc +++ b/src/audioinputenginemidi.cc @@ -78,7 +78,7 @@ bool AudioInputEngineMidi::loadMidiMap(const std::string& file, instrmap[instruments[i]->getName()] = i; } - mmap.swap(instrmap, midimap_parser.midimap); + mmap.swap(instrmap, midimap_parser.midimap, midimap_parser.ccmap); midimap = file; is_valid = true; @@ -100,6 +100,7 @@ bool AudioInputEngineMidi::isValid() const static const std::uint8_t NoteOff = 0x80; static const std::uint8_t NoteOn = 0x90; static const std::uint8_t NoteAftertouch = 0xA0; +static const std::uint8_t CC = 0xB0; // Note type mask: static int const NoteMask = 0xF0; @@ -114,9 +115,23 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, return; } + if(((midi_buffer[0] & NoteMask) == CC) && (midi_buffer[2] == 127)) + { + std::uint8_t intermediateBuffer[3]; + auto notes = mmap.lookupCC(midi_buffer[1]); + intermediateBuffer[0] = NoteOn; + intermediateBuffer[2] = 127; + for(const auto& note_idx : notes) + { + intermediateBuffer[1] = (std::size_t)note_idx; + processNote(intermediateBuffer, 3, offset, events); + } + return; + } + auto key = midi_buffer[1]; auto velocity = midi_buffer[2]; - auto instrument_idx = mmap.lookup(key); + //auto instrument_idx = mmap.lookup(key); auto instruments = mmap.lookup(key); for(const auto& instrument_idx : instruments) { diff --git a/src/midimapparser.cc b/src/midimapparser.cc index 363e1d5..1e41244 100644 --- a/src/midimapparser.cc +++ b/src/midimapparser.cc @@ -54,5 +54,19 @@ bool MidiMapParser::parseFile(const std::string& filename) midimap.push_back(entry); } + for(pugi::xml_node ccmap_node : midimap_node.children("CCmap")) + { + constexpr int bad_value = 10000; + auto cc = ccmap_node.attribute("cc").as_int(bad_value); + auto note = ccmap_node.attribute("note").as_int(bad_value); + if(cc == bad_value || note == bad_value) + { + continue; + } + + MidiCCmapEntry entry{cc, note}; + ccmap.push_back(entry); + } + return true; } diff --git a/src/midimapparser.h b/src/midimapparser.h index d2f2ddd..7f0692c 100644 --- a/src/midimapparser.h +++ b/src/midimapparser.h @@ -35,4 +35,5 @@ public: bool parseFile(const std::string& filename); midimap_t midimap; + ccmap_t ccmap; }; diff --git a/src/midimapper.cc b/src/midimapper.cc index b9316c5..b8dafc0 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -47,12 +47,30 @@ std::vector<int> MidiMapper::lookup(int note_id) return instruments; } -void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap) +std::vector<int> MidiMapper::lookupCC(int cc_id) +{ + std::vector<int> notes; + + std::lock_guard<std::mutex> guard(mutex); + + for(const auto& map_entry : ccmap) + { + if(map_entry.cc_id == cc_id) + { + notes.push_back(map_entry.note_id); + } + } + + return notes; +} + +void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap, ccmap_t& ccmap) { std::lock_guard<std::mutex> guard(mutex); std::swap(this->instrmap, instrmap); std::swap(this->midimap, midimap); + std::swap(this->ccmap, ccmap); } const midimap_t& MidiMapper::getMap() diff --git a/src/midimapper.h b/src/midimapper.h index 94781d4..97f3552 100644 --- a/src/midimapper.h +++ b/src/midimapper.h @@ -37,19 +37,28 @@ struct MidimapEntry std::string instrument_name; }; +struct MidiCCmapEntry +{ + int cc_id; + int note_id; +}; + using midimap_t = std::vector<MidimapEntry>; using instrmap_t = std::map<std::string, int>; +using ccmap_t = std::vector<MidiCCmapEntry>; class MidiMapper { public: //! Lookup note in map and returns the corresponding instrument index list. std::vector<int> lookup(int note_id); + std::vector<int> lookupCC(int cc_id); //! Set new map sets. - void swap(instrmap_t& instrmap, midimap_t& midimap); + void swap(instrmap_t& instrmap, midimap_t& midimap, ccmap_t& ccmap); const midimap_t& getMap(); + ccmap_t ccmap; private: instrmap_t instrmap; |