Ejemplo n.º 1
0
 def score_encoders(self):
     return [('chords',
              music_encoders.TextChordsEncoder(steps_per_quarter=4)),
             ('melody',
              music_encoders.TextMelodyEncoder(steps_per_quarter=4,
                                               min_pitch=MIN_PITCH,
                                               max_pitch=MAX_PITCH))]
Ejemplo n.º 2
0
 def testVocabSize(self):
   encoder = music_encoders.CompositeScoreEncoder([
       music_encoders.TextChordsEncoder(steps_per_quarter=4),
       music_encoders.TextMelodyEncoder(
           steps_per_quarter=4, min_pitch=21, max_pitch=108)
   ])
   self.assertEqual([51, 92], encoder.vocab_size)
Ejemplo n.º 3
0
  def testEncode(self):
    encoder = music_encoders.TextChordsEncoder(steps_per_quarter=1)

    ids = encoder.encode('C G Am F')
    expected_ids = [
        3,   # C major
        10,  # G major
        24,  # A minor
        8    # F major
    ]

    self.assertEqual(expected_ids, ids)
Ejemplo n.º 4
0
  def testEncodeNoteSequence(self):
    encoder = music_encoders.TextChordsEncoder(steps_per_quarter=1)

    ns = music_pb2.NoteSequence()
    ns.tempos.add(qpm=60)
    testing_lib.add_chords_to_sequence(
        ns, [('C', 1), ('Dm', 3), ('Bdim', 4)])
    ns.total_time = 5.0
    ids = encoder.encode_note_sequence(ns)

    expected_ids = [
        2,   # no-chord
        3,   # C major
        3,   # C major
        17,  # D minor
        50   # B diminished
    ]

    self.assertEqual(expected_ids, ids)
Ejemplo n.º 5
0
    def testEncodeNoteSequence(self):
        encoder = music_encoders.CompositeScoreEncoder([
            music_encoders.TextChordsEncoder(steps_per_quarter=4),
            music_encoders.TextMelodyEncoder(steps_per_quarter=4,
                                             min_pitch=21,
                                             max_pitch=108)
        ])

        ns = music_pb2.NoteSequence()
        ns.tempos.add(qpm=60)
        testing_lib.add_chords_to_sequence(ns, [('C', 0.5), ('Dm', 1.0)])
        testing_lib.add_track_to_sequence(ns, 0, [(60, 127, 0.0, 0.25),
                                                  (62, 127, 0.25, 0.75),
                                                  (64, 127, 1.25, 2.0)])
        chord_ids, melody_ids = zip(*encoder.encode_note_sequence(ns))

        expected_chord_ids = [
            2,  # no-chord
            2,  # no-chord
            3,  # C major
            3,  # C major
            17,  # D minor
            17,  # D minor
            17,  # D minor
            17  # D minor
        ]

        expected_melody_ids = [
            43,  # ON(60)
            45,  # ON(62)
            2,  # HOLD(62)
            3,  # OFF(62)
            2,  # REST
            47,  # ON(64)
            2,  # HOLD(64)
            2  # HOLD(64)
        ]

        self.assertEqual(expected_chord_ids, list(chord_ids))
        self.assertEqual(expected_melody_ids, list(melody_ids))
Ejemplo n.º 6
0
 def testVocabSize(self):
   encoder = music_encoders.TextChordsEncoder(steps_per_quarter=1)
   self.assertEqual(51, encoder.vocab_size)
Ejemplo n.º 7
0
 def score_encoders(self):
     return [('chords',
              music_encoders.TextChordsEncoder(steps_per_quarter=1))]