# Path: bl/utils.py
# def getClock(clock=None):
#     if clock is None:
#         from bl.scheduler import BeatClock
#         return BeatClock.defaultClock
#     return clock
# 
# Path: bl/instrument/interfaces.py
# class IMIDIInstrument(Interface):
#     """
#     A MIDI-like instrument supported a minimal subset of MIDI commands.
#     """
# 
#     channel = Attribute("""
#         The MIDI channel or None if this is a virtual MIDI instrument with no
#         real channel assigned.
#         """)
# 
#     def noteon(note, velocity):
#         """
#         Send a "Note On" event with a MIDI note and velocity ("loudness").
# 
#         @param note: The note [0,127]
#         @param velocity: The velocity [0,127]
#         """
# 
#     def noteoff(note):
#         """
#         Send a "Note Off" event with a MIDI note.
# 
#         @param note: The note [0,127]
#         """
# 
#     def chordon(chord, velocity):
#         """
#         Call noteon(note, velocity) for each note in chord.
# 
#         @param chord: The notes (list)
#         @param velocity: The velocity for the chord.
#         """
# 
#     def chordoff(chord):
#         """
#         Call noteoff(note) for each note in chord.
# 
#         @param chord: The notes (list)
#         """
# 
#     def controlChange(vibrato=None, pan=None, expression=None, sustain=None,
#                       reverb=None, chorus=None, **other):
#         """
#         Send a "Control Change" (CC) event. The implementation may support 0 to
#         all of the predefined controls.
# 
#         @param vibrato: vibrato (Control #76) [0,127]
#         @param pan: pan (Control #10) [0,127]
#         @param expression: expression (Control #11) [0,127]
#         @param sustain: sustain/pedal (Control #64) [0,127]
#         @param reverb: reverb effect (Control #91) [0,127]
#         @param chorus: chorus effect (Control #93) [0,127]
#         @param other: Other control keyword arguments (naming may vary by
#         implementation)
#         """
# 
#     def pitchBend(value):
#         """
#         Send a "Pitch Bend" event.
# 
#         @param value: The pitch bend amount [0,127]
#         """


from pprint import pformat
from warnings import warn
from zope.interface import implements
from fluidsynth import Synth
from bl.utils import getClock
from bl.instrument.interfaces import IMIDIInstrument
import os
        v = lambda: velocity
        if callable(velocity):
            v = lambda: velocity()
        for (i, note) in enumerate(notes):
            later = 1
            self.clock.callLater(i * later, self.playnote, note, v())

    def chordon(self, notes, velocity=80):
        if self.strumming:
            return self.strum(notes, velocity)
        for note in notes:
            self.playnote(note, velocity)

    playchord = chordon

    def chordoff(self, notes):
        for note in notes:
            self.stopnote(note)

    stopchord = chordoff

    def stopall(self):
        for note in range(128):
            self.noteoff(note)


class Recorder(object):

    def __init__(self, clock=None):
        self._instruments = {}

# Path: bl/utils.py
# def getClock(clock=None):
#     if clock is None:
#         from bl.scheduler import BeatClock
#         return BeatClock.defaultClock
#     return clock
# 
# Path: bl/instrument/interfaces.py
# class IMIDIInstrument(Interface):
#     """
#     A MIDI-like instrument supported a minimal subset of MIDI commands.
#     """
# 
#     channel = Attribute("""
#         The MIDI channel or None if this is a virtual MIDI instrument with no
#         real channel assigned.
#         """)
# 
#     def noteon(note, velocity):
#         """
#         Send a "Note On" event with a MIDI note and velocity ("loudness").
# 
#         @param note: The note [0,127]
#         @param velocity: The velocity [0,127]
#         """
# 
#     def noteoff(note):
#         """
#         Send a "Note Off" event with a MIDI note.
# 
#         @param note: The note [0,127]
#         """
# 
#     def chordon(chord, velocity):
#         """
#         Call noteon(note, velocity) for each note in chord.
# 
#         @param chord: The notes (list)
#         @param velocity: The velocity for the chord.
#         """
# 
#     def chordoff(chord):
#         """
#         Call noteoff(note) for each note in chord.
# 
#         @param chord: The notes (list)
#         """
# 
#     def controlChange(vibrato=None, pan=None, expression=None, sustain=None,
#                       reverb=None, chorus=None, **other):
#         """
#         Send a "Control Change" (CC) event. The implementation may support 0 to
#         all of the predefined controls.
# 
#         @param vibrato: vibrato (Control #76) [0,127]
#         @param pan: pan (Control #10) [0,127]
#         @param expression: expression (Control #11) [0,127]
#         @param sustain: sustain/pedal (Control #64) [0,127]
#         @param reverb: reverb effect (Control #91) [0,127]
#         @param chorus: chorus effect (Control #93) [0,127]
#         @param other: Other control keyword arguments (naming may vary by
#         implementation)
#         """
# 
#     def pitchBend(value):
#         """
#         Send a "Pitch Bend" event.
# 
#         @param value: The pitch bend amount [0,127]
#         """


# Path: bl/instrument/fsynth.py
from pprint import pformat
from warnings import warn
from zope.interface import implements
from fluidsynth import Synth
from bl.utils import getClock
from bl.instrument.interfaces import IMIDIInstrument
import os

        v = lambda: velocity
        if callable(velocity):
            v = lambda: velocity()
        for (i, note) in enumerate(notes):
            later = 1
            self.clock.callLater(i * later, self.playnote, note, v())

    def chordon(self, notes, velocity=80):
        if self.strumming:
            return self.strum(notes, velocity)
        for note in notes:
            self.playnote(note, velocity)

    playchord = chordon

    def chordoff(self, notes):
        for note in notes:
            self.stopnote(note)

    stopchord = chordoff

    def stopall(self):
        for note in range(128):
            self.noteoff(note)


class Recorder(object):

    def __init__(self, clock=None):
        self._instruments = {}

        self.clock = getClock(clock)