# Path: bl/utils.py
# def getClock(clock=None):
#     if clock is None:
#         from bl.scheduler import BeatClock
#         return BeatClock.defaultClock
#     return clock
# 
# def exhaustCall(v):
#     """
#     Get an uncallable value at the end of a call chain or `v` itself
#     if `v` is not callable.
#     """
#     while callable(v):
#         v = v()
#     return v


from itertools import cycle
from twisted.python import log
from twisted.python.failure import Failure
from bl.utils import getClock, exhaustCall
        if event is not None:
            (func, args) = event

            # TODO exhaustCall is "BAD" b/c we might want to actually pass
            # functions! This should be replaced maybe by exhaustUgens which
            # has prequisite: unit generators (ugens). bl.player's ad-hoc ugens
            # should be put in bl.ugens (new module) and implement IUgen or
            # something

            exhaustedArgs = dict((k, exhaustCall(v))
                                  for (k, v) in args.iteritems())
            func(**exhaustedArgs)
            stoppedChildren = []
            for child in self._scheduleChildren:
                try:
                    (func, args) = child.next()
                except StopIteration:
                    stoppedChildren.append(child)
                    continue
                exhaustedArgs = dict((k, exhaustCall(v))
                                      for (k, v) in args.iteritems())
                func(**exhaustedArgs)
            for child in stoppedChildren:
                while child in self._scheduleChildren:
                    self._scheduleChildren.remove(child)
        try:
            event = schedule.next()
        except StopIteration:
            return
        if event:

# Path: bl/utils.py
# def getClock(clock=None):
#     if clock is None:
#         from bl.scheduler import BeatClock
#         return BeatClock.defaultClock
#     return clock
# 
# def exhaustCall(v):
#     """
#     Get an uncallable value at the end of a call chain or `v` itself
#     if `v` is not callable.
#     """
#     while callable(v):
#         v = v()
#     return v


# Path: bl/orchestra/base.py
from itertools import cycle
from twisted.python import log
from twisted.python.failure import Failure
from bl.utils import getClock, exhaustCall

        if event is not None:
            (func, args) = event

            # TODO exhaustCall is "BAD" b/c we might want to actually pass
            # functions! This should be replaced maybe by exhaustUgens which
            # has prequisite: unit generators (ugens). bl.player's ad-hoc ugens
            # should be put in bl.ugens (new module) and implement IUgen or
            # something

            exhaustedArgs = dict((k, exhaustCall(v))
                                  for (k, v) in args.iteritems())
            func(**exhaustedArgs)
            stoppedChildren = []
            for child in self._scheduleChildren:
                try:
                    (func, args) = child.next()
                except StopIteration:
                    stoppedChildren.append(child)
                    continue
                exhaustedArgs = dict((k, exhaustCall(v))
                                      for (k, v) in args.iteritems())
                func(**exhaustedArgs)
            for child in stoppedChildren:
                while child in self._scheduleChildren:
                    self._scheduleChildren.remove(child)
        try:
            event = schedule.next()
        except StopIteration:
            return
        if event:

            when, event = exhaustCall(event[0]), event[1:]