-
-
Save aisot/1d373829315356591cba170447f3f4d4 to your computer and use it in GitHub Desktop.
pythonを使う場合
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OSC_PORT = 19100 | |
import pygame.midi as m | |
from pythonosc import udp_client | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--ip", default="127.0.0.1") | |
parser.add_argument("--port", type=int, default=OSC_PORT) | |
args = parser.parse_args() | |
print("--------------------") | |
print("osc port:" + str(args.port)) | |
client = udp_client.SimpleUDPClient(args.ip, args.port) | |
m.init() | |
i_num=m.get_count() | |
midi_input_device_list = [] | |
for i in range(i_num): | |
device_info = m.get_device_info(i) | |
if device_info[2]:#true=midi input device | |
midi_input_device_list.append([device_info[1],i]) | |
print("------------------------------") | |
print("MIDI input device list") | |
print("------------------------------") | |
for num in range(len(midi_input_device_list)): | |
device_name = midi_input_device_list[num][0].decode() | |
device_num = midi_input_device_list[num][1] | |
print (str(num) + "=[" + device_name + "]") | |
print("------------------------------") | |
select_num = int(input("Enter your MIDI device number:")) | |
device_num = midi_input_device_list[select_num][1] | |
device_name = midi_input_device_list[select_num][0].decode() | |
print("------------------------------") | |
print("MIDI input device : [" + device_name + "]") | |
i = m.Input(device_num) | |
while True: | |
if i.poll(): | |
midi_events = i.read(4)[0][0] | |
midi_events.pop() | |
midi_hex = [hex(i) for i in midi_events] | |
print ("/rawmidi\t" + str(midi_hex)) | |
client.send_message("/rawmidi", midi_events) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment