def testMelodyRNNPipeline(self): note_sequence = testing_lib.parse_test_proto( music_pb2.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { bpm: 120}""") testing_lib.add_track( note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) quantizer = pipelines_common.Quantizer(steps_per_beat=4) melody_extractor = pipelines_common.MonophonicMelodyExtractor( min_bars=7, min_unique_pitches=5, gap_bars=1.0) one_hot_encoder = melody_rnn_create_dataset.OneHotEncoder() quantized = quantizer.transform(note_sequence)[0] melody = melody_extractor.transform(quantized)[0] one_hot = one_hot_encoder.transform(melody)[0] expected_result = {'melody_rnn_train': [one_hot], 'melody_rnn_eval': []} pipeline_inst = melody_rnn_create_dataset.MelodyRNNPipeline(eval_ratio=0) result = pipeline_inst.transform(note_sequence) self.assertEqual(expected_result, result)
def testMelodyRNNPipeline(self): FLAGS.eval_ratio = 0.0 note_sequence = testing_lib.parse_test_proto( music_pb2.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { qpm: 120}""") testing_lib.add_track(note_sequence, 0, [(12, 100, 0.00, 2.0), (11, 55, 2.1, 5.0), (40, 45, 5.1, 8.0), (55, 120, 8.1, 11.0), (53, 99, 11.1, 14.1)]) quantizer = pipelines_common.Quantizer(steps_per_quarter=4) melody_extractor = pipelines_common.MonophonicMelodyExtractor( min_bars=7, min_unique_pitches=5, gap_bars=1.0, ignore_polyphonic_notes=False) one_hot_encoder = melodies_lib.OneHotEncoderDecoder(0, 127, 0) quantized = quantizer.transform(note_sequence)[0] print quantized.tracks melody = melody_extractor.transform(quantized)[0] one_hot = one_hot_encoder.encode(melody) print one_hot expected_result = {'training_melodies': [one_hot], 'eval_melodies': []} pipeline_inst = melody_rnn_create_dataset.get_pipeline(one_hot_encoder) result = pipeline_inst.transform(note_sequence) self.assertEqual(expected_result, result)
def testFromNoteSequence_TimeSignatureChange(self): testing_lib.add_track(self.note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) del self.note_sequence.time_signatures[:] quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter) # Single time signature. self.note_sequence.time_signatures.add(numerator=4, denominator=4) quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter) # Multiple time signatures with no change. self.note_sequence.time_signatures.add(numerator=4, denominator=4) quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter) # Time signature change. self.note_sequence.time_signatures.add(numerator=2, denominator=4) with self.assertRaises(sequences_lib.MultipleTimeSignatureException): quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter)
def testQuantizer(self): steps_per_quarter = 4 note_sequence = testing_lib.parse_test_proto( music_pb2.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { qpm: 60}""") testing_lib.add_track(note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) expected_quantized_sequence = sequences_lib.QuantizedSequence() expected_quantized_sequence.qpm = 60.0 expected_quantized_sequence.steps_per_quarter = steps_per_quarter testing_lib.add_quantized_track(expected_quantized_sequence, 0, [(12, 100, 0, 40), (11, 55, 1, 2), (40, 45, 10, 14), (55, 120, 16, 17), (52, 99, 19, 20)]) unit = pipelines_common.Quantizer(steps_per_quarter) self._unit_transform_test(unit, note_sequence, [expected_quantized_sequence])
def testQuantizer(self): steps_per_beat = 4 note_sequence = testing_lib.parse_test_proto( music_pb2.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { bpm: 60}""") testing_lib.add_track( note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) expected_quantized_sequence = sequences_lib.QuantizedSequence() expected_quantized_sequence.bpm = 60.0 expected_quantized_sequence.steps_per_beat = steps_per_beat testing_lib.add_quantized_track( expected_quantized_sequence, 0, [(12, 100, 0, 40), (11, 55, 1, 2), (40, 45, 10, 14), (55, 120, 16, 17), (52, 99, 19, 20)]) unit = pipelines_common.Quantizer(steps_per_beat) self._unit_transform_test(unit, note_sequence, [expected_quantized_sequence])
def testRounding(self): testing_lib.add_track( self.note_sequence, 1, [(12, 100, 0.01, 0.24), (11, 100, 0.22, 0.55), (40, 100, 0.50, 0.75), (41, 100, 0.689, 1.18), (44, 100, 1.19, 1.69), (55, 100, 4.0, 4.01)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 1, [(12, 100, 0, 1), (11, 100, 1, 2), (40, 100, 2, 3), (41, 100, 3, 4), (44, 100, 5, 7), (55, 100, 16, 17)]) quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_beat) self.assertEqual(self.expected_quantized_sequence, quantized)
def testFromNoteSequence(self): testing_lib.add_track( self.note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 0, [(12, 100, 0, 40), (11, 55, 1, 2), (40, 45, 10, 14), (55, 120, 16, 17), (52, 99, 19, 20)]) quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_beat) self.assertEqual(self.expected_quantized_sequence, quantized)
def testRounding(self): testing_lib.add_track( self.note_sequence, 1, [(12, 100, 0.01, 0.24), (11, 100, 0.22, 0.55), (40, 100, 0.50, 0.75), (41, 100, 0.689, 1.18), (44, 100, 1.19, 1.69), (55, 100, 4.0, 4.01)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 1, [(12, 100, 0, 1), (11, 100, 1, 2), (40, 100, 2, 3), (41, 100, 3, 5), (44, 100, 5, 7), (55, 100, 16, 17)]) quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter) self.assertEqual(self.expected_quantized_sequence, quantized)
def testFromNoteSequence(self): testing_lib.add_track( self.note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 0, [(12, 100, 0, 40), (11, 55, 1, 2), (40, 45, 10, 14), (55, 120, 16, 17), (52, 99, 19, 20)]) quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter) self.assertEqual(self.expected_quantized_sequence, quantized)
def testDeepcopy(self): quantized = sequences_lib.QuantizedSequence() testing_lib.add_track(self.note_sequence, 0, [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)]) quantized.from_note_sequence(self.note_sequence, self.steps_per_quarter) quantized_copy = quantized.deepcopy() self.assertEqual(quantized, quantized_copy) testing_lib.add_quantized_track(self.quantized, 1, [(12, 100, 4, 20), (19, 100, 8, 16), (24, 100, 12, 14)]) self.assertNotEqual(quantized, quantized_copy)
def testMultiTrack(self): testing_lib.add_track(self.note_sequence, 0, [(12, 100, 1.0, 4.0), (19, 100, 0.95, 3.0)]) testing_lib.add_track(self.note_sequence, 3, [(12, 100, 1.0, 4.0), (19, 100, 2.0, 5.0)]) testing_lib.add_track(self.note_sequence, 7, [(12, 100, 1.0, 5.0), (19, 100, 2.0, 4.0), (24, 100, 3.0, 3.5)]) testing_lib.add_quantized_track(self.expected_quantized_sequence, 0, [(12, 100, 4, 16), (19, 100, 4, 12)]) testing_lib.add_quantized_track(self.expected_quantized_sequence, 3, [(12, 100, 4, 16), (19, 100, 8, 20)]) testing_lib.add_quantized_track(self.expected_quantized_sequence, 7, [(12, 100, 4, 20), (19, 100, 8, 16), (24, 100, 12, 14)]) quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_beat) self.assertEqual(self.expected_quantized_sequence, quantized)
def testMultiTrack(self): testing_lib.add_track( self.note_sequence, 0, [(12, 100, 1.0, 4.0), (19, 100, 0.95, 3.0)]) testing_lib.add_track( self.note_sequence, 3, [(12, 100, 1.0, 4.0), (19, 100, 2.0, 5.0)]) testing_lib.add_track( self.note_sequence, 7, [(12, 100, 1.0, 5.0), (19, 100, 2.0, 4.0), (24, 100, 3.0, 3.5)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 0, [(12, 100, 4, 16), (19, 100, 4, 12)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 3, [(12, 100, 4, 16), (19, 100, 8, 20)]) testing_lib.add_quantized_track( self.expected_quantized_sequence, 7, [(12, 100, 4, 20), (19, 100, 8, 16), (24, 100, 12, 14)]) quantized = sequences_lib.QuantizedSequence() quantized.from_note_sequence(self.note_sequence, self.steps_per_beat) self.assertEqual(self.expected_quantized_sequence, quantized)