Пример #1
0
 def setUp(self):
     self.meters = [Meter(4, 4), Meter(3, 4)]
     self.meterStandard = self.meters[0]
     self.meter34 = self.meters[1]
     self.clock = BeatClock(Tempo(135),
                            meters=self.meters,
                            reactor=TestReactor())
Пример #2
0
def runWithProtocol(klass, audioDev, channels, bpm, tpb, meter):
    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    tempo = Tempo(bpm, tpb)
    meter = toMeter(meter, tempo)
    try:
        # TODO - cleaner strategy for collecting parameters and
        # initializing fluidsynth
        # - initializing fluidsynth shouldn't be necessary
        if EXPERIMENTAL:
            from bl.sync import SystemClock
            clock = BeatClock(tempo=tempo,
                              meter=meter,
                              default=True,
                              syncClockClass=SystemClock)
        else:
            clock = BeatClock(tempo=tempo, meter=meter, default=True)
        clock.synthAudioDevice = audioDev
        clock.synthChannels = channels
        p = ServerProtocol(klass)
        stdio.StandardIO(p)
        clock.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, "\r\x1bc\r")
Пример #3
0
 def setUp(self):
     checkPypm()
     tempo = Tempo(135)
     self.clock = BeatClock(tempo, reactor=TestReactor())
     self.instr1 = TestInstrument(self.clock)
     self.instr2 = TestInstrument(self.clock)
     self.handler = NoteOnOffHandler({1: self.instr1, 2: self.instr2})
Пример #4
0
 def test_defaultMeterIsStandard(self):
     clock = BeatClock(Tempo(120))
     self.assertEquals(len(clock.meters), 1)
     meter = clock.meter
     self.assertEquals(meter.length, 4)
     self.assertEquals(meter.division, 4)
     self.assertEquals(meter.number, 1)
Пример #5
0
 def setUp(self):
     checkPypm()
     tempo = Tempo(120)
     self.clock = BeatClock(tempo, reactor=TestReactor())
     self.patch(pypm, 'Time', FakeTime(self.clock).Time)
     self.midiout = FakeMidiOutput()
     self.clockSender = ClockSender(self.midiout, clock=self.clock)
     self.clockSender.start()
Пример #6
0
 def setUp(self):
     tempo = Tempo(135)
     self.meter = Meter(4, 4, tempo=tempo)
     self.meterStandard = self.meter
     self.clock = BeatClock(tempo, meter=self.meter, reactor=TestReactor())
     self.instr1 = TestInstrument(self.clock)
     self.instr2 = TestInstrument(self.clock)
     self.dtt = self.clock.meter.dtt
Пример #7
0
    def setUp(self):
        random.seed(0)
        testReactor = TestReactor()
        clockBefore = BeatClock.defaultClock
        self.clock = BeatClock(reactor=testReactor, default=True)
        self.patch(Instrument, 'recorder', Recorder(self.clock))

        def reset():
            BeatClock.defaultClock = clockBefore
            scheduler.clock = clockBefore

        self.addCleanup(reset)
Пример #8
0
 def setUp(self):
     checkPypm()
     tempo = Tempo(153)
     self.meter = Meter(4, 4, tempo=tempo)
     self.clock = BeatClock(tempo=tempo,
                            meter=self.meter,
                            reactor=TestReactor())
     self.midiin = FakeMidiInput()
     self.midiin._buffer.extend([[NOTEON_CHAN1, i % 128, 100, 0], i]
                                for i in range(32 * 3 + 5))
     self.handler = TestHandler()
     self.dispatcher = MidiDispatcher(self.midiin, [self.handler],
                                      clock=self.clock)
     self.dispatcher.start()
Пример #9
0
def runWithProtocol(klass, audioDev, channels, bpm, tpb, meter):
    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    tempo = Tempo(bpm, tpb)
    meter = toMeter(meter, tempo)
    try:
        # TODO - cleaner strategy for collecting parameters and
        # initializing fluidsynth
        # - initializing fluidsynth shouldn't be necessary
        if EXPERIMENTAL:
            from bl.sync import SystemClock
            clock = BeatClock(tempo=tempo, meter=meter, default=True,
                              syncClockClass=SystemClock)
        else:
            clock = BeatClock(tempo=tempo, meter=meter, default=True)
        clock.synthAudioDevice = audioDev
        clock.synthChannels = channels
        p = ServerProtocol(klass)
        stdio.StandardIO(p)
        clock.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, "\r\x1bc\r")
Пример #10
0
 def setUp(self):
     self.clock = BeatClock(reactor=TestReactor())
Пример #11
0
class ClockTests(TestCase, ClockRunner):

    def setUp(self):
        self.meters = [Meter(4, 4), Meter(3, 4)]
        self.meterStandard = self.meters[0]
        self.meter34 = self.meters[1]
        self.clock = BeatClock(Tempo(135), meters=self.meters,
                               reactor=TestReactor())

    def test_defaultMeterIsStandard(self):
        clock = BeatClock(Tempo(120))
        self.assertEquals(len(clock.meters), 1)
        meter = clock.meter
        self.assertEquals(meter.length, 4)
        self.assertEquals(meter.division, 4)
        self.assertEquals(meter.number, 1)

    def test_startAfterTicks(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        n = self.clock.meter.dtt
        nm = self.clock.meter.nm

        self.clock.schedule(instr1).startAfterTicks(0, n(1, 4))
        self._runTicks(96 * 2)

        expected = [(0, 'f1'), (24, 'f1'), (48, 'f1'), (72, 'f1'), (96, 'f1'),
                    (120, 'f1'), (144, 'f1'), (168, 'f1'), (192, 'f1')]
        self.assertEquals(called, expected)

        called[:] = []

        instr2 = TestInstrument('f2', self.clock, called)

        t = self.clock.ticks
        self.clock.schedule(instr2).startAfterTicks(nm(t, 1) - t, n(1, 3))
        self._runTicks(96 * 2)
        expected = [(216, 'f1'), (240, 'f1'), (264, 'f1'), (288, 'f2'),
                    (288, 'f1'), (312, 'f1'), (320, 'f2'), (336, 'f1'),
                    (352, 'f2'), (360, 'f1'), (384, 'f2'), (384, 'f1')]
        self.assertEquals(called, expected)

    def test_startAfter(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        self.clock.schedule(instr1).startAfter((0, 1), (1, 4))
        self._runTicks(96 * 2)

        expected = [(0, 'f1'), (24, 'f1'), (48, 'f1'), (72, 'f1'), (96, 'f1'),
                    (120, 'f1'), (144, 'f1'), (168, 'f1'), (192, 'f1')]
        self.assertEquals(called, expected)

        called[:] = []

        instr2 = TestInstrument('f2', self.clock, called)

        self.clock.schedule(instr2).startAfter((1, 1), (1, 3))
        self._runTicks(96 * 2)
        expected = [(216, 'f1'), (240, 'f1'), (264, 'f1'), (288, 'f2'),
                    (288, 'f1'), (312, 'f1'), (320, 'f2'), (336, 'f1'),
                    (352, 'f2'), (360, 'f1'), (384, 'f2'), (384, 'f1')]
        self.assertEquals(called, expected)

    def test_stopAfterTicks(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        nm = self.clock.meter.nextMeasure
        n = self.clock.meter.dtt
        t = self.clock.ticks

        self.clock.schedule(instr1).startAfterTicks(nm(t, 1), n(1, 4)
                ).stopAfterTicks(nm(t, 3) + n(1, 2))
        self._runTicks(96 * 5)
        expected = [
            (96,  'f1'),
            (120, 'f1'),
            (144, 'f1'),
            (168, 'f1'),
            (192, 'f1'),
            (216, 'f1'),
            (240, 'f1'),
            (264, 'f1'),
            (288, 'f1'),
            (312, 'f1')]

        self.assertEquals(len(called), len(expected))
        self.assertEquals(called, expected)

    def test_stopAfter(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        self.clock.schedule(instr1).startAfter((0, 1), (1, 4)
                ).stopAfter((2, 1))
        self._runTicks(96 * 3)

        expected = [(0, 'f1'), (24, 'f1'), (48, 'f1'), (72, 'f1'), (96, 'f1'),
                    (120, 'f1'), (144, 'f1'), (168, 'f1')]
        self.assertEquals(called, expected)

    def test_setTempo(self):
        self.clock.setTempo(Tempo(60))
        interval_before = 60. / self.clock.tempo.tpm
        called = []
        self.clock.startTicking()
        self.clock.on_stop.addCallback(called.append)
        self.clock.setTempo(Tempo(120))
        self.assertEquals(len(called), 1)
        self.assertEquals(60. / self.clock.tempo.tpm, interval_before / 2.)
        self.clock.task.stop()

    def test_nudge(self):
        self.clock.startTicking()
        self.clock.nudge()
        self.assertEquals(self.clock.reactor.scheduled,
            [(0.1, self.clock.task.start, (60. / self.clock.tempo.tpm, True),
             {})])
        self.clock.task.start(1, True)
        self.clock.nudge(pause=0.5)
        self.assertEquals(self.clock.reactor.scheduled,
            [(0.1, self.clock.task.start, (60. / self.clock.tempo.tpm, True),
             {}),
             (0.5, self.clock.task.start, (60. / self.clock.tempo.tpm, True),
             {})])
Пример #12
0
class ClockTests(TestCase, ClockRunner):
    def setUp(self):
        self.meters = [Meter(4, 4), Meter(3, 4)]
        self.meterStandard = self.meters[0]
        self.meter34 = self.meters[1]
        self.clock = BeatClock(Tempo(135),
                               meters=self.meters,
                               reactor=TestReactor())

    def test_defaultMeterIsStandard(self):
        clock = BeatClock(Tempo(120))
        self.assertEquals(len(clock.meters), 1)
        meter = clock.meter
        self.assertEquals(meter.length, 4)
        self.assertEquals(meter.division, 4)
        self.assertEquals(meter.number, 1)

    def test_startAfterTicks(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        n = self.clock.meter.dtt
        nm = self.clock.meter.nm

        self.clock.schedule(instr1).startAfterTicks(0, n(1, 4))
        self._runTicks(96 * 2)

        expected = [(0, 'f1'), (24, 'f1'), (48, 'f1'), (72, 'f1'), (96, 'f1'),
                    (120, 'f1'), (144, 'f1'), (168, 'f1'), (192, 'f1')]
        self.assertEquals(called, expected)

        called[:] = []

        instr2 = TestInstrument('f2', self.clock, called)

        t = self.clock.ticks
        self.clock.schedule(instr2).startAfterTicks(nm(t, 1) - t, n(1, 3))
        self._runTicks(96 * 2)
        expected = [(216, 'f1'), (240, 'f1'), (264, 'f1'), (288, 'f2'),
                    (288, 'f1'), (312, 'f1'), (320, 'f2'), (336, 'f1'),
                    (352, 'f2'), (360, 'f1'), (384, 'f2'), (384, 'f1')]
        self.assertEquals(called, expected)

    def test_startAfter(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        self.clock.schedule(instr1).startAfter((0, 1), (1, 4))
        self._runTicks(96 * 2)

        expected = [(0, 'f1'), (24, 'f1'), (48, 'f1'), (72, 'f1'), (96, 'f1'),
                    (120, 'f1'), (144, 'f1'), (168, 'f1'), (192, 'f1')]
        self.assertEquals(called, expected)

        called[:] = []

        instr2 = TestInstrument('f2', self.clock, called)

        self.clock.schedule(instr2).startAfter((1, 1), (1, 3))
        self._runTicks(96 * 2)
        expected = [(216, 'f1'), (240, 'f1'), (264, 'f1'), (288, 'f2'),
                    (288, 'f1'), (312, 'f1'), (320, 'f2'), (336, 'f1'),
                    (352, 'f2'), (360, 'f1'), (384, 'f2'), (384, 'f1')]
        self.assertEquals(called, expected)

    def test_stopAfterTicks(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        nm = self.clock.meter.nextMeasure
        n = self.clock.meter.dtt
        t = self.clock.ticks

        self.clock.schedule(instr1).startAfterTicks(nm(t, 1), n(
            1, 4)).stopAfterTicks(nm(t, 3) + n(1, 2))
        self._runTicks(96 * 5)
        expected = [(96, 'f1'), (120, 'f1'), (144, 'f1'), (168, 'f1'),
                    (192, 'f1'), (216, 'f1'), (240, 'f1'), (264, 'f1'),
                    (288, 'f1'), (312, 'f1')]

        self.assertEquals(len(called), len(expected))
        self.assertEquals(called, expected)

    def test_stopAfter(self):
        called = []

        instr1 = TestInstrument('f1', self.clock, called)

        self.clock.schedule(instr1).startAfter((0, 1), (1, 4)).stopAfter(
            (2, 1))
        self._runTicks(96 * 3)

        expected = [(0, 'f1'), (24, 'f1'), (48, 'f1'), (72, 'f1'), (96, 'f1'),
                    (120, 'f1'), (144, 'f1'), (168, 'f1')]
        self.assertEquals(called, expected)

    def test_setTempo(self):
        self.clock.setTempo(Tempo(60))
        interval_before = 60. / self.clock.tempo.tpm
        called = []
        self.clock.startTicking()
        self.clock.on_stop.addCallback(called.append)
        self.clock.setTempo(Tempo(120))
        self.assertEquals(len(called), 1)
        self.assertEquals(60. / self.clock.tempo.tpm, interval_before / 2.)
        self.clock.task.stop()

    def test_nudge(self):
        self.clock.startTicking()
        self.clock.nudge()
        self.assertEquals(self.clock.reactor.scheduled,
                          [(0.1, self.clock.task.start,
                            (60. / self.clock.tempo.tpm, True), {})])
        self.clock.task.start(1, True)
        self.clock.nudge(pause=0.5)
        self.assertEquals(self.clock.reactor.scheduled,
                          [(0.1, self.clock.task.start,
                            (60. / self.clock.tempo.tpm, True), {}),
                           (0.5, self.clock.task.start,
                            (60. / self.clock.tempo.tpm, True), {})])
Пример #13
0
 def setUp(self):
     self.tempo = Tempo(135)
     self.meter = Meter(4, 4, tempo=self.tempo)
     self.clock = BeatClock(tempo=self.tempo,
                            meter=self.meter,
                            reactor=TestReactor())
Пример #14
0
 def setUp(self):
     self.clock = BeatClock(reactor=TestReactor())
     self.pyo = DummyPyoObject()
Пример #15
0
 def setUp(self):
     self.meters = [Meter(4, 4), Meter(3, 4)]
     self.meterStandard = self.meters[0]
     self.meter34 = self.meters[1]
     self.clock = BeatClock(Tempo(135), meters=self.meters,
                            reactor=TestReactor())
Пример #16
0
 def setUp(self):
     tempo = Tempo(135)
     self.meter = Meter(4, 4, tempo=tempo)
     self.clock = BeatClock(tempo, meter=self.meter, reactor=TestReactor())
     self.instr = TestInstrument(self.clock)
Пример #17
0
 def setUp(self):
     tempo = Tempo(135)
     self.clock = BeatClock(tempo, reactor=TestReactor())
     self.phraseRecorder = PhraseRecordingArp(self.clock)