Пример #1
0
def _convert_partials_to_vibrations(
    apply_frequency_response: bool,
) -> basic.SimultaneousEvent[
    basic.SimultaneousEvent[
        basic.SimultaneousEvent[
            basic.SequentialEvent[sixtycombinations.classes.Vibration]
        ]
    ]
]:
    partials_to_vibrations_converter = sixtycombinations.converters.symmetrical.PartialsToVibrationsConverter(
        apply_frequency_response=apply_frequency_response
    )
    return basic.SimultaneousEvent(
        # cycles
        [
            # loudspeakers
            basic.SimultaneousEvent(
                [
                    # a / b
                    basic.SimultaneousEvent(
                        functools.reduce(
                            operator.add,
                            (
                                partials_to_vibrations_converter.convert(partials)
                                for partials in speaker
                            ),
                        )
                    )
                    for speaker in cycle
                ]
            )
            for cycle in sixtycombinations.constants.NESTED_PARTIALS
        ]
    )
Пример #2
0
 def _render_soundfile_for_keyboard(instrument_id, filtered_time_brackets):
     time_brackets_converter = (converters.symmetrical.time_brackets.
                                TimeBracketsToEventConverter(instrument_id))
     converted_time_brackets = time_brackets_converter.convert(
         filtered_time_brackets)
     if converted_time_brackets:
         n_sequential_events = max(
             len(simultaneous_event)
             for simultaneous_event in converted_time_brackets
             if isinstance(simultaneous_event, basic.SimultaneousEvent))
         simultaneous_event = basic.SimultaneousEvent([
             basic.SequentialEvent([]) for _ in range(n_sequential_events)
         ])
         for event in converted_time_brackets:
             if isinstance(event, basic.SimpleEvent):
                 rest = basic.SimpleEvent(event.duration)
                 for seq in simultaneous_event:
                     seq.append(rest)
             else:
                 for ev, sequential_event in zip(event, simultaneous_event):
                     ev = PLAYING_INDICATORS_CONVERTER.convert(ev)
                     sequential_event.extend(ev)
         for nth_seq_event, sequential_event in enumerate(
                 simultaneous_event):
             midi_file_converter = (
                 ot2_converters.frontends.midi.
                 KeyboardEventToMidiFileConverter(nth_seq_event))
             midi_file_converter.convert(sequential_event)
Пример #3
0
def _render_vibrations_to_filtered_isis_files(
    nested_vibrations: basic.SimultaneousEvent,
):
    threads = []
    for nth_cycle, cycle in enumerate(nested_vibrations):
        sample_player_event = basic.SimpleEvent(sixtycombinations.constants.DURATION)
        sample_player_event.path = "{}/{}.wav".format(
            sixtycombinations.constants.ISIS_FILES_BUILD_PATH, nth_cycle
        )

        for nth_speaker, speaker_data in enumerate(cycle):
            adapted_speaker_data = basic.SimultaneousEvent(
                [basic.SequentialEvent([sample_player_event])] + speaker_data[:]
            )

            sound_file_converter = sixtycombinations.converters.frontends.VibrationsToFilteredIsisSoundFileConverter(
                nth_cycle, nth_speaker
            )
            thread = threading.Thread(
                target=lambda: sound_file_converter.convert(adapted_speaker_data)
            )
            thread.start()
            threads.append(thread)

    while any([th.isAlive() for th in threads]):
        time.sleep(0.5)
Пример #4
0
def _convert_partials_to_note_likes() -> basic.SimultaneousEvent[
    basic.SimultaneousEvent[
        basic.SimultaneousEvent[
            basic.SequentialEvent[sixtycombinations.classes.Vibration]
        ]
    ]
]:
    partials_to_note_likes_converter = (
        sixtycombinations.converters.symmetrical.PartialsToNoteLikesConverter()
    )
    note_likes_per_group = basic.SimultaneousEvent([])
    for cycle in sixtycombinations.constants.NESTED_PARTIALS:
        groupA = basic.SimultaneousEvent([])
        groupB = basic.SimultaneousEvent([])
        for speaker in cycle:
            for part, partials in zip((groupA, groupB), speaker):
                part.extend(partials_to_note_likes_converter.convert(partials))
        note_likes_per_group.append((groupA, groupB))
    return note_likes_per_group
Пример #5
0
def convert_dict_to_tagged_event(
    data: typing.Dict[str, basic.SequentialEvent]
) -> ot2_basic.TaggedSimultaneousEvent:
    return ot2_basic.TaggedSimultaneousEvent(
        [
            basic.SimultaneousEvent([data[instrument_name]])
            for instrument_name in
            "sus0 sus1 sus2 drone percussion noise".split(" ")
        ],
        tag_to_event_index=instruments.INSTRUMENT_ID_TO_INDEX,
    )
    def _make_remix_events(
        split_annotated_note_likes: typing.Tuple[typing.Tuple[
            basic.SequentialEvent[typing.Union[basic.SimpleEvent,
                                               classes.AnnotatedNoteLike]],
            float,  # start
            str,  # path
        ]],
    ) -> basic.SimultaneousEvent[basic.SequentialEvent[basic.SimpleEvent]]:
        remix_events = basic.SimultaneousEvent([])
        for annotated_note_likes, start, path in split_annotated_note_likes:
            sequential_event = basic.SequentialEvent([])
            if start > 0:
                rest_before_remix_event = basic.SimpleEvent(start)
                sequential_event.append(rest_before_remix_event)
            remix_event = basic.SimpleEvent(annotated_note_likes.duration)
            remix_event.path = "{}.wav".format(path)
            sequential_event.append(remix_event)
            remix_events.append(sequential_event)

        return remix_events
Пример #7
0
def _mix_sound_files(n_channels: int):
    if n_channels == 2:
        csound_score_converter = converters.frontends.csound.CsoundScoreConverter(
            "sixtycombinations/synthesis/StereoMixdown.sco",
            p4=lambda stereo_sample_player: stereo_sample_player.path,
            p5=lambda stereo_sample_player: stereo_sample_player.panning,
        )
        csound_converter = converters.frontends.csound.CsoundConverter(
            "{}/stereo.wav".format(sixtycombinations.constants.MIX_PATH),
            "sixtycombinations/synthesis/StereoMixdown.orc",
            csound_score_converter,
            converters.frontends.csound_constants.SILENT_FLAG,
            converters.frontends.csound_constants.FORMAT_64BIT,
        )
        simultaneous_event = basic.SimultaneousEvent([])
        for nth_cycle, loudspeakers in enumerate(
            sixtycombinations.constants.RING_POSITION_TO_LOUDSPEAKER
        ):
            n_loudspeakers = len(loudspeakers)
            for nth_loudspeaker, _ in enumerate(loudspeakers):
                panning = nth_loudspeaker / (n_loudspeakers - 1)
                sample_path = "{}/{}_{}.wav".format(
                    sixtycombinations.constants.LOUDSPEAKER_MONO_FILES_BUILD_PATH_ABSOLUTE,
                    nth_cycle,
                    nth_loudspeaker,
                )
                duration_in_seconds_of_sample = sox.file_info.duration(sample_path)
                simultaneous_event.append(
                    sixtycombinations.classes.StereoSamplePlayer(
                        duration_in_seconds_of_sample, sample_path, panning
                    )
                )

        csound_converter.convert(simultaneous_event)
        os.remove(csound_score_converter.path)  # remove score file

    elif n_channels == 15:
        pass

    else:
        raise NotImplementedError()
Пример #8
0
def _render_soundfile_or_midi_file_for_instrument(
    instrument_id,
    filtered_time_brackets,
    midi_file_converter,
    return_pitch: bool = False,
):
    time_brackets_converter = (converters.symmetrical.time_brackets.
                               TimeBracketsToEventConverter(instrument_id))
    converted_time_brackets = time_brackets_converter.convert(
        filtered_time_brackets)
    if converted_time_brackets:
        n_sequential_events = max(
            len(simultaneous_event)
            for simultaneous_event in converted_time_brackets
            if isinstance(simultaneous_event, basic.SimultaneousEvent))
        simultaneous_event = basic.SimultaneousEvent(
            [basic.SequentialEvent([]) for _ in range(n_sequential_events)])
        for event in converted_time_brackets:
            if isinstance(event, basic.SimpleEvent):
                rest = basic.SimpleEvent(event.duration)
                for seq in simultaneous_event:
                    seq.append(rest)
            else:
                for ev, sequential_event in zip(event, simultaneous_event):
                    ev = PLAYING_INDICATORS_CONVERTER.convert(ev)
                    sequential_event.extend(ev)

                event_duration = event.duration
                missing_sequential_events = n_sequential_events - len(event)
                if missing_sequential_events:
                    for sequential_event in simultaneous_event[
                            -missing_sequential_events:]:
                        sequential_event.append(
                            basic.SimpleEvent(event_duration))

        if return_pitch:
            simultaneous_event.set_parameter("return_pitch", True)

        midi_file_converter.convert(simultaneous_event)
Пример #9
0
    def test_convert(self):
        musical_data = ot2_basic.TaggedSimultaneousEvent(
            [
                basic.SimultaneousEvent([
                    basic.SequentialEvent([
                        music.NoteLike("1/1", 1, "pp"),
                        music.NoteLike("15/16", 1, "pp"),
                        music.NoteLike([], 0.5, "pp"),
                        music.NoteLike("16/15", 0.75, "p"),
                        music.NoteLike([], 1.25, "p"),
                        music.NoteLike("9/8", 1.5, "p"),
                    ])
                ]),
                basic.SimultaneousEvent([
                    basic.SequentialEvent([
                        music.NoteLike("5/8", 0.5, "pp"),
                        music.NoteLike("11/16", 1, "pp"),
                        music.NoteLike([], 1, "pp"),
                        music.NoteLike("3/4", 0.75, "p"),
                        music.NoteLike([], 0.25, "p"),
                        music.NoteLike("3/4", 0.75, "p"),
                    ])
                ]),
                basic.SimultaneousEvent([
                    basic.SequentialEvent([
                        music.NoteLike([], 0.75, "pp"),
                        music.NoteLike("11/9", 1, "pp"),
                        music.NoteLike("4/3", 1, "pp"),
                        music.NoteLike("3/2", 0.75, "ppp"),
                        music.NoteLike([], 0.75, "ppp"),
                        music.NoteLike("3/5", 0.75, "ppp"),
                    ])
                ]),
                basic.SimultaneousEvent([
                    basic.SequentialEvent([
                        music.NoteLike("1/4", 4, "pp"),
                        music.NoteLike([], 1, "pp"),
                        music.NoteLike("1/4", 1, "pp"),
                    ]),
                    basic.SequentialEvent([
                        music.NoteLike([], 3, "pp"),
                        music.NoteLike("3/8", 2.5, "pp"),
                        music.NoteLike([], 0.5, "pp"),
                    ]),
                ]),
                basic.SimultaneousEvent([
                    basic.SequentialEvent([
                        music.NoteLike("g", 0.25, "pp"),
                        music.NoteLike("g", 0.5, "pp"),
                        music.NoteLike("g", 0.25, "pp"),
                        music.NoteLike("b", fractions.Fraction(1, 6), "pp"),
                        music.NoteLike("f", fractions.Fraction(1, 12), "pp"),
                        music.NoteLike("g", 1, "pp"),
                        music.NoteLike("f", 1, "pp"),
                        music.NoteLike("g", 1, "pp"),
                        music.NoteLike("g", 1, "pp"),
                    ])
                ]),
                basic.SimultaneousEvent(
                    [basic.SequentialEvent([music.NoteLike([], 6, "ppp")])]),
            ],
            tag_to_event_index=instruments.INSTRUMENT_ID_TO_INDEX,
        )

        abjad_score_converter = ot2_abjad.TaggedSimultaneousEventToAbjadScoreConverter(
            (
                abjad.TimeSignature((4, 2)),
                abjad.TimeSignature((4, 2)),
                abjad.TimeSignature((4, 2)),
                abjad.TimeSignature((4, 2)),
            ))
        abjad_score = abjad_score_converter.convert(musical_data)

        lilypond_file_converter = ot2_abjad.AbjadScoreToLilypondFileConverter()
        lilypond_file = lilypond_file_converter.convert(abjad_score)

        abjad.persist.as_pdf(lilypond_file,
                             "tests/converters/frontends/score_test.pdf")
Пример #10
0
"""

from mutwo.events import basic

from sixtycombinations.classes import Partial
from sixtycombinations.constants import GROUPS
from sixtycombinations.constants import PITCH_TO_LOUDSPEAKER_MAPPING
from sixtycombinations.constants import RING_POSITION_TO_LOUDSPEAKER

NESTED_PARTIALS = basic.SimultaneousEvent(
    [
        basic.SimultaneousEvent(
            [
                basic.SimultaneousEvent(
                    [basic.SequentialEvent([]), basic.SequentialEvent([])]
                )
                for nth_speaker in cycle
            ]
        )
        for cycle in RING_POSITION_TO_LOUDSPEAKER
    ]
)

for nth_cycle, cycle in enumerate(GROUPS):
    is_first = True
    for nth_group, group in enumerate(cycle):
        if is_first:
            n_phases_rest = group.attack + group.sustain
            is_first = False
        else:
            n_phases_rest = group.sustain
    def convert(
        self,
        groups_per_cycle: typing.Tuple[typing.Tuple[type(
            constants.GROUPS[0][0])]],
    ):
        reaper_marker_events = basic.SimultaneousEvent([])
        for nth_cycle, groups in enumerate(groups_per_cycle):
            absolute_start_time_for_cycle = constants.ABSOLUTE_START_TIME_PER_GROUP[
                nth_cycle]

            for nth_group, group in enumerate(groups):
                reaper_marker_events_for_group = basic.SequentialEvent([])
                absolute_start_time_for_group = (
                    absolute_start_time_for_cycle + group.relative_start_time)
                absolute_start_time_for_group %= constants.DURATION
                reaper_marker_events_for_group.append(
                    basic.SimpleEvent(absolute_start_time_for_group))

                for state_name in "attack sustain release".split(" "):
                    n_phases = getattr(group, state_name)
                    duration_of_state = (
                        1 / group.fundamental.frequency) * n_phases
                    state_marker = basic.SimpleEvent(duration_of_state)
                    state_marker.name = "Group({},{})-{}".format(
                        nth_cycle, nth_group, state_name.upper())
                    state_marker.color = self.cycle_index_to_color[nth_cycle]
                    reaper_marker_events_for_group.append(state_marker)

                absolute_start_time_and_reaper_marker_events_pairs = []
                for absolute_time, state_marker in zip(
                        reaper_marker_events_for_group.absolute_times[1:],
                        reaper_marker_events_for_group[1:],
                ):
                    absolute_time %= constants.DURATION
                    absolute_start_time_and_reaper_marker_events_pairs.append(
                        (absolute_time, state_marker))

                sorted_absolute_start_time_and_reaper_marker_events_pairs = sorted(
                    absolute_start_time_and_reaper_marker_events_pairs,
                    key=operator.itemgetter(0),
                )
                if sorted_absolute_start_time_and_reaper_marker_events_pairs[
                        0][0] != 0:
                    sorted_absolute_start_time_and_reaper_marker_events_pairs.insert(
                        0, (0, basic.SimpleEvent(1)))

                sorted_absolute_start_times = tuple(
                    map(
                        lambda pair: pair[0],
                        sorted_absolute_start_time_and_reaper_marker_events_pairs,
                    ))

                adjusted_reaper_marker_events_for_group = basic.SequentialEvent(
                    [])
                for absolute_start_time0, absolute_start_time1, event in zip(
                        sorted_absolute_start_times,
                        sorted_absolute_start_times[1:] + (1, ),
                        map(
                            lambda pair: pair[1],
                            sorted_absolute_start_time_and_reaper_marker_events_pairs,
                        ),
                ):
                    event.duration = absolute_start_time1 - absolute_start_time0
                    adjusted_reaper_marker_events_for_group.append(event)

                reaper_marker_events.append(
                    adjusted_reaper_marker_events_for_group)

        with open(self._path, "w") as f:
            f.write(
                self._reaper_marker_converter.convert(reaper_marker_events))