Hello everyone -
So the larger story about my efforts today is that I need to do some basic string processing that seems very difficult to do in PD, but easy in Python. I'm trying to decide whether to use the pyext external (which I finally got to compile last night), or to pass the text via UDP to a separate python program for processing, using netsend and netreceive. My questions about using [route] after netreceive come from my implementation of the socket strategy. I am still trying to understand how to [route] the output of netreceive and look forward to hearing from anyone who has an idea about why it isn't working. In parallel, I am also exploring pyext, which at first glance seems like a more straightforward way to go.
You might wonder why I'm bothering with sockets at all if I got pyext to compile - the answer is that I am having a hard time finding examples of doing some basic things with pyext. What I'd like to do is to pass a message to my pyext object, such as:
[/home/myusername/wavs(
..and in the python code, look for wave files in that directory then output each of them in turn, like:
"/home/myusername/wavs/a.wav" "/home/myusername/wavs/b.wav" "/home/myusername/wavs/c.wav" (these will be sent into soundfiler, so they should also be messages)
So my questions include:
tried def _anything_1, def symbol_1, def message_1, and none of them work. I keep getting "pyext: message unhandled" warnings..
I mentioned, I think it needs to be in [message( form..
thanks again! -David M.
Hallo, David Merrill hat gesagt: // David Merrill wrote:
You might wonder why I'm bothering with sockets at all if I got pyext to compile - the answer is that I am having a hard time finding examples of doing some basic things with pyext.
There are some examples in the pyext docs, but I'm attaching an IMO very useful "catch all" pyexternal. It basically is a wrapper around (m)any python modules and makes their methods and attributes directly useable inside Pd. It's simple but immensely powerful.
You soundfile problem could be solved with the "listdir" example on the left side and a [list-drip] connected to the pyext-outlet.
Frank Barknecht _ ______footils.org_ __goto10.org__
Thanks very much Frank. I'll give this one a try, as well as stripping my bug down to a simple patch for review. much appreciated! -David
Frank Barknecht wrote:
Hallo, David Merrill hat gesagt: // David Merrill wrote:
You might wonder why I'm bothering with sockets at all if I got pyext to compile - the answer is that I am having a hard time finding examples of doing some basic things with pyext.
There are some examples in the pyext docs, but I'm attaching an IMO very useful "catch all" pyexternal. It basically is a wrapper around (m)any python modules and makes their methods and attributes directly useable inside Pd. It's simple but immensely powerful.
You soundfile problem could be solved with the "listdir" example on the left side and a [list-drip] connected to the pyext-outlet.
Ciao
import pyext import string
class pymod(pyext._class):
_inlets = 1 _outlets = 1 # constructor def __init__(self, mod): mod = str(mod) self.mod = __import__(mod, globals(), locals(), []) self.mod_string = mod def _anything_1(self, func, *args): """inlet to accept everything""" # TODO this needs proper error checking ... or maybe not. func = str(func) args = [str(x) for x in args] # HACK: replace the string "[BS]" with a backslash, that cannot be input in Pd: args = [string.replace(x, "[BS]",'\\') for x in args] if hasattr(self.mod, func): result = None if callable(getattr(self.mod, func)): result = getattr(self.mod, func)(*args) else: result = getattr(self.mod, func) self._outlet(1, result) else: print "No such attribute: %s.%s" % (self.mod_string, func)
#N canvas 103 11 985 619 10; #X obj 41 363 pyext pycall pymod os; #X msg 41 331 reload; #X msg 281 227 listdir /tmp; #X msg 279 458 bogus; #X msg 283 270 listdir .; #X msg 280 324 __doc__; #X msg 280 346 name; #X msg 280 367 curdir; #X msg 281 387 pardir; #X msg 281 407 path; #X msg 279 183 mkdir /tmp/python-test; #X msg 280 205 rmdir /tmp/python-test; #X msg 282 248 getcwd; #X msg 278 160 getloadavg; #X msg 276 138 getpid; #X msg 275 116 getenv HOME; #X msg 276 92 system gvim; #X obj 520 175 pyext pycall pymod string; #X msg 721 102 letters; #X obj 524 450 print REGEX; #X obj 520 200 print STRING; #X obj 41 392 print OS; #X msg 721 81 replace 12345 3 -THREE-; #X msg 524 400 reload; #X obj 524 425 pyext pycall pymod sre; #X text 494 336 "[BS]" internally gets replaced by a backslash. Yes , I know it's a hack.; #X msg 721 123 count iiiiiiiiiiiieeeehhh i; #X msg 722 169 lower ABC; #X msg 722 146 split X---Y---Z ---; #X msg 673 388 sub [BS]d _NUM_ 12a3b4c5; #X connect 0 0 21 0; #X connect 1 0 0 0; #X connect 2 0 0 1; #X connect 3 0 0 1; #X connect 4 0 0 1; #X connect 5 0 0 1; #X connect 6 0 0 1; #X connect 7 0 0 1; #X connect 8 0 0 1; #X connect 9 0 0 1; #X connect 10 0 0 1; #X connect 11 0 0 1; #X connect 12 0 0 1; #X connect 13 0 0 1; #X connect 14 0 0 1; #X connect 15 0 0 1; #X connect 16 0 0 1; #X connect 17 0 20 0; #X connect 18 0 17 1; #X connect 22 0 17 1; #X connect 23 0 24 0; #X connect 24 0 19 0; #X connect 26 0 17 1; #X connect 27 0 17 1; #X connect 28 0 17 1; #X connect 29 0 24 1;
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list