# 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
            self.phrase = [
                (w, n, v, s or self.elapsed - w)
                for (w, n, v, s) in self.phrase
            ]
            if DEBUG:
                log.msg('>phrase===\n%s' % pformat(self.phrase))

    def _eraseTape(self):
        if self._tape and self._tape['whens']:
            self._last_tape = dict(self._tape)
            self._last_tape['dirty'] = False
        self._tape = {'whens': [], 'notes': [], 'velocities': [],
                      'sustains': [], 'indexes': {}, 'last_ticks': {}}

    def recordNoteOn(self, note, velocity=100, ticks=None):
        if ticks is None:
            ticks = self.clock.ticks
        self._tape['indexes'][(self.clock.ticks, note)] = len(
                                                        self._tape['notes'])
        self._tape['last_ticks'][note] = self.clock.ticks
        self._tape['notes'].append(note)
        self._tape['velocities'].append(velocity)
        self._tape['whens'].append(ticks - self._phraseStartTicks)

    def recordNoteOff(self, note):
        tape = self._tape
        last = tape['last_ticks'].get(note, None)
        if last is None:
            if self._last_tape:
                last = self._last_tape['last_ticks'].get(note, None)

# 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

            self.phrase = [
                (w, n, v, s or self.elapsed - w)
                for (w, n, v, s) in self.phrase
            ]
            if DEBUG:
                log.msg('>phrase===\n%s' % pformat(self.phrase))

    def _eraseTape(self):
        if self._tape and self._tape['whens']:
            self._last_tape = dict(self._tape)
            self._last_tape['dirty'] = False
        self._tape = {'whens': [], 'notes': [], 'velocities': [],
                      'sustains': [], 'indexes': {}, 'last_ticks': {}}

    def recordNoteOn(self, note, velocity=100, ticks=None):
        if ticks is None:
            ticks = self.clock.ticks
        self._tape['indexes'][(self.clock.ticks, note)] = len(
                                                        self._tape['notes'])
        self._tape['last_ticks'][note] = self.clock.ticks
        self._tape['notes'].append(note)
        self._tape['velocities'].append(velocity)
        self._tape['whens'].append(ticks - self._phraseStartTicks)

    def recordNoteOff(self, note):
        tape = self._tape
        last = tape['last_ticks'].get(note, None)
        if last is None:
            if self._last_tape:
                last = self._last_tape['last_ticks'].get(note, None)

                debug('got last tick from past recording: %s' % last)