gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit df551ad97062dbd13cc246f306d4bc1a4bc831f9
parent b39b8d0cd238163ebb5f4bc7e35628c30595cd3e
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Tue, 30 Jul 2024 17:31:53 +0200

patch manager implementation

Diffstat:
Msource/nord/n2x/n2xJucePlugin/n2xController.cpp | 43+++++++++++++++++++++++++++++++++++++++++--
Msource/nord/n2x/n2xJucePlugin/n2xController.h | 4+++-
Msource/nord/n2x/n2xJucePlugin/n2xPatchManager.cpp | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Msource/nord/n2x/n2xJucePlugin/n2xPatchManager.h | 1-
Msource/nord/n2x/n2xLib/n2xmiditypes.h | 3++-
5 files changed, 101 insertions(+), 14 deletions(-)

diff --git a/source/nord/n2x/n2xJucePlugin/n2xController.cpp b/source/nord/n2x/n2xJucePlugin/n2xController.cpp @@ -148,4 +148,44 @@ namespace n2xJucePlugin sendSysEx(MidiPacketType::RequestDump, params); } -} -\ No newline at end of file + + std::vector<uint8_t> Controller::createSingleDump(uint8_t _bank, uint8_t _program, uint8_t _part) const + { + pluginLib::MidiPacket::Data data; + + data.insert(std::make_pair(pluginLib::MidiDataType::DeviceId, n2x::SysexByte::DefaultDeviceId)); + data.insert(std::make_pair(pluginLib::MidiDataType::Bank, _bank)); + data.insert(std::make_pair(pluginLib::MidiDataType::Program, _program)); + + std::vector<uint8_t> dst; + + if (!createMidiDataFromPacket(dst, midiPacketName(MidiPacketType::SingleDump), data, _part)) + return {}; + + return dst; + } + + bool Controller::activatePatch(const std::vector<uint8_t>& _sysex, const uint32_t _part) + { + if(_part >= getPartCount()) + return false; + + const auto isSingle =_sysex.size() == n2x::g_singleDumpSize; + const auto isMulti = _sysex.size() == n2x::g_multiDumpSize; + + if(!isSingle && !isMulti) + return false; + + if(isMulti && _part != 0) + return false; + + auto d = _sysex; + + d[n2x::SysexIndex::IdxMsgType] = isSingle ? n2x::SysexByte::SingleDumpBankEditBuffer : n2x::SysexByte::MultiDumpBankEditBuffer; + d[n2x::SysexIndex::IdxMsgSpec] = static_cast<uint8_t>(_part); + + pluginLib::Controller::sendSysEx(d); + + return true; + } +} diff --git a/source/nord/n2x/n2xJucePlugin/n2xController.h b/source/nord/n2x/n2xJucePlugin/n2xController.h @@ -21,7 +21,6 @@ namespace n2xJucePlugin Controller(AudioPluginAudioProcessor&); ~Controller() override; - private: static std::string loadParameterDescriptions(); void onStateLoaded() override @@ -42,5 +41,8 @@ namespace n2xJucePlugin bool sendSysEx(MidiPacketType _packet, const std::map<pluginLib::MidiDataType, uint8_t>& _params) const; void requestDump(uint8_t _bank, uint8_t _patch) const; + + std::vector<uint8_t> createSingleDump(uint8_t _bank, uint8_t _program, uint8_t _part) const; + bool activatePatch(const std::vector<uint8_t>& _sysex, uint32_t _part); }; } \ No newline at end of file diff --git a/source/nord/n2x/n2xJucePlugin/n2xPatchManager.cpp b/source/nord/n2x/n2xJucePlugin/n2xPatchManager.cpp @@ -1,12 +1,31 @@ #include "n2xPatchManager.h" #include "n2xController.h" +#include "n2xEditor.h" +#include "n2xLib/n2xmiditypes.h" namespace n2xJucePlugin { + static constexpr std::initializer_list<jucePluginEditorLib::patchManager::GroupType> g_groupTypes = + { + jucePluginEditorLib::patchManager::GroupType::Favourites, + jucePluginEditorLib::patchManager::GroupType::LocalStorage, + jucePluginEditorLib::patchManager::GroupType::DataSources, + }; + + PatchManager::PatchManager(Editor& _editor, Component* _root, const juce::File& _dir) + : jucePluginEditorLib::patchManager::PatchManager(_editor, _root, _dir, g_groupTypes) + , m_editor(_editor) + , m_controller(_editor.getN2xController()) + { + } + + PatchManager::~PatchManager() = default; + bool PatchManager::requestPatchForPart(pluginLib::patchDB::Data& _data, uint32_t _part) { - return false; + _data = m_controller.createSingleDump(n2x::SysexByte::SingleDumpBankA, 0, static_cast<uint8_t>(_part)); + return !_data.empty(); } bool PatchManager::loadRomData(pluginLib::patchDB::DataList& _results, uint32_t _bank, uint32_t _program) @@ -16,17 +35,44 @@ namespace n2xJucePlugin pluginLib::patchDB::PatchPtr PatchManager::initializePatch(pluginLib::patchDB::Data&& _sysex) { - return {}; + const auto isSingle = _sysex.size() == n2x::g_singleDumpSize; + const auto isMulti = _sysex.size() == n2x::g_multiDumpSize; + + if(!isSingle && !isMulti) + return {}; + + auto p = std::make_shared<pluginLib::patchDB::Patch>(); + + const auto bank = _sysex[n2x::SysexIndex::IdxMsgType]; + const auto program = _sysex[n2x::SysexIndex::IdxMsgSpec]; + + char name[128]{0}; + + if(isSingle) + { + (void)snprintf(name, sizeof(name), "%c.%02d", bank == n2x::SingleDumpBankEditBuffer ? 'e' : ('1' + bank), program); + } + else + { + (void)snprintf(name, sizeof(name), "P%c.%02d", bank == n2x::MultiDumpBankEditBuffer ? 'e' : ('1' + bank), program); + } + + p->name = name; + p->sysex = std::move(_sysex); + p->program = program; + p->bank = bank; + + return p; } pluginLib::patchDB::Data PatchManager::prepareSave(const pluginLib::patchDB::PatchPtr& _patch) const { - return {}; - } + auto d = _patch->sysex; - bool PatchManager::equals(const pluginLib::patchDB::PatchPtr& _a, const pluginLib::patchDB::PatchPtr& _b) const - { - return _a.get() == _b.get(); + d[n2x::SysexIndex::IdxMsgType] = static_cast<uint8_t>(_patch->bank); + d[n2x::SysexIndex::IdxMsgSpec] = static_cast<uint8_t>(_patch->program); + + return d; } uint32_t PatchManager::getCurrentPart() const @@ -36,12 +82,12 @@ namespace n2xJucePlugin bool PatchManager::activatePatch(const pluginLib::patchDB::PatchPtr& _patch) { - return false; + return activatePatch(_patch, getCurrentPart()); } bool PatchManager::activatePatch(const pluginLib::patchDB::PatchPtr& _patch, uint32_t _part) { - return false; + return m_controller.activatePatch(_patch->sysex, _part); } bool PatchManager::parseFileData(pluginLib::patchDB::DataList& _results, const pluginLib::patchDB::Data& _data) diff --git a/source/nord/n2x/n2xJucePlugin/n2xPatchManager.h b/source/nord/n2x/n2xJucePlugin/n2xPatchManager.h @@ -18,7 +18,6 @@ namespace n2xJucePlugin bool loadRomData(pluginLib::patchDB::DataList& _results, uint32_t _bank, uint32_t _program) override; pluginLib::patchDB::PatchPtr initializePatch(pluginLib::patchDB::Data&& _sysex) override; pluginLib::patchDB::Data prepareSave(const pluginLib::patchDB::PatchPtr& _patch) const override; - bool equals(const pluginLib::patchDB::PatchPtr& _a, const pluginLib::patchDB::PatchPtr& _b) const override; uint32_t getCurrentPart() const override; bool activatePatch(const pluginLib::patchDB::PatchPtr& _patch) override; bool activatePatch(const pluginLib::patchDB::PatchPtr& _patch, uint32_t _part) override; diff --git a/source/nord/n2x/n2xLib/n2xmiditypes.h b/source/nord/n2x/n2xLib/n2xmiditypes.h @@ -11,7 +11,8 @@ namespace n2x SingleDumpBankEditBuffer = 0x00, SingleDumpBankA = 0x01, SingleDumpBankB = 0x02, SingleDumpBankC = 0x03, SingleDumpBankD = 0x04, SingleRequestBankEditBuffer = 0x0e, SingleRequestBankA = 0x0f, SingleRequestBankB = 0x10, SingleRequestBankC = 0x11, SingleRequestBankD = 0x12, - MultiRequestBankEditBuffer = 0x28, + MultiDumpBankEditBuffer = 30, + MultiRequestBankEditBuffer = 40, }; enum SysexIndex