LoginSignup
4
4

More than 3 years have passed since last update.

PythonからMIDIメッセージを送ってDAWを操作

Last updated at Posted at 2020-12-18
  • MIDI Machine Control (MMC)を使って、Nuendoを外部から操作できる。
  • PythonのモジュールでMIDIメッセージを送ることができる

これらを利用して、PythonからNuendoを動かす。
もちろん、Nuendoでなくとも、一般的なDAWであれば、同じことができると思います。

0. 環境

  • MacOS 10.15.6 Catalina
  • Nuendo 10.3

1. MIDI Port を開く

Audio MIDI設定

  • Audio Midi Setup を開く
  • ⌘2 で MIDI Studio を開く

Screen_Shot_2020-11-09_at_17.39.32.png

  • 新規作成

Screen_Shot_2020-11-09_at_17.41.06.png

  • IAC Driverをダブルクリック
  • プロパティタブ
  • 機能の、MIDIマシンコントロールをチェック

_2020-11-09_18.56.19.png

  • ポートタブ
  • デバイスをオンラインにする。
  • ポートの名前を決める。
  • 適用

Screen_Shot_2020-11-09_at_17.47.35.png

  • Audio MIDI設定は立ち上げたまま

2. PythonでMIDIを送信する

Install Modules

$ pip install mido python-rtmidi

Document

Mido - MIDI Objects for Python - Mido 1.2.9 documentation

Python でMIDI Portを開く

import mido

print(mido.get_output_names())
# ['IAC Driver MMC Port']

port = mido.open_output('IAC Driver MMC Port')

MIDI Messageを送る

  • sysex(system exclusive) messageを 16進数のコマンドで送る。

MIDI Machine Control

# Control Play and Stop
# F0 7F <Device-ID> 06 [<Sub-ID#2> [<parameters>]] F7

# Device-ID -> 7F (ALL Devices)
# Sub-ID#2 -> 01 (Stop)

msg_start = mido.Message.from_hex("F0 7F 7F 06 02 F7")
msg_stop = mido.Message.from_hex("F0 7F 7F 06 01 F7")

# Control Locator
# F0 7F <Device-ID> 06 44 06 01 <hr> <mn> <sc> <fr> <ff> F7

# <hr> -> hour
# <mn> -> minute
# <sc> -> second
# <fr> -> frames
# <ff> -> sub-frames (0 basically)

# move Locater to 00:05:00:00
msg_locate = mido.Message.from_hex("F0 7F 7F 06 44 06 01 00 05 00 00 00 F7")

# send messages

port.send(msg_locate)
port.send(msg_start)
port.send(msg_stop)

# close port

port.close()

関数化してみよう

import mido
import time

def test():
    with mido.open_output('IAC Driver MMC Port') as port:
        port.send(msg_locate)
        port.send(msg_start)
        time.sleep(3)
        port.send(msg_stop)

3. Nuendoで受け取る

  • トランスポート > プロジェクト同期設定... を開く

_2020-11-09_18.29.51.png

  • ソースのタブ

_2020-11-09_18.39.10.png

  • マシンコントロールのタブ
  • マシンコントロール入力をMIDI マシンコントロールに設定
  • MMC入力を、さっき作ったポートに設定

_2020-11-09_18.33.21.png

完成!!!!!!!!!!!!!

未解決問題

  • 稀に、Nuendoの警告で、"24フレームに変更されました、無視しますか?"と聞いてくる。
  • とりあえず無視しています。
4
4
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
4
4