Esempio n. 1
0
    def test_average_pitch_range(self):

        feature = vs.separators.neural.network.features.voice_level.AveragePitchRange

        note1 = vs.Note("C", 4, (0, 0), onset=0)
        note2 = vs.Note("G", 4, (0, 0), onset=1)

        voice1 = vs.Voice(note1)
        voice2 = vs.Voice(note2)

        voice1.link(voice2)

        active_voices = vs.ActiveVoices()

        MIN_PITCH = vs.separators.neural.network.features.constants.MIN_PITCH
        MAX_PITCH = vs.separators.neural.network.features.constants.MAX_PITCH
        GRANULARITY = vs.separators.neural.network.features.constants.GRANULARITY

        interval = (MAX_PITCH - MIN_PITCH) / GRANULARITY

        true_data = [0] * len(np.arange(MIN_PITCH, MAX_PITCH, interval))
        true_data[5] = 1

        expected_data = feature.generate(voice2, active_voices)

        self.assertEqual(true_data, expected_data)
Esempio n. 2
0
    def test_equal(self):

        note = vs.Note(name="C", octave=4, location=(0, 0))

        with self.subTest("equal"):
            self.assertEqual(self.note, note)

        with self.subTest("hash"):
            self.assertEqual(hash(self.note), hash(note))
Esempio n. 3
0
    def test_position_difference(self):

        feature = vs.separators.neural.network.features.pair_level.PositionDifference

        note1 = vs.Note("C", 4, (0, 0), index=0)
        note2 = vs.Note("D", 4, (0, 0), index=1)
        note3 = vs.Note("E", 4, (0, 1), index=0)

        voice1 = vs.Voice(note1)
        voice2 = vs.Voice(note2)

        active_voices = vs.ActiveVoices()
        active_voices.insert([voice1, voice2])

        data = feature.generate(note3, voice1, active_voices)
        
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0], 1)
Esempio n. 4
0
    def setUp(self):

        self.note = vs.Note(name="C",
                            octave=4,
                            location=(0, 0),
                            attribute=True)
Esempio n. 5
0
    def test_less_than(self):

        note_d = vs.Note(name="D", octave=4, location=(0, 0))

        self.assertLess(self.note, note_d)
Esempio n. 6
0
    def test_not_equal(self):

        note = vs.Note(name="D", octave=4, location=(0, 0))

        self.assertNotEqual(self.note, note)
Esempio n. 7
0
    def setUp(self):

        self.note = vs.Note(name="C", octave=4, location=(0, 0))
        self.voice = vs.Voice(self.note)
Esempio n. 8
0
    def test_less_than(self):

        note_d = vs.Note(name="D", octave=4, location=(0, 0))
        voice_d = vs.Voice(note_d)

        self.assertLess(self.voice, voice_d)
Esempio n. 9
0
    def test_not_equal(self):

        note = vs.Note(name="D", octave=4, location=(0, 0))
        voice = vs.Voice(note)

        self.assertNotEqual(self.voice, voice)
Esempio n. 10
0
def validate_annotations(args):

    sheet = args.sheet
    beat_horizon = args.beat_horizon

    score = m21.converter.parse(sheet)

    color_map = {}
    id_map = {}
    pair_map = {}

    denomination = 0

    onset_origin = F()
    ql_origin = F()

    measures = score.semiFlat.getElementsByClass("Measure").stream()
    measure_groups = map(m21.stream.Stream,
                         m21.stream.iterator.OffsetIterator(measures))
    for measure_index, measure_group in enumerate(measure_groups, start=1):
        top_measure = measure_group[0]

        if top_measure.getElementsByClass("TimeSignature"):
            logger.debug("m{} | changing time signature".format(measure_index))

            ql_distance = top_measure.offset - ql_origin

            onset_origin += ql_distance * denomination / vs.Score.QUARTER
            ql_origin = F(top_measure.offset)

            timesig = top_measure.getElementsByClass("TimeSignature")[0]
            denomination = timesig.denominator

        chords = measure_group.flat.notes.stream()
        chord_groups = m21.stream.iterator.OffsetIterator(chords)
        for chord_index, chord_group in enumerate(chord_groups, start=1):
            top_chord = chord_group[0]

            ql_distance = top_chord.offset - ql_origin
            onset = onset_origin + ql_distance * denomination / vs.Score.QUARTER

            onset_colors = {}
            onset_ids = {}
            for chord_part in chord_group:
                if chord_part.duration.isGrace:
                    continue

                lyrics = [lyric.text.split(",") for lyric in chord_part.lyrics]

                note_group = chord_part if chord_part.isChord else [chord_part]
                for part_index, note_part in enumerate(reversed(note_group)):

                    note = vs.Note(name=note_part.name,
                                   octave=note_part.octave,
                                   location=(measure_index, chord_index),
                                   onset=onset)

                    assert part_index < len(
                        lyrics) if lyrics else True, "{} | {}".format(
                            note, "missing lyric")

                    lyric = lyrics[part_index] if lyrics else []
                    color = note_part.style.color

                    assert color != "#000000" and color is not None, "{} | {}".format(
                        note, "black")

                    assert not any(id_ in onset_ids
                                   for id_ in lyric), "{} | {}".format(
                                       note, "duplicate id")

                    assert color not in onset_colors, "{} | {}".format(
                        note, "duplicate color")

                    assert color in color_map or lyric, "{} | {}".format(
                        note, "missing lyric")

                    assert (color_map[color][0] == lyric[0]
                            if color in color_map and lyric else
                            True), ("{} | {}".format(
                                note,
                                "leading id changed from {} to {}".format(
                                    color_map[color][0], lyric[0])))

                    if lyric:
                        color_map[color] = lyric

                    if color_map[color][0] in id_map:

                        assert id_map[
                            color_map[color][0]] == color, "{} | {}".format(
                                note, "color changed from leading id {} to {}".
                                format(id_map[color_map[color][0]], color))

                    id_map[color_map[color][0]] = color

                    for id_ in color_map[color]:

                        if id_ in pair_map:
                            left_note = pair_map[id_]

                            if note.onset - left_note.onset > beat_horizon:
                                logger.warning("{} - {} | {}".format(
                                    left_note, note, "beat horizon exceeded"))

                        pair_map[id_] = note

    for id_, note in pair_map.items():
        logger.info("{} | last use of id {}".format(note, id_))
Esempio n. 11
0
    def setUp(self):

        self.note = vs.Note(name="C", octave=4, location=(0, 0))
        self.chord = vs.Chord(notes=[self.note], attribute=True)