def testQuantizeNoteSequence(self): testing_lib.add_track_to_sequence( 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_chords_to_sequence(self.note_sequence, [("B7", 0.22), ("Em9", 4.0)]) expected_quantized_sequence = copy.deepcopy(self.note_sequence) expected_quantized_sequence.quantization_info.steps_per_quarter = self.steps_per_quarter testing_lib.add_quantized_steps_to_sequence( expected_quantized_sequence, [(0, 40), (1, 2), (10, 14), (16, 17), (19, 20)] ) testing_lib.add_quantized_chord_steps_to_sequence(expected_quantized_sequence, [1, 16]) quantized_sequence = sequences_lib.quantize_note_sequence( self.note_sequence, steps_per_quarter=self.steps_per_quarter ) self.assertProtoEquals(expected_quantized_sequence, quantized_sequence)
def testInferChordsForSequence(self): # Test non-quantized sequence. sequence = copy.copy(self.note_sequence) testing_lib.add_track_to_sequence( sequence, 0, [(60, 100, 1.0, 3.0), (64, 100, 1.0, 2.0), (67, 100, 1.0, 2.0), (65, 100, 2.0, 3.0), (69, 100, 2.0, 3.0), (62, 100, 3.0, 5.0), (65, 100, 3.0, 4.0), (69, 100, 3.0, 4.0)]) expected_sequence = copy.copy(sequence) testing_lib.add_chords_to_sequence( expected_sequence, [('C', 1.0), ('F/C', 2.0), ('Dm', 3.0)]) sequences_lib.infer_chords_for_sequence(sequence) self.assertProtoEquals(expected_sequence, sequence) # Test quantized sequence. sequence = copy.copy(self.note_sequence) sequence.quantization_info.steps_per_quarter = 1 testing_lib.add_track_to_sequence( sequence, 0, [(60, 100, 1.1, 3.0), (64, 100, 1.0, 1.9), (67, 100, 1.0, 2.0), (65, 100, 2.0, 3.2), (69, 100, 2.1, 3.1), (62, 100, 2.9, 4.8), (65, 100, 3.0, 4.0), (69, 100, 3.0, 4.1)]) testing_lib.add_quantized_steps_to_sequence( sequence, [(1, 3), (1, 2), (1, 2), (2, 3), (2, 3), (3, 5), (3, 4), (3, 4)]) expected_sequence = copy.copy(sequence) testing_lib.add_chords_to_sequence( expected_sequence, [('C', 1.0), ('F/C', 2.0), ('Dm', 3.0)]) testing_lib.add_quantized_chord_steps_to_sequence( expected_sequence, [1, 2, 3]) sequences_lib.infer_chords_for_sequence(sequence) self.assertProtoEquals(expected_sequence, sequence)
def testQuantizeNoteSequenceAbsolute(self): testing_lib.add_track_to_sequence( 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_chords_to_sequence( self.note_sequence, [('B7', 0.22), ('Em9', 4.0)]) testing_lib.add_control_changes_to_sequence( self.note_sequence, 0, [(2.0, 64, 127), (4.0, 64, 0)]) expected_quantized_sequence = copy.deepcopy(self.note_sequence) expected_quantized_sequence.quantization_info.steps_per_second = 4 testing_lib.add_quantized_steps_to_sequence( expected_quantized_sequence, [(0, 40), (1, 2), (10, 14), (16, 17), (19, 20)]) testing_lib.add_quantized_chord_steps_to_sequence( expected_quantized_sequence, [1, 16]) testing_lib.add_quantized_control_steps_to_sequence( expected_quantized_sequence, [8, 16]) quantized_sequence = sequences_lib.quantize_note_sequence_absolute( self.note_sequence, steps_per_second=4) self.assertProtoEquals(expected_quantized_sequence, quantized_sequence)
def testMultiTrack(self): testing_lib.add_track_to_sequence(self.note_sequence, 0, [(12, 100, 1.0, 4.0), (19, 100, 0.95, 3.0)]) testing_lib.add_track_to_sequence(self.note_sequence, 3, [(12, 100, 1.0, 4.0), (19, 100, 2.0, 5.0)]) testing_lib.add_track_to_sequence( self.note_sequence, 7, [(12, 100, 1.0, 5.0), (19, 100, 2.0, 4.0), (24, 100, 3.0, 3.5)] ) expected_quantized_sequence = copy.deepcopy(self.note_sequence) expected_quantized_sequence.quantization_info.steps_per_quarter = self.steps_per_quarter testing_lib.add_quantized_steps_to_sequence( expected_quantized_sequence, [(4, 16), (4, 12), (4, 16), (8, 20), (4, 20), (8, 16), (12, 14)] ) quantized_sequence = sequences_lib.quantize_note_sequence(self.note_sequence, self.steps_per_quarter) self.assertProtoEquals(expected_quantized_sequence, quantized_sequence)
def testRounding(self): testing_lib.add_track_to_sequence( 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)]) expected_quantized_sequence = copy.deepcopy(self.note_sequence) expected_quantized_sequence.quantization_info.steps_per_quarter = ( self.steps_per_quarter) testing_lib.add_quantized_steps_to_sequence( expected_quantized_sequence, [(0, 1), (1, 2), (2, 3), (3, 5), (5, 7), (16, 17)]) quantized_sequence = sequences_lib.quantize_note_sequence( self.note_sequence, self.steps_per_quarter) self.assertProtoEquals(expected_quantized_sequence, quantized_sequence)
def testMultiTrack(self): testing_lib.add_track_to_sequence( self.note_sequence, 0, [(12, 100, 1.0, 4.0), (19, 100, 0.95, 3.0)]) testing_lib.add_track_to_sequence( self.note_sequence, 3, [(12, 100, 1.0, 4.0), (19, 100, 2.0, 5.0)]) testing_lib.add_track_to_sequence( self.note_sequence, 7, [(12, 100, 1.0, 5.0), (19, 100, 2.0, 4.0), (24, 100, 3.0, 3.5)]) expected_quantized_sequence = copy.deepcopy(self.note_sequence) expected_quantized_sequence.quantization_info.steps_per_quarter = ( self.steps_per_quarter) testing_lib.add_quantized_steps_to_sequence( expected_quantized_sequence, [(4, 16), (4, 12), (4, 16), (8, 20), (4, 20), (8, 16), (12, 14)]) quantized_sequence = sequences_lib.quantize_note_sequence( self.note_sequence, self.steps_per_quarter) self.assertProtoEquals(expected_quantized_sequence, quantized_sequence)