def testExtractChords(self): self.quantized_sequence.steps_per_quarter = 1 testing_lib.add_quantized_chords_to_sequence( self.quantized_sequence, [('C', 2), ('G7', 6), ('F', 8)]) self.quantized_sequence.total_steps = 10 chord_progressions, _ = chords_lib.extract_chords(self.quantized_sequence) expected = [[NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'G7', 'G7', 'F', 'F']] self.assertEqual(expected, [list(chords) for chords in chord_progressions])
def testExtractChords(self): testing_lib.add_chords_to_sequence( self.note_sequence, [('C', 2), ('G7', 6), ('F', 8)]) quantized_sequence = sequences_lib.quantize_note_sequence( self.note_sequence, self.steps_per_quarter) quantized_sequence.total_quantized_steps = 10 chord_progressions, _ = chords_lib.extract_chords(quantized_sequence) expected = [[NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'G7', 'G7', 'F', 'F']] self.assertEqual(expected, [list(chords) for chords in chord_progressions])
def testExtractChordsAllTranspositions(self): self.quantized_sequence.steps_per_quarter = 1 testing_lib.add_quantized_chords_to_sequence( self.quantized_sequence, [('C', 1)]) self.quantized_sequence.total_steps = 2 chord_progressions, _ = chords_lib.extract_chords(self.quantized_sequence, all_transpositions=True) expected = zip([NO_CHORD] * 12, ['G-', 'G', 'A-', 'A', 'B-', 'B', 'C', 'D-', 'D', 'E-', 'E', 'F']) self.assertEqual(expected, [tuple(chords) for chords in chord_progressions])
def testExtractChordsAllTranspositions(self): testing_lib.add_chords_to_sequence( self.note_sequence, [('C', 1)]) quantized_sequence = sequences_lib.quantize_note_sequence( self.note_sequence, self.steps_per_quarter) quantized_sequence.total_quantized_steps = 2 chord_progressions, _ = chords_lib.extract_chords(quantized_sequence, all_transpositions=True) expected = list(zip([NO_CHORD] * 12, ['Gb', 'G', 'Ab', 'A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', 'E', 'F'])) self.assertEqual(expected, [tuple(chords) for chords in chord_progressions])
def transform(self, quantized_sequence): try: chord_progressions, stats = chords_lib.extract_chords( quantized_sequence, max_steps=self._max_steps, all_transpositions=self._all_transpositions) except events_lib.NonIntegerStepsPerBarError as detail: tf.logging.warning('Skipped sequence: %s', detail) chord_progressions = [] stats = [statistics.Counter('non_integer_steps_per_bar', 1)] except chords_lib.CoincidentChordsError as detail: tf.logging.warning('Skipped sequence: %s', detail) chord_progressions = [] stats = [statistics.Counter('coincident_chords', 1)] except chord_symbols_lib.ChordSymbolError as detail: tf.logging.warning('Skipped sequence: %s', detail) chord_progressions = [] stats = [statistics.Counter('chord_symbol_exception', 1)] self._set_stats(stats) return chord_progressions
def transform(self, quantized_sequence): try: chord_progressions, stats = chords_lib.extract_chords( quantized_sequence, max_steps=self._max_steps, all_transpositions=self._all_transpositions) except events_lib.NonIntegerStepsPerBarException as detail: tf.logging.warning('Skipped sequence: %s', detail) chord_progressions = [] stats = [statistics.Counter('non_integer_steps_per_bar', 1)] except chords_lib.CoincidentChordsException as detail: tf.logging.warning('Skipped sequence: %s', detail) chord_progressions = [] stats = [statistics.Counter('coincident_chords', 1)] except chord_symbols_lib.ChordSymbolException as detail: tf.logging.warning('Skipped sequence: %s', detail) chord_progressions = [] stats = [statistics.Counter('chord_symbol_exception', 1)] self._set_stats(stats) return chord_progressions