claudeha / pure-data

Pure Data - tracking puredata SourceForge git repository
Other
6 stars 1 forks source link

Is it possible to send messages to empd from JS? #8

Closed ethanmuller closed 2 years ago

ethanmuller commented 2 years ago

Hi @claudeha!

I'm primarily a JS dev, with very little experience in C and Emscripten.

I'm looking to create a UI in HTML/CSS/JS that uses Pd patches for audio synthesis. I started with WebPd, but it is missing some Pd objects I'd like to use, which brought me to empd.

Is there any way to send and receive messages between empd and the JS in my own UI? WebPd has the Pd.send and Pd.receive methods. Is it possible to do something similar with empd?

Thanks for your work on this project!

claudeha commented 2 years ago

It should be possible but it's not implemented in an easy to use way yet. So far I've only implemented GUI in C using SDL2 and OpenGL (WebGL).

You'll need to call libpd C functions from JS, see Emscripten docs on how to do that, especially how to expose the functions (keepalive etc). Then see the libpd docs for constructing and sending messages. Maybe if you have a small vocabulary writing C functions that call libpd and calling those from JS would be easier.

Writing a generic send function would be a good exercise.

Receiving is trickier because that requires callbacks from libpd back into JS. I have no experience of that part of libpd but you'll probably have to write a small C function to translate data from libpd and forward to JS.

A generic receiver callable from JS would be a good addition.

These would probably best be contributed to my libpd repo, if they have same or similar API as webpd that would be a bonus.

ethanmuller commented 2 years ago

Okay! This looks like the relevant page of Emscripten docs.

If I figure out how to do this I'll send you a PR.

Thanks for the thoughtful reply!