Hi list,
I need to implement an object that I will call a "scheduler" (suggestions for a better name are welcome too) which would be very similar to a [qlist] (without the need for the capability of changing the tempo), with two differences:
initial instant) rather than relative to the previous message
previously added messages.
This basically means implementing a priority queue (doesn't it?). Is a binary heap the most efficient structure (in inserting an element and extracting the minimum) for implementing that?
I thought I'd dive into pdlua and use lua to implement such an object (I am completely new to lua though)... would you suggest that or pyext and implement it in python? It seems python has standard heap functions in its library; does lua have something equivalent or will I have to write the code for the priority queue?
Would be interesting to know if anyone has ever run into the same necessity and how you did it.
Thanks m.
Hallo, Matteo Sisti Sette hat gesagt: // Matteo Sisti Sette wrote:
I need to implement an object that I will call a "scheduler" (suggestions for a better name are welcome too) which would be very similar to a [qlist] (without the need for the capability of changing the tempo), with two differences:
- the leading number in a message represents absolute time (since some
initial instant) rather than relative to the previous message
I think, this could be as simple as a combination of [textfile] and [pipe], where you dump the whole content of the textfile to [pipe] in one go using [until].
- you can [add( messages with a scheduled time that is not greater than all
previously added messages.
I don't understand what you mean with this one. Could you give an example?
I thought I'd dive into pdlua and use lua to implement such an object (I am completely new to lua though)... would you suggest that or pyext and implement it in python?
pdlua has clock support which might be helpful for this. I don't know ATM, if pyext also supports clocks, but I think it doesn't.
It seems python has standard heap functions in its library; does lua have something equivalent or will I have to write the code for the priority queue?
Lua has only one data structure, the table, which you use to build other structures. As tables are very flexible, this generally isn't very complicated.
Frank Barknecht _ ______footils.org__
On Tue, 2008-03-11 at 21:50 +0100, Matteo Sisti Sette wrote:
Hi list,
I need to implement an object that I will call a "scheduler" (suggestions for a better name are welcome too) which would be very similar to a [qlist] (without the need for the capability of changing the tempo), with two differences:
- the leading number in a message represents absolute time (since some
initial instant) rather than relative to the previous message
- you can [add( messages with a scheduled time that is not greater than all
previously added messages.
you could easily convert relative time to absolute time in pd with a few objects around [qlist] for playing. vice versa, it should be quite feasible to convert absolute time to relative time for recording with [qlist]. i don't quite see the need for an external here.
roman
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
you could easily convert relative time to absolute time in pd with a few objects around [qlist] for playing. vice versa, it should be quite feasible to convert absolute time to relative time for recording with [qlist]. i don't quite see the need for an external here.
Yes of course the conversion of relative / absolute time is not the issue: I needed to mention it because otherwise the second point (the real issue) couldn't be understood (or I should have phrased it in terms of negative time offsets).
The problem is I need to be able to add (at any time) a scheduled message whose time isn't necessarily "later" than all previoisly scheduled events.
Let's make an example. For the sake of simplicity I will keep using "absolute" times, though indeed I'd like to implement it in such a way that the time is always specified relative to the time when the message is _added_ to the queue (not relative to the time of the last event in the queue) - this would be in order to avoid infinitely growing times. But for now let's not think about time conversions.
It would work like this: (times are in milliseconds)
At time 0 the object is "started" (i.e. it starts counting time). At time 200 I send a message [add 3000 message1( This schedules a message "message1" to be output at time 3000
At time 1000 I send a message [add 2000 message2(
At time 2000 message "message2" is output
At time 3000 message "message1" is output
An easy way of implementing it in pure PD would be by using two [textfile]s or [qlist]s. Every time a new event is to be added to the queue, the existing queue is "scanned" and copied to a dummy queue, where the new event is inserted at the desired point; then the dummy queue is copied back to the nondummy [textfile]/[qlist]. The timimg would be managed with a [delay] or with the builtin timing funcionality of [qlist], whichever is simpler.
But this means that inserting an event takes a time linear with the number of events currently in the queue.
Since I need to accumulate thousands of messages, a part from being very cpu-greedy, this would probably cause audio dropouts when adding events to a queue already populated with thousands of events.
I also thought about an alternative, fast but memory-costly implementation, with thousands of "delay lines" (i.e. instances of an abstraction containing a [delay] and needed stuff), and a [poly] used to distribute incoming events to "free" delays.
But with a few thousands of instances of any object, the patch would take ages to load. I tried that! I dunnow if it would ever complete loading and work!!
Even if I implemented a binary heap in PD, I still need to store a vector of a few thousand lists, and the only way I know of doing this is to use a few thousand instances of [list append], so again I have the problem of load time.
By the way, is perhaps the loading time of a patch greater-than-linear with the number of objects in it? perhaps quadratic?