# Path: bl/utils.py
# def getClock(clock=None):
#     if clock is None:
#         from bl.scheduler import BeatClock
#         return BeatClock.defaultClock
#     return clock
# 
# Path: bl/debug.py
# def debug(message):
#     if DEBUG:
#         log.msg(message)


import pypm
from bl.utils import getClock
from bl.debug import debug
_add_global('TIMINGCLOCK', 2, 0xF8)
_add_global('RESERVED3', 2, 0xF9)
_add_global('START',  2, 0xFA)
_add_global('CONTINUE', 2, 0xFB)
_add_global('STOP', 2, 0xFC)
_add_global('ACTIVESENSING', 2, 0xFE)
_add_global('SYSTEMRESET', 2, 0xFF)

del _add_global

# pyflakes
START = globals()['START']
TIMINGCLOCK = globals()['TIMINGCLOCK']


class MidiDispatcher(object):
    """
    Dispatcher for events received from a midi input channel.

    Example usage:

        init()
        input = getInput(3)
        def debug_event(event):
            print event
        disp = MidiDispatcher(input, [debug_event, NoteOnOffHandler(instr)])
        disp.start()
    """

    def __init__(self, midiInput, handlers, clock=None):

# Path: bl/utils.py
# def getClock(clock=None):
#     if clock is None:
#         from bl.scheduler import BeatClock
#         return BeatClock.defaultClock
#     return clock
# 
# Path: bl/debug.py
# def debug(message):
#     if DEBUG:
#         log.msg(message)


# Path: bl/midi.py
import pypm
from bl.utils import getClock
from bl.debug import debug

_add_global('TIMINGCLOCK', 2, 0xF8)
_add_global('RESERVED3', 2, 0xF9)
_add_global('START',  2, 0xFA)
_add_global('CONTINUE', 2, 0xFB)
_add_global('STOP', 2, 0xFC)
_add_global('ACTIVESENSING', 2, 0xFE)
_add_global('SYSTEMRESET', 2, 0xFF)

del _add_global

# pyflakes
START = globals()['START']
TIMINGCLOCK = globals()['TIMINGCLOCK']


class MidiDispatcher(object):
    """
    Dispatcher for events received from a midi input channel.

    Example usage:

        init()
        input = getInput(3)
        def debug_event(event):
            print event
        disp = MidiDispatcher(input, [debug_event, NoteOnOffHandler(instr)])
        disp.start()
    """

    def __init__(self, midiInput, handlers, clock=None):

        self.clock = getClock(clock)