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 20bc87380975a317703ae740d72cbbe1daacb577
parent 45ca552e613edb8b018d753fe277ae9ae73dc90d
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sun, 29 Sep 2024 12:59:36 +0200

parse raw sysex data instead of pre-parsed data by editor, required to read cache

Diffstat:
Msource/xtJucePlugin/weData.cpp | 106++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msource/xtJucePlugin/weData.h | 14++++++++------
Msource/xtJucePlugin/xtWaveEditor.cpp | 4++--
3 files changed, 83 insertions(+), 41 deletions(-)

diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp @@ -49,43 +49,30 @@ namespace xtJucePlugin onAllDataReceived(); } - void WaveEditorData::onReceiveWave(const pluginLib::MidiPacket::Data& _data, const std::vector<uint8_t>& _msg) + void WaveEditorData::onReceiveWave(const std::vector<uint8_t>& _msg) { - const auto index = toIndex(_data); - - if(!xt::Wave::isValidWaveIndex(index)) + if(!parseMidi(_msg)) return; - const auto id = xt::WaveId(index); - - xt::WaveData data; - xt::State::parseWaveData(data, _msg); - - setWave(id, data); - - if(m_currentWaveRequestIndex == id) + const auto command = toCommand(_msg); + const auto id = xt::WaveId(toIndex(_msg)); + + if(command == xt::SysexCommand::WaveDump && m_currentWaveRequestIndex == id) { m_currentWaveRequestIndex = g_invalidWaveIndex; requestData(); } } - void WaveEditorData::onReceiveTable(const pluginLib::MidiPacket::Data& _data, const std::vector<uint8_t>& _msg) + void WaveEditorData::onReceiveTable(const std::vector<uint8_t>& _msg) { - const auto index = toIndex(_data); - - if(!xt::Wave::isValidTableIndex(index)) + if(!parseMidi(_msg)) return; - const auto id = xt::TableId(index); - - xt::TableData table; + const auto command = toCommand(_msg); + const auto id = xt::TableId(toIndex(_msg)); - xt::State::parseTableData(table, _msg); - - setTable(id, table); - - if(m_currentTableRequestIndex == id) + if(command == xt::SysexCommand::WaveCtlDump && m_currentTableRequestIndex == id) { m_currentTableRequestIndex = g_invalidTableIndex; requestData(); @@ -193,14 +180,6 @@ namespace xtJucePlugin return getWave(getWaveIndex(_tableIndex, _indexInTable)); } - uint16_t WaveEditorData::toIndex(const pluginLib::MidiPacket::Data& _data) - { - const uint32_t hh = _data.at(pluginLib::MidiDataType::Bank); - const uint32_t ll = _data.at(pluginLib::MidiDataType::Program); - - return static_cast<uint16_t>((hh << 7) | ll); - } - bool WaveEditorData::setWave(xt::WaveId _id, const xt::WaveData& _data) { auto i = _id.rawId(); @@ -284,7 +263,68 @@ namespace xtJucePlugin data.insert(data.end(), sysex.begin(), sysex.end()); } synthLib::writeFile(romWaves, data); - } + } + + xt::SysexCommand WaveEditorData::toCommand(const std::vector<uint8_t>& _sysex) + { + return static_cast<xt::SysexCommand>(_sysex[4]); + } + + uint16_t WaveEditorData::toIndex(const std::vector<uint8_t>& _sysex) + { + const uint32_t hh = _sysex[5]; + const uint32_t ll = _sysex[6]; + + const uint16_t index = static_cast<uint16_t>((hh << 7) | ll); + + return index; + } + + bool WaveEditorData::parseMidi(const std::vector<uint8_t>& _sysex) + { + if(_sysex.size() < 10 || _sysex.front() != 0xf0 || _sysex.back() != 0xf7) + return false; + if(_sysex[1] != wLib::IdWaldorf) + return false; + if(_sysex[2] != xt::IdMw2) + return false; + + const auto cmd = toCommand(_sysex); + const auto index = toIndex(_sysex); + + switch (cmd) // NOLINT(clang-diagnostic-switch-enum) + { + case xt::SysexCommand::WaveDump: + { + if(!xt::Wave::isValidWaveIndex(index)) + return false; + + const auto id = xt::WaveId(index); + + xt::WaveData data; + xt::State::parseWaveData(data, _sysex); + + setWave(id, data); + } + return true; + case xt::SysexCommand::WaveCtlDump: + { + if(!xt::Wave::isValidTableIndex(index)) + return false; + + const auto id = xt::TableId(index); + + xt::TableData table; + + xt::State::parseTableData(table, _sysex); + + setTable(id, table); + } + return true; + default: + return false; + } + } bool WaveEditorData::isAlgorithmicTable(const xt::TableId _index) { diff --git a/source/xtJucePlugin/weData.h b/source/xtJucePlugin/weData.h @@ -29,8 +29,8 @@ namespace xtJucePlugin bool isWaitingForTable() const { return m_currentTableRequestIndex != g_invalidTableIndex; } bool isWaitingForData() const { return isWaitingForWave() || isWaitingForTable(); } - void onReceiveWave(const pluginLib::MidiPacket::Data& _data, const std::vector<uint8_t>& _msg); - void onReceiveTable(const pluginLib::MidiPacket::Data& _data, const std::vector<uint8_t>& _msg); + void onReceiveWave(const std::vector<uint8_t>& _msg); + void onReceiveTable(const std::vector<uint8_t>& _msg); std::optional<xt::WaveData> getWave(xt::WaveId _waveId) const; std::optional<xt::WaveData> getWave(xt::TableId _tableIndex, xt::TableIndex _indexInTable) const; @@ -41,10 +41,8 @@ namespace xtJucePlugin bool swapTableEntries(xt::TableId _tableId, xt::TableIndex _indexA, xt::TableIndex _indexB); bool setTableWave(xt::TableId _tableId, xt::TableIndex _tableIndex, xt::WaveId _waveId); - bool copyTable(const xt::TableId _dest, const xt::TableId _source); - bool copyWave(const xt::WaveId _dest, const xt::WaveId _source); - - static uint16_t toIndex(const pluginLib::MidiPacket::Data& _data); + bool copyTable(xt::TableId _dest, xt::TableId _source); + bool copyWave(xt::WaveId _dest, xt::WaveId _source); static bool isAlgorithmicTable(xt::TableId _index); static bool isReadOnly(xt::TableId _table); @@ -60,6 +58,10 @@ namespace xtJucePlugin void onAllDataReceived() const; + static xt::SysexCommand toCommand(const std::vector<uint8_t>& _sysex); + static uint16_t toIndex(const std::vector<uint8_t>& _sysex); + bool parseMidi(const std::vector<uint8_t>& _sysex); + Controller& m_controller; const std::string m_cacheDir; diff --git a/source/xtJucePlugin/xtWaveEditor.cpp b/source/xtJucePlugin/xtWaveEditor.cpp @@ -199,12 +199,12 @@ namespace xtJucePlugin void WaveEditor::onReceiveWave(const pluginLib::MidiPacket::Data& _data, const std::vector<uint8_t>& _msg) { - m_data.onReceiveWave(_data, _msg); + m_data.onReceiveWave(_msg); } void WaveEditor::onReceiveTable(const pluginLib::MidiPacket::Data& _data, const std::vector<uint8_t>& _msg) { - m_data.onReceiveTable(_data, _msg); + m_data.onReceiveTable(_msg); } void WaveEditor::setSelectedTable(xt::TableId _index)