Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-23 Thread Lorenzo Sutton

On 22/01/13 17:06, Charles Goyard wrote:

Hi,

Lorenzo Sutton wrote:

In python use sockets... in Pd use [netreceive] - I'm sure there's
loads of good examples out there and I'm working on some pygtk for a
project (but it's still very very early). Menwhile this is a very
minimal python - Pd example

it seems your example is missing the newline (;\n). iirc I've had a few
pd lockups when sending lots of messages from Processing without the
newline.
Good to know, and easy to add to the script. And of course you wouldn't 
really be hard-coding stuff like that.

Just for curiosity, how many is 'lots'?.

Lorenzo.


Cheers,
Charles

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-23 Thread IOhannes m zmoelnig
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2013-01-23 10:22, Lorenzo Sutton wrote:
 it seems your example is missing the newline (;\n). iirc I've had
 a few pd lockups when sending lots of messages from Processing
 without the newline.
 Good to know, and easy to add to the script. And of course you
 wouldn't really be hard-coding stuff like that. Just for curiosity,
 how many is 'lots'?.

[netsend] will only emit the message once it receives the terminator.
so it has to buffer all the data, till it encounters the terminator.
and since the term never comes, it will eventually get out of memory.
(and long before that it will start to choke, but *when* is really
depending on your system)

fgam,sdr
IOhannes
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlD/rTwACgkQkX2Xpv6ydvQt0wCggdsNEElUUCMcjgkZf9Tab5U/
JwoAoLn4D8y70iCf62vdwSk4Brj+eBKL
=5NKT
-END PGP SIGNATURE-

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-23 Thread Charles Goyard
Lorenzo Sutton wrote:
 Just for curiosity, how many is 'lots'?.

lots is a bit more than many I think :).

Seriously I don't know, but I was basically hooking a slider in
processing/controlP5 (for setting a crossfade length) to a netreceive in
pd. I could lock (or crash, don't remember) pd in a few slider moves, so
it's not that much of lots (much being less than many ?).

Cheers,
Charles

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-23 Thread Lorenzo Sutton


On 23/01/13 10:28, IOhannes m zmoelnig wrote:

On 2013-01-23 10:22, Lorenzo Sutton wrote:

it seems your example is missing the newline (;\n). iirc I've had
a few pd lockups when sending lots of messages from Processing
without the newline.

Good to know, and easy to add to the script. And of course you
wouldn't really be hard-coding stuff like that. Just for curiosity,
how many is 'lots'?.
Actually... I'm not sure the \n is really so relevant for *sending* to 
Pd, as if I understand correctly the ; is...

[netsend] will only emit the message once it receives the terminator.
so it has to buffer all the data, till it encounters the terminator.
and since the term never comes, it will eventually get out of memory.
(and long before that it will start to choke, but *when* is really
depending on your system)


Ok.. but in the example there is no [netsend]... there is [netreceive] 
and Python is doing the sending through sockets.


The attached seem to work fine sending the 1 messages (ready for a 
[tabwrite]) down until 0.08s (80 ms) interval, even with dsp turned on.
As soon as the INTERVAL goes below 0.08s (see python script) Pd starts 
to choke badly on my system. Again adding an \n doesn't seem to be 
relevant.


Lorenzo.
#N canvas 639 306 545 359 10;
#X floatatom 386 42 5 0 0 0 - - -;
#X obj 386 62 sel 0;
#X obj 413 86 print CONNECTION(S);
#X msg 386 106 DISCONNECTED;
#X obj 386 125 print --;
#X text 429 41 # of connections;
#X text 44 256 See http://en.wikipedia.org/wiki/FUDI for info about
the message format as well as the [netreceive] help;
#X obj 39 4 netreceive 54321;
#X obj 380 210 table array1 1;
#X msg 69 152 stop;
#X obj 47 220 dac~;
#X msg 209 195 \; pd dsp \$1;
#X obj 210 160 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X obj 47 188 tabplay~ array1;
#X msg 49 129 bang;
#X obj 40 66 print CLIENT;
#X obj 284 99 timer;
#X floatatom 284 130 10 0 0 0 - - -;
#X obj 40 27 route python begin end;
#X obj 169 83 tabwrite array1;
#X msg 284 74 bang;
#X msg 327 74 bang;
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 1 1 2 0;
#X connect 3 0 4 0;
#X connect 7 0 18 0;
#X connect 7 1 0 0;
#X connect 9 0 13 0;
#X connect 12 0 11 0;
#X connect 13 0 10 0;
#X connect 13 0 10 1;
#X connect 13 1 14 0;
#X connect 14 0 13 0;
#X connect 16 0 17 0;
#X connect 18 0 15 0;
#X connect 18 1 20 0;
#X connect 18 2 21 0;
#X connect 18 3 19 0;
#X connect 20 0 16 0;
#X connect 21 0 16 1;
#!/usr/bin/env python

Simple example of sending a counter via TCP to Pure Data on localhost. In PD the
[netreceive] object must use the same port specified by TCP_PORT. Python sockets
part based on Python tcp documentation.

import socket
import time
import sys
import random

# TCP stuff
TCP_IP = '127.0.0.1'
TCP_PORT = 54321
BUFFER_SIZE = 1024
INTERVAL_STEP = 0.001
INTERVAL_MAX = 0.12
INTERVAL_MIN = 0.01
CHOKE_POINT = 0.08
INTERVAL = INTERVAL_MAX # secondsA

# Try to open the connection to PD
print (Opening connection on port %d) % (TCP_PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print (Connencting...)
try:
s.connect((TCP_IP, TCP_PORT))
print Connected. Press CTRL + C to exit.
s.send(python Hello from the python client)
except socket.error as err:
# Exit on error
print Could not connect. Aborting.\nError: %s % (err)
sys.exit(1)

while True:
try:
# We send a 'begin' and 'end' which we route in Pd
print sending...
s.send(begin;)
for x in range(0,1):
# Format messages ready for [tabwrite]: [value index(
s.send( (%f %d;) % (random.random(), x))
time.sleep (INTERVAL)
INTERVAL = INTERVAL - INTERVAL_STEP
print(Interval is now %f % (INTERVAL))
s.send(end;)
if INTERVAL  CHOKE_POINT:
print('Pd is probably @ \033[91mCHOKING\033[0m  now ...')
else:
print('Pd is porbaly ok and !! \033[92mRESPONSIVE\033[0m ! now...')
if (INTERVAL  INTERVAL_MIN) or (INTERVAL = INTERVAL_MAX):
INTERVAL_STEP = INTERVAL_STEP * -1
print '\033[96m Inverting interval step... \033[0m'
s.send(end;)
except KeyboardInterrupt:
# Press CTRL + C to stop.
s.send(python Bye from python;)
time.sleep(0.2)
print Closing connection
s.close()
break
try:
s.close()
except:
pass

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-23 Thread IOhannes m zmoelnig
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2013-01-23 12:45, Lorenzo Sutton wrote:
 
 On 23/01/13 10:28, IOhannes m zmoelnig wrote:
 On 2013-01-23 10:22, Lorenzo Sutton wrote:
 it seems your example is missing the newline (;\n). iirc I've
 had a few pd lockups when sending lots of messages from
 Processing without the newline.
 Good to know, and easy to add to the script. And of course you 
 wouldn't really be hard-coding stuff like that. Just for
 curiosity, how many is 'lots'?.
 Actually... I'm not sure the \n is really so relevant for
 *sending* to Pd, as if I understand correctly the ; is...
 [netsend] will only emit the message once it receives the
 terminator. so it has to buffer all the data, till it encounters
 the terminator. and since the term never comes, it will
 eventually get out of memory. (and long before that it will start
 to choke, but *when* is really depending on your system)
 
 Ok.. but in the example there is no [netsend]... there is
 [netreceive] and Python is doing the sending through sockets.

that was a typo on my side, i meant to write [netreceive].

([netsend]  doesn't need to wait for a terminating semicolon/newline,
since it gets pre-parsed Pd-messages any how; only [netreceive] has to
translate byte-streams into Pd-messages, and it does so by splitting
the streams at ;\n)

fgamsdr
IOhannes
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlD/zoAACgkQkX2Xpv6ydvRuyACfQOwzcISnF9p1KDgYZFOms6Dc
tlAAn0VziNfZBSJvNztjBWFuCvhVTUNf
=DoSy
-END PGP SIGNATURE-

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-23 Thread Lorenzo Sutton

On 23/01/13 12:50, IOhannes m zmoelnig wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2013-01-23 12:45, Lorenzo Sutton wrote:

On 23/01/13 10:28, IOhannes m zmoelnig wrote:

On 2013-01-23 10:22, Lorenzo Sutton wrote:

it seems your example is missing the newline (;\n). iirc I've
had a few pd lockups when sending lots of messages from
Processing without the newline.

Good to know, and easy to add to the script. And of course you
wouldn't really be hard-coding stuff like that. Just for
curiosity, how many is 'lots'?.

Actually... I'm not sure the \n is really so relevant for
*sending* to Pd, as if I understand correctly the ; is...

[netsend] will only emit the message once it receives the
terminator. so it has to buffer all the data, till it encounters
the terminator. and since the term never comes, it will
eventually get out of memory. (and long before that it will start
to choke, but *when* is really depending on your system)

Ok.. but in the example there is no [netsend]... there is
[netreceive] and Python is doing the sending through sockets.

that was a typo on my side, i meant to write [netreceive].

([netsend]  doesn't need to wait for a terminating semicolon/newline,
since it gets pre-parsed Pd-messages any how; only [netreceive] has to
translate byte-streams into Pd-messages, and it does so by splitting
the streams at ;\n)


Ok... but sending this from python works as expected (i.e. each message 
is separated at the ';'):


s.send(hello 1;world 2;foo 3;bas\n4;bat 5;)

Lorenzo.




fgamsdr
IOhannes
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlD/zoAACgkQkX2Xpv6ydvRuyACfQOwzcISnF9p1KDgYZFOms6Dc
tlAAn0VziNfZBSJvNztjBWFuCvhVTUNf
=DoSy
-END PGP SIGNATURE-

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-22 Thread Charles Goyard
Hi,

Lorenzo Sutton wrote:
 In python use sockets... in Pd use [netreceive] - I'm sure there's
 loads of good examples out there and I'm working on some pygtk for a
 project (but it's still very very early). Menwhile this is a very
 minimal python - Pd example

it seems your example is missing the newline (;\n). iirc I've had a few
pd lockups when sending lots of messages from Processing without the
newline.

Cheers,
Charles

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Olivier Baudu

Hi,

I've succeed in make Pd and Python communicate by OSC (no sure it's the 
best way) with mrpeach library.
I'll try to find the simple version of my patch/script but if not, you 
know now it's possible.


To be continued...

Cheers

01ivier

Le 21.01.2013 15:42, Pierre Massat a écrit :

Dear List,

I've been working a lot with Python and Pd lately, and i would like
to have better means of communication between the two.
I know next to nothing about inter-process communication, I know
nothing about FUDI (except that it's the protocol used by pdsend and
pdreceive), and I have no idea what pdreceive was originally designed
for. I've only used the subprocess (formerly popen) module in python,
but i don't know how to use it with streams of messages coming from
the standard output of a running process.
 I don't want to use libpd for now because i only need to send and
receive simple messages between Python and Pd.

Can someone please provide a few hints ?

Cheers!

Pierre.

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -
http://lists.puredata.info/listinfo/pd-list


--
On ne peut pas vivre dans un monde où l'on croit que l'élégance 
exquise du plumage de la pintade est inutile. Ceci est tout à fait à 
part. J'ai eu envie de le dire, je l'ai dit. Jean Giono, Un roi sans 
divertissement.


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Hans-Christoph Steiner

FUDI is not just netsend/netreceive, its all Pd messages, including what
pd-gui sends to pd.  Its basically space-separated data terminated with a
semi-colon and a newline i.e. ;\n

.hc

On 01/21/2013 09:42 AM, Pierre Massat wrote:
 Dear List,
 
 I've been working a lot with Python and Pd lately, and i would like to have
 better means of communication between the two.
 I know next to nothing about inter-process communication, I know nothing
 about FUDI (except that it's the protocol used by pdsend and pdreceive),
 and I have no idea what pdreceive was originally designed for. I've only
 used the subprocess (formerly popen) module in python, but i don't know how
 to use it with streams of messages coming from the standard output of a
 running process.
 I don't want to use libpd for now because i only need to send and receive
 simple messages between Python and Pd.
 
 Can someone please provide a few hints ?
 
 Cheers!
 
 Pierre.
 
 
 
 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - 
 http://lists.puredata.info/listinfo/pd-list
 

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Olivier Baudu

Well,

You can look at the attached archive.
I repeat that I'm not sure it a good way...
But it's a working way... :-p

Cheers

01ivier

Le 21.01.2013 15:42, Pierre Massat a écrit :

Dear List,

I've been working a lot with Python and Pd lately, and i would like
to have better means of communication between the two.
I know next to nothing about inter-process communication, I know
nothing about FUDI (except that it's the protocol used by pdsend and
pdreceive), and I have no idea what pdreceive was originally designed
for. I've only used the subprocess (formerly popen) module in python,
but i don't know how to use it with streams of messages coming from
the standard output of a running process.
 I don't want to use libpd for now because i only need to send and
receive simple messages between Python and Pd.

Can someone please provide a few hints ?

Cheers!

Pierre.

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -
http://lists.puredata.info/listinfo/pd-list


--
On ne peut pas vivre dans un monde où l'on croit que l'élégance 
exquise du plumage de la pintade est inutile. Ceci est tout à fait à 
part. J'ai eu envie de le dire, je l'ai dit. Jean Giono, Un roi sans 
divertissement.

Py2Pd2Py.tar.gz
Description: GNU Zip compressed data
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Jonathan Wilkes
- Original Message -
 From: Hans-Christoph Steiner h...@at.or.at
 To: pd-list@iem.at
 Cc: 
 Sent: Monday, January 21, 2013 11:17 AM
 Subject: Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !
 
 
 FUDI is not just netsend/netreceive, its all Pd messages, including what
 pd-gui sends to pd.  Its basically space-separated data terminated with a
 semi-colon and a newline i.e. ;\n

Someone should add the description of the FUDI protocol to
the man pages for pdsend/pdreceive, since its not a standard
protocol and is slightly different from the messages people
are used to sending from within the gui (i.e., without a terminating
semicolon).
 
-Jonathan

 
 .hc
 
 On 01/21/2013 09:42 AM, Pierre Massat wrote:
 Dear List,
 
 I've been working a lot with Python and Pd lately, and i would like to 
 have
 better means of communication between the two.
 I know next to nothing about inter-process communication, I know nothing
 about FUDI (except that it's the protocol used by pdsend and 
 pdreceive),
 and I have no idea what pdreceive was originally designed for. I've 
 only
 used the subprocess (formerly popen) module in python, but i don't know 
 how
 to use it with streams of messages coming from the standard output of a
 running process.
 I don't want to use libpd for now because i only need to send and 
 receive
 simple messages between Python and Pd.
 
 Can someone please provide a few hints ?
 
 Cheers!
 
 Pierre.
 
 
 
 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - 
 http://lists.puredata.info/listinfo/pd-list
 
 
 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - 
 http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Pierre Massat
Yes, I only want to launch Pd from Python and the status of some objects in
return, so nothing too critical.

I'll try the OSC example.

Cheers,

Pierre.

2013/1/21 padawa...@obiwannabe.co.uk padawa...@obiwannabe.co.uk

 **

  With popen you'll quickly discover the joys of unix buffers, queueing
  and all the reasons libPd was invented :)

  Probably a frustrating journey if you want to do any kind of time
  critical musical control this way. If transferring bulk data, or
 launching
  Pd instances for control by other sources is your aim, then
  it will be okay.


 On 21 January 2013 at 14:42 Pierre Massat pimas...@gmail.com wrote:

 Dear List,

 I've been working a lot with Python and Pd lately, and i would like to
 have better means of communication between the two.
 I know next to nothing about inter-process communication, I know nothing
 about FUDI (except that it's the protocol used by pdsend and pdreceive),
 and I have no idea what pdreceive was originally designed for. I've only
 used the subprocess (formerly popen) module in python, but i don't know how
 to use it with streams of messages coming from the standard output of a
 running process.
 I don't want to use libpd for now because i only need to send and receive
 simple messages between Python and Pd.

 Can someone please provide a few hints ?

 Cheers!

 Pierre.
 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list




___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Pierre Massat
Assuming that i can find a description of this protocol, how would I use it
to communicate between Pd and Python ? I guess this more a question to ask
in a Python forum, but still, i'd love to have at least some hints...

Cheers,

Pierre.

2013/1/21 Jonathan Wilkes jancs...@yahoo.com

 - Original Message -
  From: Hans-Christoph Steiner h...@at.or.at
  To: pd-list@iem.at
  Cc:
  Sent: Monday, January 21, 2013 11:17 AM
  Subject: Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !
 
 
  FUDI is not just netsend/netreceive, its all Pd messages, including what
  pd-gui sends to pd.  Its basically space-separated data terminated with a
  semi-colon and a newline i.e. ;\n

 Someone should add the description of the FUDI protocol to
 the man pages for pdsend/pdreceive, since its not a standard
 protocol and is slightly different from the messages people
 are used to sending from within the gui (i.e., without a terminating
 semicolon).

 -Jonathan

 
  .hc
 
  On 01/21/2013 09:42 AM, Pierre Massat wrote:
  Dear List,
 
  I've been working a lot with Python and Pd lately, and i would like to
  have
  better means of communication between the two.
  I know next to nothing about inter-process communication, I know nothing
  about FUDI (except that it's the protocol used by pdsend and
  pdreceive),
  and I have no idea what pdreceive was originally designed for. I've
  only
  used the subprocess (formerly popen) module in python, but i don't know
  how
  to use it with streams of messages coming from the standard output of a
  running process.
  I don't want to use libpd for now because i only need to send and
  receive
  simple messages between Python and Pd.
 
  Can someone please provide a few hints ?
 
  Cheers!
 
  Pierre.
 
 
 
  ___
  Pd-list@iem.at mailing list
  UNSUBSCRIBE and account-management -
  http://lists.puredata.info/listinfo/pd-list
 
 
  ___
  Pd-list@iem.at mailing list
  UNSUBSCRIBE and account-management -
  http://lists.puredata.info/listinfo/pd-list
 


 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Jonathan Wilkes
Try:
man pdsend
man pdreceive
 
There's a thread where I think matju and Tim Blechmann gives
examples of how to use them on the command line.
 
-Jonathan


From: Pierre Massat pimas...@gmail.com
To: Jonathan Wilkes jancs...@yahoo.com 
Cc: Hans-Christoph Steiner h...@at.or.at; pd-list@iem.at pd-list@iem.at 
Sent: Monday, January 21, 2013 12:52 PM
Subject: Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !


Assuming that i can find a description of this protocol, how would I use it to 
communicate between Pd and Python ? I guess this more a question to ask in a 
Python forum, but still, i'd love to have at least some hints...

Cheers,

Pierre.


2013/1/21 Jonathan Wilkes jancs...@yahoo.com

- Original Message -
 From: Hans-Christoph Steiner h...@at.or.at
 To: pd-list@iem.at
 Cc:
 Sent: Monday, January 21, 2013 11:17 AM
 Subject: Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !


 FUDI is not just netsend/netreceive, its all Pd messages, including what
 pd-gui sends to pd.  Its basically space-separated data terminated with a
 semi-colon and a newline i.e. ;\n

Someone should add the description of the FUDI protocol to
the man pages for pdsend/pdreceive, since its not a standard
protocol and is slightly different from the messages people
are used to sending from within the gui (i.e., without a terminating
semicolon).
 
-Jonathan



 .hc

 On 01/21/2013 09:42 AM, Pierre Massat wrote:
 Dear List,

 I've been working a lot with Python and Pd lately, and i would like to
 have
 better means of communication between the two.
 I know next to nothing about inter-process communication, I know nothing
 about FUDI (except that it's the protocol used by pdsend and
 pdreceive),
 and I have no idea what pdreceive was originally designed for. I've
 only
 used the subprocess (formerly popen) module in python, but i don't know
 how
 to use it with streams of messages coming from the standard output of a
 running process.
 I don't want to use libpd for now because i only need to send and
 receive
 simple messages between Python and Pd.

 Can someone please provide a few hints ?

 Cheers!

 Pierre.



 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list


 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list





___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !

2013-01-21 Thread Lorenzo Sutton

On 21/01/13 18:52, Pierre Massat wrote:

Assuming that i can find a description of this protocol, how would I use
it to communicate between Pd and Python ? I guess this more a question
to ask in a Python forum, but still, i'd love to have at least some hints...


In python use sockets... in Pd use [netreceive] - I'm sure there's loads 
of good examples out there and I'm working on some pygtk for a project 
(but it's still very very early). Menwhile this is a very minimal python 
- Pd example


Lorenzo.





Cheers,

Pierre.

2013/1/21 Jonathan Wilkes jancs...@yahoo.com mailto:jancs...@yahoo.com

- Original Message -
  From: Hans-Christoph Steiner h...@at.or.at mailto:h...@at.or.at
  To: pd-list@iem.at mailto:pd-list@iem.at
  Cc:
  Sent: Monday, January 21, 2013 11:17 AM
  Subject: Re: [PD] Pd -- Python, IPC, FUDI, pdreceive, et cetera !
 
 
  FUDI is not just netsend/netreceive, its all Pd messages,
including what
  pd-gui sends to pd.  Its basically space-separated data
terminated with a
  semi-colon and a newline i.e. ;\n

Someone should add the description of the FUDI protocol to
the man pages for pdsend/pdreceive, since its not a standard
protocol and is slightly different from the messages people
are used to sending from within the gui (i.e., without a terminating
semicolon).

-Jonathan

 
  .hc
 
  On 01/21/2013 09:42 AM, Pierre Massat wrote:
  Dear List,
 
  I've been working a lot with Python and Pd lately, and i would
like to
  have
  better means of communication between the two.
  I know next to nothing about inter-process communication, I know
nothing
  about FUDI (except that it's the protocol used by pdsend and
  pdreceive),
  and I have no idea what pdreceive was originally designed for. I've
  only
  used the subprocess (formerly popen) module in python, but i
don't know
  how
  to use it with streams of messages coming from the standard
output of a
  running process.
  I don't want to use libpd for now because i only need to send and
  receive
  simple messages between Python and Pd.
 
  Can someone please provide a few hints ?
 
  Cheers!
 
  Pierre.
 
 
 
  ___
  Pd-list@iem.at mailto:Pd-list@iem.at mailing list
  UNSUBSCRIBE and account-management -
  http://lists.puredata.info/listinfo/pd-list
 
 
  ___
  Pd-list@iem.at mailto:Pd-list@iem.at mailing list
  UNSUBSCRIBE and account-management -
  http://lists.puredata.info/listinfo/pd-list
 


___
Pd-list@iem.at mailto:Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -
http://lists.puredata.info/listinfo/pd-list




___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list



#N canvas 635 330 439 281 10;
#X floatatom 215 70 5 0 0 0 - - -;
#X obj 215 90 sel 0;
#X obj 242 114 print CONNECTION(S);
#X msg 215 134 DISCONNECTED;
#X obj 215 153 print --;
#X floatatom 54 94 5 0 0 0 - - -;
#X obj 40 147 print raw_tcp;
#X text 258 69 # of connections;
#X obj 54 70 route count foo;
#X floatatom 97 94 5 0 0 0 - - -;
#X text 38 183 Print the incoming tcp in the message window;
#X text 40 201 See http://en.wikipedia.org/wiki/FUDI for info about
the message format as well as the [netreceive] help;
#X obj 40 40 netreceive 54321;
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 1 1 2 0;
#X connect 3 0 4 0;
#X connect 8 0 5 0;
#X connect 8 1 9 0;
#X connect 12 0 6 0;
#X connect 12 0 8 0;
#X connect 12 1 0 0;
#!/usr/bin/env python

Simple example of sending a counter via TCP to Pure Data on localhost. In PD the
[netreceive] object must use the same port specified by TCP_PORT. Python sockets
part based on Python tcp documentation.

import socket
import time
import sys

# TCP stuff
TCP_IP = '127.0.0.1'
TCP_PORT = 54321
BUFFER_SIZE = 1024
# A counter
counter = 0

# Try to open the connection to PD
print (Opening connection on port %d) % (TCP_PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print (Connencting...)
try:
s.connect((TCP_IP, TCP_PORT))
print Connected. Press CTRL + C to exit.
except socket.error as err:
# Exit on error
print Could not connect. Aborting.\nError: %s % (err)
sys.exit(1)

# A dictionary for possibly multiple messages
messages = {}
s.send (Hello from Python!;)

while True:
try:
messages['count'] = counter
messages['foo'] = counter * 2
for k in messages.keys():
# Here the semicolon (;) is important!! See http://en.wikipedia.org/wiki/FUDI
message_string = (%s %d;) % (k, messages[k])
print Sending %s % (message_string