On Mon, 15 Dec 2008, John O'Hagan wrote: > On Sun, 14 Dec 2008, Bad Mutha Hubbard wrote: > > John O'Hagan wrote: > > > On Wed, 10 Dec 2008, badmuthahubbard wrote: > > [...] > > > > from time import time, sleep > > > > > > start = time() > > > for event in music: > > > duration=len(event) #Really, the length of the event > > > play(event) > > > while 1: > > > timer = time() > > > remaining = start + duration - timer > > > if remaining < 0.001: > > > break > > > else: > > > sleep(remaining / 2) > > > stop(event) > > > start += duration > > > > Very interesting approach, halving the remaining duration. Right now > > I'm not working with note-offs, Csound takes care of the duration. I > > just need to be able to call the notes at the right times. > > [...] > > I'm also using the above code without the "stop(event)" line for playing > non-midi stuff (fixed-length samples for example), which from the sound of > it also applies to your requirement - IOW, you _can_ use it just to start > notes at the right time, because the note-playing loop sleeps till then. >
And as I realized after having a good sleep myself, this is only useful for timing events which occur sequentially and do not overlap, which is how my program works because it generates the events in real time, but which may be of no use in your case. But I suppose the same principle could be applied to reduce the number of calls needed in a separate timing thread. Unless of course each event contained the start-time of the next event as an attribute....? John -- http://mail.python.org/mailman/listinfo/python-list