# Path: bl/ugen.py
# W = Weight
# 
# Path: bl/arp.py
# class ChordPatternArp(PatternArp):
#     """
#     Like PatternArp except values generated by call are always lists or tuples.
#     """
# 
#     def coerce(self, noteOrChord):
#         if type(noteOrChord) not in (list, tuple):
#             return (noteOrChord,)
#         return noteOrChord
# 
# class OrderedArp(IndexedArp):
# 
#     def sort(self, values):
#         return values
# 
# class RandomArp(BaseArp):
# 
#     def reset(self, values):
#         self._current = list(values)
#         self._next = []
#         self.count = len(values)
#         self.values = values
# 
#     def __call__(self):
#         if not self._current:
#             self._current = self._next
#         if not self._current:
#             return
#         l = len(self._current)
#         index = random.randint(0, l - 1)
#         next = self._current.pop(index)
#         self._next.append(next)
#         return next
# 
# class ArpMap(ArpSwitcher):
#     """
#     An ArpSwitcher that maps values returning from underlying C{arp} through a
#     function C{func}.
# 
#     Example:
# 
#         from pyo import midiToHz
#         freqArp = ArpMap(midiToHz, RandomArp(range(128)))
#     """
# 
#     def __init__(self, func, arp, values=None):
#         ArpSwitcher.__init__(self, arp, values)
#         self.func = func
# 
#     def __call__(self):
#         return self.func(exhaustCall(self.arp()))
# 
# 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/orchestra/midi.py
# class ChordPlayer(Player):
# 
#     onMethodName = 'chordon'
#     offMethodName = 'chordoff'
# 
# Path: tutor/complib.py
# _HERE = os.path.dirname(__file__)
# def sf2(sf2name):
# def kitFactory(kit_name):
#     def f(connection='mono'):


from itertools import cycle
from bl.ugen import W
from bl.arp import ChordPatternArp, OrderedArp, RandomArp, ArpMap
from bl.scheduler import clock
from bl.orchestra.midi import ChordPlayer
from tutor.complib import piano_f
               [36, 53, 55, 65, 67, 81],
               [38, 53, 55, 65, 67, 81],
               [38, 53, 55, 67, 69, 81],
               [38, 53, 55, 67, 69, 74],
               [38, 53, 55, 65, 67, 74],
               [36, 53, 55, 65, 67, 74],
               [36, 55, 57, 65, 67, 74],
               [36, 55, 57, 60, 67, 74],
               [36, 55, 57, 60, 64, 74],
               [36, 55, 57, 60, 64, 80],
               [36, 55, 57, 60, 64, 81],
               [36, 55, 57, 60, 64, 84],
               [36, 55, 57, 60, 63, 84],
               [36, 55, 57, 60, 64, 84],
               [36, 55, 57, 60, 69, 84],
               [36, 55, 57, 60, 69, 81],
               [36, 55, 57, 60, 69, 78],
               [36, 53, 55, 60, 69, 78],
               [36, 53, 55, 62, 69, 78]])

piano = piano_f()
piano.controlChange(reverb=120, sustain=100, chorus=50, vibrato=15)

r = W((0, 5), (12, 2), (-12, 3))
f = lambda chord: [r() + n for n in chord]
arp = ArpMap(f, ChordPatternArp(notes.next(), pattern))

player = ChordPlayer(piano, arp,
                     velocity=OrderedArp([127, 80, 90, 80, 90, 120, 120, 80]),
                     release=RandomArp([11, 10, 9, 8]))

# Path: bl/ugen.py
# W = Weight
# 
# Path: bl/arp.py
# class ChordPatternArp(PatternArp):
#     """
#     Like PatternArp except values generated by call are always lists or tuples.
#     """
# 
#     def coerce(self, noteOrChord):
#         if type(noteOrChord) not in (list, tuple):
#             return (noteOrChord,)
#         return noteOrChord
# 
# class OrderedArp(IndexedArp):
# 
#     def sort(self, values):
#         return values
# 
# class RandomArp(BaseArp):
# 
#     def reset(self, values):
#         self._current = list(values)
#         self._next = []
#         self.count = len(values)
#         self.values = values
# 
#     def __call__(self):
#         if not self._current:
#             self._current = self._next
#         if not self._current:
#             return
#         l = len(self._current)
#         index = random.randint(0, l - 1)
#         next = self._current.pop(index)
#         self._next.append(next)
#         return next
# 
# class ArpMap(ArpSwitcher):
#     """
#     An ArpSwitcher that maps values returning from underlying C{arp} through a
#     function C{func}.
# 
#     Example:
# 
#         from pyo import midiToHz
#         freqArp = ArpMap(midiToHz, RandomArp(range(128)))
#     """
# 
#     def __init__(self, func, arp, values=None):
#         ArpSwitcher.__init__(self, arp, values)
#         self.func = func
# 
#     def __call__(self):
#         return self.func(exhaustCall(self.arp()))
# 
# 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/orchestra/midi.py
# class ChordPlayer(Player):
# 
#     onMethodName = 'chordon'
#     offMethodName = 'chordoff'
# 
# Path: tutor/complib.py
# _HERE = os.path.dirname(__file__)
# def sf2(sf2name):
# def kitFactory(kit_name):
#     def f(connection='mono'):


# Path: tutor/song5.py
from itertools import cycle
from bl.ugen import W
from bl.arp import ChordPatternArp, OrderedArp, RandomArp, ArpMap
from bl.scheduler import clock
from bl.orchestra.midi import ChordPlayer
from tutor.complib import piano_f

               [36, 53, 55, 65, 67, 81],
               [38, 53, 55, 65, 67, 81],
               [38, 53, 55, 67, 69, 81],
               [38, 53, 55, 67, 69, 74],
               [38, 53, 55, 65, 67, 74],
               [36, 53, 55, 65, 67, 74],
               [36, 55, 57, 65, 67, 74],
               [36, 55, 57, 60, 67, 74],
               [36, 55, 57, 60, 64, 74],
               [36, 55, 57, 60, 64, 80],
               [36, 55, 57, 60, 64, 81],
               [36, 55, 57, 60, 64, 84],
               [36, 55, 57, 60, 63, 84],
               [36, 55, 57, 60, 64, 84],
               [36, 55, 57, 60, 69, 84],
               [36, 55, 57, 60, 69, 81],
               [36, 55, 57, 60, 69, 78],
               [36, 53, 55, 60, 69, 78],
               [36, 53, 55, 62, 69, 78]])

piano = piano_f()
piano.controlChange(reverb=120, sustain=100, chorus=50, vibrato=15)

r = W((0, 5), (12, 2), (-12, 3))
f = lambda chord: [r() + n for n in chord]
arp = ArpMap(f, ChordPatternArp(notes.next(), pattern))

player = ChordPlayer(piano, arp,
                     velocity=OrderedArp([127, 80, 90, 80, 90, 120, 120, 80]),
                     release=RandomArp([11, 10, 9, 8]))

resetter = clock.schedule(lambda: arp.reset(notes.next())