[PD] First time PD troubles: A programmers confusion.
Frank Barknecht
fbar at footils.org
Fri Nov 9 07:59:22 CET 2007
Hallo,
Chuckk Hubbard hat gesagt: // Chuckk Hubbard wrote:
> [float 0] or [f 0] is an instance of [float]; it has the property 0, which
> can change, and float, which can't; it has one method to replace its value
> (a float sent to its right inlet), one method to send a message of its value
> (a "bang" message to its left inlet), and one method to do both in that
> order (a float to the left inlet replaces and then sends a message). Where
> it sends the messages it sends, and from where it receives the instructions
> it receives, are not for the object itself to worry about.
>
> The [+ 1] object has one method to add 1 to its input and output the result
> (a float to the left inlet); a method to replace the argument 1 (float to
> the right inlet); and if I'm not mistaken, it also remembers its last
> left-side input, so if it has already received a float to the left inlet,
> then a "bang" to the left inlet repeats the operation the same as before.
> AFAIK there are no other methods of the [+ 1] object; anything it does is
> one of those three things. Not including error checking (it won't accept a
> symbol as input or argument).
To illustrate that with Python:
class Float(pyext._class):
"""[float] in Python"""
_inlets=2
_outlets=1
# constructor
def __init__(self,*args)
self.stored=args[0] or 0
def bang_1(self):
"Bang into first inlet: send float to outlet"
self._outlet(1,self.stored)
def float_1(self,f):
self.stored = f
self._outlet(1,f)
def float_2(self,f)
self.stored = f
class Add(pyext._class):
"""[+ ] in Python"""
_inlets=2
_outlets=1
# constructor
def __init__(self,*args)
self.stored = 0
self.add=args[0] or 0
def bang_1(self):
"Bang into first inlet: send float to outlet"
self._outlet(1,self.stored)
def float_1(self,f):
self.stored = f + self.add
self._outlet(1,self.stored)
def float_2(self,f)
self.add = f
# use it:
f0 = Float(0)
add1 = Add(1)
connect((f0, outlet0), (add1, inlet0))
connect((add1, outlet0), (f0, inlet1))
for i in range(10):
send_bang_to(f0, inlet0)
The classes are actually almost valid code.
sys.exit()
--
Frank Barknecht _ ______footils.org__
More information about the Pd-list
mailing list