예제 #1
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)
예제 #2
0
  def testEncodeNoteSequence(self):
    encoder = music_encoders.TextMelodyEncoder(
        steps_per_quarter=4, min_pitch=21, max_pitch=108)
    encoder_absolute = music_encoders.TextMelodyEncoderAbsolute(
        steps_per_second=4, min_pitch=21, max_pitch=108)

    ns = music_pb2.NoteSequence()
    ns.tempos.add(qpm=60)
    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)])
    ids = encoder.encode_note_sequence(ns)
    ids_absolute = encoder_absolute.encode_note_sequence(ns)

    expected_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_ids, ids)
    self.assertEqual(expected_ids, ids_absolute)
예제 #3
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))]
예제 #4
0
  def testEncode(self):
    encoder = music_encoders.TextMelodyEncoder(
        steps_per_quarter=4, min_pitch=21, max_pitch=108)

    ids = encoder.encode('60 -2 62 -1 64 -2')
    expected_ids = [
        43,  # ON(60)
        2,   # HOLD(60)
        45,  # ON(62)
        3,   # OFF(62)
        47,  # ON(64)
        2    # HOLD(64)
    ]

    self.assertEqual(expected_ids, ids)
예제 #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))
예제 #6
0
 def testVocabSize(self):
   encoder = music_encoders.TextMelodyEncoder(
       steps_per_quarter=4, min_pitch=21, max_pitch=108)
   self.assertEqual(92, encoder.vocab_size)