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

use faustwasm for compilation #7

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
compile :
tsc --noImplicitThis --noUnusedLocals -target es6 -outFile js/faustplayground.js js/Main.ts
tsc --noImplicitThis --noUnusedLocals --sourcemap -target es6 -outFile js/faustplayground.js js/Main.ts

test :
cd .. && python -m http.server 8000
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
<script src="js/Lib/AudioContextMonkeyPatch.js"></script>
<script src="js/Lib/qrcode.js"></script>
<script src="js/Lib/perfectScrollBar/js/perfect-scrollbar.min.js"></script>
<!--
<script src="js/Lib/faustwasm/index.js"></script>
<script src="js/Lib/libfaust-wasm.js"></script>
<script src="js/Lib/webaudio-wasm-wrapper.js"></script>
-->
<script src="js/Lib/FileSaver.min.js"></script>
<script src="https://apis.google.com/js/client.js?onload=checkAuth"></script>
<script src="js/faustplayground.js"></script>
Expand All @@ -50,10 +53,7 @@
if (!isWasm) {
alert("WebAssembly is not supported in this browser, the page will not work !")
}
// 'faust_module' global is defined in webaudio-wasm-wrapper.js file, 'onRuntimeInitialized' will be called when code is ready
// (see https://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html)

faust_module['onRuntimeInitialized'] = init;
init();
</script>

</html>
25 changes: 14 additions & 11 deletions js/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Create Factories and Modules
/// <reference path="Error.ts"/>
/// <reference path="Dragging.ts"/>
/// <reference path="Utilitary.ts"/>
/// <reference path="Lib/webaudio-asm-worker-wrapper.d.ts"/>
/// <reference path="Modules/FaustInterface.ts"/>
/// <reference path="Scenes/SceneView.ts"/>
/// <reference path="Menu/Export.ts"/>
Expand Down Expand Up @@ -90,7 +89,7 @@ class App {
**************** CREATE FAUST FACTORIES AND MODULES ****************
********************************************************************/

compileFaust(compileFaust: CompileFaust) {
async compileFaust(compileFaust: CompileFaust) {

// Temporarily Saving parameters of compilation
this.tempModuleName = compileFaust.name;
Expand All @@ -103,12 +102,16 @@ class App {
if (currentScene) { currentScene.muteScene() };

// Libraries are now included and loaded from the EMCC locale FS inluded in libfaust
var libpath = "libraries";
var args: string[] = ["-I", libpath, "-ftz", "2"];
// var libpath = "libraries";
// var args: string[] = ["-I", libpath, "-ftz", "2"];

//try to create the wasm code/factory with the given Faust code. Then callback to function passing the factory.
try {
this.factory = faust.createDSPFactory(compileFaust.sourceCode, args, (factory) => { compileFaust.callback(factory) });
const faustMonoDspGenerator = new faustWasmEnv.FaustMonoDspGenerator();
await faustMonoDspGenerator.compile(faustWasmEnv.faustCompiler, "FaustDSP", compileFaust.sourceCode, "-ftz 2");
if (!faustMonoDspGenerator.factory) throw new Error("Faust DSP is not compiled");
this.factory = faustMonoDspGenerator.factory;
compileFaust.callback(this.factory);
} catch (error) {
new Message(error)
}
Expand All @@ -120,7 +123,7 @@ class App {
//
private createModule(factory: Factory): void {
if (!factory) {
new Message(Utilitary.messageRessource.errorFactory + faust.getErrorMessage());
new Message(Utilitary.messageRessource.errorFactory /*+ faust.getErrorMessage() */);
Utilitary.hideFullPageLoading();
return;
}
Expand Down Expand Up @@ -167,7 +170,7 @@ class App {
setGeneralAppListener(app: App): void {

//custom event to load file from the load menu with the file explorer
document.addEventListener("fileload", (e: CustomEvent) => { this.loadFileEvent(e) })
document.addEventListener("fileload", (e: Event) => { this.loadFileEvent(e as CustomEvent<File>) })

//All drog and drop events
window.ondragover = function () { return false; };
Expand Down Expand Up @@ -207,7 +210,7 @@ class App {
};

//custom double touch from library menu to load an effect or an intrument.
document.addEventListener("dbltouchlib", (e: CustomEvent) => { this.dblTouchUpload(e) });
document.addEventListener("dbltouchlib", (e: Event) => { this.dblTouchUpload(e as CustomEvent<string>) });
}

//-- Upload content dropped on the page and allocate the content to the right function
Expand Down Expand Up @@ -317,15 +320,15 @@ class App {
};
}
//used when a custom event from loading file with the browser dialogue
loadFileEvent(e: CustomEvent) {
loadFileEvent(e: CustomEvent<File>) {
Utilitary.showFullPageLoading();
var file: File = <File>e.detail;
var file = e.detail;
var position: PositionModule = Utilitary.currentScene.positionDblTapModule();
this.loadFile(file, null, position.x, position.y)

}
//used with the library double touch custom event
dblTouchUpload(e: CustomEvent) {
dblTouchUpload(e: CustomEvent<string>) {
Utilitary.showFullPageLoading();
var position: PositionModule = Utilitary.currentScene.positionDblTapModule();
this.uploadUrl(this, null, position.x, position.y, e.detail);
Expand Down