def augment(self, note_sequence): """Python implementation that augments the NoteSequence.""" trans_amt = (random.randint( *self._transpose_range) if self._transpose_range else 0) stretch_factor = (random.uniform( *self._stretch_range) if self._stretch_range else 1.0) augmented_ns = copy.deepcopy(note_sequence) del augmented_ns.notes[:] for note in note_sequence.notes: aug_pitch = note.pitch if not note.is_drum: aug_pitch += trans_amt if MIN_MIDI_PITCH <= aug_pitch <= MAX_MIDI_PITCH: augmented_ns.notes.add().CopyFrom(note) augmented_ns.notes[-1].pitch = aug_pitch for ta in augmented_ns.text_annotations: if ta.annotation_type == CHORD_SYMBOL and ta.text != mm.NO_CHORD: try: figure = chord_symbols_lib.transpose_chord_symbol( ta.text, trans_amt) except chord_symbols_lib.ChordSymbolException: tf.logging.warning('Unable to transpose chord symbol: %s', ta.text) figure = mm.NO_CHORD ta.text = figure augmented_ns = sequences_lib.stretch_note_sequence( augmented_ns, stretch_factor) return augmented_ns
def augment(self, note_sequence): """Python implementation that augments the NoteSequence.""" trans_amt = (random.randint(*self._transpose_range) if self._transpose_range else 0) stretch_factor = (random.uniform(*self._stretch_range) if self._stretch_range else 1.0) augmented_ns = copy.deepcopy(note_sequence) del augmented_ns.notes[:] for note in note_sequence.notes: aug_pitch = note.pitch if not note.is_drum: aug_pitch += trans_amt if MIN_MIDI_PITCH <= aug_pitch <= MAX_MIDI_PITCH: augmented_ns.notes.add().CopyFrom(note) augmented_ns.notes[-1].pitch = aug_pitch for ta in augmented_ns.text_annotations: if ta.annotation_type == CHORD_SYMBOL and ta.text != mm.NO_CHORD: try: figure = chord_symbols_lib.transpose_chord_symbol(ta.text, trans_amt) except chord_symbols_lib.ChordSymbolException: tf.logging.warning('Unable to transpose chord symbol: %s', ta.text) figure = mm.NO_CHORD ta.text = figure augmented_ns = sequences_lib.stretch_note_sequence( augmented_ns, stretch_factor) return augmented_ns
def testTransposeChordSymbol(self): # Test basic triads. figure = chord_symbols_lib.transpose_chord_symbol('C', 2) self.assertEqual('D', figure) figure = chord_symbols_lib.transpose_chord_symbol('Abm', -3) self.assertEqual('Fm', figure) figure = chord_symbols_lib.transpose_chord_symbol('F#', 0) self.assertEqual('F#', figure) figure = chord_symbols_lib.transpose_chord_symbol('Cbb', 6) self.assertEqual('Fb', figure) figure = chord_symbols_lib.transpose_chord_symbol('C#', -5) self.assertEqual('G#', figure) # Test more complex chords. figure = chord_symbols_lib.transpose_chord_symbol('Co7', 7) self.assertEqual('Go7', figure) figure = chord_symbols_lib.transpose_chord_symbol('D+', -3) self.assertEqual('B+', figure) figure = chord_symbols_lib.transpose_chord_symbol('Fb9/Ab', 2) self.assertEqual('Gb9/Bb', figure) figure = chord_symbols_lib.transpose_chord_symbol('A6/9', -7) self.assertEqual('D6/9', figure) figure = chord_symbols_lib.transpose_chord_symbol('E7(add#9)', 0) self.assertEqual('E7(add#9)', figure)
def transpose(self, transpose_amount): """Transpose chords in this ChordProgression. Args: transpose_amount: The number of half steps to transpose this ChordProgression. Positive values transpose up. Negative values transpose down. Raises: ChordSymbolError: If a chord (other than "no chord") fails to be interpreted by the `chord_symbols_lib` module. """ for i in range(len(self._events)): if self._events[i] != NO_CHORD: self._events[i] = chord_symbols_lib.transpose_chord_symbol( self._events[i], transpose_amount % NOTES_PER_OCTAVE)
def transpose(self, transpose_amount): """Transpose chords in this ChordProgression. Args: transpose_amount: The number of half steps to transpose this ChordProgression. Positive values transpose up. Negative values transpose down. Raises: ChordSymbolException: If a chord (other than "no chord") fails to be interpreted by the `chord_symbols_lib` module. """ for i in range(len(self._events)): if self._events[i] != NO_CHORD: self._events[i] = chord_symbols_lib.transpose_chord_symbol( self._events[i], transpose_amount % NOTES_PER_OCTAVE)