commit 3aa30cf3e6078bfe00b53b7de892a9bf8f93f721
parent 267cb3cc9f4b1e531527a285707f8247c13f1e6d
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Tue, 5 Nov 2024 17:02:18 +0100
allow to export waves & tables as midi via drag & drop
Diffstat:
7 files changed, 92 insertions(+), 10 deletions(-)
diff --git a/source/xtJucePlugin/weControlTreeItem.cpp b/source/xtJucePlugin/weControlTreeItem.cpp
@@ -63,10 +63,14 @@ namespace xtJucePlugin
if(m_wave == g_invalidWaveIndex || xt::wave::isReadOnly(m_table) || xt::wave::isReadOnly(m_index))
return TreeViewItem::getDragSourceDescription();
- auto* desc = new WaveDesc();
+ auto* desc = new WaveDesc(m_editor);
+
desc->waveId = m_wave;
desc->source = WaveDescSource::ControlTableList;
desc->tableIndex = m_index;
+
+ desc->fillData(m_editor.getData());
+
return desc;
}
diff --git a/source/xtJucePlugin/weTablesTreeItem.cpp b/source/xtJucePlugin/weTablesTreeItem.cpp
@@ -12,9 +12,7 @@ namespace xtJucePlugin
setPaintRootItemInBold(false);
setDrawsInLeftMargin(true);
- const auto& wavetableNames = _editor.getEditor().getXtController().getParameterDescriptions().getValueList("waveType");
-
- const auto name = wavetableNames->valueToText(_tableIndex.rawId());
+ const auto name = _editor.getTableName(_tableIndex);
setText(name);
@@ -33,9 +31,13 @@ namespace xtJucePlugin
juce::var TablesTreeItem::getDragSourceDescription()
{
- auto* waveDesc = new WaveDesc();
+ auto* waveDesc = new WaveDesc(m_editor);
+
waveDesc->tableId = m_index;
waveDesc->source = WaveDescSource::TablesList;
+
+ waveDesc->fillData(m_editor.getData());
+
return waveDesc;
}
diff --git a/source/xtJucePlugin/weWaveDesc.cpp b/source/xtJucePlugin/weWaveDesc.cpp
@@ -1,5 +1,7 @@
#include "weWaveDesc.h"
+#include "synthLib/sysexToMidi.h"
+
namespace xtJucePlugin
{
WaveDesc* WaveDesc::fromDragSource(const juce::DragAndDropTarget::SourceDetails& _sourceDetails)
@@ -7,4 +9,47 @@ namespace xtJucePlugin
auto* desc = dynamic_cast<WaveDesc*>(_sourceDetails.description.getObject());
return desc;
}
+
+ bool WaveDesc::writeToFile(const juce::File& _file) const
+ {
+ std::vector<xt::SysEx> sysex;
+
+ if(tableData)
+ sysex.emplace_back(xt::State::createTableData(*tableData, tableId.rawId(), false));
+ if(waveData)
+ sysex.emplace_back(xt::State::createWaveData(*waveData, waveId.rawId(), false));
+
+ if(sysex.empty())
+ return false;
+
+ return synthLib::SysexToMidi::write(_file.getFullPathName().toStdString().c_str(), sysex);
+ }
+
+ bool WaveDesc::canDropExternally() const
+ {
+ return waveData || tableData;
+ }
+
+ std::string WaveDesc::getExportFileName(const pluginLib::Processor& _processor) const
+ {
+ std::stringstream name;
+ name << _processor.getProperties().name << " - ";
+
+ if(tableData)
+ name << "Table " << m_editor.getTableName(tableId);
+ else if(waveData)
+ name << "Wave " << WaveTreeItem::getWaveName(waveId);
+ else
+ return DragAndDropObject::getExportFileName(_processor);
+
+ name << ".mid";
+
+ return name.str();
+ }
+
+ void WaveDesc::fillData(const WaveEditorData& _data)
+ {
+ waveData = _data.getWave(waveId);
+ tableData = _data.getTable(tableId);
+ }
}
diff --git a/source/xtJucePlugin/weWaveDesc.h b/source/xtJucePlugin/weWaveDesc.h
@@ -2,10 +2,14 @@
#include "weData.h"
+#include "jucePluginEditorLib/dragAndDropObject.h"
+
#include "juce_gui_basics/juce_gui_basics.h"
namespace xtJucePlugin
{
+ class WaveEditor;
+
enum class WaveDescSource
{
Invalid,
@@ -14,13 +18,28 @@ namespace xtJucePlugin
TablesList
};
- struct WaveDesc : juce::ReferenceCountedObject
+ struct WaveDesc : jucePluginEditorLib::DragAndDropObject
{
+ WaveDesc(WaveEditor& _editor) : m_editor(_editor) {}
+
+ static WaveDesc* fromDragSource(const juce::DragAndDropTarget::SourceDetails& _sourceDetails);
+
+ bool writeToFile(const juce::File& _file) const override;
+ bool canDropExternally() const override;
+ std::string getExportFileName(const pluginLib::Processor& _processor) const override;
+
+ void fillData(const WaveEditorData& _data);
+
+ WaveEditor& m_editor;
+
xt::WaveId waveId;
xt::TableId tableId;
+
xt::TableIndex tableIndex;
- xt::WaveData data;
+
+ std::optional<xt::WaveData> waveData;
+ std::optional<xt::TableData> tableData;
+
WaveDescSource source = WaveDescSource::Invalid;
- static WaveDesc* fromDragSource(const juce::DragAndDropTarget::SourceDetails& _sourceDetails);
};
}
diff --git a/source/xtJucePlugin/weWaveTreeItem.cpp b/source/xtJucePlugin/weWaveTreeItem.cpp
@@ -65,9 +65,13 @@ namespace xtJucePlugin
juce::var WaveTreeItem::getDragSourceDescription()
{
- auto* desc = new WaveDesc();
+ auto* desc = new WaveDesc(m_editor);
+
desc->waveId = m_waveIndex;
desc->source = WaveDescSource::WaveList;
+
+ desc->fillData(m_editor.getData());
+
return desc;
}
diff --git a/source/xtJucePlugin/xtWaveEditor.cpp b/source/xtJucePlugin/xtWaveEditor.cpp
@@ -105,8 +105,8 @@ namespace xtJucePlugin
void WaveEditor::destroy()
{
m_waveTree.reset();
- m_controlTree.reset();
m_tablesTree.reset();
+ m_controlTree.reset();
m_graphFreq.reset();
m_graphPhase.reset();
m_graphTime.reset();
@@ -237,4 +237,10 @@ namespace xtJucePlugin
onWaveDataChanged(*wave);
}
}
+
+ std::string WaveEditor::getTableName(const xt::TableId _id) const
+ {
+ const auto& wavetableNames = getEditor().getXtController().getParameterDescriptions().getValueList("waveType");
+ return wavetableNames->valueToText(_id.rawId());
+ }
}
diff --git a/source/xtJucePlugin/xtWaveEditor.h b/source/xtJucePlugin/xtWaveEditor.h
@@ -49,6 +49,8 @@ namespace xtJucePlugin
void setSelectedTable(xt::TableId _index);
void setSelectedWave(xt::WaveId _waveIndex, bool _forceRefresh = false);
+ std::string getTableName(xt::TableId _id) const;
+
private:
// ComponentMovementWatcher
void componentVisibilityChanged() override { checkFirstTimeVisible(); }