Compare commits
1 Commits
master
...
f5c6e36d05
| Author | SHA1 | Date | |
|---|---|---|---|
| f5c6e36d05 |
39
music_tracker.py
Normal file
39
music_tracker.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import argparse
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
from mido import MidiFile
|
||||||
|
from pythonosc import udp_client
|
||||||
|
import mido
|
||||||
|
|
||||||
|
mid = MidiFile('2gelb.mid')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
angle = 0
|
||||||
|
magnitude = 20
|
||||||
|
|
||||||
|
for msg in mid.tracks[1]:
|
||||||
|
t = mido.tick2second(msg.time, mid.ticks_per_beat, 1000000)
|
||||||
|
beats = msg.time / mid.ticks_per_beat
|
||||||
|
time.sleep(t)
|
||||||
|
rotation = 2 * math.pi * beats / 16
|
||||||
|
|
||||||
|
angle += rotation
|
||||||
|
magnitude += beats
|
||||||
|
if msg.type != "note_on":
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(angle)
|
||||||
|
print(magnitude)
|
||||||
|
|
||||||
|
y = math.sin(angle) * magnitude
|
||||||
|
x = math.cos(angle) * magnitude
|
||||||
|
client.send_message("/tcp_coordinates", (x, y, 10, 0, 0, 0))
|
||||||
Reference in New Issue
Block a user