def render(self, sequence): # Sort text annotations by time. annotations = sorted(sequence.text_annotations, key=lambda a: a.time) prev_time = 0.0 prev_figure = NO_CHORD for annotation in annotations: if annotation.time >= sequence.total_time: break if annotation.annotation_type == CHORD_SYMBOL: if prev_figure != NO_CHORD: # Render the previous chord. pitches = chord_symbols_lib.chord_symbol_pitches(prev_figure) bass_pitch = chord_symbols_lib.chord_symbol_bass(prev_figure) self._render_notes(sequence=sequence, pitches=pitches, bass_pitch=bass_pitch, start_time=prev_time, end_time=annotation.time) prev_time = annotation.time prev_figure = annotation.text if (prev_time < sequence.total_time and prev_figure != NO_CHORD): # Render the last chord. pitches = chord_symbols_lib.chord_symbol_pitches(prev_figure) bass_pitch = chord_symbols_lib.chord_symbol_bass(prev_figure) self._render_notes(sequence=sequence, pitches=pitches, bass_pitch=bass_pitch, start_time=prev_time, end_time=sequence.total_time)
def render(self, sequence): # Sort text annotations by time. annotations = sorted(sequence.text_annotations, key=lambda a: a.time) prev_time = 0.0 prev_figure = NO_CHORD for annotation in annotations: if annotation.time >= sequence.total_time: break if annotation.annotation_type == CHORD_SYMBOL: if prev_figure != NO_CHORD: # Render the previous chord. pitches = chord_symbols_lib.chord_symbol_pitches(prev_figure) bass_pitch = chord_symbols_lib.chord_symbol_bass(prev_figure) self._render_notes(sequence=sequence, pitches=pitches, bass_pitch=bass_pitch, start_time=prev_time, end_time=annotation.time) prev_time = annotation.time prev_figure = annotation.text if (prev_time < sequence.total_time and prev_figure != NO_CHORD): # Render the last chord. pitches = chord_symbols_lib.chord_symbol_pitches(prev_figure) bass_pitch = chord_symbols_lib.chord_symbol_bass(prev_figure) self._render_notes(sequence=sequence, pitches=pitches, bass_pitch=bass_pitch, start_time=prev_time, end_time=sequence.total_time)
def events_to_input(self, events, position): """Returns the input vector for the given position in the chord progression. Indices [0, 36]: [0]: Whether or not this chord is "no chord". [1, 12]: A one-hot encoding of the chord root pitch class. [13, 24]: Whether or not each pitch class is present in the chord. [25, 36]: A one-hot encoding of the chord bass pitch class. Args: events: A magenta.music.ChordProgression object. position: An integer event position in the chord progression. Returns: An input vector, an self.input_size length list of floats. """ chord = events[position] input_ = [0.0] * self.input_size if chord == NO_CHORD: input_[0] = 1.0 return input_ root = chord_symbols_lib.chord_symbol_root(chord) input_[1 + root] = 1.0 pitches = chord_symbols_lib.chord_symbol_pitches(chord) for pitch in pitches: input_[1 + NOTES_PER_OCTAVE + pitch] = 1.0 bass = chord_symbols_lib.chord_symbol_bass(chord) input_[1 + 2 * NOTES_PER_OCTAVE + bass] = 1.0 return input_
def events_to_input(self, events, position): """Returns the input vector for the given position in the chord progression. Indices [0, 36]: [0]: Whether or not this chord is "no chord". [1, 12]: A one-hot encoding of the chord root pitch class. [13, 24]: Whether or not each pitch class is present in the chord. [25, 36]: A one-hot encoding of the chord bass pitch class. Args: events: A magenta.music.ChordProgression object. position: An integer event position in the chord progression. Returns: An input vector, an self.input_size length list of floats. """ chord = events[position] input_ = [0.0] * self.input_size if chord == NO_CHORD: input_[0] = 1.0 return input_ root = chord_symbols_lib.chord_symbol_root(chord) input_[1 + root] = 1.0 pitches = chord_symbols_lib.chord_symbol_pitches(chord) for pitch in pitches: input_[1 + NOTES_PER_OCTAVE + pitch] = 1.0 bass = chord_symbols_lib.chord_symbol_bass(chord) input_[1 + 2 * NOTES_PER_OCTAVE + bass] = 1.0 return input_
def testChordSymbolPitches(self): pitches = chord_symbols_lib.chord_symbol_pitches('Am') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([0, 4, 9]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('D7b9') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([0, 2, 3, 6, 9]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('F/o') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([3, 5, 8, 11]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('C-(M7)') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([0, 3, 7, 11]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('E##13') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([1, 3, 4, 6, 8, 10, 11]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('G(add2)(#5)') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([3, 7, 9, 11]), pitch_classes)
def testChordSymbolPitches(self): pitches = chord_symbols_lib.chord_symbol_pitches('Am') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([0, 4, 9]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('D7b9') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([0, 2, 3, 6, 9]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('F/o') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([3, 5, 8, 11]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('C-(M7)') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([0, 3, 7, 11]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('E##13') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([1, 3, 4, 6, 8, 10, 11]), pitch_classes) pitches = chord_symbols_lib.chord_symbol_pitches('G(add2)(#5)') pitch_classes = set(pitch % 12 for pitch in pitches) self.assertEqual(set([3, 7, 9, 11]), pitch_classes)