示例#1
0
def test_event_group_list__group_by_types_resulting_groups(events):
    event_groups = events.group_by_type(['Silence'])
    assert event_groups.selected_groups == EventGroupList([EventList([Silence(6)]),
                                                          EventList([Silence(30)])])
    assert event_groups.unselected_groups == EventGroupList([EventList([Beat(12),
                                                                       Beat(18),
                                                                       Beat(24)])])

    # Not specifying type selects all groups
    event_groups = events.group_by_type()
    assert event_groups.selected_groups == event_groups
示例#2
0
def prepare_events(generator: MusicVideoGenerator, args) -> EventList:
    audio = generator.audio

    audio_events_mode = args.audio_events_mode
    beats_mode = args.beats_mode
    onsets_mode = args.onsets_mode
    event_locations = args.event_locations
    events_offset = args.events_offset
    events_speed = args.events_speed
    events_speed_offset = args.events_speed_offset
    group_events_by_slices = args.group_events_by_slices
    group_events_by_type = args.group_events_by_type
    target_groups = args.target_groups
    group_speeds = args.group_speeds
    group_speed_offsets = args.group_speed_offsets

    if audio_events_mode:
        message("Analyzing audio...")

        if audio_events_mode == AudioEventsMode.BEATS:
            if beats_mode == BeatsMode.BEATS:
                events = audio.beats()
            elif beats_mode == BeatsMode.WEAK_BEATS:
                events = audio.beats(trim=True)
            else:
                raise ParameterError(f"Unsupported beats mode {beats_mode}.")
        elif audio_events_mode == AudioEventsMode.ONSETS:
            if onsets_mode == OnsetsMode.ONSETS:
                events = audio.onsets()
            elif onsets_mode == OnsetsMode.BACKTRACK:
                events = audio.onsets(backtrack=True)
            else:
                raise ParameterError(f"Unsupported onsets mode {onsets_mode}.")
        else:
            raise ParameterError(
                f"Unsupported audio events mode {audio_events_mode}.")

        if events_speed:
            events.speed_multiply(events_speed, events_speed_offset)

        if group_events_by_type is not None or group_events_by_slices:
            if group_events_by_type is not None:
                event_groups = events.group_by_type(
                    select_types=group_events_by_type)
            else:
                event_groups = events.group_by_slices(
                    slices=group_events_by_slices)

            if target_groups == TargetGroups.ALL:
                event_groups.speed_multiply(group_speeds, group_speed_offsets)
            elif target_groups == TargetGroups.SELECTED:
                event_groups.selected_groups.speed_multiply(
                    group_speeds, group_speed_offsets)
            elif target_groups == TargetGroups.UNSELECTED:
                event_groups.unselected_groups.speed_multiply(
                    group_speeds, group_speed_offsets)

            events = event_groups.flatten()
        else:
            event_groups = EventGroupList([events])

        message(f"Events:\n{event_groups}")

        if event_locations:
            events.add_events(event_locations)
    elif event_locations:
        events = EventList(event_locations, end=generator.duration)
    else:
        raise ParameterError(
            "Must provide either audio events mode or event locations.")

    if events_offset:
        events.offset(events_offset)

    return events
示例#3
0
def events_grouped_by_type() -> EventGroupList:
    return EventGroupList([EventList([Silence(6)]),
                           EventList([Beat(12), Beat(18), Beat(24)]),
                           EventList([Silence(30)])])
示例#4
0
def test_event_group_list__flatten():
    assert EventGroupList([EventList([1, 2, 3], end=50), EventList([4, 5, 6], end=50)]).flatten() == \
           EventList([1, 2, 3, 4, 5, 6], end=50)
示例#5
0
def test_event_group_list__group_by_slices_resulting_groups():
    events = EventList([1, 2, 3, 4, 5, 6, 7, 8])
    event_groups = events.group_by_slices([(1, 3), (5, 7)])
    assert event_groups.selected_groups == EventGroupList([[2, 3], [6, 7]])
    assert event_groups.unselected_groups == EventGroupList([[1], [4, 5], [8]])
示例#6
0
def test_event_group_list__initializes_non_uniform_inputs_successfully():
    EventGroupList([[1, 2, 3], EventList([1, 2, 3, Beat(4)])])
示例#7
0
@pytest.mark.parametrize("events_a, events_b, expected_events", [
    (EventList([6, 12], end=30), EventList([18, 24], end=30), EventList([6, 12, 18, 24], end=30)),
    (EventList([6, 12], end=18), EventList([18, 24], end=30), EventList([6, 12, 18, 24], end=30))
])
def test_event_list_concatenate(events_a, events_b, expected_events):
    assert events_a + events_b == expected_events


def test_event_group_list__initializes_non_uniform_inputs_successfully():
    EventGroupList([[1, 2, 3], EventList([1, 2, 3, Beat(4)])])


@pytest.mark.parametrize("events, expected_event_group_list", [
    (events(), events_grouped_by_type()),
    (EventList([1]), EventGroupList([EventList([1])]))
])
def test_group_by_type(events, expected_event_group_list):
    assert events.group_by_type() == expected_event_group_list


@pytest.mark.parametrize("events, slices, expected_event_groups", [
    (EventList(), [(1, 2)], EventGroupList([[], []])),
    (EventList([1, 2]), [(2, 3)], EventGroupList([[1, 2], []])),
    (EventList([1, 2]), [(0, 8)], EventGroupList([[1, 2]])),
    (EventList([1, 2, 3, 4, 5]), [(1, 3)], EventGroupList([[1], [2, 3], [4, 5]])),
    (EventList([1, 2, 3, 4, 5]), [(0, 3), (3, 4)], EventGroupList([[1, 2, 3], [4], [5]])),
    (EventList([1, 2, 3, 4, 5, 6, 7, 8]), [(1, 3), (5, 7)], EventGroupList([[1], [2, 3], [4, 5], [6, 7], [8]]))
])
def test_group_by_slices(events, slices, expected_event_groups):
    assert events.group_by_slices(slices) == expected_event_groups