6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MIDIの演奏楽器を変更する

Last updated at Posted at 2016-10-11

はじめに

TensorFlow製の音楽生成プロジェクト「Magenta」をいじっています。

参考:[サカナクションさんをTensorFlow製アート・音楽生成プロジェクト「Magenta」に学習させてみる。]
(http://qiita.com/tackey/items/1295a0347a8b4cc30d46)

その過程で、MIDIファイルの演奏楽器を変換したいと思い、pretty_midiを用いて変更してみます。
なお、環境はPython2.7、MIDIファイルはlogic Xでみたりしています。

コード例

sample.py
import pretty_midi

# 変更したいファイルの読み込み
midi_data = pretty_midi.PrettyMIDI('piano.mid')

# 楽器の確認
midi_data.instruments[0].program

# 結果
# [Instrument(program=0, is_drum=False, name="hoge")]


# program(楽器番号)を変更
midi_data.instruments[0].program = 30

# 楽器の確認
midi_data.instruments

# 結果
# [Instrument(program=30, is_drum=False, name="hoge")]

# ファイルの書き出し
midi_data.write('guitar.mid')

おわりに

簡単に楽器の変更ができました。
ありがとうございました。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?