예제 #1
0
    def testSetLength(self):
        events = [DRUMS(60)]
        drums = drums_lib.DrumTrack(events, start_step=9)
        drums.set_length(5)
        self.assertListEqual(
            [DRUMS(60), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS], list(drums))
        self.assertEquals(9, drums.start_step)
        self.assertEquals(14, drums.end_step)

        drums = drums_lib.DrumTrack(events, start_step=9)
        drums.set_length(5, from_left=True)
        self.assertListEqual(
            [NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
             DRUMS(60)], list(drums))
        self.assertEquals(5, drums.start_step)
        self.assertEquals(10, drums.end_step)

        events = [DRUMS(60), NO_DRUMS, NO_DRUMS, NO_DRUMS]
        drums = drums_lib.DrumTrack(events)
        drums.set_length(3)
        self.assertListEqual([DRUMS(60), NO_DRUMS, NO_DRUMS], list(drums))
        self.assertEquals(0, drums.start_step)
        self.assertEquals(3, drums.end_step)

        drums = drums_lib.DrumTrack(events)
        drums.set_length(3, from_left=True)
        self.assertListEqual([NO_DRUMS, NO_DRUMS, NO_DRUMS], list(drums))
        self.assertEquals(1, drums.start_step)
        self.assertEquals(4, drums.end_step)
예제 #2
0
    def testToSequenceSimple(self):
        drums = drums_lib.DrumTrack([
            NO_DRUMS,
            DRUMS(1, 2), NO_DRUMS, NO_DRUMS, NO_DRUMS,
            DRUMS(2),
            DRUMS(3), NO_DRUMS, NO_DRUMS
        ])
        sequence = drums.to_sequence(velocity=10,
                                     sequence_start_time=2,
                                     qpm=60.0)

        self.assertProtoEquals(
            'ticks_per_quarter: 220 '
            'tempos < qpm: 60.0 > '
            'total_time: 3.75 '
            'notes < '
            '  pitch: 1 velocity: 10 instrument: 9 start_time: 2.25 end_time: 2.5 '
            '  is_drum: true '
            '> '
            'notes < '
            '  pitch: 2 velocity: 10 instrument: 9 start_time: 2.25 end_time: 2.5 '
            '  is_drum: true '
            '> '
            'notes < '
            '  pitch: 2 velocity: 10 instrument: 9 start_time: 3.25 end_time: 3.5 '
            '  is_drum: true '
            '> '
            'notes < '
            '  pitch: 3 velocity: 10 instrument: 9 start_time: 3.5 end_time: 3.75 '
            '  is_drum: true '
            '> ', sequence)
예제 #3
0
 def testFromQuantizedNoteSequenceMultipleTracks(self):
     testing_lib.add_track_to_sequence(self.note_sequence,
                                       0, [(12, 100, 0, 10),
                                           (40, 45, 2.5, 3.5),
                                           (60, 100, 4, 5.5)],
                                       is_drum=True)
     testing_lib.add_track_to_sequence(self.note_sequence,
                                       1, [(11, 55, .25, .5),
                                           (55, 120, 4, 4.25),
                                           (52, 99, 4.75, 5)],
                                       is_drum=True)
     testing_lib.add_track_to_sequence(self.note_sequence,
                                       2, [(13, 100, 0, 10),
                                           (14, 45, 2.5, 3.5),
                                           (15, 100, 4, 5.5)])
     quantized_sequence = sequences_lib.quantize_note_sequence(
         self.note_sequence, self.steps_per_quarter)
     drums = drums_lib.DrumTrack()
     drums.from_quantized_sequence(quantized_sequence, start_step=0)
     expected = ([
         DRUMS(12),
         DRUMS(11), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(40), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(55, 60), NO_DRUMS, NO_DRUMS,
         DRUMS(52)
     ])
     self.assertEqual(expected, list(drums))
     self.assertEqual(16, drums.steps_per_bar)
예제 #4
0
 def testFromQuantizedSequenceMultipleTracks(self):
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 0, [(12, 100, 0, 40),
                                                     (40, 45, 10, 14),
                                                     (60, 100, 16, 22)],
                                                 is_drum=True)
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 1, [(11, 55, 1, 2),
                                                     (55, 120, 16, 17),
                                                     (52, 99, 19, 20)],
                                                 is_drum=True)
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence, 2,
                                                 [(13, 100, 0, 40),
                                                  (14, 45, 10, 14),
                                                  (15, 100, 16, 22)])
     drums = drums_lib.DrumTrack()
     drums.from_quantized_sequence(self.quantized_sequence, start_step=0)
     expected = ([
         DRUMS(12),
         DRUMS(11), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(40), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(55, 60), NO_DRUMS, NO_DRUMS,
         DRUMS(52)
     ])
     self.assertEqual(expected, list(drums))
     self.assertEqual(16, drums.steps_per_bar)
예제 #5
0
    def testFromQuantizedNoteSequenceNotCommonTimeSig(self):
        self.note_sequence.time_signatures[0].numerator = 7
        self.note_sequence.time_signatures[0].denominator = 8

        testing_lib.add_track_to_sequence(self.note_sequence,
                                          0, [(12, 100, 0, 10),
                                              (11, 55, .25, .5),
                                              (40, 45, 2.5, 3.5),
                                              (30, 80, 2.5, 2.75),
                                              (55, 120, 4, 4.25),
                                              (52, 99, 4.75, 5)],
                                          is_drum=True)
        quantized_sequence = sequences_lib.quantize_note_sequence(
            self.note_sequence, self.steps_per_quarter)
        drums = drums_lib.DrumTrack()
        drums.from_quantized_sequence(quantized_sequence, start_step=0)
        expected = ([
            DRUMS(12),
            DRUMS(11), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
            NO_DRUMS, NO_DRUMS, NO_DRUMS,
            DRUMS(30, 40), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
            DRUMS(55), NO_DRUMS, NO_DRUMS,
            DRUMS(52)
        ])
        self.assertEqual(expected, list(drums))
        self.assertEqual(14, drums.steps_per_bar)
예제 #6
0
 def testDrumsExtractor(self):
     note_sequence = common_testing_lib.parse_test_proto(
         music_pb2.NoteSequence, """
     time_signatures: {
       numerator: 4
       denominator: 4}
     tempos: {
       qpm: 60}""")
     testing_lib.add_track_to_sequence(note_sequence,
                                       0, [(12, 100, 2, 4), (11, 1, 6, 7),
                                           (12, 1, 6, 8)],
                                       is_drum=True)
     testing_lib.add_track_to_sequence(note_sequence, 1, [(12, 127, 2, 4),
                                                          (14, 50, 6, 8)])
     quantized_sequence = sequences_lib.quantize_note_sequence(
         note_sequence, steps_per_quarter=1)
     expected_events = [[
         NO_DRUMS, NO_DRUMS,
         DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(11, 12)
     ]]
     expected_drum_tracks = []
     for events_list in expected_events:
         drums = drums_lib.DrumTrack(events_list,
                                     steps_per_quarter=1,
                                     steps_per_bar=4)
         expected_drum_tracks.append(drums)
     unit = drum_pipelines.DrumsExtractor(min_bars=1, gap_bars=1)
     self._unit_transform_test(unit, quantized_sequence,
                               expected_drum_tracks)
예제 #7
0
    def testFromNotesStepsPerBar(self):
        self.note_sequence.time_signatures[0].numerator = 7
        self.note_sequence.time_signatures[0].denominator = 8

        quantized_sequence = sequences_lib.quantize_note_sequence(
            self.note_sequence, steps_per_quarter=12)
        drums = drums_lib.DrumTrack()
        drums.from_quantized_sequence(quantized_sequence, start_step=0)
        self.assertEqual(42, drums.steps_per_bar)
예제 #8
0
 def testFromNotesStepsPerBar(self):
     self.quantized_sequence.time_signature = (
         sequences_lib.QuantizedSequence.TimeSignature(numerator=7,
                                                       denominator=8))
     self.quantized_sequence.steps_per_quarter = 12
     self.quantized_sequence.tracks[0] = []
     drums = drums_lib.DrumTrack()
     drums.from_quantized_sequence(self.quantized_sequence, start_step=0)
     self.assertEqual(42, drums.steps_per_bar)
예제 #9
0
    def testToSequenceEmpty(self):
        drums = drums_lib.DrumTrack()
        sequence = drums.to_sequence(velocity=10,
                                     sequence_start_time=2,
                                     qpm=60.0)

        self.assertProtoEquals(
            'ticks_per_quarter: 220 '
            'tempos < qpm: 60.0 > ', sequence)
예제 #10
0
 def testFromNotesTrimEmptyMeasures(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, 1.5, 1.75), (11, 100, 2, 2.25)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, self.steps_per_quarter)
   drums = drums_lib.DrumTrack()
   drums.from_quantized_sequence(quantized_sequence, search_start_step=0)
   expected = [NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
               DRUMS(12), NO_DRUMS, DRUMS(11)]
   self.assertEqual(expected, list(drums))
   self.assertEqual(16, drums.steps_per_bar)
예제 #11
0
 def testFromNotesTrimEmptyMeasures(self):
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 0, [(12, 100, 6, 7),
                                                     (11, 100, 8, 9)],
                                                 is_drum=True)
     drums = drums_lib.DrumTrack()
     drums.from_quantized_sequence(self.quantized_sequence, start_step=0)
     expected = [
         NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(12), NO_DRUMS,
         DRUMS(11)
     ]
     self.assertEqual(expected, list(drums))
     self.assertEqual(16, drums.steps_per_bar)
예제 #12
0
    def testToSequenceEndsWithNonzeroStart(self):
        drums = drums_lib.DrumTrack([NO_DRUMS, DRUMS(1), NO_DRUMS],
                                    start_step=4)
        sequence = drums.to_sequence(velocity=100,
                                     sequence_start_time=0.5,
                                     qpm=60.0)

        self.assertProtoEquals(
            'ticks_per_quarter: 220 '
            'tempos < qpm: 60.0 > '
            'total_time: 2.0 '
            'notes < '
            '  pitch: 1 velocity: 100 instrument: 9 start_time: 1.75 end_time: 2.0 '
            '  is_drum: true '
            '> ', sequence)
예제 #13
0
 def testFromQuantizedNoteSequence(self):
   music_testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, 0.0, 10.0), (11, 55, 0.25, 0.50), (40, 45, 2.50, 3.50),
        (55, 120, 4.0, 4.25), (60, 100, 4.0, 5.5), (52, 99, 4.75, 5.0)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, self.steps_per_quarter)
   drums = drums_lib.DrumTrack()
   drums.from_quantized_sequence(quantized_sequence, search_start_step=0)
   expected = ([DRUMS(12), DRUMS(11), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
                NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, DRUMS(40), NO_DRUMS,
                NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, DRUMS(55, 60),
                NO_DRUMS, NO_DRUMS, DRUMS(52)])
   self.assertEqual(expected, list(drums))
   self.assertEqual(16, drums.steps_per_bar)
예제 #14
0
  def testFromNotesStartAndEndStep(self):
    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(12, 100, 1, 2), (11, 100, 2.25, 2.5), (13, 100, 3.25, 3.75),
         (14, 100, 8.75, 9), (15, 100, 9.25, 10.75)],
        is_drum=True)

    quantized_sequence = sequences_lib.quantize_note_sequence(
        self.note_sequence, self.steps_per_quarter)

    drums = drums_lib.DrumTrack()
    drums.from_quantized_sequence(quantized_sequence, search_start_step=18)
    expected = [NO_DRUMS, DRUMS(14), NO_DRUMS, DRUMS(15)]
    self.assertEqual(expected, list(drums))
    self.assertEqual(34, drums.start_step)
    self.assertEqual(38, drums.end_step)
예제 #15
0
 def testFromNotesStartAndEndStep(self):
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 0, [(12, 100, 4, 8),
                                                     (11, 100, 9, 10),
                                                     (13, 100, 13, 15),
                                                     (14, 100, 19, 20),
                                                     (15, 100, 21, 27)],
                                                 is_drum=True)
     drums = drums_lib.DrumTrack()
     drums.from_quantized_sequence(self.quantized_sequence, start_step=18)
     expected = [
         NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(14), NO_DRUMS,
         DRUMS(15)
     ]
     self.assertEqual(expected, list(drums))
     self.assertEqual(16, drums.start_step)
     self.assertEqual(22, drums.end_step)
예제 #16
0
 def testDrumsExtractor(self):
   quantized_sequence = sequences_lib.QuantizedSequence()
   quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_track_to_sequence(
       quantized_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 7), (12, 1, 6, 8)],
       is_drum=True)
   testing_lib.add_quantized_track_to_sequence(
       quantized_sequence, 1,
       [(12, 127, 2, 4), (14, 50, 6, 8)])
   expected_events = [
       [NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
        DRUMS(11, 12)]]
   expected_drum_tracks = []
   for events_list in expected_events:
     drums = drums_lib.DrumTrack(
         events_list, steps_per_quarter=1, steps_per_bar=4)
     expected_drum_tracks.append(drums)
   unit = drum_pipelines.DrumsExtractor(min_bars=1, gap_bars=1)
   self._unit_transform_test(unit, quantized_sequence, expected_drum_tracks)
예제 #17
0
 def testFromQuantizedSequenceNotCommonTimeSig(self):
     self.quantized_sequence.time_signature = (
         sequences_lib.QuantizedSequence.TimeSignature(numerator=7,
                                                       denominator=8))
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 0, [(12, 100, 0, 40),
                                                     (11, 55, 1, 2),
                                                     (40, 45, 10, 14),
                                                     (30, 80, 10, 11),
                                                     (55, 120, 16, 17),
                                                     (52, 99, 19, 20)],
                                                 is_drum=True)
     drums = drums_lib.DrumTrack()
     drums.from_quantized_sequence(self.quantized_sequence, start_step=0)
     expected = ([
         DRUMS(12),
         DRUMS(11), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(30, 40), NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(55), NO_DRUMS, NO_DRUMS,
         DRUMS(52)
     ])
     self.assertEqual(expected, list(drums))
     self.assertEqual(14, drums.steps_per_bar)