Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasm builds; requires emsdk path #1928

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we just call it WebAssembly?
(it looks a bit off like this)

};

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 @@ -84,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;
Expand All @@ -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;
}
};