Пример #1
0
 def test_glissando_line(self):
     p0 = old.PitchInterpolation(3, mel.SimplePitch(0, 300))
     p1 = old.PitchInterpolation(4, mel.SimplePitch(0, 0))
     p2 = old.PitchInterpolation(0, mel.SimplePitch(0, -300))
     line = interpolations.InterpolationLine((p0, p1, p2))
     gliss = old.GlissandoLine(line)
     interpol0 = gliss.interpolate(1)
     self.assertEqual(interpol0, (300, 200, 100, 0, -100, -200, -300))
Пример #2
0
def add_glissando(
    nth_event: int,
    scale_degrees: tuple,
    novent_line: lily.NOventLine,
    durations: tuple = tuple([]),
    verse_maker: mus.SegmentMaker = None,
    adapt_by_changed_structure: bool = False,
):
    n_scale_degrees = len(scale_degrees)

    assert verse_maker or durations or n_scale_degrees in (1, 2)

    if not durations:
        if n_scale_degrees == 2:
            durations = (novent_line[nth_event].duration, )
        elif n_scale_degrees > 2:
            durations = tuple(
                fractions.Fraction(nv.delay) for nv in split_by_structure(
                    nth_event,
                    n_scale_degrees - 1,
                    novent_line,
                    verse_maker=verse_maker,
                    change_novent_line=False,
                    adapt_by_changed_structure=adapt_by_changed_structure,
                ))

    assert len(durations) == len(scale_degrees) - 1

    novent = novent_line[nth_event].copy()
    normalized_pitch = novent.pitch[0].normalize()

    instrument = globals_.PITCH2INSTRUMENT[normalized_pitch]
    octave = novent.pitch[0].octave
    pitch_zone = tuple(
        p.register(octave) for p in sorted(
            tuple(
                p.copy() for p in globals_.SCALE_PER_INSTRUMENT[instrument])))
    pitch_zone = functools.reduce(
        operator.add,
        (tuple(p + ji.JIPitch([n - 1]) for p in pitch_zone) for n in range(3)),
    )

    pitch_null_idx = pitch_zone.index(novent.pitch[0])

    durations += (0, )

    interpolation_line = []
    for relative_pitch_class, duration in zip(scale_degrees, durations):
        pc = relative_pitch_class % 7
        octave = relative_pitch_class // 7
        pitch = pitch_zone[pc + pitch_null_idx] + ji.JIPitch(
            [octave]) - novent.pitch[0]
        interpolation_line.append(old.PitchInterpolation(duration, pitch))

    novent_line[nth_event].glissando = old.GlissandoLine(
        interpolations.InterpolationLine(interpolation_line))
Пример #3
0
    def _convert_dissonant_tones2glissandi(self, melody: old.Melody):
        consonant_tones_positions = tools.find_all_indices_of_n(
            True, self.__is_not_dissonant_pitch_per_tone)
        new_melody = melody[:consonant_tones_positions[0]].copy()

        melody_size = len(melody)

        consonant_and_its_dissonant_tones = tuple(
            (melody[idx0], melody[idx0 + 1:idx1]) for idx0, idx1 in zip(
                consonant_tones_positions,
                consonant_tones_positions[1:] + (melody_size, ),
            ))

        for main_and_its_side_tones in consonant_and_its_dissonant_tones:
            main_tone, additional_tones = main_and_its_side_tones
            if not main_tone.pitch.is_empty:
                duration_per_pitch = (main_tone.duration, ) + tuple(
                    t.duration for t in additional_tones)
                summed_duration = sum(duration_per_pitch)

                glissando = []
                for t0, t1 in zip((main_tone, ) + tuple(additional_tones),
                                  additional_tones):

                    pitch_difference = t0.pitch - main_tone.pitch
                    duration = t0.duration

                    if duration > self.glissando_duration:
                        staying = duration - self.glissando_duration
                        changing = self.glissando_duration
                    else:
                        staying = duration * 0.5
                        changing = float(staying)

                    glissando.append(
                        old.PitchInterpolation(staying, pitch_difference))
                    glissando.append(
                        old.PitchInterpolation(changing, pitch_difference))

                last_pitch = mel.TheEmptyPitch
                last_pitch_idx = -1
                while last_pitch.is_empty:
                    try:
                        last_pitch = additional_tones[last_pitch_idx].pitch
                    except IndexError:
                        last_pitch = None
                        break
                    last_pitch_idx -= 1

                if last_pitch is not None:
                    pitch_difference = last_pitch - main_tone.pitch
                    glissando.append(
                        old.PitchInterpolation(0, pitch_difference))
                    glissando = old.GlissandoLine(
                        interpolations.InterpolationLine(glissando))
                else:
                    glissando = None

                new_tone = old.Tone(
                    main_tone.pitch,
                    delay=summed_duration,
                    duration=summed_duration,
                    glissando=glissando,
                )

                new_melody.append(new_tone)

            else:
                new_melody.extend((main_tone, ) + tuple(additional_tones))

        return new_melody
Пример #4
0
        if nchnls == 1:
            cmd += "--mono "
        if preset is not None:
            cmd += "--preset {0} ".format(preset)
        if fxp is not None:
            cmd += "--fxp {0} ".format(fxp)
        cmd += "--midi {0}.mid --wav {0}.wav".format(name)
        os.system(cmd)


if __name__ == "__main__":
    from mu.mel import ji

    gliss0 = old.GlissandoLine(
        old.InterpolationLine([
            old.PitchInterpolation(1, ji.r(8, 7)),
            old.PitchInterpolation(2, ji.r(1, 1)),
            old.PitchInterpolation(0, ji.r(1, 1)),
        ]))
    gliss1 = old.GlissandoLine(
        old.InterpolationLine([
            old.PitchInterpolation(1, ji.r(1, 1)),
            old.PitchInterpolation(1, ji.r(7, 8)),
            old.PitchInterpolation(1, ji.r(1, 1)),
            old.PitchInterpolation(0, ji.r(1, 1)),
        ]))
    vib0 = old.VibratoLine(
        old.InterpolationLine([
            old.PitchInterpolation(2, ji.r(30, 29)),
            old.PitchInterpolation(0, ji.r(1, 1)),
        ]),
        old.InterpolationLine([
Пример #5
0
    def __call__(self, melody: old.Melody) -> old.Melody:
        new_melody = melody.copy()
        melody_size = len(melody)

        for idx, tone in enumerate(new_melody):
            halved_duration = tone.duration * 0.5

            # only add ornamentation if there isn't any glissando yet
            if (not tone.glissando and not tone.pitch.is_empty
                    and halved_duration > self.__minima_gissando_duration):
                previous = None
                following = None
                previous_distance = None
                following_distance = None

                if idx != 0 and not melody[idx - 1].pitch.is_empty:
                    previous = melody[idx - 1]
                    previous_distance = previous.pitch.cents - tone.pitch.cents

                if idx + 1 != melody_size and not melody[idx +
                                                         1].pitch.is_empty:
                    following = melody[idx + 1]
                    following_distance = following.pitch.cents - tone.pitch.cents

                beginning_and_end_glissando = (
                    previous is not None
                    and abs(previous_distance) > self.__minima_gissando_size,
                    following is not None
                    and abs(following_distance) > self.__minima_gissando_size,
                )

                if any(beginning_and_end_glissando):

                    if next(self.__al):
                        if all(beginning_and_end_glissando):
                            glissando_type = next(
                                self.__glissando_type_generator)
                        else:
                            glissando_type = beginning_and_end_glissando.index(
                                True)

                        glissando_type = ((True, False), (False, True),
                                          (True, True))[glissando_type]

                        glissando_line = []
                        is_first = True
                        for is_allowed, distance in zip(
                                glissando_type,
                            (previous_distance, following_distance)):
                            if is_allowed:
                                data = self.get_glissando_values(
                                    halved_duration, distance)
                                remaining_time = halved_duration - data[1]
                                if is_first:
                                    data = (
                                        old.PitchInterpolation(
                                            data[1],
                                            mel.SimplePitch(0, data[0])),
                                        old.PitchInterpolation(
                                            remaining_time,
                                            mel.SimplePitch(0, 0)),
                                    )
                                else:
                                    data = (
                                        old.PitchInterpolation(
                                            remaining_time,
                                            mel.SimplePitch(0, 0)),
                                        old.PitchInterpolation(
                                            data[1], mel.SimplePitch(0, 0)),
                                        old.PitchInterpolation(
                                            0, mel.SimplePitch(0, data[0])),
                                    )
                            else:
                                data = [
                                    old.PitchInterpolation(
                                        halved_duration, mel.SimplePitch(0, 0))
                                ]
                                if not is_first:
                                    data.append(
                                        old.PitchInterpolation(
                                            0, mel.SimplePitch(0, 0)))

                            glissando_line.extend(data)
                            is_first = False

                        new_melody[idx].glissando = old.GlissandoLine(
                            interpolations.InterpolationLine(glissando_line))

        return new_melody