Last active
January 12, 2022 19:36
-
-
Save ggorlen/0c28c0bd5404811ae293c87aeb1ffe1e to your computer and use it in GitHub Desktop.
Controlling PD with a socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #N canvas 116 315 450 300 12; | |
| #X obj 48 90 route start stop; | |
| #X obj 82 170 dac~; | |
| #X obj 39 119 noise~; | |
| #X obj 82 143 *~ 0; | |
| #X msg 134 118 0, f 1; | |
| #X msg 90 117 0.5; | |
| #X obj 221 103 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 | |
| -1 -1; | |
| #X text 160 42 0 for tcp \, see [help]; | |
| #X obj 48 63 netreceive 5005 0; | |
| #X connect 0 0 5 0; | |
| #X connect 0 1 4 0; | |
| #X connect 2 0 3 0; | |
| #X connect 3 0 1 0; | |
| #X connect 3 0 1 1; | |
| #X connect 4 0 3 1; | |
| #X connect 5 0 3 1; | |
| #X connect 8 0 0 0; | |
| #X connect 8 0 6 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TCP https://gist.github.com/sid24rane/2b10b8f4b2f814bd0851d861d3515a10 | |
| const net = require("net"); | |
| const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
| const sock = {host: "127.0.0.1", port: 5005}; | |
| const client = net.connect(sock, async () => { | |
| //console.log("connected to server!"); | |
| client.write("start;\n"); | |
| await sleep(5000); | |
| client.write("stop;\n"); | |
| client.end(); | |
| }); | |
| client.on("end", () => { | |
| //console.log("disconnected from server"); | |
| }); | |
| // UDP https://gist.github.com/sid24rane/6e6698e93360f2694e310dd347a2e2eb | |
| /* | |
| const udp = require("dgram"); | |
| const buffer = require("buffer"); | |
| const client = udp.createSocket("udp4"); | |
| const data = Buffer.from("start;\n"); | |
| client.send(data, 5005, "localhost", err => { | |
| if (err) { | |
| console.error(erro); | |
| } | |
| client.close(); | |
| }); | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://stackoverflow.com/questions/24097175/pure-data-on-mac-os-x-how-to-send-messages/24886508#24886508 | |
| # https://stackoverflow.com/questions/61285324/how-to-send-messages-from-pure-data-to-python | |
| # https://stackoverflow.com/questions/36563485/communicating-with-pure-data-in-c/36594153#36594153 | |
| import socket | |
| from time import sleep | |
| IP = "127.0.0.1" | |
| PORT = 5005 | |
| addr = IP, PORT | |
| EOL = ";\n" | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| # or socket.SOCK_STREAM for TCP | |
| # which requires PD to use 0 instead of 1 for netreceive | |
| msg = "start" | |
| sock.sendto(bytes(msg + EOL, "utf-8"), addr) | |
| sleep(5) | |
| msg = "stop" | |
| sock.sendto(bytes(msg + EOL, "utf-8"), addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment