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 2698533bbffc55a5f3cae440d357483e75c825e5
parent b435ea4c39826ebc050ed68504cfae49cdd93af5
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat, 28 Sep 2024 21:27:37 +0200

create typesafe id types for wave, table and table index

Diffstat:
Msource/xtJucePlugin/weControlTree.cpp | 10+++++-----
Msource/xtJucePlugin/weControlTree.h | 8++++----
Msource/xtJucePlugin/weControlTreeItem.cpp | 18+++++++++---------
Msource/xtJucePlugin/weControlTreeItem.h | 14+++++++-------
Msource/xtJucePlugin/weData.cpp | 134++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msource/xtJucePlugin/weData.h | 34+++++++++++++++++-----------------
Msource/xtJucePlugin/weTablesTree.cpp | 6+++---
Msource/xtJucePlugin/weTablesTreeItem.cpp | 8++++----
Msource/xtJucePlugin/weTablesTreeItem.h | 10++++++----
Msource/xtJucePlugin/weTypes.h | 4++--
Msource/xtJucePlugin/weWaveCategoryTreeItem.cpp | 2+-
Msource/xtJucePlugin/weWaveDesc.h | 6+++---
Msource/xtJucePlugin/weWaveTreeItem.cpp | 22+++++++++++-----------
Msource/xtJucePlugin/weWaveTreeItem.h | 14+++++++-------
Msource/xtJucePlugin/xtWaveEditor.cpp | 7+++----
Msource/xtJucePlugin/xtWaveEditor.h | 8++++----
Msource/xtLib/CMakeLists.txt | 2++
Msource/xtLib/xtMidiTypes.h | 10+++++-----
Msource/xtLib/xtState.cpp | 13++++++-------
Msource/xtLib/xtTypes.h | 4+++-
20 files changed, 174 insertions(+), 160 deletions(-)

diff --git a/source/xtJucePlugin/weControlTree.cpp b/source/xtJucePlugin/weControlTree.cpp @@ -7,21 +7,21 @@ namespace xtJucePlugin { ControlTree::ControlTree(WaveEditor& _editor) : Tree(_editor) { - m_onTableChanged.set(_editor.getData().onTableChanged, [this](const uint32_t& _index) + m_onTableChanged.set(_editor.getData().onTableChanged, [this](const xt::TableId& _index) { if(_index == m_table) onTableChanged(true); }); - for(uint32_t i=0; i<m_items.size(); ++i) + for(uint16_t i=0; i<static_cast<uint16_t>(m_items.size()); ++i) { - m_items[i] = new ControlTreeItem(_editor, i); + m_items[i] = new ControlTreeItem(_editor, static_cast<xt::TableIndex>(i)); getRootItem()->addSubItem(m_items[i]); } setIndentSize(5); } - void ControlTree::setTable(const uint32_t _index) + void ControlTree::setTable(const xt::TableId _index) { if(_index == m_table) return; @@ -29,7 +29,7 @@ namespace xtJucePlugin onTableChanged(false); } - void ControlTree::onTableChanged(bool _tableHasChanged) + void ControlTree::onTableChanged(const bool _tableHasChanged) const { for (auto* item : m_items) item->setTable(m_table, _tableHasChanged); diff --git a/source/xtJucePlugin/weControlTree.h b/source/xtJucePlugin/weControlTree.h @@ -13,13 +13,13 @@ namespace xtJucePlugin public: ControlTree(WaveEditor& _editor); - void setTable(uint32_t _index); + void setTable(xt::TableId _index); private: - void onTableChanged(bool _tableHasChanged); + void onTableChanged(bool _tableHasChanged) const; - pluginLib::EventListener<uint32_t> m_onTableChanged; - uint32_t m_table = ~0; + pluginLib::EventListener<xt::TableId> m_onTableChanged; + xt::TableId m_table; std::array<ControlTreeItem*, xt::Wave::g_wavesPerTable> m_items; }; } diff --git a/source/xtJucePlugin/weControlTreeItem.cpp b/source/xtJucePlugin/weControlTreeItem.cpp @@ -8,9 +8,9 @@ namespace xtJucePlugin { class WaveEditor; - ControlTreeItem::ControlTreeItem(WaveEditor& _editor, const uint32_t _index) : m_editor(_editor), m_index(_index) + ControlTreeItem::ControlTreeItem(WaveEditor& _editor, const xt::TableIndex _index) : m_editor(_editor), m_index(_index) { - m_onWaveChanged.set(_editor.getData().onWaveChanged, [this](const unsigned& _wave) + m_onWaveChanged.set(_editor.getData().onWaveChanged, [this](const xt::WaveId& _wave) { if(_wave == m_wave) onWaveChanged(); @@ -28,19 +28,19 @@ namespace xtJucePlugin TreeItem::paintItem(_g, _width, _height); } - void ControlTreeItem::setWave(const uint32_t _wave) + void ControlTreeItem::setWave(const xt::WaveId _wave) { if(m_wave == _wave) return; m_wave = _wave; const auto name = WaveTreeItem::getWaveName(m_wave); char prefix[16] = {0}; - snprintf(prefix, std::size(prefix), "%02d: ", m_index); + (void)snprintf(prefix, std::size(prefix), "%02d: ", m_index.rawId()); setText(prefix + (name.empty() ? "-" : name)); repaintItem(); } - void ControlTreeItem::setTable(const uint32_t _table, const bool _tableHasChanged) + void ControlTreeItem::setTable(const xt::TableId _table, const bool _tableHasChanged) { if(m_table == _table && !_tableHasChanged) return; @@ -54,9 +54,9 @@ namespace xtJucePlugin return TreeViewItem::getDragSourceDescription(); auto* desc = new WaveDesc(); - desc->waveIndex = m_wave; + desc->waveId = m_wave; desc->source = WaveDescSource::ControlList; - desc->listIndex = m_index; + desc->tableIndex = m_index; return desc; } @@ -76,12 +76,12 @@ namespace xtJucePlugin // if the source is the control list, we swap two entries. if the source is the wave list, we add a new wave if(waveDesc->source == WaveDescSource::ControlList) { - data.swapTableEntries(m_table, m_index, waveDesc->listIndex); + data.swapTableEntries(m_table, m_index, waveDesc->tableIndex); setSelected(true, true, juce::dontSendNotification); } else if(waveDesc->source == WaveDescSource::WaveList) { - data.setTableWave(m_table, m_index, waveDesc->waveIndex); + data.setTableWave(m_table, m_index, waveDesc->waveId); } } diff --git a/source/xtJucePlugin/weControlTreeItem.h b/source/xtJucePlugin/weControlTreeItem.h @@ -12,14 +12,14 @@ namespace xtJucePlugin class ControlTreeItem : public TreeItem { public: - ControlTreeItem(WaveEditor& _editor, uint32_t _index); + ControlTreeItem(WaveEditor& _editor, xt::TableIndex _index); bool mightContainSubItems() override { return false; } void paintItem(juce::Graphics& _g, int _width, int _height) override; - void setWave(uint32_t _wave); - void setTable(uint32_t _table, bool _tableHasChanged); + void setWave(xt::WaveId _wave); + void setTable(xt::TableId _table, bool _tableHasChanged); juce::var getDragSourceDescription() override; bool isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails) override; void itemDropped(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails, int _insertIndex) override; @@ -28,11 +28,11 @@ namespace xtJucePlugin void onWaveChanged() const; WaveEditor& m_editor; - const uint32_t m_index; + const xt::TableIndex m_index; - uint32_t m_wave = g_invalidWaveIndex; - uint32_t m_table = g_invalidTableIndex; + xt::WaveId m_wave = g_invalidWaveIndex; + xt::TableId m_table = g_invalidTableIndex; - pluginLib::EventListener<uint32_t> m_onWaveChanged; + pluginLib::EventListener<xt::WaveId> m_onWaveChanged; }; } diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp @@ -15,21 +15,23 @@ namespace xtJucePlugin if(isWaitingForData()) return; - for(uint32_t i=0; i<m_tables.size(); ++i) + for(uint16_t i=0; i<static_cast<uint16_t>(m_tables.size()); ++i) { - if(!m_tables[i] && !isAlgorithmicTable(i)) + const auto id = xt::TableId(i); + if(!m_tables[i] && !isAlgorithmicTable(id)) { LOG("Request table " << i); - requestTable(i); + requestTable(id); return; } } - for(uint32_t i=0; i<m_romWaves.size(); ++i) + for(uint16_t i=0; i<static_cast<uint16_t>(m_romWaves.size()); ++i) { + const auto id = xt::WaveId(i); if(!m_romWaves[i]) { - requestWave(i); + requestWave(id); return; } } @@ -38,7 +40,7 @@ namespace xtJucePlugin { if(!m_ramWaves[i]) { - requestWave(i + xt::Wave::g_firstRamWaveIndex); + requestWave(xt::WaveId(static_cast<uint16_t>(i + xt::Wave::g_firstRamWaveIndex))); return; } } @@ -51,12 +53,14 @@ namespace xtJucePlugin if(!xt::Wave::isValidWaveIndex(index)) return; + const auto id = xt::WaveId(index); + xt::WaveData data; xt::State::parseWaveData(data, _msg); - setWave(index, data); + setWave(id, data); - if(m_currentWaveRequestIndex == index) + if(m_currentWaveRequestIndex == id) { m_currentWaveRequestIndex = g_invalidWaveIndex; requestData(); @@ -70,160 +74,166 @@ namespace xtJucePlugin if(!xt::Wave::isValidTableIndex(index)) return; + const auto id = xt::TableId(index); + xt::TableData table; xt::State::parseTableData(table, _msg); - setTable(index, table); + setTable(id, table); - if(m_currentTableRequestIndex == index) + if(m_currentTableRequestIndex == id) { - m_currentTableRequestIndex = g_invalidWaveIndex; + m_currentTableRequestIndex = g_invalidTableIndex; requestData(); } } - std::optional<xt::WaveData> WaveEditorData::getWave(uint32_t _waveIndex) const + std::optional<xt::WaveData> WaveEditorData::getWave(xt::WaveId _waveId) const { - if(_waveIndex < m_romWaves.size()) - return m_romWaves[_waveIndex]; + auto i = _waveId.rawId(); - if(_waveIndex < xt::Wave::g_firstRamWaveIndex) + if(i < m_romWaves.size()) + return m_romWaves[i]; + + if(i < xt::Wave::g_firstRamWaveIndex) return {}; - _waveIndex -= xt::Wave::g_firstRamWaveIndex; - if(_waveIndex >= m_ramWaves.size()) + i -= xt::Wave::g_firstRamWaveIndex; + if(i >= m_ramWaves.size()) return {}; - if(!m_ramWaves[_waveIndex]) + if(!m_ramWaves[i]) return {}; - return m_ramWaves[_waveIndex]; + return m_ramWaves[i]; } - uint32_t WaveEditorData::getWaveIndex(uint32_t _tableIndex, uint32_t _indexInTable) const + xt::WaveId WaveEditorData::getWaveIndex(xt::TableId _tableIndex, xt::TableIndex _indexInTable) const { - if(_tableIndex >= m_tables.size()) + if(_tableIndex.rawId() >= m_tables.size()) return g_invalidWaveIndex; - if(_indexInTable >= std::tuple_size<xt::TableData>()) + if(_indexInTable.rawId() >= std::tuple_size<xt::TableData>()) return g_invalidWaveIndex; - const auto table = m_tables[_tableIndex]; + const auto table = m_tables[_tableIndex.rawId()]; if(!table) return g_invalidWaveIndex; - return (*table)[_indexInTable]; + return (*table)[_indexInTable.rawId()]; } - std::optional<xt::TableData> WaveEditorData::getTable(uint32_t _tableIndex) const + std::optional<xt::TableData> WaveEditorData::getTable(xt::TableId _tableIndex) const { - if(_tableIndex >= m_tables.size()) + if(_tableIndex.rawId() >= m_tables.size()) return {}; - return m_tables[_tableIndex]; + return m_tables[_tableIndex.rawId()]; } - bool WaveEditorData::swapTableEntries(uint32_t _table, uint32_t _indexA, uint32_t _indexB) + bool WaveEditorData::swapTableEntries(xt::TableId _table, xt::TableIndex _indexA, xt::TableIndex _indexB) { if(_indexA == _indexB) return false; - if(_table >= m_tables.size()) + if(_table.rawId() >= m_tables.size()) return false; - const auto& table = m_tables[_table]; + const auto& table = m_tables[_table.rawId()]; if(!table) return false; auto t = *table; - std::swap(t[_indexA], t[_indexB]); - m_tables[_table] = t; + std::swap(t[_indexA.rawId()], t[_indexB.rawId()]); + m_tables[_table.rawId()] = t; onTableChanged(_table); return true; } - bool WaveEditorData::setTableWave(uint32_t _table, uint32_t _index, uint32_t _waveIndex) + bool WaveEditorData::setTableWave(xt::TableId _table, xt::TableIndex _index, xt::WaveId _waveIndex) { - if(_table >= m_tables.size()) + if(_table.rawId() >= m_tables.size()) return false; - const auto& table = m_tables[_table]; + const auto& table = m_tables[_table.rawId()]; if(!table) return false; auto t = *table; - if(_index >= t.size()) + if(_index.rawId() >= t.size()) return false; - if(t[_index] == _waveIndex) + if(t[_index.rawId()] == _waveIndex) return false; - t[_index] = static_cast<uint16_t>(_waveIndex); - m_tables[_table] = t; + t[_index.rawId()] = _waveIndex; + m_tables[_table.rawId()] = t; onTableChanged(_table); return true; } - std::optional<xt::WaveData> WaveEditorData::getWave(const uint32_t _tableIndex, const uint32_t _indexInTable) const + std::optional<xt::WaveData> WaveEditorData::getWave(const xt::TableId _tableIndex, const xt::TableIndex _indexInTable) const { return getWave(getWaveIndex(_tableIndex, _indexInTable)); } - uint32_t WaveEditorData::toIndex(const pluginLib::MidiPacket::Data& _data) + uint16_t WaveEditorData::toIndex(const pluginLib::MidiPacket::Data& _data) { - const auto hh = _data.at(pluginLib::MidiDataType::Bank); - const auto ll = _data.at(pluginLib::MidiDataType::Program); + const uint32_t hh = _data.at(pluginLib::MidiDataType::Bank); + const uint32_t ll = _data.at(pluginLib::MidiDataType::Program); - return (hh << 7) | ll; + return static_cast<uint16_t>((hh << 7) | ll); } - bool WaveEditorData::requestWave(const uint32_t _index) + bool WaveEditorData::requestWave(const xt::WaveId _index) { if(isWaitingForData()) return false; - if(!m_controller.requestWave(_index)) + if(!m_controller.requestWave(_index.rawId())) return false; m_currentWaveRequestIndex = _index; return true; } - bool WaveEditorData::requestTable(const uint32_t _index) + bool WaveEditorData::requestTable(const xt::TableId _index) { if(isWaitingForData()) return false; - if(!m_controller.requestTable(_index)) + if(!m_controller.requestTable(_index.rawId())) return false; m_currentTableRequestIndex = _index; return true; } - bool WaveEditorData::setWave(uint32_t _index, const xt::WaveData& _data) + bool WaveEditorData::setWave(xt::WaveId _id, const xt::WaveData& _data) { - if(_index < m_romWaves.size()) + auto i = _id.rawId(); + + if(i < m_romWaves.size()) { - m_romWaves[_index] = _data; - onWaveChanged(_index); + m_romWaves[i] = _data; + onWaveChanged(_id); return true; } - if(_index < xt::Wave::g_firstRamWaveIndex) + if(i < xt::Wave::g_firstRamWaveIndex) return false; - _index -= xt::Wave::g_firstRamWaveIndex; + i -= xt::Wave::g_firstRamWaveIndex; - if(_index >= m_ramWaves.size()) + if(i >= m_ramWaves.size()) return false; - m_ramWaves[_index] = _data; - onWaveChanged(_index + xt::Wave::g_firstRamWaveIndex); + m_ramWaves[i] = _data; + onWaveChanged(_id); return true; } - bool WaveEditorData::setTable(uint32_t _index, const xt::TableData& _data) + bool WaveEditorData::setTable(xt::TableId _index, const xt::TableData& _data) { - if(_index >= m_tables.size()) + if(_index.rawId() >= m_tables.size()) return false; - m_tables[_index] = _data; + m_tables[_index.rawId()] = _data; onTableChanged(_index); return true; } - bool WaveEditorData::isAlgorithmicTable(const uint32_t _index) + bool WaveEditorData::isAlgorithmicTable(const xt::TableId _index) { for (const uint32_t i : xt::Wave::g_algorithmicWavetables) { - if(_index == i) + if(_index.rawId() == i) return true; } return false; diff --git a/source/xtJucePlugin/weData.h b/source/xtJucePlugin/weData.h @@ -19,44 +19,44 @@ namespace xtJucePlugin class WaveEditorData { public: - pluginLib::Event<uint32_t> onWaveChanged; - pluginLib::Event<uint32_t> onTableChanged; + pluginLib::Event<xt::WaveId> onWaveChanged; + pluginLib::Event<xt::TableId> onTableChanged; WaveEditorData(Controller& _controller); void requestData(); bool isWaitingForWave() const { return m_currentWaveRequestIndex != g_invalidWaveIndex; } - bool isWaitingForTable() const { return m_currentTableRequestIndex != g_invalidWaveIndex; } + 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); - std::optional<xt::WaveData> getWave(uint32_t _waveIndex) const; - std::optional<xt::WaveData> getWave(uint32_t _tableIndex, uint32_t _indexInTable) const; + std::optional<xt::WaveData> getWave(xt::WaveId _waveIndex) const; + std::optional<xt::WaveData> getWave(xt::TableId _tableIndex, xt::TableIndex _indexInTable) const; - uint32_t getWaveIndex(uint32_t _tableIndex, uint32_t _indexInTable) const; + xt::WaveId getWaveIndex(xt::TableId _tableIndex, xt::TableIndex _indexInTable) const; - std::optional<xt::TableData> getTable(uint32_t _tableIndex) const; - bool swapTableEntries(uint32_t _table, uint32_t _indexA, uint32_t _indexB); - bool setTableWave(uint32_t _table, uint32_t _index, uint32_t _waveIndex); + std::optional<xt::TableData> getTable(xt::TableId _tableIndex) const; + bool swapTableEntries(xt::TableId _table, xt::TableIndex _indexA, xt::TableIndex _indexB); + bool setTableWave(xt::TableId _table, xt::TableIndex _index, xt::WaveId _waveIndex); - static uint32_t toIndex(const pluginLib::MidiPacket::Data& _data); - static bool isAlgorithmicTable(uint32_t _index); + static uint16_t toIndex(const pluginLib::MidiPacket::Data& _data); + static bool isAlgorithmicTable(xt::TableId _index); private: - bool requestWave(uint32_t _index); - bool requestTable(uint32_t _index); + bool requestWave(xt::WaveId _index); + bool requestTable(xt::TableId _index); - bool setWave(uint32_t _index, const xt::WaveData& _data); - bool setTable(uint32_t _index, const xt::TableData& _data); + bool setWave(xt::WaveId _id, const xt::WaveData& _data); + bool setTable(xt::TableId _index, const xt::TableData& _data); Controller& m_controller; - uint32_t m_currentWaveRequestIndex = g_invalidWaveIndex; - uint32_t m_currentTableRequestIndex = g_invalidWaveIndex; + 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; diff --git a/source/xtJucePlugin/weTablesTree.cpp b/source/xtJucePlugin/weTablesTree.cpp @@ -10,12 +10,12 @@ namespace xtJucePlugin { TablesTree::TablesTree(WaveEditor& _editor) : Tree(_editor) { - for(uint32_t i=0; i<xt::Wave::g_tableCount; ++i) + for(uint16_t i=0; i<xt::Wave::g_tableCount; ++i) { - if(WaveEditorData::isAlgorithmicTable(i)) + if(WaveEditorData::isAlgorithmicTable(xt::TableId(i))) continue; - getRootItem()->addSubItem(new TablesTreeItem(_editor, i)); + getRootItem()->addSubItem(new TablesTreeItem(_editor, xt::TableId(i))); } setIndentSize(5); } diff --git a/source/xtJucePlugin/weTablesTreeItem.cpp b/source/xtJucePlugin/weTablesTreeItem.cpp @@ -6,18 +6,18 @@ namespace xtJucePlugin { - TablesTreeItem::TablesTreeItem(WaveEditor& _editor, const uint32_t _tableIndex) : m_editor(_editor), m_index(_tableIndex) + TablesTreeItem::TablesTreeItem(WaveEditor& _editor, const xt::TableId _tableIndex) : m_editor(_editor), m_index(_tableIndex) { setPaintRootItemInBold(false); setDrawsInLeftMargin(true); const auto& wavetableNames = _editor.getEditor().getXtController().getParameterDescriptions().getValueList("waveType"); - const auto name = wavetableNames->valueToText(_tableIndex); + const auto name = wavetableNames->valueToText(_tableIndex.rawId()); setText(name); - m_onTableChanged.set(_editor.getData().onTableChanged, [this](const uint32_t& _index) + m_onTableChanged.set(_editor.getData().onTableChanged, [this](const xt::TableId& _index) { onTableChanged(_index); }); @@ -29,7 +29,7 @@ namespace xtJucePlugin m_editor.setSelectedTable(m_index); } - void TablesTreeItem::onTableChanged(uint32_t _index) + void TablesTreeItem::onTableChanged(xt::TableId _index) { if(_index != m_index) return; diff --git a/source/xtJucePlugin/weTablesTreeItem.h b/source/xtJucePlugin/weTablesTreeItem.h @@ -4,6 +4,8 @@ #include "jucePluginLib/event.h" +#include "xtLib/xtId.h" + namespace xtJucePlugin { class WaveEditor; @@ -11,18 +13,18 @@ namespace xtJucePlugin class TablesTreeItem : public TreeItem { public: - TablesTreeItem(WaveEditor& _editor, uint32_t _tableIndex); + TablesTreeItem(WaveEditor& _editor, xt::TableId _tableIndex); bool mightContainSubItems() override { return false; } void itemSelectionChanged(bool _isNowSelected) override; private: - void onTableChanged(uint32_t _index); + void onTableChanged(xt::TableId _index); void onTableChanged(); WaveEditor& m_editor; - const uint32_t m_index; - pluginLib::EventListener<uint32_t> m_onTableChanged; + const xt::TableId m_index; + pluginLib::EventListener<xt::TableId> m_onTableChanged; }; } diff --git a/source/xtJucePlugin/weTypes.h b/source/xtJucePlugin/weTypes.h @@ -18,6 +18,6 @@ namespace xtJucePlugin static constexpr float g_waveEditorScale = 2.0f * 1.3f; static constexpr uint32_t g_invalidIndex = std::numeric_limits<uint32_t>::max(); - static constexpr uint32_t g_invalidWaveIndex = g_invalidIndex; - static constexpr uint32_t g_invalidTableIndex = g_invalidIndex; + static constexpr xt::WaveId g_invalidWaveIndex = xt::WaveId::invalid(); + static constexpr xt::TableId g_invalidTableIndex = xt::TableId::invalid(); } diff --git a/source/xtJucePlugin/weWaveCategoryTreeItem.cpp b/source/xtJucePlugin/weWaveCategoryTreeItem.cpp @@ -49,6 +49,6 @@ namespace xtJucePlugin void WaveCategoryTreeItem::addItem(const uint32_t _index) { - addSubItem(new WaveTreeItem(m_editor, m_category, _index)); + addSubItem(new WaveTreeItem(m_editor, m_category, xt::WaveId(_index))); } } diff --git a/source/xtJucePlugin/weWaveDesc.h b/source/xtJucePlugin/weWaveDesc.h @@ -15,9 +15,9 @@ namespace xtJucePlugin struct WaveDesc : juce::ReferenceCountedObject { - uint32_t waveIndex = g_invalidWaveIndex; - uint32_t tableIndex = g_invalidIndex; - uint32_t listIndex = g_invalidIndex; + xt::WaveId waveId; + xt::TableId tableId; + xt::TableIndex tableIndex; xt::WaveData data; WaveDescSource source = WaveDescSource::Invalid; static WaveDesc* fromDragSource(const juce::DragAndDropTarget::SourceDetails& _sourceDetails); diff --git a/source/xtJucePlugin/weWaveTreeItem.cpp b/source/xtJucePlugin/weWaveTreeItem.cpp @@ -6,12 +6,12 @@ namespace xtJucePlugin { - WaveTreeItem::WaveTreeItem(WaveEditor& _editor, const WaveCategory _category, const uint32_t _waveIndex) + WaveTreeItem::WaveTreeItem(WaveEditor& _editor, const WaveCategory _category, const xt::WaveId _waveIndex) : m_editor(_editor) , m_category(_category) , m_waveIndex(_waveIndex) { - m_onWaveChanged.set(m_editor.getData().onWaveChanged, [this](const unsigned& _waveIndex) + m_onWaveChanged.set(m_editor.getData().onWaveChanged, [this](const xt::WaveId& _waveIndex) { onWaveChanged(_waveIndex); }); @@ -38,19 +38,19 @@ namespace xtJucePlugin } } - std::string WaveTreeItem::getWaveName(const uint32_t _waveIndex) + std::string WaveTreeItem::getWaveName(const xt::WaveId _waveIndex) { - if(!xt::Wave::isValidWaveIndex(_waveIndex)) + if(!xt::Wave::isValidWaveIndex(_waveIndex.rawId())) return {}; const auto category = getCategory(_waveIndex); - return WaveCategoryTreeItem::getCategoryName(category) + ' ' + std::to_string(_waveIndex); + return WaveCategoryTreeItem::getCategoryName(category) + ' ' + std::to_string(_waveIndex.rawId()); } - WaveCategory WaveTreeItem::getCategory(const uint32_t _waveIndex) + WaveCategory WaveTreeItem::getCategory(const xt::WaveId _waveIndex) { - if(_waveIndex < xt::Wave::g_romWaveCount) + if(_waveIndex.rawId() < xt::Wave::g_romWaveCount) return WaveCategory::Rom; - if(_waveIndex >= xt::Wave::g_firstRamWaveIndex && _waveIndex < 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; } @@ -66,19 +66,19 @@ namespace xtJucePlugin juce::var WaveTreeItem::getDragSourceDescription() { auto* desc = new WaveDesc(); - desc->waveIndex = m_waveIndex; + desc->waveId = m_waveIndex; desc->source = WaveDescSource::WaveList; return desc; } - void WaveTreeItem::onWaveChanged(const uint32_t _index) + void WaveTreeItem::onWaveChanged(const xt::WaveId _index) const { if(_index != m_waveIndex) return; onWaveChanged(); } - void WaveTreeItem::onWaveChanged() + void WaveTreeItem::onWaveChanged() const { repaintItem(); } diff --git a/source/xtJucePlugin/weWaveTreeItem.h b/source/xtJucePlugin/weWaveTreeItem.h @@ -13,27 +13,27 @@ namespace xtJucePlugin class WaveTreeItem : public TreeItem { public: - WaveTreeItem(WaveEditor& _editor, WaveCategory _category, uint32_t _waveIndex); + WaveTreeItem(WaveEditor& _editor, WaveCategory _category, xt::WaveId _waveIndex); bool mightContainSubItems() override { return false; } static void paintWave(const xt::WaveData& _data, juce::Graphics& _g, int _x, int _y, int _width, int _height, const juce::Colour& _colour); - static std::string getWaveName(uint32_t _waveIndex); - static WaveCategory getCategory(uint32_t _waveIndex); + static std::string getWaveName(xt::WaveId _waveIndex); + static WaveCategory getCategory(xt::WaveId _waveIndex); void itemSelectionChanged(bool isNowSelected) override; juce::var getDragSourceDescription() override; private: - void onWaveChanged(uint32_t _index); - void onWaveChanged(); + void onWaveChanged(xt::WaveId _index) const; + void onWaveChanged() const; void paintItem(juce::Graphics& g, int width, int height) override; WaveEditor& m_editor; WaveCategory m_category; - const uint32_t m_waveIndex; - pluginLib::EventListener<uint32_t> m_onWaveChanged; + const xt::WaveId m_waveIndex; + pluginLib::EventListener<xt::WaveId> m_onWaveChanged; }; } diff --git a/source/xtJucePlugin/xtWaveEditor.cpp b/source/xtJucePlugin/xtWaveEditor.cpp @@ -1,6 +1,5 @@ #include "xtWaveEditor.h" -#include "weTree.h" #include "weWaveTree.h" #include "weTablesTree.h" #include "weControlTree.h" @@ -18,7 +17,7 @@ namespace xtJucePlugin { addComponentListener(this); - m_data.onWaveChanged.addListener([this](const uint32_t& _waveIndex) + m_data.onWaveChanged.addListener([this](const xt::WaveId& _waveIndex) { if(_waveIndex != m_selectedWave) return; @@ -147,7 +146,7 @@ namespace xtJucePlugin m_data.onReceiveTable(_data, _msg); } - void WaveEditor::setSelectedTable(uint32_t _index) + void WaveEditor::setSelectedTable(xt::TableId _index) { if(m_selectedTable == _index) return; @@ -156,7 +155,7 @@ namespace xtJucePlugin m_controlTree->setTable(_index); } - void WaveEditor::setSelectedWave(const uint32_t _waveIndex, bool _forceRefresh/* = false*/) + void WaveEditor::setSelectedWave(const xt::WaveId _waveIndex, bool _forceRefresh/* = false*/) { if(m_selectedWave == _waveIndex && !_forceRefresh) return; diff --git a/source/xtJucePlugin/xtWaveEditor.h b/source/xtJucePlugin/xtWaveEditor.h @@ -44,8 +44,8 @@ namespace xtJucePlugin Editor& getEditor() const { return m_editor; } GraphData& getGraphData() { return m_graphData; } - void setSelectedTable(uint32_t _index); - void setSelectedWave(uint32_t _waveIndex, bool _forceRefresh = false); + void setSelectedTable(xt::TableId _index); + void setSelectedWave(xt::WaveId _waveIndex, bool _forceRefresh = false); private: // ComponentMovementWatcher @@ -82,8 +82,8 @@ namespace xtJucePlugin bool m_wasVisible = false; - uint32_t m_selectedTable = ~0; - uint32_t m_selectedWave = ~0; + xt::TableId m_selectedTable; + xt::WaveId m_selectedWave; WaveEditorStyle m_style; }; diff --git a/source/xtLib/CMakeLists.txt b/source/xtLib/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES xtDevice.cpp xtDevice.h xtDSP.cpp xtDSP.h xtHardware.cpp xtHardware.h + xtId.cpp xtId.h xtLcd.cpp xtLcd.h xtLeds.cpp xtLeds.h xtMidiTypes.h @@ -17,6 +18,7 @@ set(SOURCES xtRomLoader.cpp xtRomLoader.h xtState.cpp xtState.h xtSysexRemoteControl.cpp xtSysexRemoteControl.h + xtTypes.h xtUc.cpp xtUc.h xtWavePreview.cpp xtWavePreview.h ) diff --git a/source/xtLib/xtMidiTypes.h b/source/xtLib/xtMidiTypes.h @@ -188,11 +188,11 @@ namespace xt namespace Wave { - static constexpr uint32_t g_romWaveCount = 300; - static constexpr uint32_t g_ramWaveCount = 250; - static constexpr uint32_t g_firstRamWaveIndex = 1000; - static constexpr uint32_t g_tableCount = 128; - static constexpr uint32_t g_wavesPerTable = 64; + static constexpr uint16_t g_romWaveCount = 300; + static constexpr uint16_t g_ramWaveCount = 250; + static constexpr uint16_t g_firstRamWaveIndex = 1000; + static constexpr uint16_t g_tableCount = 128; + static constexpr uint16_t g_wavesPerTable = 64; // these are either algorithmic or invalid, we cannot request them via MIDI static constexpr uint32_t g_algorithmicWavetables[] = {28, 29, diff --git a/source/xtLib/xtState.cpp b/source/xtLib/xtState.cpp @@ -773,7 +773,7 @@ namespace xt waveIdx |= _sysex[i4+off+2] << 4; waveIdx |= _sysex[i4+off+3]; - _table[i] = static_cast<uint16_t>(waveIdx); + _table[i] = WaveId(static_cast<uint16_t>(waveIdx)); } } @@ -788,13 +788,12 @@ namespace xt for(uint32_t i=0; i<_table.size(); ++i) { - const auto i4 = i<<2; + const auto waveId = _table[i].rawId(); - const auto waveIndex = _table[i]; - sysex.push_back((waveIndex >> 12) & 0xf); - sysex.push_back((waveIndex >> 8) & 0xf); - sysex.push_back((waveIndex >> 4) & 0xf); - sysex.push_back((waveIndex ) & 0xf); + sysex.push_back((waveId >> 12) & 0xf); + sysex.push_back((waveId >> 8) & 0xf); + sysex.push_back((waveId >> 4) & 0xf); + sysex.push_back((waveId ) & 0xf); } sysex.push_back(0); diff --git a/source/xtLib/xtTypes.h b/source/xtLib/xtTypes.h @@ -6,6 +6,8 @@ #include "dsp56kEmu/types.h" +#include "xtId.h" + namespace xt { static constexpr uint32_t g_ramSize = 0x00020000; @@ -18,5 +20,5 @@ namespace xt using TAudioInputs = TAudioBuffer<2>; using WaveData = std::array<int8_t, 128>; - using TableData = std::array<uint16_t, 64>; + using TableData = std::array<WaveId, 64>; }