[PD-dev] Multiple Instance of pdlib

Dan Wilcox danomatika at gmail.com
Mon Feb 24 15:02:53 CET 2014

On Feb 24, 2014, at 6:00 AM, pd-dev-request at iem.at wrote:

> when i (last) looked into the libpd API, i noticed that libpd works on
> a global namespace as well...what i mean is, that the API (at least
> the C-API, i haven't checked the others) does not allow to specify an
> "instance" of pd.

That's correct. Because there isn't currently a way to multiple instances beyond previously mentioned hacks to the core or non-portable linker flags, the api isn't in place to support it. 

> but i fail to see why libpd doesn't provide the API for this, even if
> the "instance" pointer would not be used (until Pd does support
> multiple instances).
> e.g. the application programmer would have to check that libpd_init()
> returns non-NULL anyhow, and in the current implementation it would
> always return NULL but the first time being called.
> this would have allowed for a transition to multiple instances without
> having to change the API...

Good point. I wasn't involved when Peter first started the project and I'm sure, back then, multiple PD instances seemed waaay off into the future. I think the best/easiest way to handle this without breaking anyone's current code, would be to shadow all of the functions with functions that take an instance pointer, as you suggest. The default ones would simply handle a single internal pointer to the first opened instance, as it does now. If you use the pointer manually, then it's up to you to keep track of it. I we don't mind breaking compatibility, we can simply add an instance handle to each function we have now. Either way, not that difficult.

The C++ wrapper I wrote has api support for multiple instances (aka you can create multiple PdBase classes). Internally, that is handled by a PdContext static class which would theoretically return new instance pointers but, for now, it simply calls the global libpd functions and there is a big warning in the documentation about only using 1 PdBase instance for now.

Again, wouldn't be too hard to add, just currently waiting whether this could become a reality.

Dan Wilcox

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20140224/37c27750/attachment.htm>

More information about the Pd-dev mailing list