コード例 #1
0
  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)
コード例 #2
0
ファイル: chords_lib.py プロジェクト: Alice-ren/magenta
  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)
コード例 #3
0
  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_
コード例 #4
0
    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_
コード例 #5
0
 def testChordSymbolBass(self):
     bass = chord_symbols_lib.chord_symbol_bass('Dm9')
     self.assertEqual(2, bass)
     bass = chord_symbols_lib.chord_symbol_bass('E/G#')
     self.assertEqual(8, bass)
     bass = chord_symbols_lib.chord_symbol_bass('Bsus2/A')
     self.assertEqual(9, bass)
     bass = chord_symbols_lib.chord_symbol_bass('Abm7/Cb')
     self.assertEqual(11, bass)
     bass = chord_symbols_lib.chord_symbol_bass('C#6/9/E#')
     self.assertEqual(5, bass)
     bass = chord_symbols_lib.chord_symbol_bass('G/o')
     self.assertEqual(7, bass)
コード例 #6
0
 def testChordSymbolBass(self):
   bass = chord_symbols_lib.chord_symbol_bass('Dm9')
   self.assertEqual(2, bass)
   bass = chord_symbols_lib.chord_symbol_bass('E/G#')
   self.assertEqual(8, bass)
   bass = chord_symbols_lib.chord_symbol_bass('Bsus2/A')
   self.assertEqual(9, bass)
   bass = chord_symbols_lib.chord_symbol_bass('Abm7/Cb')
   self.assertEqual(11, bass)
   bass = chord_symbols_lib.chord_symbol_bass('C#6/9/E#')
   self.assertEqual(5, bass)
   bass = chord_symbols_lib.chord_symbol_bass('G/o')
   self.assertEqual(7, bass)