class MeterTests(TestCase): def setUp(self): self.meterStandard = Meter(4, 4) self.meter34 = Meter(3, 4) self.meter54 = Meter(5, 4) self.meter98 = Meter(9, 8) def test_beat(self): beats = [] for i in range(96 * 2): beats.append(self.meterStandard.beat(i)) self.assertEquals(beats, data.measure_standard_beats) beats = [] for i in range(96 * 2): beats.append(self.meter34.beat(i)) self.assertEquals(beats, data.measure_34_beats) beats = [] for i in range(96 * 2): beats.append(self.meter54.beat(i)) self.assertEquals(beats, data.measure_54_beats) beats = [] for i in range(96 * 2): beats.append(self.meter98.beat(i)) self.assertEquals(beats, data.measure_98_beats)
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_record_with_non_standard_meter(self): loopRecorder = LoopRecorder(1, self.clock, Meter(3, 4)) for c in 'abcde': loopRecorder.record(c) self.runTicks(24) current = loopRecorder.latch() self.assertEquals(current, [('a', 0), ('b', 24), ('c', 48)])
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
def test_record_and_latch(self): self.runTicks(23) loopRecorder = LoopRecorder(1, self.clock, Meter(4, 4)) self.runTicks(73) for c in 'abcdefghi': loopRecorder.record(c) self.runTicks(24) current = loopRecorder.latch() self.assertEquals(current, [('e', 0), ('f', 24), ('g', 48), ('h', 72)]) last = loopRecorder.latch(1) self.assertEquals(last, [('a', 0), ('b', 24), ('c', 48), ('d', 72)])
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()
def test_divisionToTicks(self): tempo = Tempo() meter = Meter(4, 4, tempo=tempo) self.assertEquals(meter.divisionToTicks(1, 4), 24) self.assertEquals(meter.divisionToTicks(3, 4), 72) self.assertEquals(meter.divisionToTicks(1, 1), 96) self.assertEquals(meter.divisionToTicks(8, 4), 192) self.assertEquals(meter.divisionToTicks(1, 12), 8) tempo = Tempo(bpm=120, tpb=96) meter = Meter(4, 4, tempo=tempo) self.assertEquals(meter.divisionToTicks(1, 4), 96) self.assertEquals(meter.divisionToTicks(3, 4), 96 * 3) self.assertEquals(meter.divisionToTicks(1, 1), 96 * 4) self.assertEquals(meter.divisionToTicks(8, 4), 96 * 8) self.assertEquals(meter.divisionToTicks(1, 12), 32) self.assertEquals(meter.divisionToTicks(1, 48), 8) self.assertEquals(meter.divisionToTicks(1, 128), 3) self.assertEquals(meter.divisionToTicks(1, 192), 2)
def test_ticks_are_relative_to_loop_start(self): loopRecorder = LoopRecorder(3, self.clock, Meter(4, 4)) self.runTicks(12) loopRecorder.record('a') self.runTicks(84) loopRecorder.record('b') self.runTicks(12) loopRecorder.record('c') self.runTicks(84) loopRecorder.record('d') self.runTicks(12) loopRecorder.record('e') self.runTicks(84) loopRecorder.record('f') current = loopRecorder.latch() self.assertEquals(current, [('a', 12), ('b', 96), ('c', 108), ('d', 192), ('e', 204)])
def test_max_loop_depth(self): loopRecorder = LoopRecorder(1, self.clock, Meter(4, 4)) for i in range(80): loopRecorder.record(i) self.runTicks(24) self.assertEquals(len(loopRecorder._loops), 10)
def test_divitionToTicksNonStandardMeasure(self): tempo = Tempo() meter = Meter(3, 4, tempo=tempo) self.assertEquals(meter.divisionToTicks(1, 4), 24) meter = Meter(7, 8, tempo=tempo) self.assertEquals(meter.divisionToTicks(1, 4), 24)
def setUp(self): self.meterStandard = Meter(4, 4) self.meter34 = Meter(3, 4) self.meter54 = Meter(5, 4) self.meter98 = Meter(9, 8)
def toMeter(s, tempo): count, division = s.split('/') return Meter(int(count), int(division), tempo=tempo)
def test_invalidDivisionToTicks(self): tempo = Tempo() meter = Meter(4, 4, tempo=tempo) self.assertRaises(ValueError, meter.dtt, 1, 192) self.assertRaises(ValueError, meter.dtt, 1, 25) self.assertRaises(ValueError, meter.dtt, 1, 7) tempo.reset(tpb=192) meter.resetTempo(tempo) meter.dtt(1, 192) tempo.reset(tpb=25) meter.resetTempo(tempo) meter.dtt(1, 25) tempo.reset(tpb=24 * 7) meter.resetTempo(tempo) meter.dtt(1, 7) meter.strict = False tempo.reset(tpb=24) meter.resetTempo(tempo) meter.dtt(1, 192) meter.dtt(1, 25) meter.dtt(1, 7) errors = self.flushLoggedErrors() self.assertEquals(len(errors), 3)
def test_nextDivision(self): ticks = 0 tempo = Tempo() meter = Meter(4, 4, tempo=tempo) self.assertEquals(meter.nextDivision(ticks, 1, 4), 24) self.assertEquals(meter.nextDivision(ticks, 2, 4), 48) self.assertEquals(meter.nextDivision(ticks, 1, 1), 96) self.assertEquals(meter.nextDivision(ticks, 5, 4), 96 + 24) ticks = 48 self.assertEquals(meter.nextDivision(ticks, 1, 4), 96 + 24) self.assertEquals(meter.nextDivision(ticks, 2, 4), 48) self.assertEquals(meter.nextDivision(ticks, 1, 1), 96) self.assertEquals(meter.nextDivision(ticks, 5, 4), 96 + 24) ticks = 96 + 48 self.assertEquals(meter.nextDivision(ticks, 1, 4), (96 * 2) + 24) self.assertEquals(meter.nextDivision(ticks, 2, 4), 96 + 48) self.assertEquals(meter.nextDivision(ticks, 1, 1), 96 * 2) self.assertEquals(meter.nextDivision(ticks, 5, 4), (96 * 2) + 24) ticks = 0 tempo = Tempo(tpb=48) meter = Meter(4, 4, tempo=tempo) self.assertEquals(meter.nextDivision(ticks, 1, 4), 48) self.assertEquals(meter.nextDivision(ticks, 2, 4), 96) self.assertEquals(meter.nextDivision(ticks, 1, 1), 192) self.assertEquals(meter.nextDivision(ticks, 5, 4), 240) ticks = 96 self.assertEquals(meter.nextDivision(ticks, 1, 4), 240) self.assertEquals(meter.nextDivision(ticks, 2, 4), 96) self.assertEquals(meter.nextDivision(ticks, 1, 1), 192) self.assertEquals(meter.nextDivision(ticks, 5, 4), 240) ticks = 192 + 96 self.assertEquals(meter.nextDivision(ticks, 1, 4), (192 * 2) + 48) self.assertEquals(meter.nextDivision(ticks, 2, 4), 192 + 96) self.assertEquals(meter.nextDivision(ticks, 1, 1), 192 * 2) self.assertEquals(meter.nextDivision(ticks, 5, 4), (192 * 2) + 48)
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())
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)