commit 4c5caea4241829a65b3f951ec0aa2ecfb0e81ccd
parent f4d1fa78a85f1055b04c6b7ab69fd153141f93c6
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 29 Jul 2024 22:57:42 +0200
move controller map into separate file and add parameter to CC lookup
Diffstat:
6 files changed, 70 insertions(+), 23 deletions(-)
diff --git a/source/jucePluginLib/CMakeLists.txt b/source/jucePluginLib/CMakeLists.txt
@@ -7,6 +7,7 @@ set(SOURCES
createVersionDateTime.cmake
clipboard.cpp clipboard.h
controller.cpp controller.h
+ controllermap.cpp controllermap.h
dummydevice.cpp dummydevice.h
event.cpp event.h
midipacket.cpp midipacket.h
diff --git a/source/jucePluginLib/controller.cpp b/source/jucePluginLib/controller.cpp
@@ -249,7 +249,7 @@ namespace pluginLib
return sendSysEx(_packetName, params);
}
- bool Controller::sendSysEx(const std::string& _packetName, const std::map<pluginLib::MidiDataType, uint8_t>& _params) const
+ bool Controller::sendSysEx(const std::string& _packetName, const std::map<MidiDataType, uint8_t>& _params) const
{
std::vector<uint8_t> sysex;
diff --git a/source/jucePluginLib/controllermap.cpp b/source/jucePluginLib/controllermap.cpp
@@ -0,0 +1,38 @@
+#include "controllermap.h"
+
+namespace pluginLib
+{
+ void ControllerMap::add(synthLib::MidiStatusByte _midiStatusByte, uint8_t _cc, uint32_t _paramIndex)
+ {
+ m_ccToParamIndex[_midiStatusByte][_cc].push_back(_paramIndex);
+ m_paramIndexToCC[_midiStatusByte][_paramIndex].push_back(_cc);
+ }
+
+ const std::vector<uint32_t>& ControllerMap::getControlledParameters(const synthLib::SMidiEvent& _ev) const
+ {
+ static std::vector<uint32_t> empty;
+ const uint8_t type = _ev.a & 0xf0;
+
+ const auto itType = m_ccToParamIndex.find(type);
+ if(itType == m_ccToParamIndex.end())
+ return empty;
+
+ const auto itValue = itType->second.find(_ev.b);
+ if(itValue == itType->second.end())
+ return empty;
+
+ return itValue->second;
+ }
+
+ std::vector<uint8_t> ControllerMap::getControlChanges(const synthLib::MidiStatusByte _midiStatusByte, const uint32_t _paramIndex) const
+ {
+ static std::vector<uint8_t> empty;
+ const auto itType = m_paramIndexToCC.find(_midiStatusByte);
+ if(itType == m_paramIndexToCC.end())
+ return empty;
+ const auto itCCList = itType->second.find(_paramIndex);
+ if(itCCList == itType->second.end())
+ return empty;
+ return itCCList->second;
+ }
+}
diff --git a/source/jucePluginLib/controllermap.h b/source/jucePluginLib/controllermap.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <cstdint>
+#include <unordered_map>
+#include <vector>
+
+#include "parameter.h"
+#include "synthLib/midiTypes.h"
+
+namespace pluginLib
+{
+ class ControllerMap
+ {
+ public:
+ void add(synthLib::MidiStatusByte _midiStatusByte, uint8_t _cc, uint32_t _paramIndex);
+
+ const std::vector<uint32_t>& getControlledParameters(const synthLib::SMidiEvent& _ev) const;
+ std::vector<uint8_t> getControlChanges(synthLib::MidiStatusByte _midiStatusByte, uint32_t _paramIndex) const;
+
+ private:
+ std::unordered_map<uint8_t, std::unordered_map<uint8_t, std::vector<uint32_t>>> m_ccToParamIndex; // type (control change, poly pressure) => index (modwheel, main vol, ...) => parameter index
+ std::unordered_map<uint8_t, std::unordered_map<uint32_t, std::vector<uint8_t>>> m_paramIndexToCC; // type (control change, poly pressure) => parameter index => index (modwheel, main vol, ...)
+ };
+}
diff --git a/source/jucePluginLib/parameterdescriptions.cpp b/source/jucePluginLib/parameterdescriptions.cpp
@@ -62,23 +62,6 @@ namespace pluginLib
return &it->second;
}
- const std::vector<uint32_t>& ParameterDescriptions::getControlledParameters(const synthLib::SMidiEvent& _ev)
- {
- static std::vector<uint32_t> empty;
-
- const uint8_t type = _ev.a & 0xf0;
-
- const auto itType = m_controllerMap.find(type);
- if(itType == m_controllerMap.end())
- return empty;
-
- const auto itValue = itType->second.find(_ev.b);
- if(itValue == itType->second.end())
- return empty;
-
- return itValue->second;
- }
-
std::string ParameterDescriptions::loadJson(const std::string& _jsonString)
{
// juce' JSON parser doesn't like JSON5-style comments
@@ -842,9 +825,9 @@ namespace pluginLib
}
if(cc != Invalid)
- m_controllerMap[synthLib::M_CONTROLCHANGE][cc].push_back(paramIndex);
+ m_controllerMap.add(synthLib::M_CONTROLCHANGE, cc, paramIndex);
if(pp != Invalid)
- m_controllerMap[synthLib::M_POLYPRESSURE][pp].push_back(paramIndex);
+ m_controllerMap.add(synthLib::M_POLYPRESSURE, pp, paramIndex);
}
}
diff --git a/source/jucePluginLib/parameterdescriptions.h b/source/jucePluginLib/parameterdescriptions.h
@@ -4,6 +4,7 @@
#include <string>
#include <vector>
+#include "controllermap.h"
#include "midipacket.h"
#include "parameterdescription.h"
#include "parameterlink.h"
@@ -44,11 +45,11 @@ namespace pluginLib
const ValueList* getValueList(const std::string& _key) const;
- const std::vector<uint32_t>& getControlledParameters(const synthLib::SMidiEvent& _ev);
-
const std::string& getErrors() const { return m_errors; }
bool isValid() const { return getErrors().empty(); }
+ const auto& getControllerMap() const { return m_controllerMap; }
+
private:
std::string loadJson(const std::string& _jsonString);
@@ -69,7 +70,7 @@ namespace pluginLib
std::unordered_map<std::string, MidiPacket> m_midiPackets;
std::vector<ParameterLink> m_parameterLinks;
std::unordered_map<std::string, ParameterRegion> m_regions;
- std::unordered_map<uint8_t, std::unordered_map<uint8_t, std::vector<uint32_t>>> m_controllerMap; // type (control change, poly pressure) => index (modwheel, main vol, ...) => parameter index
+ ControllerMap m_controllerMap;
std::string m_errors;
};