コード例 #1
0
ファイル: test_fmt_feature.py プロジェクト: akortman/mud
 def test(self):
     f = feature.IsNote()
     self.assertEqual(f.dim(), 1)
     self.assertEqual(f.make_subvector(note).shape, (1, ))
     self.assertEqual(f.make_subvector(note), np.ones(1))
     self.assertEqual(f.make_subvector(note)[0], 1)
     self.assertEqual(f.make_subvector(rest).shape, (1, ))
     self.assertEqual(f.make_subvector(rest), np.zeros(1))
     self.assertEqual(f.make_subvector(rest)[0], 0)
コード例 #2
0
ファイル: test_fmt_data.py プロジェクト: akortman/mud
    def test_pitch_labels_with_include_rest(self):
        pitch_labels = label.PitchLabels(octave_range=(4, 6),
                                         include_rest=True)
        formatter = mud.fmt.EventDataBuilder(features=(feature.IsNote(), ),
                                             labels=(pitch_labels, ))
        event_rest = mud.Event(mud.Rest(mud.Time(3.0)), mud.Time(1.0))

        rest_label = pitch_labels.get_label_of(None)
        self.assertEqual(rest_label, pitch_labels.num_labels - 1)
        l = formatter.make_labels(event_rest)
        self.assertEqual(len(l), 1)
        self.assertEqual(l[0], rest_label)
コード例 #3
0
ファイル: test_corpus.py プロジェクト: akortman/mud
    def test(self):
        from mud.fmt import label, feature
        files = ('test/test-files/canon_in_d.mxl',
                 'test/test-files/piece.musicxml')
        corpus = mud.Corpus(patterns=files)
        formatter = mud.fmt.EventDataBuilder(
            features=(feature.IsNote(), feature.IsRest(),
                      feature.NoteRelativePitch()),
            labels=(label.IsNote(), label.RelativePitchLabels()))
        resolution = 1.0 / 4.0
        data_corpus = corpus.format_data(formatter, resolution)

        # First piece
        self.assertEqual(len(data_corpus.data[0].bars), 27)
        self.assertEqual(len(data_corpus.data[1].bars), 1)
コード例 #4
0
ファイル: test_fmt_data.py プロジェクト: akortman/mud
    def test(self):
        pitch_labels = label.PitchLabels(octave_range=(4, 6))
        formatter = mud.fmt.EventDataBuilder(features=(
            feature.IsNote(),
            feature.IsRest(),
            feature.NotePitch(pitch_labels),
        ),
                                             labels=(pitch_labels, ))

        # TEST INPUT VECTOR CONSTRUCTION
        event_note = mud.Event(mud.Note('C#4', mud.Time(1.0)), mud.Time(0.0))
        v = formatter.make_vector(event_note)
        self.assertEqual(
            v.shape,
            (12 * 3 + 2, ))  # 3 octaves + 1 note indicator + 1 rest indicator
        note_label = pitch_labels.get_label_of('C#4')
        self.assertEqual(note_label, 1)
        for i in range(v.shape[0]):
            if (i == 0  # The note indicator
                    or i == 2 + note_label):  # The pitch marker
                self.assertAlmostEqual(v[i], 1.0)
            else:
                self.assertAlmostEqual(v[i], 0.0)

        event_rest = mud.Event(mud.Rest(mud.Time(3.0)), mud.Time(1.0))
        v = formatter.make_vector(event_rest)
        self.assertEqual(
            v.shape,
            (12 * 3 + 2, ))  # 3 octaves + 1 note indicator + 1 rest indicator
        for i in range(v.shape[0]):
            if i == 1:  # note indicator
                self.assertAlmostEqual(v[i], 1.0)
            else:
                self.assertAlmostEqual(v[i], 0.0)

        # TEST LABEL GENERATION
        l = formatter.make_labels(event_note)
        self.assertEqual(len(l), 1)
        self.assertEqual(l[0], note_label)
        self.assertEqual(l[0], 1)

        l = formatter.make_labels(event_rest)
        self.assertEqual(len(l), 1)
        self.assertEqual(l[0], None)
コード例 #5
0
import unittest
import mud
import mud.fmt.feature as feature
import mud.fmt.label as label
import numpy as np

formatter = mud.fmt.EventDataBuilder(
    features=(feature.IsNote(),
                feature.IsRest(),
                feature.NoteRelativePitch(),
                feature.ContinuesNextEvent()),
    labels  =(label.RelativePitchLabels(),
                label.ContinuesNextEventLabel())
)

class TestEventData(unittest.TestCase):
    def test(self):
        event = mud.Event(mud.Note('A6', 1.0), 2.0)
        event = mud.SlicedEvent((2.0, 2.5), event)
        # The event is a 1/2 note slice that continues into the next slice.
        event_data = mud.fmt.EventData(event, formatter)
        self.assertEqual(event_data.vec.tolist(),
                         [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0])
        self.assertEqual(event_data.labels, (9, 1))

class TestTimeSliceData(unittest.TestCase):
    def test(self):
        span = mud.Span([
            (mud.Note('C4', 1), mud.Time(0)),
            (mud.Note('G5', 1), mud.Time(0)),
            (mud.Rest(      1), mud.Time(1)),