Esempio n. 1
0
 def testExtractDrumTracksPadEnd(self):
   music_testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 127, 2, 4), (14, 50, 6, 7)],
       is_drum=True)
   music_testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, 2, 4), (15, 50, 6, 8)],
       is_drum=True)
   music_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, _ = drum_pipelines.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)
Esempio n. 2
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, 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)
  def testExtractMelodiesMelodyTooShort(self):
    music_testing_lib.add_track_to_sequence(
        self.note_sequence, 0,
        [(12, 127, 2, 4), (14, 50, 6, 7)])
    music_testing_lib.add_track_to_sequence(
        self.note_sequence, 1,
        [(12, 127, 2, 4), (14, 50, 6, 8)])
    music_testing_lib.add_track_to_sequence(
        self.note_sequence, 2,
        [(12, 127, 2, 4), (14, 50, 6, 9)])

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

    expected = [[NO_EVENT, NO_EVENT, 12, NO_EVENT, NOTE_OFF, NO_EVENT, 14,
                 NO_EVENT],
                [NO_EVENT, NO_EVENT, 12, NO_EVENT, NOTE_OFF, NO_EVENT, 14,
                 NO_EVENT, NO_EVENT]]
    melodies, _ = melody_pipelines.extract_melodies(
        quantized_sequence, min_bars=2, gap_bars=1, min_unique_pitches=2,
        ignore_polyphonic_notes=True)
    melodies = [list(melody) for melody in melodies]
    self.assertEqual(expected, melodies)
Esempio n. 4
0
 def _SyntheticSequence(self, duration, note):
     seq = music_pb2.NoteSequence(total_time=duration)
     testing_lib.add_track_to_sequence(seq, 0, [(note, 100, 0, duration)])
     return seq
 def _CreateSyntheticSequence(self):
     seq = music_pb2.NoteSequence(total_time=10)
     testing_lib.add_track_to_sequence(seq, 0, [(50, 20, 0, 5)])
     testing_lib.add_track_to_sequence(seq, 0, [(50, 80, 5, 10)])
     return seq
    def testToNoteSequenceWithChords(self):
        sequence = copy.deepcopy(self.sequence)
        testing_lib.add_track_to_sequence(sequence, 0, [
            (64, 100, 0, 2),
            (60, 100, 0, 4),
            (67, 100, 2, 4),
            (62, 100, 4, 6),
            (59, 100, 4, 8),
            (67, 100, 6, 8),
        ])
        testing_lib.add_track_to_sequence(sequence,
                                          1, [
                                              (40, 100, 0, 0.125),
                                              (50, 100, 0, 0.125),
                                              (50, 100, 2, 2.125),
                                              (40, 100, 4, 4.125),
                                              (50, 100, 4, 4.125),
                                              (50, 100, 6, 6.125),
                                          ],
                                          is_drum=True)
        testing_lib.add_chords_to_sequence(sequence, [('C', 0), ('G', 4)])
        converter = data_hierarchical.MultiInstrumentPerformanceConverter(
            hop_size_bars=2,
            chunk_size_bars=2,
            chord_encoding=note_seq.MajorMinorChordOneHotEncoding())
        tensors = converter.to_tensors(sequence)
        self.assertEqual(2, len(tensors.outputs))
        sequences = converter.from_tensors(tensors.outputs, tensors.controls)
        self.assertEqual(2, len(sequences))

        sequence1 = copy.deepcopy(self.sequence)
        testing_lib.add_track_to_sequence(sequence1, 0, [(64, 100, 0, 2),
                                                         (60, 100, 0, 4),
                                                         (67, 100, 2, 4)])
        testing_lib.add_track_to_sequence(sequence1,
                                          1, [(40, 100, 0, 0.125),
                                              (50, 100, 0, 0.125),
                                              (50, 100, 2, 2.125)],
                                          is_drum=True)
        testing_lib.add_chords_to_sequence(sequence1, [('C', 0)])
        self.assertProtoEquals(sequence1, sequences[0])

        sequence2 = copy.deepcopy(self.sequence)
        testing_lib.add_track_to_sequence(sequence2, 0, [(62, 100, 0, 2),
                                                         (59, 100, 0, 4),
                                                         (67, 100, 2, 4)])
        testing_lib.add_track_to_sequence(sequence2,
                                          1, [(40, 100, 0, 0.125),
                                              (50, 100, 0, 0.125),
                                              (50, 100, 2, 2.125)],
                                          is_drum=True)
        testing_lib.add_chords_to_sequence(sequence2, [('G', 0)])
        self.assertProtoEquals(sequence2, sequences[1])
    def testToNoteSequence(self):
        sequence = copy.deepcopy(self.sequence)
        testing_lib.add_track_to_sequence(sequence, 0, [
            (64, 100, 0, 2),
            (60, 100, 0, 4),
            (67, 100, 2, 4),
            (62, 100, 4, 6),
            (59, 100, 4, 8),
            (67, 100, 6, 8),
        ])
        testing_lib.add_track_to_sequence(sequence,
                                          1, [
                                              (40, 100, 0, 0.125),
                                              (50, 100, 0, 0.125),
                                              (50, 100, 2, 2.125),
                                              (40, 100, 4, 4.125),
                                              (50, 100, 4, 4.125),
                                              (50, 100, 6, 6.125),
                                          ],
                                          is_drum=True)
        converter = data_hierarchical.MultiInstrumentPerformanceConverter(
            hop_size_bars=2, chunk_size_bars=2)
        tensors = converter.to_tensors(sequence)
        self.assertEqual(2, len(tensors.outputs))
        sequences = converter.from_tensors(tensors.outputs)
        self.assertEqual(2, len(sequences))

        sequence1 = copy.deepcopy(self.sequence)
        testing_lib.add_track_to_sequence(sequence1, 0, [(64, 100, 0, 2),
                                                         (60, 100, 0, 4),
                                                         (67, 100, 2, 4)])
        testing_lib.add_track_to_sequence(sequence1,
                                          1, [(40, 100, 0, 0.125),
                                              (50, 100, 0, 0.125),
                                              (50, 100, 2, 2.125)],
                                          is_drum=True)
        self.assertProtoEquals(sequence1, sequences[0])

        sequence2 = copy.deepcopy(self.sequence)
        testing_lib.add_track_to_sequence(sequence2, 0, [(62, 100, 0, 2),
                                                         (59, 100, 0, 4),
                                                         (67, 100, 2, 4)])
        testing_lib.add_track_to_sequence(sequence2,
                                          1, [(40, 100, 0, 0.125),
                                              (50, 100, 0, 0.125),
                                              (50, 100, 2, 2.125)],
                                          is_drum=True)
        self.assertProtoEquals(sequence2, sequences[1])