コード例 #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 test_pitch_interpolation(self):
     p0 = old.PitchInterpolation(3, mel.SimplePitch(0, 200))
     p1 = old.PitchInterpolation(0, mel.SimplePitch(0, 0))
     p2 = old.PitchInterpolation(0, mel.SimplePitch(0, 0))
     self.assertNotEqual(hash(p0), hash(p1))
     self.assertEqual(hash(p1), hash(p2))
     interp0 = (200, 100, 0)
     self.assertEqual(p0.interpolate(p1, 3), interp0)
コード例 #3
0
 def test_interpolation(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))
     interpol = line(1)
     self.assertEqual(interpol, (300, 200, 100, 0, -100, -200, -300))
     self.assertRaises(
         ValueError, lambda: interpolations.InterpolationLine((p0, p0, p1))
     )
コード例 #4
0
    def from_concert_pitch(
        cls,
        name: str,
        concert_pitch: float = None,
        tempo_estimation_method: str = "essentia",
    ) -> "Transcription":

        root = cls._get_root("{}.svl".format(name))
        frequency_range = root[0][0].attrib["minimum"], root[0][0].attrib[
            "maximum"]
        data = cls._filter_data_from_root(root)

        if concert_pitch is None:
            concert_pitch = data[0][0]

        new_data = []
        for tone in data:
            freq = tone[0]
            cents = mel.SimplePitch.hz2ct(concert_pitch, freq)
            pitch = mel.SimplePitch(concert_pitch_freq=concert_pitch,
                                    cents=cents)
            new_data.append((pitch, ) + tone[1:])

        melody = cls._convert_data2melody(new_data, name,
                                          tempo_estimation_method)
        return cls(name, tuple(melody), frequency_range)
コード例 #5
0
 def test_vibrato_line(self):
     p0 = old.PitchInterpolation(2, mel.SimplePitch(0, 300))
     p1 = old.PitchInterpolation(4, mel.SimplePitch(0, 200))
     p2 = old.PitchInterpolation(0, mel.SimplePitch(0, 600))
     p3 = old.PitchInterpolation(4, mel.SimplePitch(0, -200))
     p4 = old.PitchInterpolation(2, mel.SimplePitch(0, -600))
     p5 = old.PitchInterpolation(0, mel.SimplePitch(0, -900))
     r0 = old.RhythmicInterpolation(6, rhy.Unit(2))
     r1 = old.RhythmicInterpolation(0, rhy.Unit(2))
     line0 = interpolations.InterpolationLine((p0, p1, p2))
     line1 = interpolations.InterpolationLine((p3, p4, p5))
     line2 = interpolations.InterpolationLine((r0, r1))
     vib0 = old.VibratoLine(line0, line1, line2, "up")
     vib1 = old.VibratoLine(line0, line1, line2, "down")
     interpol0 = vib0.interpolate(0.5)
     interpol1 = vib1.interpolate(0.5)
     self.assertNotEqual(interpol0, interpol1)
     self.assertEqual(
         tuple(round(n, 2) for n in interpol0),
         (
             -0.0,
             275.0,
             -0.0,
             -371.43,
             -0.0,
             257.14,
             -0.0,
             -600.0,
             -0.0,
             485.71,
             -0.0,
             -900.0,
         ),
     )
     self.assertEqual(
         tuple(round(n, 2) for n in interpol1),
         (
             0.0,
             -257.14,
             0.0,
             225.0,
             0.0,
             -485.71,
             0.0,
             371.43,
             0.0,
             -750.0,
             0.0,
             600.0,
         ),
     )
コード例 #6
0
 def mk_division_floats() -> tuple:
     cents = MonochordString.mk_cents()
     return tuple(mel.SimplePitch(1, ct).freq for ct in cents)
コード例 #7
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