def test_nonrealtime(): at = 1.0 until = 1.5 pattern = GroupPattern( BusPattern( MonoEventPattern(frequency=SequencePattern([440, 550, 660])))) clock = OfflineClock() provider = Provider.nonrealtime() pattern.play(provider=provider, clock=clock, at=at, until=until) # Session should not map in_ or out, but use their bus numbers as consts. assert provider.session.to_strings(True) == normalize(""" 0.0: NODE TREE 0 group 1.0: NODE TREE 0 group 1000 group 1001 group 1003 default amplitude: 0.1, frequency: 440.0, gate: 1.0, out: 16.0, pan: 0.5 1002 system_link_audio_1 done_action: 2.0, fade_time: 0.25, gate: 1.0, in_: 16.0, out: 0.0 3.0: NODE TREE 0 group 1000 group 1001 group 1003 default amplitude: 0.1, frequency: 550.0, gate: 1.0, out: 16.0, pan: 0.5 1002 system_link_audio_1 done_action: 2.0, fade_time: 0.25, gate: 1.0, in_: 16.0, out: 0.0 4.0: NODE TREE 0 group 1000 group 1001 group 4.5: NODE TREE 0 group """)
import pytest from supriya.patterns import SequencePattern, UnaryOpPattern from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, operator, input_, expected, is_infinite", [ (None, "-", 1, [-1], True), (None, "-", [1], [(-1, )], True), (None, "-", [[1]], [((-1, ), )], True), (None, "-", [[[1]]], [(((-1, ), ), )], True), (None, "-", [1, 2], [(-1, -2)], True), (None, "-", SequencePattern([1, 2, 3]), [-1, -2, -3], False), (None, "-", SequencePattern([1, 2, 3], None), [-1, -2, -3], True), ], ) def test(stop_at, operator, input_, expected, is_infinite): pattern = UnaryOpPattern(operator, input_) run_pattern_test(pattern, expected, is_infinite, stop_at)
import pytest from supriya.patterns import EventPattern, NoteEvent, SequencePattern, UpdatePattern from supriya.patterns.testutils import MockUUID as M from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, input_a, input_b1, input_b2, input_c, expected, is_infinite", [ ( None, SequencePattern([1, 2, 3]), SequencePattern([4, 5]), SequencePattern([7, 8, 9]), SequencePattern([10, 11]), [ NoteEvent(M("A"), a=1, b=7, c=10), NoteEvent(M("B"), a=2, b=8, c=11) ], False, ), ( None, SequencePattern([1, 2, 3], None), SequencePattern([4, 5], None), SequencePattern([7, 8, 9]), SequencePattern([10, 11]), [ NoteEvent(M("A"), a=1, b=7, c=10), NoteEvent(M("B"), a=2, b=8, c=11)
import pytest from supriya.patterns import BinaryOpPattern, SequencePattern from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, operator, input_a, input_b, expected, is_infinite", [ (None, "+", 1, 7, [8], True), (None, "+", [1], 7, [(8, )], True), (None, "+", [1], [7], [(8, )], True), (None, "+", [[1]], [7], [((8, ), )], True), (None, "+", [[[1]]], [7], [(((8, ), ), )], True), (None, "+", [1, 2], [7, 8], [(8, 10)], True), (None, "+", [1, 2], [7, 8, 10], [(8, 10, 11)], True), (None, "*", SequencePattern([1, 2, 3]), 4, [4, 8, 12], False), (None, "*", SequencePattern([1, 2, 3], None), 4, [4, 8, 12], True), ], ) def test(stop_at, operator, input_a, input_b, expected, is_infinite): pattern = BinaryOpPattern(operator, input_a, input_b) run_pattern_test(pattern, expected, is_infinite, stop_at)
import operator import pytest from supriya.patterns import BinaryOpPattern, SequencePattern, UnaryOpPattern @pytest.mark.parametrize( "op, expr_one, expr_two, expected", [ ( operator.add, 23, SequencePattern([1, 2, 3]), BinaryOpPattern("+", 23, SequencePattern([1, 2, 3])), ), ( operator.add, SequencePattern([1, 2, 3]), 23, BinaryOpPattern("+", SequencePattern([1, 2, 3]), 23), ), ( operator.floordiv, 23, SequencePattern([1, 2, 3]), BinaryOpPattern("//", 23, SequencePattern([1, 2, 3])), ), ( operator.floordiv, SequencePattern([1, 2, 3]),
GroupPattern, NodeFreeEvent, NoteEvent, NullEvent, SequencePattern, ) from supriya.patterns.testutils import MockUUID as M from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, inner_pattern, release_time, expected, is_infinite", [ ( None, EventPattern(a=SequencePattern([1, 2])), 0.0, [ CompositeEvent([GroupAllocateEvent(M("A"), delta=0.0)]), NoteEvent(M("B"), a=1, target_node=M("A")), NoteEvent(M("C"), a=2, target_node=M("A")), CompositeEvent([NodeFreeEvent(M("A"), delta=0.0)]), ], False, ), ( None, EventPattern(a=SequencePattern([1, 2])), 0.25, [ CompositeEvent([GroupAllocateEvent(M("A"), delta=0.0)]),
import pytest from uqbar.iterables import nwise from supriya.patterns import ChoicePattern, SequencePattern @pytest.mark.parametrize( "sequence, iterations, forbid_repetitions, weights, is_infinite", [ ([1, 2, 3], 1, False, None, False), ([1, 2, 3], 1, True, None, False), ([1, 2, 3], None, False, None, True), ([1, 2, 3], None, True, None, True), ([1, 2, 3], None, True, [1, 2, 1], True), ( [SequencePattern(["a", "b"]), SequencePattern(["c", "d"])], None, False, None, True, ), ], ) def test(sequence, iterations, forbid_repetitions, weights, is_infinite): pattern = ChoicePattern( sequence, iterations=iterations, forbid_repetitions=forbid_repetitions, weights=weights, )
import pytest from supriya.patterns import MonoEventPattern, NoteEvent, SequencePattern from supriya.patterns.testutils import MockUUID as M from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, input_a, input_b, expected, is_infinite", [ ( None, SequencePattern([1, 2, 3], None), SequencePattern([4, 5], None), [ NoteEvent(M("A"), a=1, b=4), NoteEvent(M("A"), a=2, b=5), NoteEvent(M("A"), a=3, b=4), NoteEvent(M("A"), a=1, b=5), NoteEvent(M("A"), a=2, b=4), NoteEvent(M("A"), a=3, b=5), ], True, ), ( None, SequencePattern([1, 2, 3], None), SequencePattern([4, 5], 1), [NoteEvent(M("A"), a=1, b=4), NoteEvent(M("A"), a=2, b=5)], False,
BusPattern, EventPattern, GroupPattern, MonoEventPattern, ParallelPattern, SequencePattern, ) from supriya.providers import BusGroupProxy, GroupProxy, Provider, SynthProxy @pytest.mark.parametrize( "pattern, until, expected", [ ( SequencePattern([ EventPattern(frequency=SequencePattern([440, 550, 660])), MonoEventPattern(frequency=SequencePattern([440, 550, 660])), ]), None, lambda provider: [ call.at(0.0), call.add_synth( add_action=AddAction.ADD_TO_HEAD, synthdef=None, target_node=None, frequency=440, ), call.at(2.0), call.add_synth( add_action=AddAction.ADD_TO_HEAD, synthdef=None, target_node=None,
def test___init__(sequence, iterations, raises): if raises: with pytest.raises(raises): SequencePattern(sequence, iterations) else: SequencePattern(sequence, iterations)
def test(stop_at, sequence, iterations, expected, is_infinite): pattern = SequencePattern(sequence, iterations=iterations) run_pattern_test(pattern, expected, is_infinite, stop_at)
import pytest from supriya.patterns import SequencePattern from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, sequence, iterations, expected, is_infinite", [ (None, [1, 2, 3], None, [1, 2, 3], True), (None, [1, 2, 3], 1, [1, 2, 3], False), (None, [1, 2, 3], 2, [1, 2, 3, 1, 2, 3], False), (None, [1, 2, 3, SequencePattern(["a", "b"])], 1, [1, 2, 3, "a", "b"], False), ( None, [1, 2, 3, SequencePattern(["a", "b"], None)], 1, [1, 2, 3, "a", "b"], True, ), ( None, [SequencePattern([1, 2, 3]), SequencePattern(["a", "b"])], 1, [1, 2, 3, "a", "b"], False, ), ( None, [SequencePattern([1, 2, 3]), SequencePattern(["a", "b"])], 2,
import pytest from supriya.patterns import ChoicePattern, SeedPattern, SequencePattern from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, pattern, expected, is_infinite", [ (None, SequencePattern([1, 2, 3, 4]), [1, 2, 3, 4], False), (1, SequencePattern([1, 2, 3, 4]), [1], False), ], ) def test(stop_at, pattern, expected, is_infinite): pattern = SeedPattern(pattern) run_pattern_test(pattern, expected, is_infinite, stop_at) def test_random(): pattern = ChoicePattern([1, 2, 3]) assert len(set(tuple(pattern) for _ in range(10))) > 1 pattern = SeedPattern(ChoicePattern([1, 2, 3])) assert len(set(tuple(pattern) for _ in range(10))) == 1
NoteEvent, NullEvent, ParallelPattern, SequencePattern, ) from supriya.patterns.testutils import MockUUID as M from supriya.patterns.testutils import run_pattern_test @pytest.mark.parametrize( "stop_at, patterns, expected, is_infinite", [ ( None, [ EventPattern(frequency=SequencePattern([440, 550, 660])), EventPattern(frequency=SequencePattern([777, 888, 999])), ], [ CompositeEvent( [ NoteEvent(M("A"), delta=0.0, frequency=440), NoteEvent(M("B"), delta=0.0, frequency=777), ], delta=1.0, ), CompositeEvent( [ NoteEvent(M("C"), delta=0.0, frequency=550), NoteEvent(M("D"), delta=0.0, frequency=888), ],