Hallo, Claude Heiland-Allen hat gesagt: // Claude Heiland-Allen wrote:
Frank Barknecht wrote:
inspired by Matteo's question I briefly tried to implement a [pipe] clone in pdlua, however I ran into problems which might hint at either some design issues with clock support in pdlua or, more likely, my lack of understanding how clocks work.
Lua has lexical scope, and allows you to create closures (ie, functions that reference some part of their context). You don't need a table of events, you can just 'embed' the data in the function for each event.
I changed the interface of your object btw, having an "anything" inlet for messages and a "float" inlet for delay time, which is safer (you had an anything method, but assume the first atom is a float - bug!).
Error checking was deliberately left out. ;) In the end I'd like to have the delay time up front to be able to use qlist-ish messages like: "0 a b c, 1000 x y z, 300 bang".
Something like this probably works (untested...):
-- initialise self.nextID to some number in constructor
function M:in_2_float(f) self.deltatime = math.max(0, f) end
function M:in_1(sel, atoms) -- we need unique method names for our clock callbacks self.nextID = self.nextID + 1 local id = "trigger" .. self.nextID local clock = pd.Clock:new():register(self, id) -- the clock callback outlets the data and cleans up self[id] = function(self) self:outlet(1, sel, atoms) clock:destruct() self[id] = nil end -- now start the clock clock:delay(self.deltatime) end
Ah, a very elegant solution. It's tested now (attached) and seems to work really well.
Frank Barknecht _ ______footils.org__