# Path: bl/scheduler.py
# class Tempo(object):
# class Beat(_BeatBase):
# class Meter(object):
# class SynthControllerMixin(object):
# class BeatClock(SelectReactor, SynthControllerMixin):
# class ScheduledEvent(object):
#     def __init__(self, bpm=120, tpb=24):
#     def reset(self, bpm=None, tpb=None, tpm=None):
#     def __str__(self):
#     def __repr__(self):
#     def __init__(self, length=4, division=4, number=1, tempo=TEMPO_120_24):
#     def resetTempo(self, tempo):
#     def beat(self, ticks):
#     def ticks(self, ticks):
#     def divisionToTicks(self, n, d):
#     def nextDivision(self, ticks, n, d):
#     def nextMeasure(self, ticks, measures=1):
#     def untilNextMeasure(self, ticks, measures=1):
#     def measure(self, ticks):
#     def __repr__(self):
#     def __hash__(self):
#     def __init__(self, tempo=TEMPO_120_24, meter=None, meters=(), reactor=None,
#                  syncClockClass=None, default=False):
#     def setTempo(self, tempo):
#     def run(self):
#     def _initBackends(self):
#     def startTicking(self):
#     def tick(self):
#     def _syncToTick(self, tick, ts):
#     def seconds(self):
#     def schedule(self, _f, *args, **kwargs):
#     def callWhenRunning(self, *a, **kw):
#     def untilNextMeasure(self, measures=0):
#     def callAfterMeasures(self, measures, f, *a, **kw):
#     def nudge(self, pause=0.1):
#     def __init__(self, clock, _f, *args, **kwargs):
#     def startAfterTicks(self, ticks, interval):
#         def _start():
#     def startAfter(self, divisions=(1, 1), interval=(1, 4)):
#     def _divisions(self, divisions):
#     def start(self, ticks=None, now=True):
#         def _start():
#     def stopAfterTicks(self, ticks):
#         def _schedule_stop():
#             def _stop():
#     def stopAfter(self, divisions=(1, 1)):
#     def stop(self):
# TEMPO_120_24 = Tempo()
# STANDARD_TICKS_PER_MEASURE = 96
# 
# Path: bl/instrument/fsynth.py
# class Instrument(ChordPlayerMixin):
#     implements(IMIDIInstrument)
# 
#     recorder = None
# 
#     def __init__(self, sfpath, synth=None, connection='mono',
#                  channel=None, bank=0, preset=0, pool=None, clock=None):
#         if pool is None:
#             pool = defaultPool
#         if synth is None:
#             synth = pool.synthObject(connection=connection)
#         self.clock = getClock(clock)
#         self.synth = synth
#         self._file = os.path.basename(sfpath)
#         self.sfpath = sfpath
#         self._options = dict(sfpath=sfpath, connection=connection,
#                              channel=channel, bank=bank, preset=preset)
#         pool.connectInstrument(self.synth, self, sfpath, channel=channel,
#                                bank=bank, preset=preset)
#         self._max_velocity = 127
# 
#     def __str__(self):
#         return 'Instrument path=%s sfid=%s channel=%s' % (
#                 self._file, self.sfid, self.channel)
# 
#     def registerSoundfont(self, sfid, channel):
#         self.sfid = sfid
#         self.channel = channel
# 
#     def cap(self, maxVelocity):
#         self._max_velocity = maxVelocity
# 
#     def noteon(self, note, velocity=80):
#         if self.recorder is not None:
#             self.recorder(self, 'noteon', note=note, velocity=velocity)
#         if note is None:
#             return
#         velocity = min(velocity, self._max_velocity)
#         self.synth.noteon(self.channel, note, velocity)
# 
#     playnote = noteon
# 
#     def noteoff(self, note):
#         if self.recorder is not None:
#             self.recorder(self, 'noteoff', note=note)
#         if note is None:
#             return
#         self.synth.noteoff(self.channel, note)
# 
#     stopnote = noteoff
# 
#     def controlChange(self, vibrato=None, pan=None, expression=None,
#                       sustain=None, reverb=None, chorus=None, **ignored):
#         if self.recorder is not None:
#             self.recorder(self, 'controlChange', vibrato=vibrato, pan=pan,
#                           expression=expression, sustain=sustain,
#                           reverb=reverb, chorus=chorus, ignored=ignored)
#         if vibrato is not None:
#             self.synth.cc(self.channel, CC_VIBRATO, vibrato)
#         if pan is not None:
#             self.synth.cc(self.channel, CC_PAN, pan)
#         if expression is not None:
#             self.synth.cc(self.channel, CC_EXPRESSION, expression)
#         if sustain is not None:
#             self.synth.cc(self.channel, CC_SUSTAIN, sustain)
#         if reverb is not None:
#             self.synth.cc(self.channel, CC_REVERB, reverb)
#         if chorus is not None:
#             self.synth.cc(self.channel, CC_CHORUS, chorus)
# 
#     def pitchBend(self, value):
#         if self.recorder:
#             self.recorder(self, 'pitchBend', value=value)
#         self.synth.pitch_bend(self.channel, value)


from itertools import cycle
from bl.scheduler import clock, measuresToTicks
from bl.player import Player  # , generateSounds
from bl.filters import Sustainer
from bl.instrument.fsynth import Instrument
import optparse
#import sys




opts = None
instrument = None


def main():
    global opts, instrument
    parser = optparse.OptionParser()
    parser.add_option('-v', '--volume', dest='volume', default=100, type='int')
    parser.add_option('-s', '--range-start', dest='range_start', default=0,
                                                                    type='int')

# Path: bl/scheduler.py
# class Tempo(object):
# class Beat(_BeatBase):
# class Meter(object):
# class SynthControllerMixin(object):
# class BeatClock(SelectReactor, SynthControllerMixin):
# class ScheduledEvent(object):
#     def __init__(self, bpm=120, tpb=24):
#     def reset(self, bpm=None, tpb=None, tpm=None):
#     def __str__(self):
#     def __repr__(self):
#     def __init__(self, length=4, division=4, number=1, tempo=TEMPO_120_24):
#     def resetTempo(self, tempo):
#     def beat(self, ticks):
#     def ticks(self, ticks):
#     def divisionToTicks(self, n, d):
#     def nextDivision(self, ticks, n, d):
#     def nextMeasure(self, ticks, measures=1):
#     def untilNextMeasure(self, ticks, measures=1):
#     def measure(self, ticks):
#     def __repr__(self):
#     def __hash__(self):
#     def __init__(self, tempo=TEMPO_120_24, meter=None, meters=(), reactor=None,
#                  syncClockClass=None, default=False):
#     def setTempo(self, tempo):
#     def run(self):
#     def _initBackends(self):
#     def startTicking(self):
#     def tick(self):
#     def _syncToTick(self, tick, ts):
#     def seconds(self):
#     def schedule(self, _f, *args, **kwargs):
#     def callWhenRunning(self, *a, **kw):
#     def untilNextMeasure(self, measures=0):
#     def callAfterMeasures(self, measures, f, *a, **kw):
#     def nudge(self, pause=0.1):
#     def __init__(self, clock, _f, *args, **kwargs):
#     def startAfterTicks(self, ticks, interval):
#         def _start():
#     def startAfter(self, divisions=(1, 1), interval=(1, 4)):
#     def _divisions(self, divisions):
#     def start(self, ticks=None, now=True):
#         def _start():
#     def stopAfterTicks(self, ticks):
#         def _schedule_stop():
#             def _stop():
#     def stopAfter(self, divisions=(1, 1)):
#     def stop(self):
# TEMPO_120_24 = Tempo()
# STANDARD_TICKS_PER_MEASURE = 96
# 
# Path: bl/instrument/fsynth.py
# class Instrument(ChordPlayerMixin):
#     implements(IMIDIInstrument)
# 
#     recorder = None
# 
#     def __init__(self, sfpath, synth=None, connection='mono',
#                  channel=None, bank=0, preset=0, pool=None, clock=None):
#         if pool is None:
#             pool = defaultPool
#         if synth is None:
#             synth = pool.synthObject(connection=connection)
#         self.clock = getClock(clock)
#         self.synth = synth
#         self._file = os.path.basename(sfpath)
#         self.sfpath = sfpath
#         self._options = dict(sfpath=sfpath, connection=connection,
#                              channel=channel, bank=bank, preset=preset)
#         pool.connectInstrument(self.synth, self, sfpath, channel=channel,
#                                bank=bank, preset=preset)
#         self._max_velocity = 127
# 
#     def __str__(self):
#         return 'Instrument path=%s sfid=%s channel=%s' % (
#                 self._file, self.sfid, self.channel)
# 
#     def registerSoundfont(self, sfid, channel):
#         self.sfid = sfid
#         self.channel = channel
# 
#     def cap(self, maxVelocity):
#         self._max_velocity = maxVelocity
# 
#     def noteon(self, note, velocity=80):
#         if self.recorder is not None:
#             self.recorder(self, 'noteon', note=note, velocity=velocity)
#         if note is None:
#             return
#         velocity = min(velocity, self._max_velocity)
#         self.synth.noteon(self.channel, note, velocity)
# 
#     playnote = noteon
# 
#     def noteoff(self, note):
#         if self.recorder is not None:
#             self.recorder(self, 'noteoff', note=note)
#         if note is None:
#             return
#         self.synth.noteoff(self.channel, note)
# 
#     stopnote = noteoff
# 
#     def controlChange(self, vibrato=None, pan=None, expression=None,
#                       sustain=None, reverb=None, chorus=None, **ignored):
#         if self.recorder is not None:
#             self.recorder(self, 'controlChange', vibrato=vibrato, pan=pan,
#                           expression=expression, sustain=sustain,
#                           reverb=reverb, chorus=chorus, ignored=ignored)
#         if vibrato is not None:
#             self.synth.cc(self.channel, CC_VIBRATO, vibrato)
#         if pan is not None:
#             self.synth.cc(self.channel, CC_PAN, pan)
#         if expression is not None:
#             self.synth.cc(self.channel, CC_EXPRESSION, expression)
#         if sustain is not None:
#             self.synth.cc(self.channel, CC_SUSTAIN, sustain)
#         if reverb is not None:
#             self.synth.cc(self.channel, CC_REVERB, reverb)
#         if chorus is not None:
#             self.synth.cc(self.channel, CC_CHORUS, chorus)
# 
#     def pitchBend(self, value):
#         if self.recorder:
#             self.recorder(self, 'pitchBend', value=value)
#         self.synth.pitch_bend(self.channel, value)


# Path: bl/sf2tester.py
from itertools import cycle
from bl.scheduler import clock, measuresToTicks
from bl.player import Player  # , generateSounds
from bl.filters import Sustainer
from bl.instrument.fsynth import Instrument
import optparse

#import sys




opts = None
instrument = None


def main():
    global opts, instrument
    parser = optparse.OptionParser()
    parser.add_option('-v', '--volume', dest='volume', default=100, type='int')
    parser.add_option('-s', '--range-start', dest='range_start', default=0,
                                                                    type='int')

    parser.add_option('-e', '--range-end', dest='range_end', default=128,