Esempio n. 1
0
  def testFromQuantizedNoteSequenceWithQuantizedVelocity(self):
    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(60, 100, 0.0, 4.0), (64, 100, 0.0, 3.0), (67, 127, 1.0, 2.0)])
    quantized_sequence = sequences_lib.quantize_note_sequence_absolute(
        self.note_sequence, steps_per_second=100)
    performance = list(performance_lib.Performance(
        quantized_sequence, num_velocity_bins=16))

    pe = performance_lib.PerformanceEvent
    expected_performance = [
        pe(pe.VELOCITY, 13),
        pe(pe.NOTE_ON, 60),
        pe(pe.NOTE_ON, 64),
        pe(pe.TIME_SHIFT, 100),
        pe(pe.VELOCITY, 16),
        pe(pe.NOTE_ON, 67),
        pe(pe.TIME_SHIFT, 100),
        pe(pe.NOTE_OFF, 67),
        pe(pe.TIME_SHIFT, 100),
        pe(pe.NOTE_OFF, 64),
        pe(pe.TIME_SHIFT, 100),
        pe(pe.NOTE_OFF, 60),
    ]
    self.assertEqual(expected_performance, performance)
Esempio n. 2
0
  def testPerformanceNoteDensitySequence(self):
    performance = performance_lib.Performance(steps_per_second=100)

    pe = performance_lib.PerformanceEvent
    perf_events = [
        pe(pe.NOTE_ON, 60),
        pe(pe.NOTE_ON, 64),
        pe(pe.NOTE_ON, 67),
        pe(pe.TIME_SHIFT, 50),
        pe(pe.NOTE_OFF, 60),
        pe(pe.NOTE_OFF, 64),
        pe(pe.TIME_SHIFT, 25),
        pe(pe.NOTE_OFF, 67),
        pe(pe.NOTE_ON, 64),
        pe(pe.TIME_SHIFT, 25),
        pe(pe.NOTE_OFF, 64)
    ]
    for event in perf_events:
      performance.append(event)

    expected_density_sequence = [
        4.0, 4.0, 4.0, 4.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 0.0]

    density_sequence = performance_lib.performance_note_density_sequence(
        performance, window_size_seconds=1.0)

    self.assertEqual(expected_density_sequence, density_sequence)
Esempio n. 3
0
  def testSetLengthAddSteps(self):
    performance = performance_lib.Performance(steps_per_second=100)

    performance.set_length(50)
    self.assertEqual(50, performance.num_steps)
    self.assertListEqual([0], performance.steps)

    pe = performance_lib.PerformanceEvent
    perf_events = [pe(pe.TIME_SHIFT, 50)]
    self.assertEqual(perf_events, list(performance))

    performance.set_length(150)
    self.assertEqual(150, performance.num_steps)
    self.assertListEqual([0, 100], performance.steps)

    pe = performance_lib.PerformanceEvent
    perf_events = [
        pe(pe.TIME_SHIFT, 100),
        pe(pe.TIME_SHIFT, 50),
    ]
    self.assertEqual(perf_events, list(performance))

    performance.set_length(200)
    self.assertEqual(200, performance.num_steps)
    self.assertListEqual([0, 100], performance.steps)

    pe = performance_lib.PerformanceEvent
    perf_events = [
        pe(pe.TIME_SHIFT, 100),
        pe(pe.TIME_SHIFT, 100),
    ]
    self.assertEqual(perf_events, list(performance))
Esempio n. 4
0
  def testToSequenceWithRepeatedNotes(self):
    performance = performance_lib.Performance(steps_per_second=100)

    pe = performance_lib.PerformanceEvent
    perf_events = [
        pe(pe.NOTE_ON, 60),
        pe(pe.NOTE_ON, 64),
        pe(pe.TIME_SHIFT, 100),
        pe(pe.NOTE_ON, 60),
        pe(pe.TIME_SHIFT, 100),
    ]
    for event in perf_events:
      performance.append(event)

    performance_ns = performance.to_sequence()

    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(60, 100, 0.0, 2.0), (64, 100, 0.0, 2.0), (60, 100, 1.0, 2.0)])

    # Make comparison easier by sorting.
    performance_ns.notes.sort(key=lambda n: (n.start_time, n.pitch))
    self.note_sequence.notes.sort(key=lambda n: (n.start_time, n.pitch))

    self.assertEqual(self.note_sequence, performance_ns)
    def testFromQuantizedNoteSequence(self):
        testing_lib.add_track_to_sequence(self.note_sequence, 0,
                                          [(60, 100, 0.0, 4.0),
                                           (64, 100, 0.0, 3.0),
                                           (67, 100, 1.0, 2.0)])
        quantized_sequence = sequences_lib.quantize_note_sequence_absolute(
            self.note_sequence, steps_per_second=100)
        performance = performance_lib.Performance(quantized_sequence)

        self.assertEqual(100, performance.steps_per_second)

        pe = performance_lib.PerformanceEvent
        expected_performance = [
            pe(pe.NOTE_ON, 60),
            pe(pe.NOTE_ON, 64),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_ON, 67),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 67),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 64),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 60),
        ]
        self.assertEqual(expected_performance, list(performance))
Esempio n. 6
0
    def testExtract(self):
        performance = performance_lib.Performance(steps_per_second=100)

        pe = performance_lib.PerformanceEvent
        perf_events = [
            pe(pe.NOTE_ON, 60),
            pe(pe.NOTE_ON, 64),
            pe(pe.NOTE_ON, 67),
            pe(pe.TIME_SHIFT, 50),
            pe(pe.NOTE_OFF, 60),
            pe(pe.NOTE_OFF, 64),
            pe(pe.TIME_SHIFT, 25),
            pe(pe.NOTE_OFF, 67),
            pe(pe.NOTE_ON, 64),
            pe(pe.TIME_SHIFT, 25),
            pe(pe.NOTE_OFF, 64)
        ]
        for event in perf_events:
            performance.append(event)

        expected_density_sequence = [
            4.0, 4.0, 4.0, 4.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 0.0
        ]

        density_sequence = self.control.extract(performance)
        self.assertEqual(expected_density_sequence, density_sequence)
Esempio n. 7
0
    def testSteps(self):
        pe = performance_lib.PerformanceEvent
        perf_events = [
            pe(pe.NOTE_ON, 60),
            pe(pe.NOTE_ON, 64),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 60),
            pe(pe.NOTE_OFF, 64),
        ]

        performance = performance_lib.Performance(steps_per_second=100)
        for event in perf_events:
            performance.append(event)
        self.assertListEqual([0, 0, 0, 100, 100], performance.steps)

        performance = performance_lib.Performance(steps_per_second=100,
                                                  start_step=100)
        for event in perf_events:
            performance.append(event)
        self.assertListEqual([100, 100, 100, 200, 200], performance.steps)
Esempio n. 8
0
  def testToSequence(self):
    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(60, 100, 0.0, 4.0), (64, 100, 0.0, 3.0), (67, 100, 1.0, 2.0)])
    quantized_sequence = sequences_lib.quantize_note_sequence_absolute(
        self.note_sequence, steps_per_second=100)
    performance = performance_lib.Performance(quantized_sequence)
    performance_ns = performance.to_sequence()

    # Make comparison easier by sorting.
    performance_ns.notes.sort(key=lambda n: (n.start_time, n.pitch))
    self.note_sequence.notes.sort(key=lambda n: (n.start_time, n.pitch))

    self.assertEqual(self.note_sequence, performance_ns)
Esempio n. 9
0
  def testPerformancePitchHistogramSequence(self):
    performance = performance_lib.Performance(steps_per_second=100)

    pe = performance_lib.PerformanceEvent
    perf_events = [
        pe(pe.NOTE_ON, 60),
        pe(pe.NOTE_ON, 64),
        pe(pe.NOTE_ON, 67),
        pe(pe.TIME_SHIFT, 50),
        pe(pe.NOTE_OFF, 60),
        pe(pe.NOTE_OFF, 64),
        pe(pe.TIME_SHIFT, 25),
        pe(pe.NOTE_OFF, 67),
        pe(pe.NOTE_ON, 64),
        pe(pe.TIME_SHIFT, 25),
        pe(pe.NOTE_OFF, 64)
    ]
    for event in perf_events:
      performance.append(event)

    expected_histogram_sequence = [
        [0.25, 0, 0, 0, 0.375, 0, 0, 0.375, 0, 0, 0, 0],
        [0.25, 0, 0, 0, 0.375, 0, 0, 0.375, 0, 0, 0, 0],
        [0.25, 0, 0, 0, 0.375, 0, 0, 0.375, 0, 0, 0, 0],
        [0.25, 0, 0, 0, 0.375, 0, 0, 0.375, 0, 0, 0, 0],
        [0.0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0, 0],
        [0.0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0, 0],
        [0.0, 0, 0, 0, 0.5, 0, 0, 0.5, 0, 0, 0, 0],
        [0.0, 0, 0, 0, 1.0, 0, 0, 0.0, 0, 0, 0, 0],
        [0.0, 0, 0, 0, 1.0, 0, 0, 0.0, 0, 0, 0, 0],
        [0.0, 0, 0, 0, 1.0, 0, 0, 0.0, 0, 0, 0, 0],
        [1.0 / 12.0] * 12
    ]

    histogram_sequence = performance_lib.performance_pitch_histogram_sequence(
        performance, window_size_seconds=1.0, prior_count=0)

    self.assertEqual(expected_histogram_sequence, histogram_sequence)
Esempio n. 10
0
    def testSetLengthRemoveSteps(self):
        performance = performance_lib.Performance(steps_per_second=100)

        pe = performance_lib.PerformanceEvent
        perf_events = [
            pe(pe.NOTE_ON, 60),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 60),
            pe(pe.NOTE_ON, 64),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 64),
            pe(pe.NOTE_ON, 67),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 67),
        ]
        for event in perf_events:
            performance.append(event)

        performance.set_length(200)
        perf_events = [
            pe(pe.NOTE_ON, 60),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 60),
            pe(pe.NOTE_ON, 64),
            pe(pe.TIME_SHIFT, 100),
            pe(pe.NOTE_OFF, 64),
            pe(pe.NOTE_ON, 67),
        ]
        self.assertEqual(perf_events, list(performance))

        performance.set_length(50)
        perf_events = [
            pe(pe.NOTE_ON, 60),
            pe(pe.TIME_SHIFT, 50),
        ]
        self.assertEqual(perf_events, list(performance))
Esempio n. 11
0
    def testExtract(self):
        performance = performance_lib.Performance(steps_per_second=100)

        pe = performance_lib.PerformanceEvent
        perf_events = [
            pe(pe.NOTE_ON, 60),
            pe(pe.NOTE_ON, 64),
            pe(pe.NOTE_ON, 67),
            pe(pe.TIME_SHIFT, 50),
            pe(pe.NOTE_OFF, 60),
            pe(pe.NOTE_OFF, 64),
            pe(pe.TIME_SHIFT, 25),
            pe(pe.NOTE_OFF, 67),
            pe(pe.NOTE_ON, 64),
            pe(pe.TIME_SHIFT, 25),
            pe(pe.NOTE_OFF, 64)
        ]
        for event in perf_events:
            performance.append(event)

        expected_histogram_sequence = [
            [0.5, 0, 0, 0, 0.75, 0, 0, 0.75, 0, 0, 0, 0],
            [0.5, 0, 0, 0, 0.75, 0, 0, 0.75, 0, 0, 0, 0],
            [0.5, 0, 0, 0, 0.75, 0, 0, 0.75, 0, 0, 0, 0],
            [0.5, 0, 0, 0, 0.75, 0, 0, 0.75, 0, 0, 0, 0],
            [0, 0, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0, 0],
            [0, 0, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0, 0],
            [0, 0, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0, 0],
            [0, 0, 0, 0, 0.25, 0, 0, 0.0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0.25, 0, 0, 0.0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0.25, 0, 0, 0.0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        ]

        histogram_sequence = self.control.extract(performance)
        self.assertEqual(expected_histogram_sequence, histogram_sequence)