Beispiel #1
0
 def test_basic(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     self.assertEquals(func.calls, [(96, {
         'a': 0,
         'b': 0
     }), (120, {
         'a': 1,
         'b': 2
     }), (144, {
         'a': 2,
         'b': 4
     }), (168, {
         'a': 3,
         'b': 6
     }), (192, {
         'a': 4,
         'b': 8
     })])
Beispiel #2
0
 def test_exhausting_schedule(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 97, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule2(time, func, a, b), clock=self.clock)
     self.runTicks(96)
     player.resumePlaying()
     self.runTicks(192)
     expected = [(96, {
         'a': 0,
         'b': 0
     }), (120, {
         'a': 1,
         'b': 2
     }), (144, {
         'a': 2,
         'b': 4
     }), (168, {
         'a': 3,
         'b': 6
     }), (192, {
         'a': 4,
         'b': 8
     })]
     self.assertEquals(func.calls, expected)
Beispiel #3
0
class Player(OneSchedulePlayerMixin):

    onMethodName = 'noteon'
    offMethodName = 'noteoff'

    def __init__(self, instr, note, velocity=None, release=None,
                 interval=(1, 8), time=None, clock=None, cc=None):
        """
        @param note: A ugen for notes
        @param velocity: A ugen for the velocity
        @param release: A ugen for the release (amount of time before calling
        noteoff)
        @param time: A ugen for relative time (values returned must be greater
        than or equal to previously returned value - monotonically increasing)
        @param interval: An interval division (e.g. C{(1, 4)}) that may be
        specified as an alternative to time--this creates a metronome with the
        given interval.
        @param cc: C{dict} of control-change ugens.
        @param clock: A L{BeatClock} (defaults to global default clock)
        """
        self.instr = IMIDIInstrument(instr)
        self.clock = getClock(clock)
        if velocity is None:
            velocity = cycle([127]).next
        if release is None:
            release = cycle([None]).next
        self.note = note
        self.velocity = velocity
        self.release = release
        self.cc = cc
        self.time = timing(self.clock, time, interval)
        noteMemo = CallMemo(lambda: self.note())
        noteonSchedule = schedule(self.time, self.noteon,
                                  {'note': noteMemo,
                                   'velocity': (lambda: self.velocity())})
        self.schedulePlayer = SchedulePlayer(noteonSchedule, self.clock)
        releaseChild = childSchedule(self._scheduleNoteoff,
                                 {'note': noteMemo.lastValue,
                                  'when': (lambda: self.release())})
        self.schedulePlayer.addChild(releaseChild)
        if cc:
            ccChild = childSchedule(self.instr.controlChange, self.cc)
            self.schedulePlayer.addChild(ccChild)

    def noteon(self, note, velocity):
        m = getattr(self.instr, self.onMethodName)
        return m(note, velocity)

    def noteoff(self, note):
        m = getattr(self.instr, self.offMethodName)
        return m(note)

    def _scheduleNoteoff(self, note, when):
        if when is None:
            return
        self.clock.callLater(when, self.noteoff, note)
Beispiel #4
0
 def test_time_in_past_busts_the_scheduler(self):
     func = TestFunc(self.clock)
     time = (v for v in [0, 24, 12, 48, 96]).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     player.resumePlaying()
     self.runTicks(96)
     self.assert_(self.flushLoggedErrors())
     expected = [(0, {'a': 0, 'b': 0}), (24, {'a': 1, 'b': 2})]
     self.assertEquals(func.calls, expected)
Beispiel #5
0
 def test_time_in_past_busts_the_scheduler(self):
     func = TestFunc(self.clock)
     time = (v for v in [0, 24, 12, 48, 96]).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b),
                             clock=self.clock)
     player.resumePlaying()
     self.runTicks(96)
     self.assert_(self.flushLoggedErrors())
     expected = [(0, {'a': 0, 'b': 0}), (24, {'a': 1, 'b': 2})]
     self.assertEquals(func.calls, expected)
Beispiel #6
0
 def test_exhausting_schedule(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 97, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule2(time, func, a, b),
                             clock=self.clock)
     self.runTicks(96)
     player.resumePlaying()
     self.runTicks(192)
     expected = [(96, {'a': 0, 'b': 0}), (120, {'a': 1, 'b': 2}),
                 (144, {'a':2, 'b': 4}), (168, {'a': 3, 'b': 6}),
                 (192, {'a': 4, 'b':8})]
     self.assertEquals(func.calls, expected)
Beispiel #7
0
 def test_pause(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     player.pause()
     self.runTicks(96)
     expected = [(96, {
         'a': 0,
         'b': 0
     }), (120, {
         'a': 1,
         'b': 2
     }), (144, {
         'a': 2,
         'b': 4
     }), (168, {
         'a': 3,
         'b': 6
     }), (192, {
         'a': 4,
         'b': 8
     })]
     self.assertEquals(func.calls, expected)
     player.play()
     self.runTicks(96 * 2)
     expected.extend([(288, {
         'a': 5,
         'b': 10
     }), (312, {
         'a': 6,
         'b': 12
     }), (336, {
         'a': 7,
         'b': 14
     }), (360, {
         'a': 8,
         'b': 16
     }), (384, {
         'a': 9,
         'b': 18
     }), (408, {
         'a': 10,
         'b': 20
     }), (432, {
         'a': 11,
         'b': 22
     }), (456, {
         'a': 12,
         'b': 24
     }), (480, {
         'a': 13,
         'b': 26
     })])
     self.assertEquals(func.calls, expected)
Beispiel #8
0
 def test_basic(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     self.assertEquals(func.calls,
                       [(96, {'a': 0, 'b': 0}), (120, {'a': 1, 'b': 2}),
                        (144, {'a':2, 'b': 4}), (168, {'a': 3, 'b': 6}),
                        (192, {'a': 4, 'b':8})])
Beispiel #9
0
 def test_pausePlaying(self):
     func = TestFunc(self.clock)
     time = (v for v in [24, 48, 108, 120, 144, 168, 192, 288]).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     player.resumePlaying()
     self.runTicks(1)
     player.pausePlaying()
     self.runTicks(191)
     player.resumePlaying()
     self.runTicks(96)
     expected = [(24, {
         'a': 0,
         'b': 0
     }), (48, {
         'a': 1,
         'b': 2
     }), (204, {
         'a': 2,
         'b': 4
     }), (216, {
         'a': 3,
         'b': 6
     }), (240, {
         'a': 4,
         'b': 8
     }), (264, {
         'a': 5,
         'b': 10
     }), (288, {
         'a': 6,
         'b': 12
     })]
     self.assertEquals(func.calls, expected)
Beispiel #10
0
 def test_children_that_stop(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     func2 = TestFunc(self.clock)
     c = (v for v in xrange(0, 1024, 7)).next
     func3 = TestFunc(self.clock)
     d = (v for v in xrange(0, 1024, 3)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     g1 = ((func2, {'z': c}) for i in cycle([1]))
     player.addChild(g1)
     g2 = ((func3, {'z': d}) for i in range(3))
     player.addChild(g2)
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     self.assertEquals(func.calls,
                       [(96, {'a': 0, 'b': 0}), (120, {'a': 1, 'b': 2}),
                        (144, {'a':2, 'b': 4}), (168, {'a': 3, 'b': 6}),
                        (192, {'a': 4, 'b':8})])
     self.assertEquals(func2.calls,
                       [(96, {'z': 0}), (120, {'z': 7}), (144, {'z': 14}),
                        (168, {'z': 21}), (192, {'z': 28})])
     self.assertEquals(func3.calls, [(96, {'z': 0}), (120, {'z': 3}),
                                    (144, {'z': 6})])
     self.failIf(g2 in player._scheduleChildren)
     self.assert_(g1 in player._scheduleChildren)
Beispiel #11
0
 def test_children_that_stop(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     func2 = TestFunc(self.clock)
     c = (v for v in xrange(0, 1024, 7)).next
     func3 = TestFunc(self.clock)
     d = (v for v in xrange(0, 1024, 3)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     g1 = ((func2, {'z': c}) for i in cycle([1]))
     player.addChild(g1)
     g2 = ((func3, {'z': d}) for i in range(3))
     player.addChild(g2)
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     self.assertEquals(func.calls, [(96, {
         'a': 0,
         'b': 0
     }), (120, {
         'a': 1,
         'b': 2
     }), (144, {
         'a': 2,
         'b': 4
     }), (168, {
         'a': 3,
         'b': 6
     }), (192, {
         'a': 4,
         'b': 8
     })])
     self.assertEquals(func2.calls, [(96, {
         'z': 0
     }), (120, {
         'z': 7
     }), (144, {
         'z': 14
     }), (168, {
         'z': 21
     }), (192, {
         'z': 28
     })])
     self.assertEquals(func3.calls, [(96, {
         'z': 0
     }), (120, {
         'z': 3
     }), (144, {
         'z': 6
     })])
     self.failIf(g2 in player._scheduleChildren)
     self.assert_(g1 in player._scheduleChildren)
Beispiel #12
0
 def __init__(self, pyo, time=None, interval=(1, 8), clock=None, args=None):
     if args is None:
         args = {}
     self.pyo = pyo
     self._gatherMethods()
     self.clock = getClock(clock)
     self.time = timing(self.clock, time, interval)
     sched = schedule(self.time, self.modulate, args)
     self.args = args
     self.schedulePlayer = SchedulePlayer(sched, self.clock)
Beispiel #13
0
class Player(OneSchedulePlayerMixin):

    onMethodName = 'noteon'
    offMethodName = 'noteoff'

    def __init__(self, instr, note, velocity=None, release=None,
                 interval=(1, 8), time=None, clock=None, cc=None):
        self.instr = IMIDIInstrument(instr)
        self.clock = getClock(clock)
        if velocity is None:
            velocity = cycle([127]).next
        self.note = note
        self.velocity = velocity
        self.release = release
        self.cc = cc
        self.time = timing(self.clock, time, interval)
        noteMemo = CallMemo(lambda: self.note())
        noteonSchedule = schedule(self.time, self.noteon,
                                  {'note': noteMemo,
                                   'velocity': (lambda: self.velocity())})
        self.schedulePlayer = SchedulePlayer(noteonSchedule, self.clock)
        if self.release:
            releaseChild = childSchedule(self._scheduleNoteoff,
                                     {'note': noteMemo.lastValue,
                                      'when': (lambda: self.release())})
            self.schedulePlayer.addChild(releaseChild)
        if cc:
            ccChild = childSchedule(self.instr.controlChange, self.cc)
            self.schedulePlayer.addChild(ccChild)

    def noteon(self, note, velocity):
        m = getattr(self.instr, self.onMethodName)
        return m(note, velocity)

    def noteoff(self, note):
        m = getattr(self.instr, self.offMethodName)
        return m(note)

    def _scheduleNoteoff(self, note, when):
        if when is None:
            return
        self.clock.callLater(when, self.noteoff, note)
Beispiel #14
0
 def test_children(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     func2 = TestFunc(self.clock)
     c = (v for v in xrange(0, 1024, 7)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     player.addChild(((func2, {'z': c}) for i in cycle([1])))
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     self.assertEquals(func.calls,
                       [(96, {'a': 0, 'b': 0}), (120, {'a': 1, 'b': 2}),
                        (144, {'a':2, 'b': 4}), (168, {'a': 3, 'b': 6}),
                        (192, {'a': 4, 'b':8})])
     self.assertEquals(func2.calls,
                       [(96, {'z': 0}), (120, {'z': 7}), (144, {'z': 14}),
                        (168, {'z': 21}), (192, {'z': 28})])
Beispiel #15
0
 def test_pausePlaying(self):
     func = TestFunc(self.clock)
     time = (v for v in [24, 48, 108, 120, 144, 168, 192, 288]).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     player.resumePlaying()
     self.runTicks(1)
     player.pausePlaying()
     self.runTicks(191)
     player.resumePlaying()
     self.runTicks(96)
     expected = [(24, {'a': 0, 'b': 0}), (48, {'a': 1, 'b': 2}),
                 (204, {'a': 2, 'b': 4}), (216, {'a': 3, 'b': 6}),
                 (240, {'a': 4, 'b': 8}), (264, {'a': 5, 'b': 10}),
                 (288, {'a': 6, 'b': 12})]
     self.assertEquals(func.calls, expected)
Beispiel #16
0
 def __init__(self, instr, note, velocity=None, release=None,
              interval=(1, 8), time=None, clock=None, cc=None):
     self.instr = IMIDIInstrument(instr)
     self.clock = getClock(clock)
     if velocity is None:
         velocity = cycle([127]).next
     self.note = note
     self.velocity = velocity
     self.release = release
     self.cc = cc
     self.time = timing(self.clock, time, interval)
     noteMemo = CallMemo(lambda: self.note())
     noteonSchedule = schedule(self.time, self.noteon,
                               {'note': noteMemo,
                                'velocity': (lambda: self.velocity())})
     self.schedulePlayer = SchedulePlayer(noteonSchedule, self.clock)
     if self.release:
         releaseChild = childSchedule(self._scheduleNoteoff,
                                  {'note': noteMemo.lastValue,
                                   'when': (lambda: self.release())})
         self.schedulePlayer.addChild(releaseChild)
     if cc:
         ccChild = childSchedule(self.instr.controlChange, self.cc)
         self.schedulePlayer.addChild(ccChild)
Beispiel #17
0
 def test_pause(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     player.pause()
     self.runTicks(96)
     expected = [(96, {'a': 0, 'b': 0}), (120, {'a': 1, 'b': 2}),
                 (144, {'a':2, 'b': 4}), (168, {'a': 3, 'b': 6}),
                 (192, {'a': 4, 'b':8})]
     self.assertEquals(func.calls, expected)
     player.play()
     self.runTicks(96 * 2)
     expected.extend([(288, {'a': 5, 'b': 10}), (312, {'a': 6, 'b': 12}),
                      (336, {'a': 7, 'b': 14}), (360, {'a': 8, 'b': 16}),
                      (384, {'a': 9, 'b': 18}), (408, {'a': 10, 'b': 20}),
                      (432, {'a': 11, 'b': 22}), (456, {'a': 12, 'b': 24}),
                      (480, {'a': 13, 'b': 26})])
     self.assertEquals(func.calls, expected)
Beispiel #18
0
 def test_children(self):
     func = TestFunc(self.clock)
     time = (v for v in xrange(0, 1024, 24)).next
     a = (v for v in xrange(1024)).next
     b = (v for v in xrange(0, 1024, 2)).next
     func2 = TestFunc(self.clock)
     c = (v for v in xrange(0, 1024, 7)).next
     player = SchedulePlayer(schedule(time, func, a, b), clock=self.clock)
     player.addChild(((func2, {'z': c}) for i in cycle([1])))
     self.runTicks(25)
     self.assertEquals(func.calls, [])
     player.resumePlaying()
     self.runTicks((96 - 25) + 96)
     self.assertEquals(func.calls, [(96, {
         'a': 0,
         'b': 0
     }), (120, {
         'a': 1,
         'b': 2
     }), (144, {
         'a': 2,
         'b': 4
     }), (168, {
         'a': 3,
         'b': 6
     }), (192, {
         'a': 4,
         'b': 8
     })])
     self.assertEquals(func2.calls, [(96, {
         'z': 0
     }), (120, {
         'z': 7
     }), (144, {
         'z': 14
     }), (168, {
         'z': 21
     }), (192, {
         'z': 28
     })])