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 796139f577f120e4d3edd848f63b8a81cab1b298
parent fce37df00e31e2c447e6f952263bed947052a224
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Mon, 21 Oct 2024 00:50:27 +0200

move more tool functions to xt lib / fix namespace case

Diffstat:
Msource/xtJucePlugin/weControlTree.h | 2+-
Msource/xtJucePlugin/weControlTreeItem.cpp | 4++--
Msource/xtJucePlugin/weData.cpp | 64+++++++++++++++-------------------------------------------------
Msource/xtJucePlugin/weData.h | 11+++--------
Msource/xtJucePlugin/weTablesTree.cpp | 4++--
Msource/xtJucePlugin/weTablesTreeItem.cpp | 2+-
Msource/xtJucePlugin/weWaveCategoryTreeItem.cpp | 4++--
Msource/xtJucePlugin/weWaveTreeItem.cpp | 10+++++-----
Msource/xtJucePlugin/xtController.cpp | 4++--
Msource/xtJucePlugin/xtWaveEditor.cpp | 6+++---
Msource/xtLib/xtId.h | 4++--
Msource/xtLib/xtMidiTypes.h | 37++++++++++++++++++++++++++++++++++---
Msource/xtLib/xtState.cpp | 12+++++++++++-
Msource/xtLib/xtState.h | 4+++-
14 files changed, 86 insertions(+), 82 deletions(-)

diff --git a/source/xtJucePlugin/weControlTree.h b/source/xtJucePlugin/weControlTree.h @@ -20,6 +20,6 @@ namespace xtJucePlugin pluginLib::EventListener<xt::TableId> m_onTableChanged; xt::TableId m_table; - std::array<ControlTreeItem*, xt::Wave::g_wavesPerTable> m_items; + std::array<ControlTreeItem*, xt::wave::g_wavesPerTable> m_items; }; } diff --git a/source/xtJucePlugin/weControlTreeItem.cpp b/source/xtJucePlugin/weControlTreeItem.cpp @@ -60,7 +60,7 @@ namespace xtJucePlugin juce::var ControlTreeItem::getDragSourceDescription() { - if(m_wave == g_invalidWaveIndex || WaveEditorData::isReadOnly(m_table) || WaveEditorData::isReadOnly(m_index)) + if(m_wave == g_invalidWaveIndex || xt::wave::isReadOnly(m_table) || xt::wave::isReadOnly(m_index)) return TreeViewItem::getDragSourceDescription(); auto* desc = new WaveDesc(); @@ -72,7 +72,7 @@ namespace xtJucePlugin bool ControlTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails) { - if(WaveEditorData::isReadOnly(m_table) || WaveEditorData::isReadOnly(m_index)) + if(xt::wave::isReadOnly(m_table) || xt::wave::isReadOnly(m_index)) return false; return WaveDesc::fromDragSource(_dragSourceDetails) != nullptr; } diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp @@ -22,7 +22,7 @@ namespace xtJucePlugin for(uint16_t i=0; i<static_cast<uint16_t>(m_tables.size()); ++i) { const auto id = xt::TableId(i); - if(!m_tables[i] && !isAlgorithmicTable(id)) + if(!m_tables[i] && !xt::wave::isAlgorithmicTable(id)) { requestTable(id); return; @@ -43,7 +43,7 @@ namespace xtJucePlugin { if(!m_ramWaves[i]) { - requestWave(xt::WaveId(static_cast<uint16_t>(i + xt::Wave::g_firstRamWaveIndex))); + requestWave(xt::WaveId(static_cast<uint16_t>(i + xt::wave::g_firstRamWaveIndex))); return; } } @@ -94,9 +94,9 @@ namespace xtJucePlugin if(i < m_romWaves.size()) return m_romWaves[i]; - if(i < xt::Wave::g_firstRamWaveIndex) + if(i < xt::wave::g_firstRamWaveIndex) return {}; - i -= xt::Wave::g_firstRamWaveIndex; + i -= xt::wave::g_firstRamWaveIndex; if(i >= m_ramWaves.size()) return {}; @@ -195,10 +195,10 @@ namespace xtJucePlugin onWaveChanged(_id); return true; } - if(i < xt::Wave::g_firstRamWaveIndex) + if(i < xt::wave::g_firstRamWaveIndex) return false; - i -= xt::Wave::g_firstRamWaveIndex; + i -= xt::wave::g_firstRamWaveIndex; if(i >= m_ramWaves.size()) return false; @@ -244,14 +244,9 @@ namespace xtJucePlugin void WaveEditorData::getWaveDataForSingle(std::vector<xt::SysEx>& _results, const xt::SysEx& _single) const { - constexpr auto wavetableIndex = xt::IdxSingleParamFirst + static_cast<uint32_t>(xt::SingleParameter::Wavetable); + const auto tableId = xt::State::getWavetableFromSingleDump(_single); - if(wavetableIndex >= _single.size()) - return; - - const auto tableId = xt::TableId(_single[wavetableIndex]); - - if(isReadOnly(tableId)) + if(xt::wave::isReadOnly(tableId)) return; const auto table = getTable(tableId); @@ -263,10 +258,10 @@ namespace xtJucePlugin for (const auto waveId : t) { - if(!xt::Wave::isValidWaveIndex(waveId.rawId())) + if(!xt::wave::isValidWaveIndex(waveId.rawId())) continue; - if(isReadOnly(waveId)) + if(xt::wave::isReadOnly(waveId)) continue; const auto wave = getWave(waveId); @@ -339,7 +334,7 @@ namespace xtJucePlugin { case xt::SysexCommand::WaveDump: { - if(!xt::Wave::isValidWaveIndex(index)) + if(!xt::wave::isValidWaveIndex(index)) return false; const auto id = xt::WaveId(index); @@ -352,7 +347,7 @@ namespace xtJucePlugin return true; case xt::SysexCommand::WaveCtlDump: { - if(!xt::Wave::isValidTableIndex(index)) + if(!xt::wave::isValidTableIndex(index)) return false; const auto id = xt::TableId(index); @@ -390,12 +385,12 @@ namespace xtJucePlugin data.insert(data.end(), sysex.begin(), sysex.end()); } - assert(xt::Wave::g_firstRamTableIndex < m_tables.size()); + assert(xt::wave::g_firstRamTableIndex < m_tables.size()); - for(uint16_t i=0; i<xt::Wave::g_firstRamTableIndex; ++i) + for(uint16_t i=0; i<xt::wave::g_firstRamTableIndex; ++i) { auto& table = m_tables[i]; - assert(table || isAlgorithmicTable(xt::TableId(i))); + assert(table || xt::wave::isAlgorithmicTable(xt::TableId(i))); if(!table) continue; auto sysex = xt::State::createTableData(*table, i, false); @@ -415,33 +410,4 @@ namespace xtJucePlugin for (const auto& sysex : sysexMessages) parseMidi(sysex); } - - bool WaveEditorData::isAlgorithmicTable(const xt::TableId _index) - { - for (const uint32_t i : xt::Wave::g_algorithmicWavetables) - { - if(_index.rawId() == i) - return true; - } - return false; - } - - bool WaveEditorData::isReadOnly(const xt::TableId _table) - { - if(!_table.isValid()) - return true; - return _table.rawId() < xt::Wave::g_firstRamTableIndex; - } - - bool WaveEditorData::isReadOnly(const xt::WaveId _waveId) - { - if(!_waveId.isValid()) - return true; - return _waveId.rawId() < xt::Wave::g_firstRamWaveIndex; - } - - bool WaveEditorData::isReadOnly(const xt::TableIndex _index) - { - return _index.rawId() >= 61; // always tri/square/saw - } } diff --git a/source/xtJucePlugin/weData.h b/source/xtJucePlugin/weData.h @@ -45,11 +45,6 @@ namespace xtJucePlugin 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); - static bool isReadOnly(xt::WaveId _waveId); - static bool isReadOnly(xt::TableIndex _index); - bool setWave(xt::WaveId _id, const xt::WaveData& _data); bool setTable(xt::TableId _index, const xt::TableData& _data); @@ -78,8 +73,8 @@ namespace xtJucePlugin xt::WaveId m_currentWaveRequestIndex = g_invalidWaveIndex; xt::TableId m_currentTableRequestIndex = g_invalidTableIndex; - std::array<std::optional<xt::WaveData>, xt::Wave::g_romWaveCount> m_romWaves; - std::array<std::optional<xt::WaveData>, xt::Wave::g_ramWaveCount> m_ramWaves; - std::array<std::optional<xt::TableData>, xt::Wave::g_tableCount> m_tables; + std::array<std::optional<xt::WaveData>, xt::wave::g_romWaveCount> m_romWaves; + std::array<std::optional<xt::WaveData>, xt::wave::g_ramWaveCount> m_ramWaves; + std::array<std::optional<xt::TableData>, xt::wave::g_tableCount> m_tables; }; } diff --git a/source/xtJucePlugin/weTablesTree.cpp b/source/xtJucePlugin/weTablesTree.cpp @@ -12,9 +12,9 @@ namespace xtJucePlugin { TablesTree::TablesTree(WaveEditor& _editor) : Tree(_editor) { - for(uint16_t i=0; i<xt::Wave::g_tableCount; ++i) + for(uint16_t i=0; i<xt::wave::g_tableCount; ++i) { - if(WaveEditorData::isAlgorithmicTable(xt::TableId(i))) + if(xt::wave::isAlgorithmicTable(xt::TableId(i))) continue; getRootItem()->addSubItem(new TablesTreeItem(_editor, xt::TableId(i))); diff --git a/source/xtJucePlugin/weTablesTreeItem.cpp b/source/xtJucePlugin/weTablesTreeItem.cpp @@ -41,7 +41,7 @@ namespace xtJucePlugin bool TablesTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails) { - if(WaveEditorData::isReadOnly(m_index)) + if(xt::wave::isReadOnly(m_index)) return false; const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails); if(!waveDesc || waveDesc->source != WaveDescSource::TablesList) diff --git a/source/xtJucePlugin/weWaveCategoryTreeItem.cpp b/source/xtJucePlugin/weWaveCategoryTreeItem.cpp @@ -21,10 +21,10 @@ namespace xtJucePlugin switch (_category) { case WaveCategory::Rom: - addItems(0, xt::Wave::g_romWaveCount); + addItems(0, xt::wave::g_romWaveCount); break; case WaveCategory::User: - addItems(xt::Wave::g_firstRamWaveIndex, xt::Wave::g_ramWaveCount); + addItems(xt::wave::g_firstRamWaveIndex, xt::wave::g_ramWaveCount); break; case WaveCategory::Invalid: case WaveCategory::Plugin: diff --git a/source/xtJucePlugin/weWaveTreeItem.cpp b/source/xtJucePlugin/weWaveTreeItem.cpp @@ -40,7 +40,7 @@ namespace xtJucePlugin std::string WaveTreeItem::getWaveName(const xt::WaveId _waveIndex) { - if(!xt::Wave::isValidWaveIndex(_waveIndex.rawId())) + if(!xt::wave::isValidWaveIndex(_waveIndex.rawId())) return {}; const auto category = getCategory(_waveIndex); return WaveCategoryTreeItem::getCategoryName(category) + ' ' + std::to_string(_waveIndex.rawId()); @@ -48,9 +48,9 @@ namespace xtJucePlugin WaveCategory WaveTreeItem::getCategory(const xt::WaveId _waveIndex) { - if(_waveIndex.rawId() < xt::Wave::g_romWaveCount) + if(_waveIndex.rawId() < xt::wave::g_romWaveCount) return WaveCategory::Rom; - if(_waveIndex.rawId() >= xt::Wave::g_firstRamWaveIndex && _waveIndex.rawId() < xt::Wave::g_firstRamWaveIndex + xt::Wave::g_ramWaveCount) + if(_waveIndex.rawId() >= xt::wave::g_firstRamWaveIndex && _waveIndex.rawId() < xt::wave::g_firstRamWaveIndex + xt::wave::g_ramWaveCount) return WaveCategory::User; return WaveCategory::Invalid; } @@ -73,7 +73,7 @@ namespace xtJucePlugin bool WaveTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails) { - if(WaveEditorData::isReadOnly(m_waveIndex)) + if(xt::wave::isReadOnly(m_waveIndex)) return false; const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails); if(!waveDesc) @@ -86,7 +86,7 @@ namespace xtJucePlugin void WaveTreeItem::itemDropped(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) { TreeItem::itemDropped(dragSourceDetails, insertIndex); - if(WaveEditorData::isReadOnly(m_waveIndex)) + if(xt::wave::isReadOnly(m_waveIndex)) return; const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails); if(!waveDesc) diff --git a/source/xtJucePlugin/xtController.cpp b/source/xtJucePlugin/xtController.cpp @@ -653,7 +653,7 @@ namespace xtJucePlugin bool Controller::requestWave(const uint32_t _number) const { - if(!xt::Wave::isValidWaveIndex(_number)) + if(!xt::wave::isValidWaveIndex(_number)) return false; std::map<pluginLib::MidiDataType, uint8_t> params; @@ -666,7 +666,7 @@ namespace xtJucePlugin bool Controller::requestTable(const uint32_t _number) const { - if(!xt::Wave::isValidTableIndex(_number)) + if(!xt::wave::isValidTableIndex(_number)) return false; std::map<pluginLib::MidiDataType, uint8_t> params; diff --git a/source/xtJucePlugin/xtWaveEditor.cpp b/source/xtJucePlugin/xtWaveEditor.cpp @@ -155,13 +155,13 @@ namespace xtJucePlugin void WaveEditor::saveWave() { - if(WaveEditorData::isReadOnly(m_selectedWave) || m_btWaveSave->isRightClick()) + if(xt::wave::isReadOnly(m_selectedWave) || m_btWaveSave->isRightClick()) { // open menu and let user select one of the wave slots juce::PopupMenu menu; uint16_t count = 0; - for(uint16_t i=xt::Wave::g_firstRamWaveIndex; i<xt::Wave::g_firstRamWaveIndex+xt::Wave::g_ramWaveCount; ++i) + for(uint16_t i=xt::wave::g_firstRamWaveIndex; i<xt::wave::g_firstRamWaveIndex+xt::wave::g_ramWaveCount; ++i) { const auto id = xt::WaveId(i); menu.addItem(WaveTreeItem::getWaveName(id), true, false, [this, id] @@ -184,7 +184,7 @@ namespace xtJucePlugin bool WaveEditor::saveWaveTo(const xt::WaveId _target) { - if(WaveEditorData::isReadOnly(_target)) + if(xt::wave::isReadOnly(_target)) return false; if(!m_data.setWave(_target, m_graphData.getSource())) diff --git a/source/xtLib/xtId.h b/source/xtLib/xtId.h @@ -31,10 +31,10 @@ namespace xt bool operator == (const Id& _id) const { return m_id == _id.m_id; } bool operator != (const Id& _id) const { return m_id != _id.m_id; } - const auto& rawId() const { return m_id; } + constexpr auto& rawId() const { return m_id; } constexpr static Id invalid() { return Id(Invalid); } - bool isValid() const { return m_id != Invalid; } + constexpr bool isValid() const { return m_id != Invalid; } void invalidate() { m_id = Invalid; } private: diff --git a/source/xtLib/xtMidiTypes.h b/source/xtLib/xtMidiTypes.h @@ -2,6 +2,8 @@ #include <cstdint> +#include "xtId.h" + #include "wLib/wMidiTypes.h" namespace xt @@ -192,7 +194,7 @@ namespace xt static constexpr uint32_t g_idmPreset = 0x42; }; - namespace Wave + namespace wave { static constexpr uint16_t g_romWaveCount = 506; static constexpr uint16_t g_ramWaveCount = 250; @@ -212,7 +214,7 @@ namespace xt 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95}; - inline bool isValidWaveIndex(const uint32_t _index) + constexpr bool isValidWaveIndex(const uint32_t _index) { if(_index >= g_firstRamWaveIndex + g_ramWaveCount) return false; @@ -221,9 +223,38 @@ namespace xt return true; } - inline bool isValidTableIndex(const uint32_t _index) + constexpr bool isValidTableIndex(const uint32_t _index) { return _index < g_tableCount; } + + constexpr bool isAlgorithmicTable(const xt::TableId _index) + { + for (const uint32_t i : g_algorithmicWavetables) + { + if(_index.rawId() == i) + return true; + } + return false; + } + + constexpr bool isReadOnly(const TableId _table) + { + if(!_table.isValid()) + return true; + return _table.rawId() < g_firstRamTableIndex; + } + + constexpr bool isReadOnly(const WaveId _waveId) + { + if(!_waveId.isValid()) + return true; + return _waveId.rawId() < g_firstRamWaveIndex; + } + + constexpr bool isReadOnly(const TableIndex _index) + { + return _index.rawId() >= 61; // always tri/square/saw + } } } diff --git a/source/xtLib/xtState.cpp b/source/xtLib/xtState.cpp @@ -38,7 +38,7 @@ namespace xt bool State::getState(std::vector<uint8_t>& _state, synthLib::StateType _type) const { - append(_state, m_mode, ~0); + append(_state, m_mode, ~0u); append(_state, m_global, wLib::IdxCommand); const auto multiMode = isMultiMode(); @@ -234,6 +234,16 @@ namespace xt return loadState(_state); } + TableId State::getWavetableFromSingleDump(const SysEx& _single) + { + constexpr auto wavetableIndex = IdxSingleParamFirst + static_cast<uint32_t>(SingleParameter::Wavetable); + + if(wavetableIndex >= _single.size()) + return TableId::invalid(); + + return TableId(_single[wavetableIndex]); + } + bool State::parseSingleDump(const SysEx& _data) { Single single; diff --git a/source/xtLib/xtState.h b/source/xtLib/xtState.h @@ -88,6 +88,8 @@ namespace xt bool getState(std::vector<uint8_t>& _state, synthLib::StateType _type) const; bool setState(const std::vector<uint8_t>& _state, synthLib::StateType _type); + static TableId getWavetableFromSingleDump(const SysEx& _single); + static void createSequencerMultiData(std::vector<uint8_t>& _data); static void parseWaveData(WaveData& _wave, const SysEx& _sysex); @@ -107,7 +109,7 @@ namespace xt if(!isValid(_src)) return false; auto src = _src; - if(_checksumStartIndex != ~0) + if(_checksumStartIndex != ~0u) wLib::State::updateChecksum(src, _checksumStartIndex); _dst.insert(_dst.end(), src.begin(), src.end()); return true;