コード例 #1
0
 def testToNoteSequenceMultipleChunksWithChords(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=4,
         chunk_size_bars=2,
         chord_encoding=mm.MajorMinorChordOneHotEncoding())
     tensors = converter.to_tensors(sequence)
     self.assertEqual(1, len(tensors.outputs))
     sequences = converter.to_notesequences(tensors.outputs,
                                            tensors.controls)
     self.assertEqual(1, len(sequences))
     self.assertProtoEquals(sequence, sequences[0])
コード例 #2
0
    def testTfSlicedChordConditioned(self):
        converter = self.converter_class(
            steps_per_quarter=1,
            slice_bars=2,
            max_tensors_per_notesequence=None,
            chord_encoding=mm.MajorMinorChordOneHotEncoding())
        with self.test_session() as sess:
            sequence = tf.placeholder(tf.string)
            input_tensors_, output_tensors_, control_tensors_, lengths_ = (
                converter.tf_to_tensors(sequence))
            input_tensors, output_tensors, control_tensors, lengths = sess.run(
                [input_tensors_, output_tensors_, control_tensors_, lengths_],
                feed_dict={sequence: self.sequence.SerializeToString()})
        actual_sliced_labels = [
            np.argmax(t, axis=-1)[:l] for t, l in zip(output_tensors, lengths)
        ]
        actual_sliced_chord_labels = [
            np.argmax(t, axis=-1)[:l] for t, l in zip(control_tensors, lengths)
        ]

        self.assertArraySetsEqual(
            self.labels_to_inputs(self.expected_sliced_labels, converter),
            input_tensors)
        self.assertArraySetsEqual(self.expected_sliced_labels,
                                  actual_sliced_labels)
        self.assertArraySetsEqual(self.expected_sliced_chord_labels,
                                  actual_sliced_chord_labels)
コード例 #3
0
  def testSlicedChordConditioned(self):
    converter = self.converter_class(
        steps_per_quarter=1, slice_bars=2, max_tensors_per_notesequence=None,
        chord_encoding=mm.MajorMinorChordOneHotEncoding())
    tensors = converter.to_tensors(self.sequence)
    actual_sliced_labels = [np.argmax(t, axis=-1) for t in tensors.outputs]
    actual_sliced_chord_labels = [
        np.argmax(t, axis=-1) for t in tensors.controls]

    self.assertArraySetsEqual(
        self.labels_to_inputs(self.expected_sliced_labels, converter),
        tensors.inputs)
    self.assertArraySetsEqual(self.expected_sliced_labels, actual_sliced_labels)
    self.assertArraySetsEqual(
        self.expected_sliced_chord_labels, actual_sliced_chord_labels)
コード例 #4
0
  def testSlicedChordConditioned(self):
    converter = data.TrioConverter(
        steps_per_quarter=1, gap_bars=1, slice_bars=2,
        max_tensors_per_notesequence=None,
        chord_encoding=mm.MajorMinorChordOneHotEncoding())
    tensors = converter.to_tensors(self.sequence)
    self.assertArraySetsEqual(tensors.inputs, tensors.outputs)
    actual_sliced_labels = [
        np.stack(np.argmax(s, axis=-1) for s in np.split(t, [90, 180], axis=-1))
        for t in tensors.outputs]
    actual_sliced_chord_labels = [
        np.argmax(t, axis=-1) for t in tensors.controls]

    self.assertArraySetsEqual(self.expected_sliced_labels, actual_sliced_labels)
    self.assertArraySetsEqual(
        self.expected_sliced_chord_labels, actual_sliced_chord_labels)
コード例 #5
0
  def testToNoteSequenceChordConditioned(self):
    converter = data.OneHotMelodyConverter(
        steps_per_quarter=1, slice_bars=4, max_tensors_per_notesequence=1,
        chord_encoding=mm.MajorMinorChordOneHotEncoding())
    tensors = converter.to_tensors(
        filter_instrument(self.sequence, 0))
    sequences = converter.to_notesequences(tensors.outputs, tensors.controls)

    self.assertEqual(1, len(sequences))
    expected_sequence = music_pb2.NoteSequence(ticks_per_quarter=220)
    expected_sequence.tempos.add(qpm=120)
    testing_lib.add_track_to_sequence(
        expected_sequence, 0,
        [(32, 80, 1.0, 2.0), (33, 80, 3.0, 5.5), (34, 80, 5.5, 6.5)])
    testing_lib.add_chords_to_sequence(
        expected_sequence, [('N.C.', 0), ('F', 1), ('C', 4)])
    self.assertProtoEquals(expected_sequence, sequences[0])
コード例 #6
0
    def testToNoteSequenceChordConditioned(self):
        converter = data.TrioConverter(
            steps_per_quarter=1,
            slice_bars=2,
            max_tensors_per_notesequence=1,
            chord_encoding=mm.MajorMinorChordOneHotEncoding())

        mel_oh = data.np_onehot(self.expected_sliced_labels[3][0], 90)
        bass_oh = data.np_onehot(self.expected_sliced_labels[3][1], 90)
        drums_oh = data.np_onehot(self.expected_sliced_labels[3][2], 512)
        chords_oh = data.np_onehot(self.expected_sliced_chord_labels[3], 25)

        output_tensors = np.concatenate([mel_oh, bass_oh, drums_oh], axis=-1)

        sequences = converter.to_notesequences([output_tensors], [chords_oh])
        self.assertEqual(1, len(sequences))

        self.assertProtoEquals(
            """
        ticks_per_quarter: 220
        tempos < qpm: 120 >
        notes <
          instrument: 0 pitch: 52 start_time: 2.0 end_time: 4.0 program: 0
          velocity: 80
        >
        notes <
          instrument: 1 pitch: 50 start_time: 1.0 end_time: 2.5 program: 33
          velocity: 80
        >
        notes <
          instrument: 9 pitch: 36 start_time: 0.0 end_time: 0.5 velocity: 80
          is_drum: True
        >
        notes <
          instrument: 9 pitch: 38 start_time: 2.0 end_time: 2.5 velocity: 80
          is_drum: True
        >
        text_annotations <
          text: 'N.C.' annotation_type: CHORD_SYMBOL
        >
        text_annotations <
          time: 2.0 text: 'C' annotation_type: CHORD_SYMBOL
        >
        total_time: 4.0
        """, sequences[0])
コード例 #7
0
    def setUp(self):
        sequence = music_pb2.NoteSequence()
        sequence.tempos.add(qpm=60)
        # Mel 1, coverage bars: [3, 9] / [2, 9]
        testing_lib.add_track_to_sequence(sequence, 1, [(51, 1, 13, 37)])
        # Mel 2, coverage bars: [1, 3] / [0, 4]
        testing_lib.add_track_to_sequence(sequence, 2, [(52, 1, 4, 16)])
        # Bass, coverage bars: [0, 1], [4, 6] / [0, 7]
        testing_lib.add_track_to_sequence(sequence, 3, [(50, 1, 2, 5),
                                                        (49, 1, 16, 25)])
        # Drum, coverage bars: [0, 2], [6, 7] / [0, 3], [5, 8]
        testing_lib.add_track_to_sequence(sequence,
                                          4, [(35, 1, 0, 1), (40, 1, 4, 5),
                                              (35, 1, 9, 9), (35, 1, 25, 25),
                                              (40, 1, 29, 29)],
                                          is_drum=True)
        # Chords.
        testing_lib.add_chords_to_sequence(sequence, [('C', 4), ('Am', 16),
                                                      ('G', 32)])

        for n in sequence.notes:
            if n.instrument == 1:
                n.program = 0
            elif n.instrument == 2:
                n.program = 10
            elif n.instrument == 3:
                n.program = 33

        self.sequence = sequence

        m1 = np.array([NO_EVENT] * 13 + [30] + [NO_EVENT] * 23 + [NOTE_OFF] +
                      [NO_EVENT] * 2, np.int32) + 2
        m2 = np.array([NO_EVENT] * 4 + [31] + [NO_EVENT] * 11 + [NOTE_OFF] +
                      [NO_EVENT] * 23, np.int32) + 2
        b = np.array([NO_EVENT, NO_EVENT, 29, NO_EVENT, NO_EVENT, NOTE_OFF] +
                     [NO_EVENT] * 10 + [28] + [NO_EVENT] * 8 + [NOTE_OFF] +
                     [NO_EVENT] * 14, np.int32) + 2
        d = (
            [
                1, NO_DRUMS, NO_DRUMS, NO_DRUMS, 2, NO_DRUMS, NO_DRUMS,
                NO_DRUMS, NO_DRUMS, 1, NO_DRUMS, NO_DRUMS
            ] + [NO_DRUMS] * 12 +
            [NO_DRUMS, 1, NO_DRUMS, NO_DRUMS, NO_DRUMS, 2, NO_DRUMS, NO_DRUMS
             ] + [NO_DRUMS] * 4)

        c = [
            NO_CHORD, NO_CHORD, NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'C',
            'C', 'C', 'C', 'C', 'C', 'C', 'C', 'Am', 'Am', 'Am', 'Am', 'Am',
            'Am', 'Am', 'Am', 'Am', 'Am', 'Am', 'Am', 'Am', 'Am', 'Am', 'Am',
            'G', 'G', 'G', 'G'
        ]

        expected_sliced_sets = [
            ((2, 4), (m1, b, d)),
            ((5, 7), (m1, b, d)),
            ((6, 8), (m1, b, d)),
            ((0, 2), (m2, b, d)),
            ((1, 3), (m2, b, d)),
            ((2, 4), (m2, b, d)),
        ]

        self.expected_sliced_labels = [
            np.stack([l[i * 4:j * 4] for l in x])
            for (i, j), x in expected_sliced_sets
        ]

        chord_encoding = mm.MajorMinorChordOneHotEncoding()
        expected_sliced_chord_events = [
            c[i * 4:j * 4] for (i, j), _ in expected_sliced_sets
        ]
        self.expected_sliced_chord_labels = [
            np.array([chord_encoding.encode_event(e) for e in es])
            for es in expected_sliced_chord_events
        ]
コード例 #8
0
    def setUp(self):
        sequence = music_pb2.NoteSequence()
        sequence.tempos.add(qpm=60)
        testing_lib.add_track_to_sequence(sequence, 0, [(32, 100, 2, 4),
                                                        (33, 1, 6, 11),
                                                        (34, 1, 11, 13),
                                                        (35, 1, 17, 19)])
        testing_lib.add_track_to_sequence(sequence, 1, [(35, 127, 2, 4),
                                                        (36, 50, 6, 8),
                                                        (71, 100, 33, 37),
                                                        (73, 100, 34, 37),
                                                        (33, 1, 50, 55),
                                                        (34, 1, 55, 56)])
        testing_lib.add_chords_to_sequence(sequence, [('F', 2), ('C', 8),
                                                      ('Am', 16), ('N.C.', 20),
                                                      ('Bb7', 32), ('G', 36),
                                                      ('F', 48), ('C', 52)])
        self.sequence = sequence

        # Subtract min pitch (21).
        expected_unsliced_events = [
            (NO_EVENT, NO_EVENT, 11, NO_EVENT, NOTE_OFF, NO_EVENT, 12,
             NO_EVENT, NO_EVENT, NO_EVENT, NO_EVENT, 13, NO_EVENT, NOTE_OFF,
             NO_EVENT, NO_EVENT),
            (NO_EVENT, 14, NO_EVENT, NOTE_OFF),
            (NO_EVENT, NO_EVENT, 14, NO_EVENT, NOTE_OFF, NO_EVENT, 15,
             NO_EVENT),
            (NO_EVENT, 50, 52, NO_EVENT, NO_EVENT, NOTE_OFF, NO_EVENT,
             NO_EVENT),
            (NO_EVENT, NO_EVENT, 12, NO_EVENT, NO_EVENT, NO_EVENT, NO_EVENT,
             13),
        ]
        self.expected_unsliced_labels = [
            np.array(es) + 2 for es in expected_unsliced_events
        ]

        expected_sliced_events = [(NO_EVENT, NO_EVENT, 11, NO_EVENT, NOTE_OFF,
                                   NO_EVENT, 12, NO_EVENT),
                                  (NO_EVENT, NO_EVENT, 12, NO_EVENT, NO_EVENT,
                                   NO_EVENT, NO_EVENT, 13),
                                  (NO_EVENT, NO_EVENT, NO_EVENT, 13, NO_EVENT,
                                   NOTE_OFF, NO_EVENT, NO_EVENT),
                                  (NO_EVENT, NO_EVENT, 14, NO_EVENT, NOTE_OFF,
                                   NO_EVENT, 15, NO_EVENT),
                                  (NO_EVENT, 50, 52, NO_EVENT, NO_EVENT,
                                   NOTE_OFF, NO_EVENT, NO_EVENT)]
        self.expected_sliced_labels = [
            np.array(es) + 2 for es in expected_sliced_events
        ]

        chord_encoding = mm.MajorMinorChordOneHotEncoding()

        expected_unsliced_chord_events = [
            (NO_CHORD, NO_CHORD, 'F', 'F', 'F', 'F', 'F', 'F', 'C', 'C', 'C',
             'C', 'C', 'C', 'C', 'C'),
            ('Am', 'Am', 'Am', 'Am'),
            (NO_CHORD, NO_CHORD, 'F', 'F', 'F', 'F', 'F', 'F'),
            ('Bb7', 'Bb7', 'Bb7', 'Bb7', 'G', 'G', 'G', 'G'),
            ('F', 'F', 'F', 'F', 'C', 'C', 'C', 'C'),
        ]
        self.expected_unsliced_chord_labels = [
            np.array([chord_encoding.encode_event(e) for e in es])
            for es in expected_unsliced_chord_events
        ]

        expected_sliced_chord_events = [
            (NO_CHORD, NO_CHORD, 'F', 'F', 'F', 'F', 'F', 'F'),
            ('F', 'F', 'F', 'F', 'C', 'C', 'C', 'C'),
            ('C', 'C', 'C', 'C', 'C', 'C', 'C', 'C'),
            (NO_CHORD, NO_CHORD, 'F', 'F', 'F', 'F', 'F', 'F'),
            ('Bb7', 'Bb7', 'Bb7', 'Bb7', 'G', 'G', 'G', 'G'),
        ]
        self.expected_sliced_chord_labels = [
            np.array([chord_encoding.encode_event(e) for e in es])
            for es in expected_sliced_chord_events
        ]

        self.converter_class = data.OneHotMelodyConverter