commit d5bacbaec3d93560108f502c4729e12a7add70aa
parent 295792e31ded0b95c6decf52c3e052ec0e67fb43
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:13:01 +0100
add ability to export the current skin to a folder
Diffstat:
4 files changed, 99 insertions(+), 0 deletions(-)
diff --git a/source/jucePlugin/PluginEditor.cpp b/source/jucePlugin/PluginEditor.cpp
@@ -83,6 +83,16 @@ void AudioPluginAudioProcessorEditor::openMenu()
skinMenu.addItem("Modern", true, skinId == 0,[this] {loadSkin(0);});
skinMenu.addItem("Classic", true, skinId == 1,[this] {loadSkin(1);});
+ if(m_virusEditor)
+ {
+ auto* editor = dynamic_cast<genericVirusUI::VirusEditor*>(m_virusEditor.get());
+ if(editor)
+ {
+ skinMenu.addSeparator();
+ skinMenu.addItem("Export current skin to folder", true, false, [this]{exportCurrentSkin();});
+ }
+ }
+
juce::PopupMenu scaleMenu;
scaleMenu.addItem("50%", true, scale == 50, [this] { setGuiScale(50); });
scaleMenu.addItem("75%", true, scale == 75, [this] { setGuiScale(75); });
@@ -98,6 +108,28 @@ void AudioPluginAudioProcessorEditor::openMenu()
menu.showMenuAsync(juce::PopupMenu::Options());
}
+void AudioPluginAudioProcessorEditor::exportCurrentSkin() const
+{
+ if(!m_virusEditor)
+ return;
+
+ auto* editor = dynamic_cast<genericVirusUI::VirusEditor*>(m_virusEditor.get());
+
+ if(!editor)
+ return;
+
+ const auto res = editor->exportToFolder("skins/");
+
+ if(!res.empty())
+ {
+ juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::WarningIcon, "Export failed", "Failed to export skin:\n\n" + res, "OK", m_virusEditor.get());
+ }
+ else
+ {
+ juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::InfoIcon, "Export finished", "Skin successfully exported");
+ }
+}
+
AudioPluginAudioProcessorEditor::~AudioPluginAudioProcessorEditor()
{
m_virusEditor.reset();
diff --git a/source/jucePlugin/PluginEditor.h b/source/jucePlugin/PluginEditor.h
@@ -20,6 +20,7 @@ private:
void loadSkin(int index);
void setGuiScale(int percent);
void openMenu();
+ void exportCurrentSkin() const;
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
diff --git a/source/juceUiLib/editor.cpp b/source/juceUiLib/editor.cpp
@@ -2,6 +2,8 @@
#include "uiObject.h"
+#include "../synthLib/os.h"
+
namespace genericUI
{
Editor::Editor(EditorInterface& _interface) : m_interface(_interface)
@@ -58,6 +60,68 @@ namespace genericUI
m_scale = m_rootObject->getPropertyFloat("scale", 1.0f);
}
+ std::string Editor::exportToFolder(const std::string& _folder) const
+ {
+ if(!m_rootObject)
+ return "Nothing to export";
+
+ synthLib::createDirectory(_folder);
+
+ std::string subfolder = m_jsonFilename;
+ const auto dotIndex = m_jsonFilename.rfind('.');
+ if(dotIndex != std::string::npos)
+ subfolder = subfolder.substr(0, dotIndex);
+ const auto underscoreIndex = m_jsonFilename.find('_');
+ if(underscoreIndex != std::string::npos)
+ subfolder = subfolder.substr(underscoreIndex+1);
+
+ const auto folder = _folder + subfolder + '/';
+
+ synthLib::createDirectory(folder);
+
+ std::stringstream errors;
+
+ auto writeFile = [this, &folder, &errors](const std::string& _name)
+ {
+ uint32_t dataSize;
+ const auto data = m_interface.getResourceByFilename(_name, dataSize);
+
+ FILE* hFile = fopen((folder + _name).c_str(), "wb");
+
+ if(!hFile)
+ {
+ errors << "Failed to create file " << folder << _name << std::endl;
+ }
+ else
+ {
+ fwrite(data, dataSize, 1, hFile);
+ fclose(hFile);
+ }
+ };
+
+ auto writeData = [this, writeFile](const std::set<std::string>& _names, const std::string& _ext)
+ {
+ for (const auto& name : _names)
+ {
+ const auto dataName = name + _ext;
+ writeFile(dataName);
+ }
+ };
+
+ std::set<std::string> textures;
+ std::set<std::string> fonts;
+
+ m_rootObject->collectVariants(textures, "texture");
+ m_rootObject->collectVariants(fonts, "fontFile");
+
+ writeFile(m_jsonFilename);
+
+ writeData(textures, ".png");
+ writeData(fonts, ".ttf");
+
+ return errors.str();
+ }
+
juce::Drawable* Editor::getImageDrawable(const std::string& _texture)
{
const auto it = m_drawables.find(_texture);
diff --git a/source/juceUiLib/editor.h b/source/juceUiLib/editor.h
@@ -19,6 +19,8 @@ namespace genericUI
void create(const std::string& _jsonFilename);
+ std::string exportToFolder(const std::string& _folder) const;
+
juce::Drawable* getImageDrawable(const std::string& _texture);
std::unique_ptr<juce::Drawable> createImageDrawable(const std::string& _texture);
const juce::Font& getFont(const std::string& _fontFile);