From 6849d6431f0d57f303f00807a97262ce2433ffd8 Mon Sep 17 00:00:00 2001 From: Alexander Chalikiopoulos Date: Tue, 5 Nov 2024 20:46:55 +0100 Subject: [PATCH 1/2] add wasm builds; requires emsdk path --- Source/Heavy/HeavyExportDialog.cpp | 6 +- Source/Heavy/WASMExporter.h | 96 ++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 Source/Heavy/WASMExporter.h diff --git a/Source/Heavy/HeavyExportDialog.cpp b/Source/Heavy/HeavyExportDialog.cpp index ea88691da..8015e147a 100644 --- a/Source/Heavy/HeavyExportDialog.cpp +++ b/Source/Heavy/HeavyExportDialog.cpp @@ -22,6 +22,7 @@ #include "DPFExporter.h" #include "DaisyExporter.h" #include "PdExporter.h" +#include "WASMExporter.h" class ExporterSettingsPanel : public Component , private ListBoxModel { @@ -39,7 +40,8 @@ class ExporterSettingsPanel : public Component "C++ Code", "Electro-Smith Daisy", "DPF Audio Plugin", - "Pd External" + "Pd External", + "JS / WebAssembly" }; ExporterSettingsPanel(PluginEditor* editor, ExportingProgressView* exportingView) @@ -48,6 +50,7 @@ class ExporterSettingsPanel : public Component addChildComponent(views.add(new DaisyExporter(editor, exportingView))); addChildComponent(views.add(new DPFExporter(editor, exportingView))); addChildComponent(views.add(new PdExporter(editor, exportingView))); + addChildComponent(views.add(new WASMExporter(editor, exportingView))); addAndMakeVisible(listBox); @@ -100,6 +103,7 @@ class ExporterSettingsPanel : public Component state.appendChild(views[1]->getState(), nullptr); state.appendChild(views[2]->getState(), nullptr); state.appendChild(views[3]->getState(), nullptr); + state.appendChild(views[4]->getState(), nullptr); auto settingsTree = SettingsFile::getInstance()->getValueTree(); diff --git a/Source/Heavy/WASMExporter.h b/Source/Heavy/WASMExporter.h new file mode 100644 index 000000000..53dac0f85 --- /dev/null +++ b/Source/Heavy/WASMExporter.h @@ -0,0 +1,96 @@ +/* + // Copyright (c) 2024 Timothy Schoen and Wasted Audio + // For information on usage and redistribution, and for a DISCLAIMER OF ALL + // WARRANTIES, see the file, "LICENSE.txt," in this distribution. + */ + +class WASMExporter : public ExporterBase { +public: + + Value emsdkPathValue; + + WASMExporter(PluginEditor* editor, ExportingProgressView* exportingView) + : ExporterBase(editor, exportingView) + { + PropertiesArray properties; + properties.add(new PropertiesPanel::EditableComponent("EMSDK path", emsdkPathValue)); + + for (auto* property : properties) { + property->setPreferredHeight(28); + } + + panel.addSection("WASM", properties); + } + + ValueTree getState() override + { + ValueTree stateTree("WASM"); + + stateTree.setProperty("inputPatchValue", getValue(inputPatchValue), nullptr); + stateTree.setProperty("projectNameValue", getValue(projectNameValue), nullptr); + stateTree.setProperty("projectCopyrightValue", getValue(projectCopyrightValue), nullptr); + stateTree.setProperty("emsdkPathValue", getValue(emsdkPathValue), nullptr); + + return stateTree; + } + + void setState(ValueTree& stateTree) override + { + auto tree = stateTree.getChildWithName("WASM"); + inputPatchValue = tree.getProperty("inputPatchValue"); + projectNameValue = tree.getProperty("projectNameValue"); + projectCopyrightValue = tree.getProperty("projectCopyrightValue"); + emsdkPathValue = tree.getProperty("emsdkPathValue"); + } + + bool performExport(String pdPatch, String outdir, String name, String copyright, StringArray searchPaths) override + { + exportingView->showState(ExportingProgressView::Exporting); + + StringArray args = { heavyExecutable.getFullPathName(), pdPatch, "-o" + outdir }; + + name = name.replaceCharacter('-', '_'); + args.add("-n" + name); + + if (copyright.isNotEmpty()) { + args.add("--copyright"); + args.add("\"" + copyright + "\""); + } + + auto emsdkPath = getValue(emsdkPathValue); + + args.add("-v"); + args.add("-gjs"); + + String paths = "-p"; + for (auto& path : searchPaths) { + paths += " " + path; + } + + args.add(paths); + + if (shouldQuit) + return true; + + auto buildScript = "source " + emsdkPath + "/emsdk_env.sh; " + args.joinIntoString(" "); + + Toolchain::startShellScript(buildScript, this); + + waitForProcessToFinish(-1); + exportingView->flushConsole(); + + if (shouldQuit) + return true; + + auto outputFile = File(outdir); + outputFile.getChildFile("c").deleteRecursively(); + outputFile.getChildFile("ir").deleteRecursively(); + outputFile.getChildFile("hv").deleteRecursively(); + + // Delay to get correct exit code + Time::waitForMillisecondCounter(Time::getMillisecondCounter() + 300); + + bool generationExitCode = getExitCode(); + return generationExitCode; + } +}; From e5c47978bbfd415118d95537e7946b4f63eb61bb Mon Sep 17 00:00:00 2001 From: dreamer Date: Tue, 5 Nov 2024 21:06:00 +0100 Subject: [PATCH 2/2] increment heavyState for loop --- Source/Heavy/HeavyExportDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Heavy/HeavyExportDialog.cpp b/Source/Heavy/HeavyExportDialog.cpp index 8015e147a..228a3287c 100644 --- a/Source/Heavy/HeavyExportDialog.cpp +++ b/Source/Heavy/HeavyExportDialog.cpp @@ -87,7 +87,7 @@ class ExporterSettingsPanel : public Component auto heavyState = settingsTree.getChildWithName("HeavyState"); if (heavyState.isValid()) { this->setState(heavyState); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 5; i++) { views[i]->blockDialog = true; views[i]->setState(heavyState); views[i]->blockDialog = false;