Skip to content

Commit

Permalink
setup webchugins, update wasm makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
terryzfeng committed Nov 22, 2023
1 parent 0718394 commit 58c391e
Show file tree
Hide file tree
Showing 7 changed files with 1,176 additions and 18 deletions.
12 changes: 10 additions & 2 deletions src/core/chuck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,20 @@ t_CKBOOL ChucK::initChugins()
// push indent level
// EM_pushlog();
// load external libs | 1.5.0.4 (ge) enabled recursive search
// tf 2023: changed this for webchuck
if( !compiler()->load_external_modules( ".chug.js", dl_search_path, named_dls, TRUE ) )

#ifdef __EMSCRIPTEN__
if( !compiler()->load_external_modules( ".chug.wasm", dl_search_path, named_dls, TRUE ) )
{
// clean up
goto error;
}
#else
if( !compiler()->load_external_modules( ".chug", dl_search_path, named_dls, TRUE ) )
{
// clean up
goto error;
}
#endif
// pop log
// EM_poplog();

Expand Down
3 changes: 0 additions & 3 deletions src/core/chuck_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,6 @@ t_CKBOOL load_external_modules_in_directory( Chuck_Compiler * compiler,
// push
EM_pushlog();

// tf 2023 webchugins
printf("webchugin load: %s, %s\n", directory, extension);

// scan
t_CKBOOL retval = scan_external_modules_in_directory( directory, extension, recursiveSearch, chugins2load, dirs2search, ckfiles2load );
if( !retval )
Expand Down
2 changes: 1 addition & 1 deletion src/host-web/chuck_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ extern "C"
std::list< std::string > chugin_search;
// chugin_search.push_back( chuck_global_data_dir + "/Chugins" );
// chugin_search.push_back( chuck_global_data_dir + "/ChuGins" );
chugin_search.push_back( chuck_global_data_dir + "/chugins" );
chugin_search.push_back( chuck_global_data_dir + "chugins" );
chuck->setParam( CHUCK_PARAM_USER_CHUGIN_DIRECTORIES, chugin_search );

// default real-time audio is true | chuck-1.4.2.1 (ge) added
Expand Down
21 changes: 13 additions & 8 deletions src/host-web/chucknode-postjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ var initGlobals = function( Module )
clearGlobals = Module.cwrap( 'clearGlobals', 'number', ['number'] );
cleanupChuckInstance = Module.cwrap( 'cleanupChuckInstance', 'number', ['number'] );
cleanRegisteredChucks = Module.cwrap( 'cleanRegisteredChucks', null );

// running code
runChuckCode = Module.cwrap( 'runChuckCode', 'number', ['number', 'string'] );
runChuckCodeWithReplacementDac = Module.cwrap( 'runChuckCodeWithReplacementDac', 'number', ['number', 'string', 'string'] );
Expand Down Expand Up @@ -454,25 +454,30 @@ class ChuckNode extends AudioWorkletProcessor
{
super();

// Extract constructor options
this.srate = options.processorOptions.srate;
this.inChannels = options.outputChannelCount[0];
this.outChannels = options.outputChannelCount[0];

this.myID = options.processorOptions.chuckID;

chucks[this.myID] = this;

// do this in response to an incoming message
// Set up a message handler to respond to incoming messages
this.port.onmessage = this.handle_message.bind(this);

// Initialize properties for this ChuckNode instance
this.myPointers = {}
this.myActiveShreds = [];
this.haveInit = false;

// Initialize the Chuck AudioWorkletProcessor
this.init( options.processorOptions.preloadedFiles,
options.processorOptions.wasm );
}

/**
* Initialize the Chuck as an AudioWorkletProcessor.
*/
init( preloadedFiles, wasm )
{
if( !globalInit )
Expand All @@ -483,15 +488,13 @@ class ChuckNode extends AudioWorkletProcessor
{
return function( text )
{
console.log( text );
self.port.postMessage( { type: "console print", message: text } );
}
})( this ),
printErr: (function( self )
{
return function( text )
{
console.error( text );
self.port.postMessage( { type: "console print", message: text } );
}
})( this ),
Expand All @@ -506,8 +509,10 @@ class ChuckNode extends AudioWorkletProcessor
{
return function()
{
// Create a directory for chugins
Module["FS_createPath"]("/", "chugins", true, true);

// Preload files into the file system
for( var i = 0; i < filesToPreload.length; i++ )
{
Module["FS_createPreloadedFile"]( "/",
Expand Down Expand Up @@ -537,7 +542,7 @@ class ChuckNode extends AudioWorkletProcessor
self.outChannels, MAX_CHANNEL_COUNT);

// log
setLogLevel( 3 );
//setLogLevel( 3 );

// initialize chuck instance
// FYI this invokes `new ChucK()` + instance initialization on the C++ side
Expand All @@ -551,7 +556,7 @@ class ChuckNode extends AudioWorkletProcessor
}
})( this ) );
}

handleNewShredID( newShredID, shredCallback )
{
if( newShredID > 0 )
Expand Down Expand Up @@ -644,7 +649,7 @@ class ChuckNode extends AudioWorkletProcessor
switch( event.data.type )
{
// ================== Filesystem ===================== //
case 'loadFile':
case 'createFile':
this.Module.FS_createDataFile( '/' + event.data.directory,
event.data.filename, event.data.data, true, true, true );
break;
Expand Down
1,147 changes: 1,147 additions & 0 deletions src/host-web/webchuck/js/webchuck.js

Large diffs are not rendered by default.

Binary file added src/host-web/webchuck/js/webchuck.wasm
Binary file not shown.
9 changes: 5 additions & 4 deletions src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ emscripten: host-web/webchuck/js/webchuck.js
web: host-web/webchuck/js/webchuck.js
# recipe
host-web/webchuck/js/webchuck.js: $(EMSCRIPTENSRCS) $(EMSCRIPTEN_POSTJS)
emcc -O3 -s DISABLE_EXCEPTION_CATCHING=0 -Icore \
emcc -O3 -s MAIN_MODULE=1 -s DISABLE_EXCEPTION_CATCHING=0 -Icore \
-D__DISABLE_MIDI__ -D__DISABLE_WATCHDOG__ -D__DISABLE_NETWORK__ \
-D__DISABLE_OTF_SERVER__ -D__ALTER_HID__ -D__DISABLE_HID__ \
-D__DISABLE_SERIAL__ -D__DISABLE_ASYNCH_IO__ -D__DISABLE_THREADS__ \
-D__DISABLE_KBHIT__ -D__DISABLE_PROMPTER__ -D__DISABLE_SHELL__ \
-D__CHUCK_USE_PLANAR_BUFFERS__ -D__OLDSCHOOL_RANDOM__ \
-Wformat=0 $(EMSCRIPTENSRCS) -o host-web/webchuck/js/webchuck.js \
-s EXPORTED_FUNCTIONS="['_malloc']" \
-s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "getValue", "setValue", "addFunction", "removeFunction", "UTF8ToString", "stringToUTF8"]' \
-s LINKABLE=1 -s MODULARIZE=1 -s 'EXPORT_NAME="ChucK"' \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 -s ALLOW_MEMORY_GROWTH=1 \
-s RESERVED_FUNCTION_POINTERS=50 -s FORCE_FILESYSTEM=1 \
-s --extern-post-js $(EMSCRIPTEN_POSTJS) \
-s RESERVED_FUNCTION_POINTERS=50 -s FORCE_FILESYSTEM=1
-s 'EXPORT_NAME="ChucK"' \


################################ PLATFORMS ####################################
Expand Down

0 comments on commit 58c391e

Please sign in to comment.