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_
Пример #2
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_
    def encode_event(self, event):
        if event == NO_CHORD:
            return 0

        root = chord_symbols_lib.chord_symbol_root(event)
        quality = chord_symbols_lib.chord_symbol_quality(event)

        if quality == chord_symbols_lib.CHORD_QUALITY_MAJOR:
            return root + 1
        elif quality == chord_symbols_lib.CHORD_QUALITY_MINOR:
            return root + NOTES_PER_OCTAVE + 1
        else:
            raise ChordEncodingError('chord is neither major nor minor: %s' % event)
Пример #4
0
  def encode_event(self, event):
    if event == NO_CHORD:
      return 0

    root = chord_symbols_lib.chord_symbol_root(event)
    quality = chord_symbols_lib.chord_symbol_quality(event)

    if quality == chord_symbols_lib.CHORD_QUALITY_MAJOR:
      return root + 1
    elif quality == chord_symbols_lib.CHORD_QUALITY_MINOR:
      return root + NOTES_PER_OCTAVE + 1
    else:
      raise ChordEncodingError('chord is neither major nor minor: %s' % event)
Пример #5
0
  def encode_event(self, event):
    if event == NO_CHORD:
      return 0

    root = chord_symbols_lib.chord_symbol_root(event)
    quality = chord_symbols_lib.chord_symbol_quality(event)

    if quality == chord_symbols_lib.CHORD_QUALITY_MAJOR:
      return root + 1
    elif quality == chord_symbols_lib.CHORD_QUALITY_MINOR:
      return root + NOTES_PER_OCTAVE + 1
    elif quality == chord_symbols_lib.CHORD_QUALITY_AUGMENTED:
      return root + 2 * NOTES_PER_OCTAVE + 1
    elif quality == chord_symbols_lib.CHORD_QUALITY_DIMINISHED:
      return root + 3 * NOTES_PER_OCTAVE + 1
    else:
      raise ChordEncodingException('chord is not a standard triad: %s' % event)
    def encode_event(self, event):
        if event == NO_CHORD:
            return 0

        root = chord_symbols_lib.chord_symbol_root(event)
        quality = chord_symbols_lib.chord_symbol_quality(event)

        if quality == chord_symbols_lib.CHORD_QUALITY_MAJOR:
            return root + 1
        elif quality == chord_symbols_lib.CHORD_QUALITY_MINOR:
            return root + NOTES_PER_OCTAVE + 1
        elif quality == chord_symbols_lib.CHORD_QUALITY_AUGMENTED:
            return root + 2 * NOTES_PER_OCTAVE + 1
        elif quality == chord_symbols_lib.CHORD_QUALITY_DIMINISHED:
            return root + 3 * NOTES_PER_OCTAVE + 1
        else:
            raise ChordEncodingError('chord is not a standard triad: %s' % event)
Пример #7
0
 def testChordSymbolRoot(self):
     root = chord_symbols_lib.chord_symbol_root('Dm9')
     self.assertEqual(2, root)
     root = chord_symbols_lib.chord_symbol_root('E/G#')
     self.assertEqual(4, root)
     root = chord_symbols_lib.chord_symbol_root('Bsus2')
     self.assertEqual(11, root)
     root = chord_symbols_lib.chord_symbol_root('Abmaj7')
     self.assertEqual(8, root)
     root = chord_symbols_lib.chord_symbol_root('D##5(add6)')
     self.assertEqual(4, root)
     root = chord_symbols_lib.chord_symbol_root('F(b7)(#9)(b13)')
     self.assertEqual(5, root)
Пример #8
0
 def testChordSymbolRoot(self):
   root = chord_symbols_lib.chord_symbol_root('Dm9')
   self.assertEqual(2, root)
   root = chord_symbols_lib.chord_symbol_root('E/G#')
   self.assertEqual(4, root)
   root = chord_symbols_lib.chord_symbol_root('Bsus2')
   self.assertEqual(11, root)
   root = chord_symbols_lib.chord_symbol_root('Abmaj7')
   self.assertEqual(8, root)
   root = chord_symbols_lib.chord_symbol_root('D##5(add6)')
   self.assertEqual(4, root)
   root = chord_symbols_lib.chord_symbol_root('F(b7)(#9)(b13)')
   self.assertEqual(5, root)