# Path: bl/debug.py
# def debug(message):
#     if DEBUG:
#         log.msg(message)
# 
# DEBUG = _Debug()
# 
# 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


import random
from itertools import cycle
from pprint import pformat
from zope.interface import Interface, Attribute, implements
from twisted.python import log
from bl.debug import debug, DEBUG
from bl.utils import getClock, exhaustCall

    def __init__(self, func, arp, values=None):
        ArpSwitcher.__init__(self, arp, values)
        self.func = func

    def __call__(self):
        return self.func(exhaustCall(self.arp()))


class PhraseRecordingArp(BaseArp):

    def __init__(self, clock=None):
        self.clock = getClock(clock)
        self._phraseStartTicks = self.clock.ticks
        self._last_tape = None
        self._tape = {}
        self._eraseTape()
        self.phrase = []

    def __call__(self):
        self.elapsed = self._phraseStartTicks = self.clock.ticks
        self._resetRecording()
        return list(self.phrase)

    def _resetRecording(self):
        whens = self._tape['whens']
        notes = self._tape['notes']
        velocities = self._tape['velocities']
        sustains = self._tape['sustains']
        indexes = self._tape['indexes']

# Path: bl/debug.py
# def debug(message):
#     if DEBUG:
#         log.msg(message)
# 
# DEBUG = _Debug()
# 
# 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/arp.py
import random
from itertools import cycle
from pprint import pformat
from zope.interface import Interface, Attribute, implements
from twisted.python import log
from bl.debug import debug, DEBUG
from bl.utils import getClock, exhaustCall


    def __init__(self, func, arp, values=None):
        ArpSwitcher.__init__(self, arp, values)
        self.func = func

    def __call__(self):
        return self.func(exhaustCall(self.arp()))


class PhraseRecordingArp(BaseArp):

    def __init__(self, clock=None):
        self.clock = getClock(clock)
        self._phraseStartTicks = self.clock.ticks
        self._last_tape = None
        self._tape = {}
        self._eraseTape()
        self.phrase = []

    def __call__(self):
        self.elapsed = self._phraseStartTicks = self.clock.ticks
        self._resetRecording()
        return list(self.phrase)

    def _resetRecording(self):
        whens = self._tape['whens']
        notes = self._tape['notes']
        velocities = self._tape['velocities']
        sustains = self._tape['sustains']
        indexes = self._tape['indexes']

        if DEBUG: