# 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





__all__ = ['SynthRouter', 'SynthPool', 'StereoPool', 'QuadPool',
           'NConnectionPool', 'Instrument', 'MultiInstrument', 'Layer',
           'suggestDefaultPool']


class SynthRouter:

    def __init__(self, *p, **synth_factories):
        if not synth_factories:
            synth_factories = p[0]
        self.connections = cx = {}
        cx.update(synth_factories)

    def __getitem__(self, key):
        return self.connections[key]


class SynthPool:

    def __init__(self, router, reactor=None, audiodev=None):
        self.router = router
        self.pool = {}
        self.settings = {}
        self._channel_gen = {}
        if reactor is 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/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






__all__ = ['SynthRouter', 'SynthPool', 'StereoPool', 'QuadPool',
           'NConnectionPool', 'Instrument', 'MultiInstrument', 'Layer',
           'suggestDefaultPool']


class SynthRouter:

    def __init__(self, *p, **synth_factories):
        if not synth_factories:
            synth_factories = p[0]
        self.connections = cx = {}
        cx.update(synth_factories)

    def __getitem__(self, key):
        return self.connections[key]


class SynthPool:

    def __init__(self, router, reactor=None, audiodev=None):
        self.router = router
        self.pool = {}
        self.settings = {}
        self._channel_gen = {}
        if reactor is None:

            reactor = getClock()