aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/py/scripts')
-rw-r--r--externals/grill/py/scripts/buffer.py60
-rw-r--r--externals/grill/py/scripts/pak.py14
-rw-r--r--externals/grill/py/scripts/script.py48
-rw-r--r--externals/grill/py/scripts/sendrecv.py180
-rw-r--r--externals/grill/py/scripts/sig.py100
-rw-r--r--externals/grill/py/scripts/simple.py214
-rw-r--r--externals/grill/py/scripts/tcltk.py81
-rw-r--r--externals/grill/py/scripts/threads.py50
8 files changed, 0 insertions, 747 deletions
diff --git a/externals/grill/py/scripts/buffer.py b/externals/grill/py/scripts/buffer.py
deleted file mode 100644
index 46c47991..00000000
--- a/externals/grill/py/scripts/buffer.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""This is an example script for the py/pyext object's buffer support.
-
-PD/Max buffers can be mapped to Python arrays.
-Currently, there are three implementations:
-Numeric, numarray and Numeric3 (for all of them see http://numeric.scipy.org)
-"""
-
-import sys
-
-try:
- import pyext
-except:
- print "ERROR: This script must be loaded by the PD/Max py/pyext external"
-
-try:
- from numarray import *
-except:
- print "Failed importing numarray module:",sys.exc_value
-
-def mul(*args):
- # create buffer objects
- # as long as these variables live the underlying buffers are locked
- c = pyext.Buffer(args[0])
- a = pyext.Buffer(args[1])
- b = pyext.Buffer(args[2])
-
- # slicing causes Python arrays (mapped to buffers) to be created
- # note the c[:] - to assign contents you must assign to a slice of the buffer
- c[:] = a[:]*b[:]
-
-def add(*args):
- c = pyext.Buffer(args[0])
- a = pyext.Buffer(args[1])
- b = pyext.Buffer(args[2])
-
- # this is also possible, but is probably slower
- # the + converts a into a Python array, the argument b is taken as a sequence
- # depending on the implementation this may be as fast
- # as above or not
- c[:] = a+b
-
-def fadein(target):
- a = pyext.Buffer(target)
- # in place operations are ok
- a *= arange(len(a),type=Float32)/len(a)
-
-def neg(target):
- a = pyext.Buffer(target)
- # in place transformation (see Python array ufuncs)
- negative(a[:],a[:])
- # must mark buffer content as dirty to update graph
- # (no explicit assignment occurred)
- a.dirty()
diff --git a/externals/grill/py/scripts/pak.py b/externals/grill/py/scripts/pak.py
deleted file mode 100644
index 6394570d..00000000
--- a/externals/grill/py/scripts/pak.py
+++ /dev/null
@@ -1,14 +0,0 @@
-import pyext
-
-class pak(pyext._class):
- def __init__(self,n):
- # n should be type-checked
- self._inlets = n
- self._outlets = 1
- # initialize list
- self.lst = [0 for x in range(n)]
-
- def _anything_(self,n,arg):
- # arg should be type-checked!
- self.lst[n-1] = arg
- self._outlet(1,self.lst)
diff --git a/externals/grill/py/scripts/script.py b/externals/grill/py/scripts/script.py
deleted file mode 100644
index ff41730f..00000000
--- a/externals/grill/py/scripts/script.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""Several functions to show the py script functionality"""
-
-import sys
-
-print "Script initialized"
-
-try:
- print "Script arguments: ",sys.argv
-except:
- print
-
-def numargs(*args): # variable argument list
- """Return the number of arguments"""
- return len(args)
-
-def strlen(arg):
- """Return the string length"""
- # we must convert to string first (it's a symbol type most likely)
- return len(str(arg))
-
-
-def strcat(*args):
- """Concatenate several symbols"""
- return reduce(lambda a,b: a+str(b), args,"")
-
-def addall(*args): # variable argument list
- """Add a couple of numbers"""
- return reduce(lambda a,b: a+b, args,0)
-
-
-def ret1():
- return 1,2,3,4
-
-
-def ret2():
- return "sd","lk","ki"
-
-
-def ret3():
- return ["sd","lk","ki"]
-
diff --git a/externals/grill/py/scripts/sendrecv.py b/externals/grill/py/scripts/sendrecv.py
deleted file mode 100644
index 9d873bae..00000000
--- a/externals/grill/py/scripts/sendrecv.py
+++ /dev/null
@@ -1,180 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""This is an example script for the py/pyext object's send/receive functionality.
-
-You can:
-- bind
-
-
-There are several classes exposing py/pyext features:
-- ex1: A class receiving messages and sending them out again
-- ex2: A class receiving messages and putting them out to an outlet
-- ex3: Do some PD scripting
-
-"""
-
-try:
- import pyext
-except:
- print "ERROR: This script must be loaded by the PD/Max pyext external"
-
-
-from time import sleep
-
-#################################################################
-
-def recv_gl(arg):
- """This is a global receive function, it has no access to class members."""
- print "GLOBAL",arg
-
-class ex1(pyext._class):
- """Example of a class which receives and sends messages
-
- It has two creation arguments: a receiver and a sender name.
- There are no inlets and outlets.
- Python functions (one global function, one class method) are bound to PD's or Max/MSP's receive symbols.
- The class method sends the received messages out again.
- """
-
-
- # no inlets and outlets
- _inlets=1
- _outlets=0
-
- recvname=""
- sendname=""
-
- def recv(self,*arg):
- """This is a class-local receive function, which has access to class members."""
-
- # print some stuff
- print "CLASS",self.recvname,arg
-
- # send data to specified send address
- self._send(self.sendname,arg)
-
-
- def __init__(self,*args):
- """Class constructor"""
-
- # store sender/receiver names
- if len(args) >= 1: self.recvname = args[0]
- if len(args) >= 2: self.sendname = args[1]
-
- self.bind_1()
-
- def bind_1(self):
- # bind functions to receiver names
- # both are called upon message
- self._bind(self.recvname,self.recv)
- self._bind(self.recvname,recv_gl)
-
- def unbind_1(self):
- self._unbind(self.recvname,self.recv)
- self._unbind(self.recvname,recv_gl)
-
- def __del__(self):
- """Class destructor"""
-
- # unbinding is automatically done at destruction
- pass
-
-
-#################################################################
-
-class ex2(pyext._class):
- """Example of a class which receives a message and forwards it to an outlet
-
- It has one creation argument: the receiver name.
- """
-
-
- # define inlets and outlets
- _inlets=0
- _outlets=1
-
- recvname=""
-
- def recv(self,*arg):
- """This is a class-local receive function"""
-
- # send received data to outlet
- self._outlet(1,arg)
-
-
- def __init__(self,rname):
- """Class constructor"""
-
- # store receiver names
- self.recvname = rname
-
- # bind function to receiver name
- self._bind(self.recvname,self.recv)
-
-
-#################################################################
-
-from math import pi
-from cmath import exp
-from random import random,randint
-
-class ex3(pyext._class):
- """Example of a class which does some object manipulation by scripting"""
-
-
- # define inlets and outlets
- _inlets=1
- _outlets=0
-
- def __init__(self):
- """Class constructor"""
-
- # called scripting method should run on its own thread
- if self._isthreaded:
- print "Threading is on"
- self._detach(1)
-
- def bang_1(self):
- """Do some scripting - PD only!"""
-
- num = 12 # number of objects
- ori = complex(150,180) # origin
- rad = 100 # radius
- l = range(num) # initialize list
-
- # make flower
- self._tocanvas("obj",ori.real,ori.imag,"bng",20,250,50,0,"empty","yeah","empty",0,-6,64,8,-24198,-1,-1)
- for i in xrange(num):
- l[i] = ori+rad*exp(complex(0,i*2*pi/num))
- self._tocanvas("obj",l[i].real,l[i].imag,"bng",15,250,50,0,"empty","yeah"+str(i),"empty",0,-6,64,8,0,-1,-1)
- self._tocanvas("connect",6,0,7+i,0)
-
- # blink
- for i in range(10):
- self._send("yeah","bang")
- sleep(1./(i+1))
-
- # move objects around
- for i in xrange(200):
- ix = randint(0,num-1)
- l[ix] = ori+rad*complex(2*random()-1,2*random()-1)
- self._send("yeah"+str(ix),"pos",l[ix].real,l[ix].imag)
- sleep(0.02)
-
- # now delete
- # this is not well-done... from time to time an object remains
- self._tocanvas("editmode",1)
- for i in xrange(num):
- self._tocanvas("mouse",l[i].real,l[i].imag,0,0)
- self._tocanvas("cut")
-
- self._tocanvas("mouse",ori.real+1,ori.imag+1,0,0)
- self._tocanvas("cut")
-
- self._tocanvas("editmode",0)
-
diff --git a/externals/grill/py/scripts/sig.py b/externals/grill/py/scripts/sig.py
deleted file mode 100644
index 09be7b66..00000000
--- a/externals/grill/py/scripts/sig.py
+++ /dev/null
@@ -1,100 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""This is an example script for the py/pyext signal support.
-
-For numarray see http://numeric.scipy.org
-It will probably once be replaced by Numeric(3)
-"""
-
-try:
- import pyext
-except:
- print "ERROR: This script must be loaded by the PD/Max py/pyext external"
-
-try:
- import psyco
- psyco.full()
- print "Using JIT compilation"
-except:
- # don't care
- pass
-
-import sys,math
-
-try:
- import numarray
-except:
- print "Failed importing numarray module:",sys.exc_value
-
-
-class gain(pyext._class):
- """Just a simple gain stage"""
-
- gain = 0
-
- def _signal(self):
- # Multiply input vector by gain and copy to output
- try:
- self._outvec(0)[:] = self._invec(0)*self.gain
- except:
- pass
-
-
-class gain2(pyext._class):
- """More optimized version"""
-
- gain = 0
-
- def _dsp(self):
- if not self._arraysupport():
- print "No DSP support"
- return False
-
- # cache vectors in this scope
- self.invec = self._invec(0)
- self.outvec = self._outvec(0)
- # initialize _signal method here for optimized version
- if self.invec is self.outvec:
- self._signal = self.signal1
- else:
- self._signal = self.signal2
- return True
-
- def signal1(self):
- # Multiply signal vector in place
- self.outvec *= self.gain
-
- def signal2(self):
- # Multiply input vector by gain and copy to output
- self.outvec[:] = self.invec*self.gain
-
-
-class pan(pyext._class):
- """Stereo panning"""
-
- def __init__(self):
- self.float_1(0.5)
-
- def float_1(self,pos):
- """pos ranges from 0 to 1"""
- x = pos*math.pi/2
- self.fl = math.cos(x)
- self.fr = math.sin(x)
-
- def _dsp(self):
- # if _dsp is present it must return True to enable DSP
- return pyext._arraysupport()
-
- def _signal(self):
- # Multiply input vector by gain and copy to output
- iv = self._invec(0)
- # first process right output channel because left one could be
- # identical to input
- # we could also test with 'self._outvec(1)[:] is iv'
- self._outvec(1)[:] = iv*self.fr
- self._outvec(0)[:] = iv*self.fl
diff --git a/externals/grill/py/scripts/simple.py b/externals/grill/py/scripts/simple.py
deleted file mode 100644
index 1aa211c5..00000000
--- a/externals/grill/py/scripts/simple.py
+++ /dev/null
@@ -1,214 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2007 Thomas Grill (gr@grrrr.org)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""This is an example script for the py/pyext object's basic functionality.
-
-pyext Usage:
-- Import pyext
-
-- Inherit your class from pyext._class
-
-- Specfiy the number of inlets and outlets:
- Use the class members (variables) _inlets and _outlets
- If not given they default to 1
- You can also use class methods with the same names to return the respective number
-
-- Constructors/Destructors
- You can specify an __init__ constructor and/or an __del__ destructor.
- The constructor will be called with the object's arguments
-
- e.g. if your PD or MaxMSP object looks like
- [pyext script class arg1 arg2 arg3]
-
- then the __init__(self,*args) function will be called with a tuple argument
- args = (arg1,arg2,arg3)
- With this syntax, you will have to give at least one argument.
- By defining the constructor as __init__(self,*args) you can also initialize
- the class without arguments.
-
-- Methods called by pyext
- The general format is 'tag_inlet(self,arg)' resp. 'tag_inlet(self,*args)':
- tag is the PD or MaxMSP message header.. either bang, float, list etc.
- inlet is the inlet (starting from 1) from which messages are received.
- args is a tuple which corresponds to the content of the message. args can be omitted.
-
- The inlet index can be omitted. The method name then has the format 'tag_(self,inlet,args)'.
- Here, the inlet index is a additional parameter to the method
-
- You can also set up methods which react on any message. These have the special forms
- _anything_inlet(self,*args)
- or
- _anything_(self,inlet,*args)
-
- Please see below for examples.
-
- Any return values are ignored - use _outlet (see below).
-
- Generally, you should avoid method_, method_xx forms for your non-pyext class methods.
- Identifiers (variables and functions) with leading underscores are reserved for pyext.
-
-- Send messages to outlets:
- Use the inherited _outlet method.
- You can either use the form
- self._outlet(outlet,arg1,arg2,arg3,arg4) ... where all args are atoms (no sequence types!)
- or
- self._outlet(outlet,arg) ... where arg is a sequence containing only atoms
-
- Do not use _outlet inside __init__, since the outlets have not been created at that time.
-
-- Use pyext functions and methods:
- See the __doc__ strings of the pyext module and the pyext._class base class.
-
-"""
-
-try:
- import pyext
-except:
- print "ERROR: This script must be loaded by the PD/Max pyext external"
-
-#################################################################
-
-class ex1(pyext._class):
- """Example of a simple class which receives messages and prints to the console"""
-
- # number of inlets and outlets
- _inlets=3
- _outlets=0
-
-
- # methods for first inlet
-
- def bang_1(self):
- print "Bang into first inlet"
-
- def int_1(self,f):
- print "Integer",f,"into first inlet"
-
- def float_1(self,f):
- print "Float",f,"into first inlet"
-
- def list_1(self,*s):
- print "List",s,"into first inlet"
-
-
- # methods for second inlet
-
- def hey_2(self):
- print "Tag 'hey' into second inlet"
-
- def ho_2(self):
- print "Tag 'ho' into second inlet"
-
- def lets_2(self):
- print "Tag 'lets' into second inlet"
-
- def go_2(self):
- print "Tag 'go' into second inlet"
-
- def _anything_2(self,*args):
- print "Some other message into second inlet:",args
-
-
- # methods for third inlet
-
- def onearg_3(self,a):
- print "Tag 'onearg' into third inlet:",a
-
- def twoargs_3(self,*a):
- if len(a) == 2:
- print "Tag 'twoargs' into third inlet:",a[0],a[1]
- else:
- print "Tag 'twoargs': wrong number of arguments"
-
- def threeargs_3(self,*a):
- if len(a) == 3:
- print "Tag 'threeargs' into third inlet",a[0],a[1],a[2]
- else:
- print "Tag 'threeargs': wrong number of arguments"
-
- def varargs_3(self,*args):
- # with *args there can be arguments or not
-
- print "Tag 'varargs' into third inlet",args
-
-
-
-#################################################################
-
-class ex2(pyext._class):
- """Example of a simple class which receives messages and writes to outlets"""
-
- # number of inlets and outlets
- _inlets=3
- _outlets=2
-
- # methods for all inlets
-
- def hello_(self,n):
- print "Tag 'hello' into inlet",n
-
- def _anything_(self,n,*args):
- print "Message into inlet",n,":",args
-
-
- # methods for first inlet
-
- def float_1(self,f):
- self._outlet(2,f)
-
- # methods for second inlet
-
- def float_2(self,f):
- self._outlet(1,f)
-
-
-#################################################################
-
-# helper function - determine whether argument is a numeric type
-def isNumber(value):
- import types
- if type(value) in (types.FloatType, types.IntType, types.LongType):
- return 1
- else:
- return 0
-
-
-class ex3(pyext._class):
- """Example of a simple class doing a typical number addition
-
- It uses a constructor and a class member as temporary storage.
- """
-
- # number of inlets and outlets
- _inlets=2
- _outlets=1
-
- # temporary storage
- tmp=0
-
- # constructor
- def __init__(self,*args):
- if len(args) == 1:
- if isNumber(args[0]):
- self.tmp = args[0]
- else:
- print "ex3: __init__ has superfluous arguments"
-
- # methods
-
- def float_1(self,f):
- self._outlet(1,self.tmp+f)
-
- def float_2(self,f):
- self.tmp = f
-
- # handlers for MaxMSP int type
- def int_1(self,f):
- self.float_1(f)
-
- def int_2(self,f):
- self.float_2(f)
diff --git a/externals/grill/py/scripts/tcltk.py b/externals/grill/py/scripts/tcltk.py
deleted file mode 100644
index 08131995..00000000
--- a/externals/grill/py/scripts/tcltk.py
+++ /dev/null
@@ -1,81 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""This is an example script for showing a nonsense tcl/tk application."""
-
-try:
- import pyext
-except:
- print "ERROR: This script must be loaded by the PD/Max pyext external"
-
-from Tkinter import *
-import random
-
-
-class Application(Frame):
- """This is the TK application class"""
-
- # Button pressed
- def say_hi(self):
- self.extcl._outlet(1,"hi there, everyone!")
-
- # Mouse motion over canvas
- def evfunc(self, ev):
- x = random.uniform(-3,3)
- y = random.uniform(-3,3)
- self.mcanv.move('group',x,y)
-
- # Create interface stuff
- def createWidgets(self):
- self.hi = Button(self)
- self.hi["text"] = "Hi!"
- self.hi["fg"] = "red"
- self.hi["command"] = self.say_hi
- self.hi.pack({"side": "left"})
-
- self.mcanv = Canvas(self)
- self.mcanv.pack({"side": "left"})
- self.mcanv.bind("<Motion>", self.evfunc)
- self.mcanv.create_rectangle(50,50,200,200)
- r = self.mcanv.create_rectangle(50,50,200,200)
- self.mcanv.addtag_withtag('group',r)
-
- for i in xrange(500):
- x = random.uniform(50,200)
- y = random.uniform(50,200)
- l = self.mcanv.create_line(x,y,x+1,y)
- self.mcanv.addtag_withtag('group',l)
-
- # Constructor
- def __init__(self,cl):
- self.extcl = cl
- Frame.__init__(self)
- self.pack()
- self.createWidgets()
- pass
-
-
-# derive class from pyext._class
-
-class myapp(pyext._class):
- """This class demonstrates how a TCL/TK can be openened from within a pyext external"""
-
- # how many inlets and outlets?
- _inlets = 1
- _outlets = 1
-
- # Constructor
- def __init__(self):
- # detach bang method
- self._detach(1)
-
- def bang_1(self):
- self._priority(-3)
- # display the tcl/tk dialog
- app = Application(self)
- app.mainloop()
-
diff --git a/externals/grill/py/scripts/threads.py b/externals/grill/py/scripts/threads.py
deleted file mode 100644
index b0299101..00000000
--- a/externals/grill/py/scripts/threads.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# py/pyext - python script objects for PD and MaxMSP
-#
-# Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net)
-# For information on usage and redistribution, and for a DISCLAIMER OF ALL
-# WARRANTIES, see the file, "license.txt," in this distribution.
-#
-
-"""This is an example script for the py/pyext object's threading functionality.
-
-For threading support pyext exposes several function and variables
-
-- _detach([0/1]): by enabling thread detaching, threads will run in their own threads
-- _priority(prio+-): you can raise or lower the priority of the current thread
-- _stop({wait time in ms}): stop all running threads (you can additionally specify a wait time in ms)
-- _shouldexit: this is a flag which indicates that the running thread should terminate
-
-"""
-
-try:
- import pyext
-except:
- print "ERROR: This script must be loaded by the PD/Max pyext external"
-
-from time import sleep
-
-#################################################################
-
-class ex1(pyext._class):
- """This is a simple class with one method looping over time."""
-
- # number of inlets and outlets
- _inlets=2
- _outlets=2
-
- sltime=0.1 # sleep time
- loops=20 # loops to iterate
-
- # method for bang to any inlet
- def bang_(self,n):
- for i in xrange(self.loops):
- # if _shouldexit is true, the thread ought to stop
- if self._shouldexit:
- print "BREAK"
- break
-
- self._outlet(n,i)
- sleep(self.sltime)
-
-
-