예제 #1
0
    def test(self):
        f = feature.ContinuesNextEvent()
        self.assertEqual(f.dim(), 1)

        event = mud.Event(mud.Note('A6', mud.Time(4.0)), mud.Time(0.0))
        v = f.make_subvector(event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 0.0)

        # middle slice
        sliced_event = mud.SlicedEvent((2.0, 3.0), event)
        v = f.make_subvector(sliced_event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 1.0)

        # no slice
        sliced_event = mud.SlicedEvent((0.0, 4.0), event)
        v = f.make_subvector(sliced_event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 0.0)

        # slice from start
        sliced_event = mud.SlicedEvent((0.0, 3.5), event)
        v = f.make_subvector(sliced_event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 1.0)
예제 #2
0
    def test(self):
        f = feature.ContinuingPreviousEvent()
        self.assertEqual(f.dim(), 1)

        event = mud.Event(mud.Note('C#4', mud.Time(4.0)), mud.Time(0.0))
        v = f.make_subvector(event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 0.0)

        # middle slice
        sliced_event = mud.SlicedEvent((2.0, 3.0), event)
        v = f.make_subvector(sliced_event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 1.0)

        # no slice
        sliced_event = mud.SlicedEvent((0.0, 4.0), event)
        v = f.make_subvector(sliced_event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 0.0)

        # slice to end
        sliced_event = mud.SlicedEvent((2.0, 4.0), event)
        v = f.make_subvector(sliced_event)
        self.assertEqual(v.shape, (1, ))
        self.assertAlmostEqual(v[0], 1.0)
예제 #3
0
    def test_sliced_events(self):
        events = [
            mud.Event(mud.Note('C4', 1), mud.Time(0)),
            mud.Event(mud.Note('G5', 1), mud.Time(0)),
            mud.Event(mud.Rest(      1), mud.Time(1)),
            mud.Event(mud.Note('C4', 2), mud.Time(2)),
            mud.Event(mud.Note('A4', 2), mud.Time(2)),
        ]
        span = mud.Span(events, length=4, offset=4)

        ts = mud.TimeSlice(span, (2.5, 3.0))
        self.assertEqual(ts.num_events(), 2)

        sliced_events = list(ts.sliced_events())
        self.assertEqual(len(sliced_events), 2)

        self.assertNotEqual(sliced_events[0],
                            mud.Event(mud.Note('C4', 2.0), mud.Time(2)))
        self.assertNotEqual(sliced_events[0],
                            mud.Event(mud.Note('C4', 0.5), mud.Time(2)))
        self.assertEqual(sliced_events[0].time(), mud.Time(2.5))
        self.assertEqual(sliced_events[0].duration(), mud.Time(0.5))
        se0 = mud.SlicedEvent((2.5, 3.0), mud.Event(mud.Note('C4', 2), mud.Time(2)))
        self.assertEqual(sliced_events[0], se0)

        self.assertEqual(sliced_events[1].time(), mud.Time(2.5))
        self.assertEqual(sliced_events[1].duration(), mud.Time(0.5))
        se1 = mud.SlicedEvent((2.5, 3.0), mud.Event(mud.Note('A4', 2), mud.Time(2)))
        self.assertEqual(sliced_events[1], se1)
예제 #4
0
 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))
예제 #5
0
    def test(self):
        l = label.ContinuesNextEventLabel()
        event = mud.Event(mud.Note('A6', mud.Time(4.0)), mud.Time(0.0))
        self.assertEqual(l.get_event_label(event), 0)

        # middle slice
        sliced_event = mud.SlicedEvent((2.0, 3.0), event)
        self.assertFalse(sliced_event.is_note_end())
        self.assertEqual(l.get_event_label(sliced_event), 1)

        # no slice
        sliced_event = mud.SlicedEvent((0.0, 4.0), event)
        self.assertTrue(sliced_event.is_note_end())
        self.assertEqual(l.get_event_label(sliced_event), 0)

        # slice from start
        sliced_event = mud.SlicedEvent((0.0, 3.5), event)
        self.assertFalse(sliced_event.is_note_end())
        self.assertEqual(l.get_event_label(sliced_event), 1)