WebPd icon indicating copy to clipboard operation
WebPd copied to clipboard

Loading externals

Open fmammoli opened this issue 1 year ago • 3 comments

Hi there, First, thanks for the project, webpd is great! I am using it in a science research project in Brazil about art and climate data and I would love to share with you what we are doing if you are interested.

I was wondering if there is a way to add externals to the wasm or js patches. My scenarios are quite straightforward:

  1. We have a patch that uses some objects from the ELSE library, is there a way to add else to the wasm compilation/convertion? These objects are mostly written in C.

  2. We have a patch that uses a library made of other patches, these ones made using only vanilla pd. Can we load them during the wasm conversion? Or the only solution at the moment is to put them all in the same pd file.

I found an old issue about externals but it does not seam to relate to the current way the lib works.

Thanks,

fmammoli avatar Oct 26 '23 14:10 fmammoli

Hi @fmammoli !

I would love to share with you what we are doing if you are interested.

Please do !!! I Would love to see what you are doing !

We have a patch that uses some objects from the ELSE library, is there a way to add else to the wasm compilation/convertion? These objects are mostly written in C.

For now it is not possible, and I don't know whether it ever will be ! It's a huge task to make externals work. If someone wants to contribute that would be a great way too !

We have a patch that uses a library made of other patches, these ones made using only vanilla pd. Can we load them during the wasm conversion? Or the only solution at the moment is to put them all in the same pd file.

Yes ! That should work. Normally by default WebPd should load the abstractions the same way Pd does. Please let me know if it doesn't work ! It might be a bug ...

sebpiq avatar Oct 27 '23 07:10 sebpiq

Please do !!! I Would love to see what you are doing !

We are still in early prototyping, but you can test the first audio+p5js integration here ! Super simple example, seems to be working fine in both safari and chrome, not sure about firefox.

For now it is not possible, and I don't know whether it ever will be ! It's a huge task to make externals work. If someone wants to contribute that would be a great way too !

It really seems quite complicated dealing with externals in C. I don't have experience with compiling C to webAssembly, but maybe I can think of something just to get some very specific object working. Maybe using emscript and linking de lib in the compiled wasm patch. Seems like a good opportunity to learn something about these tools.

Yes ! That should work. Normally by default WebPd should load the abstractions the same way Pd does. Please let me know if it doesn't work ! It might be a bug ...

I was able to use abstraction when they are pd files in the same folder as the one I am compiling, but not when they are organised inside a folder, like an external. I have some sub patches made of vanilla pd in the Pd/externals/mylib/ and in my pd file I call them like lib/my-object~, this way of calling them does not work. After trying npx webpd@ [email protected] -i Pd/flor02_04.pd -o webpdOutput/flor02 -f appTemplate all I get is:

~~~ Building pdJson ✓
~~~ Building dspGraph ✘ (failed)
ERROR : Unknown object types lib/gaiaFM01~, lib/bipolar~, lib/counter01, lib/reverb03, lib/distort01~, lib/phaseMod01~, lib/stereo01~

As a solution, I just moved all my lib/stuff~ to the same folder as my patch, so not much trouble. Its there other ways to do it?

fmammoli avatar Nov 07 '23 20:11 fmammoli

@fmammoli Awesome! Looking forward to see the final result!

As for the abstractions I am not sure I understood how you get them to be found in your patch. You said they're in the Pd/externals/mylib folder but you call them with lib/ prefix? So you must do something in pure data to modify the search path no? If that's the case that's not supported yet. On the other hand you can indeed place your abstractions in a lib/ folder under your main patch. Or not sure which operating system you're using you could also create a symlink to your abstractions.

sebpiq avatar Nov 11 '23 19:11 sebpiq