58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
import argparse
|
|
import math
|
|
import time
|
|
from mido import MidiFile
|
|
from pythonosc import udp_client
|
|
import mido
|
|
import random
|
|
|
|
mid = MidiFile('6rot.mid')
|
|
|
|
random.seed(10)
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--ip", default="127.0.0.1",
|
|
help="The ip of the OSC server")
|
|
parser.add_argument("--port", type=int, default=5005,
|
|
help="The port the OSC server is listening on")
|
|
args = parser.parse_args()
|
|
|
|
client = udp_client.SimpleUDPClient(args.ip, args.port)
|
|
client.send_message("/color", "red")
|
|
|
|
|
|
accrued_time = 0
|
|
note_count = 0
|
|
center = (50, 50)
|
|
radius = 10
|
|
direction = [1, 0]
|
|
|
|
|
|
client.send_message("/tcp_coordinates", (50, 50, 0, 0, 0, 0))
|
|
for msg in mid.tracks[1]:
|
|
t = mido.tick2second(msg.time, mid.ticks_per_beat, 1000000)
|
|
beats = msg.time / mid.ticks_per_beat
|
|
accrued_time += t
|
|
if msg.type != "note_on" or msg.time == 0 or msg.velocity == 0:
|
|
time.sleep(t)
|
|
continue
|
|
print(msg.note)
|
|
|
|
note_count += 1
|
|
client.send_message("/tcp_coordinates", (center[0], center[1], 6, 0, 0, 0))
|
|
|
|
client.send_message("/tcp_coordinates", (center[0], center[1], 0, 0, 0, 0))
|
|
if note_count > 4:
|
|
client.send_message("/tcp_coordinates", (center[0], center[1], 0, 0, 0, 0))
|
|
center = (random.randint(0, 300), random.randint(0, 300))
|
|
client.send_message("/tcp_coordinates", (center[0], center[1], 0, 0, 0, 0))
|
|
|
|
note_count = 0
|
|
|
|
|
|
|
|
time.sleep(t)
|
|
|
|
|
|
client.send_message("/tcp_coordinates", (coor[0], coor[1], 0, 0, 0, 0))
|