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 982bac3425919b0cf3a41d1fdc164bb49614898b
parent 780dba9ab0b42b5871e2c95627b3812e48ea6af4
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat, 28 Sep 2024 23:54:52 +0200

support to copy tables via drag and drop

Diffstat:
Msource/xtJucePlugin/weControlTreeItem.cpp | 4++--
Msource/xtJucePlugin/weData.cpp | 65+++++++++++++++++++++++++++++++++++++++++++----------------------
Msource/xtJucePlugin/weData.h | 10++++++----
Msource/xtJucePlugin/weTablesTreeItem.cpp | 36++++++++++++++++++++++++++++++++++++
Msource/xtJucePlugin/weTablesTreeItem.h | 4++++
Msource/xtJucePlugin/weWaveDesc.h | 5+++--
6 files changed, 94 insertions(+), 30 deletions(-)

diff --git a/source/xtJucePlugin/weControlTreeItem.cpp b/source/xtJucePlugin/weControlTreeItem.cpp @@ -59,7 +59,7 @@ namespace xtJucePlugin auto* desc = new WaveDesc(); desc->waveId = m_wave; - desc->source = WaveDescSource::ControlList; + desc->source = WaveDescSource::ControlTableList; desc->tableIndex = m_index; return desc; } @@ -80,7 +80,7 @@ namespace xtJucePlugin auto& data = m_editor.getData(); // 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) + if(waveDesc->source == WaveDescSource::ControlTableList) { data.swapTableEntries(m_table, m_index, waveDesc->tableIndex); setSelected(true, true, juce::dontSendNotification); diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp @@ -161,6 +161,22 @@ namespace xtJucePlugin return true; } + bool WaveEditorData::copyTable(const xt::TableId _dest, const xt::TableId _source) + { + const auto dst = _dest.rawId(); + const auto src = _source.rawId(); + + if(dst >= m_tables.size() || src >= m_tables.size()) + return false; + + auto& srcTable = m_tables[src]; + if(!srcTable) + return false; + m_tables[dst] = *srcTable; + onTableChanged(_dest); + return true; + } + std::optional<xt::WaveData> WaveEditorData::getWave(const xt::TableId _tableIndex, const xt::TableIndex _indexInTable) const { return getWave(getWaveIndex(_tableIndex, _indexInTable)); @@ -174,28 +190,6 @@ namespace xtJucePlugin return static_cast<uint16_t>((hh << 7) | ll); } - bool WaveEditorData::requestWave(const xt::WaveId _index) - { - if(isWaitingForData()) - return false; - - if(!m_controller.requestWave(_index.rawId())) - return false; - m_currentWaveRequestIndex = _index; - return true; - } - - bool WaveEditorData::requestTable(const xt::TableId _index) - { - if(isWaitingForData()) - return false; - - if(!m_controller.requestTable(_index.rawId())) - return false; - m_currentTableRequestIndex = _index; - return true; - } - bool WaveEditorData::setWave(xt::WaveId _id, const xt::WaveData& _data) { auto i = _id.rawId(); @@ -229,6 +223,28 @@ namespace xtJucePlugin return true; } + bool WaveEditorData::requestWave(const xt::WaveId _index) + { + if(isWaitingForData()) + return false; + + if(!m_controller.requestWave(_index.rawId())) + return false; + m_currentWaveRequestIndex = _index; + return true; + } + + bool WaveEditorData::requestTable(const xt::TableId _index) + { + if(isWaitingForData()) + return false; + + if(!m_controller.requestTable(_index.rawId())) + return false; + m_currentTableRequestIndex = _index; + return true; + } + bool WaveEditorData::isAlgorithmicTable(const xt::TableId _index) { for (const uint32_t i : xt::Wave::g_algorithmicWavetables) @@ -243,4 +259,9 @@ namespace xtJucePlugin { return _table.rawId() < xt::Wave::g_firstRamTableIndex; } + + bool WaveEditorData::isReadOnly(const xt::WaveId _waveId) + { + return _waveId.rawId() < xt::Wave::g_firstRamWaveIndex; + } } diff --git a/source/xtJucePlugin/weData.h b/source/xtJucePlugin/weData.h @@ -41,19 +41,21 @@ namespace xtJucePlugin 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); + bool copyTable(const xt::TableId _dest, const xt::TableId _source); static uint16_t toIndex(const pluginLib::MidiPacket::Data& _data); + static bool isAlgorithmicTable(xt::TableId _index); static bool isReadOnly(xt::TableId _table); + static bool isReadOnly(xt::WaveId _waveId); - private: + bool setWave(xt::WaveId _id, const xt::WaveData& _data); + bool setTable(xt::TableId _index, const xt::TableData& _data); + private: bool requestWave(xt::WaveId _index); bool requestTable(xt::TableId _index); - bool setWave(xt::WaveId _id, const xt::WaveData& _data); - bool setTable(xt::TableId _index, const xt::TableData& _data); - Controller& m_controller; xt::WaveId m_currentWaveRequestIndex = g_invalidWaveIndex; diff --git a/source/xtJucePlugin/weTablesTreeItem.cpp b/source/xtJucePlugin/weTablesTreeItem.cpp @@ -1,5 +1,6 @@ #include "weTablesTreeItem.h" +#include "weWaveDesc.h" #include "xtController.h" #include "xtEditor.h" #include "xtWaveEditor.h" @@ -29,6 +30,41 @@ namespace xtJucePlugin m_editor.setSelectedTable(m_index); } + juce::var TablesTreeItem::getDragSourceDescription() + { + auto* waveDesc = new WaveDesc(); + waveDesc->tableId = m_index; + waveDesc->source = WaveDescSource::TablesList; + return waveDesc; + } + + bool TablesTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails) + { + if(WaveEditorData::isReadOnly(m_index)) + return false; + const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails); + if(!waveDesc || waveDesc->source != WaveDescSource::TablesList) + return false; + return waveDesc->tableId != m_index; + } + + void TablesTreeItem::itemDropped(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) + { + TreeItem::itemDropped(dragSourceDetails, insertIndex); + + const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails); + + if(!waveDesc || waveDesc->source != WaveDescSource::TablesList || waveDesc->tableId == m_index) + return; + + auto& data = m_editor.getData(); + if(data.copyTable(m_index, waveDesc->tableId)) + { + setSelected(true, true, juce::dontSendNotification); + m_editor.setSelectedTable(m_index); + } + } + void TablesTreeItem::onTableChanged(xt::TableId _index) { if(_index != m_index) diff --git a/source/xtJucePlugin/weTablesTreeItem.h b/source/xtJucePlugin/weTablesTreeItem.h @@ -19,6 +19,10 @@ namespace xtJucePlugin void itemSelectionChanged(bool _isNowSelected) override; + juce::var getDragSourceDescription() override; + bool isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails) override; + void itemDropped(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) override; + private: void onTableChanged(xt::TableId _index); void onTableChanged(); diff --git a/source/xtJucePlugin/weWaveDesc.h b/source/xtJucePlugin/weWaveDesc.h @@ -9,8 +9,9 @@ namespace xtJucePlugin enum class WaveDescSource { Invalid, - ControlList, - WaveList + ControlTableList, + WaveList, + TablesList }; struct WaveDesc : juce::ReferenceCountedObject