Esempio n. 1
0
    def test_squash_in(self):
        self.assertRaises(
            TypeError,
            lambda: self.sequence.squash_in(
                0, core_events.SimpleEvent(1.5), mutate=False),
        )

        simultaneous_event_to_test = core_events.SimultaneousEvent([
            core_events.SequentialEvent(
                [core_events.SimpleEvent(duration) for duration in (2, 3)]),
            core_events.SequentialEvent([
                core_events.SimpleEvent(duration) for duration in (1, 1, 1, 2)
            ]),
        ])
        expected_simultaneous_event = core_events.SimultaneousEvent([
            core_events.SequentialEvent([
                core_events.SimpleEvent(duration) for duration in (1, 1.5, 2.5)
            ]),
            core_events.SequentialEvent([
                core_events.SimpleEvent(duration)
                for duration in (1, 1.5, 0.5, 2)
            ]),
        ])

        self.assertEqual(
            simultaneous_event_to_test.squash_in(1,
                                                 core_events.SimpleEvent(1.5),
                                                 mutate=False),
            expected_simultaneous_event,
        )
Esempio n. 2
0
 def test_split_child_at(self):
     simultaneous_event0 = core_events.SimultaneousEvent(
         [core_events.SequentialEvent([core_events.SimpleEvent(3)])])
     simultaneous_event0.split_child_at(1)
     simultaneous_event_to_compare0 = core_events.SimultaneousEvent([
         core_events.SequentialEvent(
             [core_events.SimpleEvent(1),
              core_events.SimpleEvent(2)])
     ])
     self.assertEqual(simultaneous_event0, simultaneous_event_to_compare0)
Esempio n. 3
0
 def test_filter(self):
     simultaneous_event_to_filter = core_events.SimultaneousEvent([
         core_events.SimpleEvent(1),
         core_events.SimpleEvent(3),
         core_events.SimpleEvent(2),
     ])
     simultaneous_event_to_filter.filter(lambda event: event.duration > 2)
     self.assertEqual(
         simultaneous_event_to_filter,
         core_events.SimultaneousEvent([core_events.SimpleEvent(3)]),
     )
Esempio n. 4
0
    def test_cut_up(self):
        result = core_events.SimultaneousEvent(
            [core_events.SimpleEvent(0.5) for _ in range(3)])

        self.assertEqual(
            [event.duration for event in result],
            [
                event.duration
                for event in self.sequence.cut_out(0.5, 1, mutate=False)
            ],
        )
        self.assertEqual(
            [event.duration for event in result],
            [
                event.duration
                for event in self.sequence.cut_out(0, 0.5, mutate=False)
            ],
        )
        self.assertEqual(
            [event.duration for event in result],
            [
                event.duration
                for event in self.sequence.cut_out(0.25, 0.75, mutate=False)
            ],
        )

        # this will raise an error because the simultaneous event contains simple events
        # where some simple event aren't long enough for the following cut up arguments.
        self.assertRaises(ValueError, lambda: self.sequence.cut_out(2, 3))
Esempio n. 5
0
    def test_mutate_parameter(self):
        dummy_parameter_tuple = (
            self.DummyParameter(1),
            self.DummyParameter(2),
            None,
        )
        simple_event_tuple = (
            core_events.SimpleEvent(1),
            core_events.SimpleEvent(1),
            core_events.SimpleEvent(2),
        )
        for simple_event, dummy_parameter in zip(simple_event_tuple,
                                                 dummy_parameter_tuple):
            if dummy_parameter is not None:
                simple_event.dummy_parameter = dummy_parameter  # type: ignore
        simultaneous_event = core_events.SimultaneousEvent(
            simple_event_tuple).destructive_copy()
        simultaneous_event.mutate_parameter(
            "dummy_parameter",
            lambda dummy_parameter: dummy_parameter.double_value(),
        )
        for event, dummy_parameter in zip(simultaneous_event,
                                          dummy_parameter_tuple):
            if dummy_parameter is not None:
                expected_dummy_parameter = self.DummyParameter(
                    dummy_parameter.value * 2)
            else:
                expected_dummy_parameter = None

            self.assertEqual(event.get_parameter("dummy_parameter"),
                             expected_dummy_parameter)
Esempio n. 6
0
 def setUp(self) -> None:
     self.sequence: core_events.SimultaneousEvent[
         core_events.SimpleEvent] = core_events.SimultaneousEvent([
             core_events.SimpleEvent(1),
             core_events.SimpleEvent(2),
             core_events.SimpleEvent(3),
         ])
     self.nested_sequence: core_events.SimultaneousEvent[
         core_events.SequentialEvent[
             core_events.SimpleEvent]] = core_events.SimultaneousEvent([
                 core_events.SequentialEvent([
                     core_events.SimpleEvent(1),
                     core_events.SimpleEvent(2),
                     core_events.SimpleEvent(3),
                 ]) for _ in range(2)
             ])
Esempio n. 7
0
 def test_destructive_copy(self):
     simple_event = core_events.SimpleEvent(2)
     simultaneous_event = core_events.SimultaneousEvent(
         [simple_event, simple_event])
     copied_simultaneous_event = simultaneous_event.destructive_copy()
     copied_simultaneous_event[0].duration = 10
     self.assertNotEqual(copied_simultaneous_event[0].duration,
                         copied_simultaneous_event[1].duration)
Esempio n. 8
0
    def test_cut_off(self):
        result0 = core_events.SimultaneousEvent([
            core_events.SimpleEvent(duration) for duration in (0.5, 1.5, 2.5)
        ])
        result1 = core_events.SimultaneousEvent(
            [core_events.SimpleEvent(duration) for duration in (1, 2, 2.5)])

        self.assertEqual(
            [event.duration for event in result0],
            [
                event.duration
                for event in self.sequence.cut_off(0, 0.5, mutate=False)
            ],
        )
        self.assertEqual(
            [event.duration for event in result1],
            [
                event.duration
                for event in self.sequence.cut_off(2.5, 3, mutate=False)
            ],
        )
Esempio n. 9
0
 def test_convert_simultaneous_event(self):
     tempo_envelope = expenvelope.Envelope.from_levels_and_durations(
         levels=[30, 60], durations=[4])
     simple_event0 = core_events.SimpleEvent(4)
     simple_event1 = core_events.SimpleEvent(8)
     simultaneous_event = core_events.SimultaneousEvent(
         [simple_event0, simple_event0, simple_event1])
     converter = core_converters.TempoConverter(tempo_envelope)
     converted_simultaneous_event = converter.convert(simultaneous_event)
     expected_duration0 = simultaneous_event[0].duration * 1.5
     expected_duration1 = 10
     self.assertEqual(converted_simultaneous_event[0].duration,
                      expected_duration0)
     self.assertEqual(converted_simultaneous_event[1].duration,
                      expected_duration0)
     self.assertEqual(converted_simultaneous_event[2].duration,
                      expected_duration1)