commit 73749be6d3d5ab7e50aa8be5bfc3505f8540c1e8
parent 30febc27725a2b5bf2ca7e6a0c2c213633af49b3
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Tue, 5 Nov 2024 18:46:39 +0100
support import of control tables via d&d from mid/syx too
Diffstat:
4 files changed, 70 insertions(+), 14 deletions(-)
diff --git a/source/xtJucePlugin/weTablesTreeItem.cpp b/source/xtJucePlugin/weTablesTreeItem.cpp
@@ -1,6 +1,7 @@
#include "weTablesTreeItem.h"
#include "weWaveDesc.h"
+#include "weWaveTreeItem.h"
#include "xtController.h"
#include "xtEditor.h"
#include "xtWaveEditor.h"
@@ -69,6 +70,50 @@ namespace xtJucePlugin
}
}
+ bool TablesTreeItem::isInterestedInFileDrag(const juce::StringArray& files)
+ {
+ if(xt::wave::isReadOnly(getTableId()))
+ return false;
+
+ if(files.size() == 1 && files[0].endsWithIgnoreCase(".mid") || files[1].endsWithIgnoreCase(".syx"))
+ return true;
+
+ return TreeItem::isInterestedInFileDrag(files);
+ }
+
+ void TablesTreeItem::filesDropped(const juce::StringArray& files, int insertIndex)
+ {
+ if(xt::wave::isReadOnly(getTableId()))
+ return;
+
+ const auto errorTitle = m_editor.getEditor().getProcessor().getProperties().name + " - Error";
+
+ const auto sysex = WaveTreeItem::getSysexFromFiles(files);
+
+ if(sysex.empty())
+ {
+ juce::NativeMessageBox::showMessageBox(juce::AlertWindow::WarningIcon, errorTitle, "No Sysex data found in file");
+ return;
+ }
+
+ std::vector<xt::TableData> tables;
+
+ for (const auto& s : sysex)
+ {
+ xt::TableData table;
+ if (xt::State::parseTableData(table, s))
+ tables.push_back(table);
+ }
+
+ if(tables.size() == 1)
+ {
+ m_editor.getData().setTable(m_index, tables.front());
+ return;
+ }
+
+ juce::NativeMessageBox::showMessageBox(juce::AlertWindow::WarningIcon, errorTitle, tables.empty() ? "No Control Table found in files" : "Multiple control tables found in file");
+ }
+
void TablesTreeItem::onTableChanged(xt::TableId _index)
{
if(_index != m_index)
diff --git a/source/xtJucePlugin/weTablesTreeItem.h b/source/xtJucePlugin/weTablesTreeItem.h
@@ -23,6 +23,9 @@ namespace xtJucePlugin
bool isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails) override;
void itemDropped(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) override;
+ bool isInterestedInFileDrag(const juce::StringArray& files) override;
+ void filesDropped(const juce::StringArray& files, int insertIndex) override;
+
const auto& getTableId() const { return m_index; }
private:
diff --git a/source/xtJucePlugin/weWaveTreeItem.cpp b/source/xtJucePlugin/weWaveTreeItem.cpp
@@ -2,6 +2,7 @@
#include "weWaveCategoryTreeItem.h"
#include "weWaveDesc.h"
+#include "xtEditor.h"
#include "xtWaveEditor.h"
#include "synthLib/midiToSysex.h"
@@ -122,18 +123,15 @@ namespace xtJucePlugin
if(xt::wave::isReadOnly(m_waveIndex))
return;
- if(files.size() != 1 || (!files[0].endsWithIgnoreCase(".mid") && !files[0].endsWithIgnoreCase(".syx")))
- {
- TreeItem::filesDropped(files, insertIndex);
- return;
- }
+ const auto sysex = getSysexFromFiles(files);
- std::vector<std::vector<uint8_t>> sysex;
-
- synthLib::MidiToSysex::extractSysexFromFile(sysex, files[0].toStdString());
+ const auto errorTitle = m_editor.getEditor().getProcessor().getProperties().name + " - Error";
if(sysex.empty())
+ {
+ juce::NativeMessageBox::showMessageBoxAsync(juce::AlertWindow::WarningIcon, errorTitle, "No sysex data found in file");
return;
+ }
std::vector<xt::WaveData> waves;
@@ -144,19 +142,27 @@ namespace xtJucePlugin
waves.push_back(wave);
}
- if(waves.empty())
+ if(waves.size() == 1)
{
- juce::NativeMessageBox::showMessageBoxAsync(juce::AlertWindow::WarningIcon, "Error", "No wave data found in file.");
+ m_editor.getData().setWave(m_waveIndex, waves.front());
return;
}
- if(waves.size() > 1)
+ juce::NativeMessageBox::showMessageBoxAsync(juce::AlertWindow::WarningIcon, errorTitle, waves.empty() ? "No wave data found in file" : "Multiple waves found in file");
+ }
+
+ std::vector<std::vector<uint8_t>> WaveTreeItem::getSysexFromFiles(const juce::StringArray& _files)
+ {
+ std::vector<std::vector<uint8_t>> sysex;
+
+ for(const auto& file : _files)
{
- juce::NativeMessageBox::showMessageBoxAsync(juce::AlertWindow::WarningIcon, "Error", "Multiple waves found in file.");
- return;
+ std::vector<std::vector<uint8_t>> s;
+ synthLib::MidiToSysex::extractSysexFromFile(s, file.toStdString());
+ sysex.insert(sysex.end(), s.begin(), s.end());
}
- m_editor.getData().setWave(m_waveIndex, waves.front());
+ return sysex;
}
void WaveTreeItem::onWaveChanged(const xt::WaveId _index) const
diff --git a/source/xtJucePlugin/weWaveTreeItem.h b/source/xtJucePlugin/weWaveTreeItem.h
@@ -33,6 +33,8 @@ namespace xtJucePlugin
bool isInterestedInFileDrag(const juce::StringArray& files) override;
void filesDropped(const juce::StringArray& files, int insertIndex) override;
+ static std::vector<std::vector<uint8_t>> getSysexFromFiles(const juce::StringArray& _files);
+
private:
void onWaveChanged(xt::WaveId _index) const;
void onWaveChanged() const;