Esempio n. 1
0
    def testExtractDrumTracksTooShort(self):
        testing_lib.add_track_to_sequence(self.note_sequence,
                                          0, [(12, 127, 3, 4), (14, 50, 6, 7)],
                                          is_drum=True)
        quantized_sequence = sequences_lib.quantize_note_sequence(
            self.note_sequence, steps_per_quarter=1)
        drum_tracks, _ = drums_lib.extract_drum_tracks(quantized_sequence,
                                                       min_bars=2,
                                                       gap_bars=1)
        drum_tracks = [list(drums) for drums in drum_tracks]
        self.assertEqual([], drum_tracks)

        del self.note_sequence.notes[:]
        testing_lib.add_track_to_sequence(self.note_sequence,
                                          0, [(12, 127, 3, 4), (14, 50, 7, 8)],
                                          is_drum=True)
        quantized_sequence = sequences_lib.quantize_note_sequence(
            self.note_sequence, steps_per_quarter=1)
        drum_tracks, _ = drums_lib.extract_drum_tracks(quantized_sequence,
                                                       min_bars=2,
                                                       gap_bars=1)
        drum_tracks = [list(drums) for drums in drum_tracks]
        self.assertEqual([[
            NO_DRUMS, NO_DRUMS, NO_DRUMS,
            DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
            DRUMS(14)
        ]], drum_tracks)
Esempio n. 2
0
  def testExtractDrumTracksTooShort(self):
    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(12, 127, 3, 4), (14, 50, 6, 7)],
        is_drum=True)
    quantized_sequence = sequences_lib.quantize_note_sequence(
        self.note_sequence, steps_per_quarter=1)
    drum_tracks, _ = drums_lib.extract_drum_tracks(
        quantized_sequence, min_bars=2, gap_bars=1)
    drum_tracks = [list(drums) for drums in drum_tracks]
    self.assertEqual([], drum_tracks)

    del self.note_sequence.notes[:]
    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(12, 127, 3, 4), (14, 50, 7, 8)],
        is_drum=True)
    quantized_sequence = sequences_lib.quantize_note_sequence(
        self.note_sequence, steps_per_quarter=1)
    drum_tracks, _ = drums_lib.extract_drum_tracks(
        quantized_sequence, min_bars=2, gap_bars=1)
    drum_tracks = [list(drums) for drums in drum_tracks]
    self.assertEqual(
        [[NO_DRUMS, NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
          DRUMS(14)]],
        drum_tracks)
Esempio n. 3
0
 def testExtractDrumTracksPadEnd(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 0, [(12, 127, 2, 4),
                                                     (14, 50, 6, 7)],
                                                 is_drum=True)
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 1, [(12, 127, 2, 4),
                                                     (15, 50, 6, 8)],
                                                 is_drum=True)
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 2, [(12, 127, 2, 4),
                                                     (16, 50, 8, 9)],
                                                 is_drum=True)
     expected = [[
         NO_DRUMS, NO_DRUMS,
         DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
         DRUMS(14, 15), NO_DRUMS,
         DRUMS(16), NO_DRUMS, NO_DRUMS, NO_DRUMS
     ]]
     drum_tracks, _ = drums_lib.extract_drum_tracks(self.quantized_sequence,
                                                    min_bars=1,
                                                    gap_bars=1,
                                                    pad_end=True)
     drum_tracks = [list(drums) for drums in drum_tracks]
     self.assertEqual(expected, drum_tracks)
Esempio n. 4
0
 def testExtractDrumTracksTooShort(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence,
                                                 0, [(12, 127, 2, 4),
                                                     (14, 50, 6, 7)],
                                                 is_drum=True)
     drum_tracks, _ = drums_lib.extract_drum_tracks(self.quantized_sequence,
                                                    min_bars=2,
                                                    gap_bars=1)
     drum_tracks = [list(drums) for drums in drum_tracks]
     self.assertEqual([], drum_tracks)
Esempio n. 5
0
 def testExtractDrumTracksLateStart(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, 102, 103), (13, 100, 104, 106)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   expected = [[NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, DRUMS(13)]]
   drum_tracks, _ = drums_lib.extract_drum_tracks(
       quantized_sequence, min_bars=1, gap_bars=1)
   drum_tracks = sorted([list(drums) for drums in drum_tracks])
   self.assertEqual(expected, drum_tracks)
Esempio n. 6
0
 def testExtractDrumTracksTooLongDiscard(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 127, 2, 4), (14, 50, 6, 15), (14, 50, 10, 15), (16, 100, 14, 19),
        (14, 100, 18, 19)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   drum_tracks, _ = drums_lib.extract_drum_tracks(
       quantized_sequence, min_bars=1, max_steps_discard=18, gap_bars=1)
   drum_tracks = [list(drums) for drums in drum_tracks]
   self.assertEqual([], drum_tracks)
Esempio n. 7
0
 def transform(self, quantized_sequence):
   try:
     drum_tracks, stats = drums_lib.extract_drum_tracks(
         quantized_sequence,
         min_bars=self._min_bars,
         max_steps_truncate=self._max_steps,
         gap_bars=self._gap_bars)
   except events_lib.NonIntegerStepsPerBarError as detail:
     tf.logging.warning('Skipped sequence: %s', detail)
     drum_tracks = []
     stats = [statistics.Counter('non_integer_steps_per_bar', 1)]
   self._set_stats(stats)
   return drum_tracks
Esempio n. 8
0
 def transform(self, quantized_sequence):
   try:
     drum_tracks, stats = drums_lib.extract_drum_tracks(
         quantized_sequence,
         min_bars=self._min_bars,
         max_steps_truncate=self._max_steps,
         gap_bars=self._gap_bars)
   except events_lib.NonIntegerStepsPerBarError as detail:
     tf.logging.warning('Skipped sequence: %s', detail)
     drum_tracks = []
     stats = [statistics.Counter('non_integer_steps_per_bar', 1)]
   self._set_stats(stats)
   return drum_tracks
Esempio n. 9
0
 def testExtractDrumTracksTooLongTruncate(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 127, 2, 4), (14, 50, 6, 15), (14, 50, 10, 15), (16, 100, 14, 19)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   expected = [[NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
                DRUMS(14), NO_DRUMS, NO_DRUMS, NO_DRUMS, DRUMS(14), NO_DRUMS,
                NO_DRUMS, NO_DRUMS]]
   drum_tracks, _ = drums_lib.extract_drum_tracks(
       quantized_sequence, min_bars=1, max_steps_truncate=14, gap_bars=1)
   drum_tracks = [list(drums) for drums in drum_tracks]
   self.assertEqual(expected, drum_tracks)
Esempio n. 10
0
 def testExtractMultipleDrumTracks(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)],
       is_drum=True)
   testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, 2, 4), (14, 50, 6, 8),
        (50, 100, 33, 37), (52, 100, 37, 38)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   expected = [[NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
                DRUMS(11, 14)],
               [NO_DRUMS, DRUMS(50), NO_DRUMS, NO_DRUMS, NO_DRUMS, DRUMS(52)]]
   drum_tracks, _ = drums_lib.extract_drum_tracks(
       quantized_sequence, min_bars=1, gap_bars=2)
   drum_tracks = sorted([list(drums) for drums in drum_tracks])
   self.assertEqual(expected, drum_tracks)
Esempio n. 11
0
  def testExtractDrumTracksSimple(self):
    testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(12, 100, 2, 4), (11, 1, 6, 7)],
        is_drum=True)
    testing_lib.add_track_to_sequence(
        self.note_sequence, 1,
        [(12, 127, 2, 4), (14, 50, 6, 9)],
        is_drum=True)
    quantized_sequence = sequences_lib.quantize_note_sequence(
        self.note_sequence, steps_per_quarter=1)
    expected = [[NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
                 DRUMS(11, 14)]]
    drum_tracks, _ = drums_lib.extract_drum_tracks(
        quantized_sequence, min_bars=1, gap_bars=1)

    self.assertEqual(1, len(drum_tracks))
    self.assertTrue(isinstance(drum_tracks[0], drums_lib.DrumTrack))

    drum_tracks = sorted([list(drums) for drums in drum_tracks])
    self.assertEqual(expected, drum_tracks)
Esempio n. 12
0
 def testExtractDrumTracksPadEnd(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 127, 2, 4), (14, 50, 6, 7)],
       is_drum=True)
   testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, 2, 4), (15, 50, 6, 8)],
       is_drum=True)
   testing_lib.add_track_to_sequence(
       self.note_sequence, 2,
       [(12, 127, 2, 4), (16, 50, 8, 9)],
       is_drum=True)
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   expected = [[NO_DRUMS, NO_DRUMS, DRUMS(12), NO_DRUMS, NO_DRUMS, NO_DRUMS,
                DRUMS(14, 15), NO_DRUMS, DRUMS(16), NO_DRUMS, NO_DRUMS,
                NO_DRUMS]]
   drum_tracks, _ = drums_lib.extract_drum_tracks(
       quantized_sequence, min_bars=1, gap_bars=1, pad_end=True)
   drum_tracks = [list(drums) for drums in drum_tracks]
   self.assertEqual(expected, drum_tracks)