Example #1
0
def test_pattern_lshift():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 << 1) == [2, 4, 6]
    assert list(1 << p1) == [2, 4, 8]

    p2 = iso.PSequence([2, 4, 6, 8], 1)
    assert list(p2 << p1) == [4, 16, 48]
Example #2
0
def test_pattern_rshift():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 >> 1) == [0, 1, 1]
    assert list(1 >> p1) == [0, 0, 0]

    p2 = iso.PSequence([4, 8, 16, 32], 1)
    assert list(p2 >> p1) == [2, 2, 2]
Example #3
0
def test_pattern_mod():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 % 2) == [1, 0, 1]
    assert list(2 % p1) == [0, 0, 2]

    p2 = iso.PSequence([2, 4, 6, 8], 1)
    assert list(p2 % p1) == [0, 0, 0]
Example #4
0
def test_pattern_pow():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 ** 2) == [1, 4, 9]
    assert list(2 ** p1) == [2, 4, 8]

    p2 = iso.PSequence([2, 4, 6, 8], 1)
    assert list(p1 ** p2) == [1, 16, 729]
Example #5
0
def test_pattern_floordiv():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 // 2) == [0, 1, 1]
    assert list(2 // p1) == [2, 1, 0]

    p2 = iso.PSequence([2, 4, 6, 8], 1)
    assert list(p2 // p1) == [2, 2, 2]
Example #6
0
def test_pattern_add():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 + 1.5) == [2.5, 3.5, 4.5]
    assert list(-1 + p1) == [0, 1, 2]

    p2 = iso.PSequence([2, 3, 4, 5], 1)
    assert list(p1 + p2) == [3, 5, 7]
Example #7
0
def test_pattern_mul():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 * 1.5) == [1.5, 3.0, 4.5]
    assert list(-1 * p1) == [-1, -2, -3]

    p2 = iso.PSequence([2, 3, 4, 5], 1)
    assert list(p1 * p2) == [2, 6, 12]
Example #8
0
def test_pattern_div():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 / 2.0) == [0.5, 1.0, 1.5]
    assert list(2 / p1) == [2, 1, 2 / 3]

    p2 = iso.PSequence([2, 4, 6, 8], 1)
    assert list(p2 / p1) == [2, 2, 2]
Example #9
0
def test_pdegree():
    a = iso.PDegree(iso.PSequence([0, 1, -1, None, 7], 1))
    assert list(a) == [0, 2, -1, None, 12]

    # Test on array values
    a = iso.PDegree(iso.PSequence([[0, 1], [2, 3], [None, -1]], 1))
    assert list(a) == [(0, 2), (4, 5), (None, -1)]
Example #10
0
def test_pattern_sub():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert list(p1 - 0.5) == [0.5, 1.5, 2.5]
    assert list(1 + p1) == [2, 3, 4]

    p2 = iso.PSequence([2, 3, 4, 5], 1)
    assert list(p2 - p1) == [1, 1, 1]
def test_event_supercollider(dummy_timeline):
    output_device = DummySuperColliderOutputDevice()
    dummy_timeline.output_device = output_device
    dummy_timeline.schedule({
        iso.EVENT_SUPERCOLLIDER_SYNTH:
        iso.PSequence(["foo", "bar"]),
        iso.EVENT_SUPERCOLLIDER_SYNTH_PARAMS: {
            "buffer": iso.PSequence([1, 2]),
            "rate": iso.PSequence([0.5, 1, 2], 1)
        }
    })
    dummy_timeline.run()
    assert output_device.events == [
        ["foo", {
            "buffer": 1,
            "rate": 0.5
        }],
        ["bar", {
            "buffer": 2,
            "rate": 1
        }],
        ["foo", {
            "buffer": 1,
            "rate": 2
        }],
    ]
Example #12
0
def test_event_chord(dummy_timeline):
    dummy_timeline.schedule({
        iso.EVENT_NOTE:
        iso.PSequence([(0, 7), 4, (2, 9, 11), 7], 1),
        iso.EVENT_DURATION:
        iso.PSequence([1, 2]),
        iso.EVENT_AMPLITUDE:
        iso.PSequence([10, 20, 30])
    })
    dummy_timeline.run()
    assert dummy_timeline.output_device.events == [
        [0, 'note_on', 0, 10, 0],
        [0, 'note_on', 7, 10, 0],
        [1, 'note_off', 0, 0],
        [1, 'note_off', 7, 0],
        [1, 'note_on', 4, 20, 0],
        [3, 'note_off', 4, 0],
        [3, 'note_on', 2, 30, 0],
        [3, 'note_on', 9, 30, 0],
        [3, 'note_on', 11, 30, 0],
        [4, 'note_off', 2, 0],
        [4, 'note_off', 9, 0],
        [4, 'note_off', 11, 0],
        [4, 'note_on', 7, 10, 0],
        [6, 'note_off', 7, 0],
    ]
Example #13
0
def test_ppadtomultiple():
    a = iso.PSequence([1, 2, 3, 4, None, 6], 1)
    b = iso.PPadToMultiple(a, 4)
    assert list(b) == [1, 2, 3, 4, None, 6, None, None]

    a = iso.PSequence([1, None, 2], 1)
    b = iso.PPadToMultiple(a, 3)
    assert list(b) == [1, None, 2]
Example #14
0
def test_ppad():
    a = iso.PSequence([1, None, 2], 1)
    b = iso.PPad(a, 6)
    assert list(b) == [1, None, 2, None, None, None]

    a = iso.PSequence([1, None, 2], 1)
    b = iso.PPad(a, 3)
    assert list(b) == [1, None, 2]
Example #15
0
def test_pchoice_weighted():
    a = iso.PChoice(iso.PSequence([[0, 1, 2, 3], [4, 5, 6, 7]]),
                    iso.PSequence([[1, 0.5, 0.25, 0.1]]))
    a.seed(0)
    expected = [2, 5, 0, 4, 0, 4, 1, 4, 0, 5, 2, 4, 0, 5, 1, 4, 2, 7, 1, 6]
    assert a.nextn(20) == expected
    a.reset()
    assert a.nextn(20) == expected
Example #16
0
def test_pattern_copy():
    p1 = iso.PSequence([1, 2, 3], 1)
    p2 = p1.copy()
    assert p1.all() == p2.all() == [1, 2, 3]

    p1 = iso.PSequence([1, 2, 3], 1)
    next(p1)
    p2 = p1.copy()
    assert p1.all() == p2.all() == [2, 3]
Example #17
0
def test_parrayindex():
    ar = iso.PSequence([[0, 1, 2, 3, 4], [0, 1, 4, 9, 16]])
    a = iso.PSequence([0, 2, 4], 1)
    b = iso.PArrayIndex(ar, a)
    assert next(b) == 0
    assert next(b) == 4
    assert next(b) == 4
    with pytest.raises(StopIteration):
        next(b)
Example #18
0
 def generate():
     nonlocal n
     n += 1
     if n == 1:
         return iso.PSequence([0], 2)
     elif n == 2:
         return iso.PSequence([1, 2], 1)
     else:
         return None
Example #19
0
def test_pround():
    # Note that Python3 rounds x.5 to the nearest even number
    a = iso.PSequence([0, 0.1, 0.5, 1, 1.5, None, -3.9], 1)
    b = iso.PRound(a)
    assert list(b) == [0, 0, 0, 1, 2, None, -4]
    assert all(x is None or type(x) == int for x in list(b))

    a = iso.PSequence([42, 59, 0.5, -7.1, None, 1001], 1)
    b = iso.PRound(a, -1)
    assert list(b) == [40, 60, 0, -10, None, 1000]
Example #20
0
def test_pstaticpattern(dummy_timeline):
    pattern = iso.PStaticPattern(pattern=iso.PSequence([1, 2, 3, 4], 1),
                                 element_duration=iso.PSequence([1, 2, 0, 1]))
    dummy_timeline.schedule({"note": pattern})
    dummy_timeline.stop_when_done = True
    dummy_timeline.run()
    event_times = [event[0] for event in dummy_timeline.output_device.events]
    event_notes = [event[2] for event in dummy_timeline.output_device.events]
    assert event_times == [0, 1, 1, 2, 2, 3, 3, 4]
    assert event_notes == [1, 1, 2, 2, 2, 2, 4, 4]
Example #21
0
def test_pattern_value():
    p1 = iso.PSequence([1, 2, 3], 1)
    assert iso.Pattern.value(p1) == 1

    p1 = iso.PSequence([1, 2, 3], 1)
    p2 = iso.PSequence([p1])
    assert iso.Pattern.value(p2) == 1

    assert iso.Pattern.value(1) == 1
    assert iso.Pattern.value([1]) == [1]
    assert iso.Pattern.value(None) is None
Example #22
0
def test_event_dur(dummy_timeline):
    dummy_timeline.schedule({
        iso.EVENT_NOTE: iso.PSequence([1, 2, 3]),
        iso.EVENT_DURATION: iso.PSequence([1, 1.5, 2, 1.5], 1)
    })
    dummy_timeline.run()
    assert dummy_timeline.output_device.events == [
        [0, 'note_on', 1, 64, 0], [1, 'note_off', 1, 0],
        [1, 'note_on', 2, 64, 0], [2.5, 'note_off', 2, 0],
        [2.5, 'note_on', 3, 64, 0], [4.5, 'note_off', 3, 0],
        [4.5, 'note_on', 1, 64, 0], [6, 'note_off', 1, 0]
    ]
Example #23
0
def test_pref():
    a = iso.PSequence([1, 2, 3], 1)
    b = iso.PSequence([4, 5, 6], 1)
    c = iso.PRef(a)
    assert next(c) == 1
    assert next(c) == 2
    c.pattern = b
    assert next(c) == 4
    assert next(c) == 5
    assert next(c) == 6
    with pytest.raises(StopIteration):
        next(c)
Example #24
0
def test_event_scale(dummy_timeline):
    dummy_timeline.schedule({
        iso.EVENT_DEGREE: iso.PSequence([0, 1, 2, 3], 1),
        iso.EVENT_SCALE: iso.PSequence([iso.Scale.major, iso.Scale.chromatic]),
        iso.EVENT_TRANSPOSE: 36
    })
    dummy_timeline.run()
    assert dummy_timeline.output_device.events == [
        [0, 'note_on', 36, 64, 0], [1, 'note_off', 36, 0],
        [1, 'note_on', 37, 64, 0], [2, 'note_off', 37, 0],
        [2, 'note_on', 40, 64, 0], [3, 'note_off', 40, 0],
        [3, 'note_on', 39, 64, 0], [4, 'note_off', 39, 0]
    ]
Example #25
0
def test_event_key(dummy_timeline):
    dummy_timeline.schedule({
        iso.EVENT_DEGREE: iso.PSequence([0, 1, 2, 3], 1),
        iso.EVENT_KEY: iso.PSequence([iso.Key("C", "major"), iso.Key("F", "major")]),
        iso.EVENT_TRANSPOSE: 12
    })
    dummy_timeline.run()
    assert dummy_timeline.output_device.events == [
        [0, 'note_on', 12, 64, 0], [1, 'note_off', 12, 0],
        [1, 'note_on', 19, 64, 0], [2, 'note_off', 19, 0],
        [2, 'note_on', 16, 64, 0], [3, 'note_off', 16, 0],
        [3, 'note_on', 22, 64, 0], [4, 'note_off', 22, 0]
    ]
Example #26
0
def test_event_note_octave(dummy_timeline):
    dummy_timeline.schedule({
        iso.EVENT_NOTE: iso.PSequence([0, 1, 2, 3], 1),
        iso.EVENT_DURATION: 1.0,
        iso.EVENT_OCTAVE: iso.PSequence([2, 4])
    })
    dummy_timeline.run()
    assert dummy_timeline.output_device.events == [
        [0, 'note_on', 24, 64, 0], [1, 'note_off', 24, 0],
        [1, 'note_on', 49, 64, 0], [2, 'note_off', 49, 0],
        [2, 'note_on', 26, 64, 0], [3, 'note_off', 26, 0],
        [3, 'note_on', 51, 64, 0], [4, 'note_off', 51, 0]
    ]
Example #27
0
def test_pattern_all():
    p = iso.PSequence([1, 2, 3], 1)
    assert p.all() == [1, 2, 3]

    # check that the sequence is reset afterwards
    assert p.all() == [1, 2, 3]

    p = iso.PSequence([1, 2, 3], 1)
    assert p.all(2) == [1, 2]

    p1 = iso.PSequence([1, 2, 3], 1)
    p2 = iso.PSequence([1, 2, 3, 4], 1)
    p = p1 + p2
    assert p.all() == [2, 4, 6]
Example #28
0
def test_io_midifile_pdict_save(dummy_timeline):
    events = {
        iso.EVENT_NOTE: iso.PSequence([60, 62, 64, 67], 1),
        iso.EVENT_DURATION: iso.PSequence([0.5, 1.5, 1, 1], 1),
        iso.EVENT_GATE: iso.PSequence([2, 0.5, 1, 1], 1),
        iso.EVENT_AMPLITUDE: iso.PSequence([64, 32, 16, 8], 1)
    }
    pdict = iso.PDict(events)
    pdict.save("output.mid")
    d = MidiFileInputDevice("output.mid").read()
    for key in events.keys():
        assert isinstance(d[key], iso.PSequence)
        assert list(d[key]) == list(events[key])
    os.unlink("output.mid")
Example #29
0
def test_pchoice():
    a = iso.PChoice(iso.PSequence([[0, 1, 2, 3], [4, 5, 6, 7]]))
    a.seed(0)
    expected = [3, 7, 0, 6, 3, 7, 2, 7, 2, 5, 1, 6, 1, 4, 2, 5, 2, 4, 0, 6]
    assert a.nextn(20) == expected
    a.reset()
    assert a.nextn(20) == expected
Example #30
0
def test_timeline_reset(dummy_timeline):
    track = dummy_timeline.schedule({
        iso.EVENT_NOTE: iso.PSequence([1, 2], 1),
        iso.EVENT_DURATION: 1.0,
        iso.EVENT_GATE: 0.5
    })

    for n in range(dummy_timeline.ticks_per_beat):
        dummy_timeline.tick()
    assert dummy_timeline.current_time == pytest.approx(1.0)
    assert track.current_time == pytest.approx(1.0)
    dummy_timeline.reset()
    assert dummy_timeline.current_time == 0.0
    assert track.current_time == 0.0

    dummy_timeline.run()
    assert len(dummy_timeline.output_device.events) == 6
    assert dummy_timeline.output_device.events[0] == [
        pytest.approx(0.0), "note_on", 1, 64, 0
    ]
    assert dummy_timeline.output_device.events[1] == [
        pytest.approx(0.5), "note_off", 1, 0
    ]
    assert dummy_timeline.output_device.events[2] == [
        pytest.approx(1.0), "note_on", 1, 64, 0
    ]
    assert dummy_timeline.output_device.events[3] == [
        pytest.approx(1.5), "note_off", 1, 0
    ]
    assert dummy_timeline.output_device.events[4] == [
        pytest.approx(2.0), "note_on", 2, 64, 0
    ]
    assert dummy_timeline.output_device.events[5] == [
        pytest.approx(2.5), "note_off", 2, 0
    ]