Пример #1
0
    def testInstrumentInfo_NoteSequenceToPrettyMidi(self):
        source_sequence = music_pb2.NoteSequence()
        source_sequence.notes.add(pitch=60,
                                  start_time=0.0,
                                  end_time=0.5,
                                  velocity=80,
                                  instrument=0)
        source_sequence.notes.add(pitch=60,
                                  start_time=0.5,
                                  end_time=1.0,
                                  velocity=80,
                                  instrument=1)
        instrument_info1 = source_sequence.instrument_infos.add()
        instrument_info1.name = 'inst_0'
        instrument_info1.instrument = 0
        instrument_info2 = source_sequence.instrument_infos.add()
        instrument_info2.name = 'inst_1'
        instrument_info2.instrument = 1
        translated_midi = midi_io.sequence_proto_to_pretty_midi(
            source_sequence)
        translated_sequence = midi_io.midi_to_note_sequence(translated_midi)

        self.assertEqual(len(source_sequence.instrument_infos),
                         len(translated_sequence.instrument_infos))
        self.assertEqual(source_sequence.instrument_infos[0].name,
                         translated_sequence.instrument_infos[0].name)
        self.assertEqual(source_sequence.instrument_infos[1].name,
                         translated_sequence.instrument_infos[1].name)
Пример #2
0
  def testInstrumentInfo_NoteSequenceToPrettyMidi(self):
    source_sequence = music_pb2.NoteSequence()
    source_sequence.notes.add(
        pitch=60, start_time=0.0, end_time=0.5, velocity=80, instrument=0)
    source_sequence.notes.add(
        pitch=60, start_time=0.5, end_time=1.0, velocity=80, instrument=1)
    instrument_info1 = source_sequence.instrument_infos.add()
    instrument_info1.name = 'inst_0'
    instrument_info1.instrument = 0
    instrument_info2 = source_sequence.instrument_infos.add()
    instrument_info2.name = 'inst_1'
    instrument_info2.instrument = 1
    translated_midi = midi_io.sequence_proto_to_pretty_midi(source_sequence)
    translated_sequence = midi_io.midi_to_note_sequence(translated_midi)

    self.assertEqual(
        len(source_sequence.instrument_infos),
        len(translated_sequence.instrument_infos))
    self.assertEqual(source_sequence.instrument_infos[0].name,
                     translated_sequence.instrument_infos[0].name)
    self.assertEqual(source_sequence.instrument_infos[1].name,
                     translated_sequence.instrument_infos[1].name)