commit 5b4c9d4c4b8d0e2dde042521c960e8a403e190cf
parent bf2ac82ebb8b6e155b41a14e47d540cd73a7f5fd
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 29 Sep 2024 01:01:34 +0200
copy waves via drag and drop
Diffstat:
4 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp
@@ -177,6 +177,14 @@ namespace xtJucePlugin
return true;
}
+ bool WaveEditorData::copyWave(const xt::WaveId _dest, const xt::WaveId _source)
+ {
+ const auto sourceWave = getWave(_source);
+ if(!sourceWave)
+ return false;
+ return setWave(_dest, *sourceWave);
+ }
+
std::optional<xt::WaveData> WaveEditorData::getWave(const xt::TableId _tableIndex, const xt::TableIndex _indexInTable) const
{
return getWave(getWaveIndex(_tableIndex, _indexInTable));
diff --git a/source/xtJucePlugin/weData.h b/source/xtJucePlugin/weData.h
@@ -41,7 +41,9 @@ 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);
+ bool copyWave(const xt::WaveId _dest, const xt::WaveId _source);
static uint16_t toIndex(const pluginLib::MidiPacket::Data& _data);
diff --git a/source/xtJucePlugin/weWaveTreeItem.cpp b/source/xtJucePlugin/weWaveTreeItem.cpp
@@ -71,6 +71,30 @@ namespace xtJucePlugin
return desc;
}
+ bool WaveTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails)
+ {
+ if(WaveEditorData::isReadOnly(m_waveIndex))
+ return false;
+ const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails);
+ if(!waveDesc)
+ return false;
+ if(!waveDesc->waveId.isValid())
+ return false;
+ return true;
+ }
+
+ void WaveTreeItem::itemDropped(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex)
+ {
+ TreeItem::itemDropped(dragSourceDetails, insertIndex);
+ if(WaveEditorData::isReadOnly(m_waveIndex))
+ return;
+ const auto* waveDesc = WaveDesc::fromDragSource(dragSourceDetails);
+ if(!waveDesc)
+ return;
+ auto& data = m_editor.getData();
+ data.copyWave(m_waveIndex, waveDesc->waveId);
+ }
+
void WaveTreeItem::onWaveChanged(const xt::WaveId _index) const
{
if(_index != m_waveIndex)
diff --git a/source/xtJucePlugin/weWaveTreeItem.h b/source/xtJucePlugin/weWaveTreeItem.h
@@ -27,6 +27,9 @@ 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 onWaveChanged(xt::WaveId _index) const;
void onWaveChanged() const;