Skip to content

Commit

Permalink
add wasm builds; requires emsdk path
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Chalikiopoulos committed Nov 5, 2024
1 parent 4ff4d62 commit 6849d64
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Source/Heavy/HeavyExportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DPFExporter.h"
#include "DaisyExporter.h"
#include "PdExporter.h"
#include "WASMExporter.h"

class ExporterSettingsPanel : public Component
, private ListBoxModel {
Expand All @@ -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)
Expand All @@ -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);

Expand Down Expand Up @@ -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();

Expand Down
96 changes: 96 additions & 0 deletions Source/Heavy/WASMExporter.h
Original file line number Diff line number Diff line change
@@ -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<String>("EMSDK path", emsdkPathValue));

for (auto* property : properties) {
property->setPreferredHeight(28);
}

panel.addSection("WASM", properties);
}

ValueTree getState() override
{
ValueTree stateTree("WASM");

stateTree.setProperty("inputPatchValue", getValue<String>(inputPatchValue), nullptr);
stateTree.setProperty("projectNameValue", getValue<String>(projectNameValue), nullptr);
stateTree.setProperty("projectCopyrightValue", getValue<String>(projectCopyrightValue), nullptr);
stateTree.setProperty("emsdkPathValue", getValue<String>(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<String>(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;
}
};

0 comments on commit 6849d64

Please sign in to comment.