pythonnetwork-programmingpuredatalibpd

How to send a connect message from Python to Pure Data?


I have a mic patch on Pure Data and I want to connect it to a loudspeaker patch. So, it has the command connect localhost 3000, where localhost indicates where the loudspeaker patch is and 3000 is the port number that I will use for connection. Is it possible to send this message using a python script, so I don't have to click on the patch? I'm using libpd for this.


Solution

  • libpd comes with some documentation and a few examples that explain how to use the API. If the Python API docs are not detailed enough, check the documentation for some other language binding - the bindings for the different languages are typically very similar.

    Basically, you can simply send a trigger to a receiver within Pd, using libpd_bang.

    Python:

    libpd_bang("connect-to-speaker")
    

    Pd:

    [receive connect-to-speaker]
    |
    [connect localhost 3000(
    |
    

    you can of course send some payload using libpd_float() or libpd_list() or libpd_message().

    alternatively, you could also have Pd trigger the [connect( message automatically, using [loadbang].