Compare commits
6 Commits
f5c6e36d05
...
mussorgsky
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f7f6d0a1c | |||
| 0d8e0a85c7 | |||
| 06524577ff | |||
| 44b7caed76 | |||
| 3bd7de9042 | |||
| 1a07709d39 |
BIN
1ublau.mid
Executable file
BIN
1ublau.mid
Executable file
Binary file not shown.
BIN
7eisblau.mid
Executable file
BIN
7eisblau.mid
Executable file
Binary file not shown.
57
eisblau.py
Normal file
57
eisblau.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import argparse
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
from mido import MidiFile
|
||||||
|
from pythonosc import udp_client
|
||||||
|
import mido
|
||||||
|
import random
|
||||||
|
|
||||||
|
mid = MidiFile('7eisblau.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", "blue")
|
||||||
|
|
||||||
|
|
||||||
|
accrued_time = 0
|
||||||
|
note_count = 0
|
||||||
|
coor = (50, 50)
|
||||||
|
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:
|
||||||
|
time.sleep(t)
|
||||||
|
continue
|
||||||
|
note_count += 1
|
||||||
|
if note_count > 4:
|
||||||
|
note_count = 0
|
||||||
|
coor = (coor[0] + direction[0] * accrued_time * 21, coor[1] + direction[1] * accrued_time * 21)
|
||||||
|
client.send_message("/tcp_coordinates", (coor[0], coor[1], 6, 0, 0, 0))
|
||||||
|
accrued_time = 0
|
||||||
|
for i, m in enumerate(direction):
|
||||||
|
if m != 0:
|
||||||
|
direction[i] = 0
|
||||||
|
else:
|
||||||
|
direction[i] = random.choice((1, -1))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print(msg.note)
|
||||||
|
time.sleep(t)
|
||||||
|
|
||||||
|
|
||||||
|
client.send_message("/tcp_coordinates", (coor[0], coor[1], 0, 0, 0, 0))
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#N canvas 155 110 562 769 12;
|
#N canvas 1091 134 562 769 12;
|
||||||
#X obj 95 418 netsend -u -b;
|
#X obj 95 418 netsend -u -b;
|
||||||
#X obj 87 252 oscformat tcp_coordinates;
|
#X obj 87 252 oscformat tcp_coordinates;
|
||||||
#X msg 233 363 disconnect;
|
#X msg 233 363 disconnect;
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
#X msg 307 289 connect localhost 5005;
|
#X msg 307 289 connect localhost 5005;
|
||||||
#X obj 325 262 loadbang;
|
#X obj 325 262 loadbang;
|
||||||
#X msg 82 214 242 29 2 0 0 0;
|
#X msg 82 214 242 29 2 0 0 0;
|
||||||
|
#X msg 222 122 yellow;
|
||||||
|
#X obj 226 152 list;
|
||||||
|
#X obj 238 182 oscformat color;
|
||||||
#X connect 1 0 4 0;
|
#X connect 1 0 4 0;
|
||||||
#X connect 2 0 0 0;
|
#X connect 2 0 0 0;
|
||||||
#X connect 3 0 0 0;
|
#X connect 3 0 0 0;
|
||||||
@@ -14,3 +17,6 @@
|
|||||||
#X connect 5 0 0 0;
|
#X connect 5 0 0 0;
|
||||||
#X connect 6 0 5 0;
|
#X connect 6 0 5 0;
|
||||||
#X connect 7 0 1 0;
|
#X connect 7 0 1 0;
|
||||||
|
#X connect 8 0 9 0;
|
||||||
|
#X connect 9 0 10 0;
|
||||||
|
#X connect 10 0 4 0;
|
||||||
|
|||||||
@@ -18,22 +18,26 @@ args = parser.parse_args()
|
|||||||
|
|
||||||
client = udp_client.SimpleUDPClient(args.ip, args.port)
|
client = udp_client.SimpleUDPClient(args.ip, args.port)
|
||||||
angle = 0
|
angle = 0
|
||||||
magnitude = 20
|
magnitude = 0
|
||||||
|
mean = 74.1
|
||||||
|
client.send_message("/color", "yellow")
|
||||||
|
|
||||||
|
|
||||||
for msg in mid.tracks[1]:
|
for msg in mid.tracks[1]:
|
||||||
t = mido.tick2second(msg.time, mid.ticks_per_beat, 1000000)
|
t = mido.tick2second(msg.time, mid.ticks_per_beat, 1000000)
|
||||||
beats = msg.time / mid.ticks_per_beat
|
beats = msg.time / mid.ticks_per_beat
|
||||||
time.sleep(t)
|
|
||||||
rotation = 2 * math.pi * beats / 16
|
rotation = 2 * math.pi * beats / 16
|
||||||
|
|
||||||
angle += rotation
|
angle += rotation
|
||||||
magnitude += beats
|
magnitude += beats * 3
|
||||||
if msg.type != "note_on":
|
if msg.type != "note_on" or msg.time == 0:
|
||||||
|
time.sleep(t)
|
||||||
continue
|
continue
|
||||||
|
print(msg.note)
|
||||||
|
adj_angle = angle + (msg.note - mean) / 9
|
||||||
|
y = math.sin(adj_angle) * magnitude
|
||||||
|
x = math.cos(adj_angle) * magnitude
|
||||||
|
client.send_message("/tcp_coordinates", (x, y, 6, 0, 0, 0))
|
||||||
|
time.sleep(t)
|
||||||
|
|
||||||
print(angle)
|
client.send_message("/tcp_coordinates", (x, y, 0, 0, 0, 0))
|
||||||
print(magnitude)
|
|
||||||
|
|
||||||
y = math.sin(angle) * magnitude
|
|
||||||
x = math.cos(angle) * magnitude
|
|
||||||
client.send_message("/tcp_coordinates", (x, y, 10, 0, 0, 0))
|
|
||||||
15
main.py
15
main.py
@@ -8,14 +8,26 @@ from pythonosc import osc_server
|
|||||||
t = turtle.Turtle()
|
t = turtle.Turtle()
|
||||||
screen = turtle.Screen()
|
screen = turtle.Screen()
|
||||||
screen.title("Painting robot sim")
|
screen.title("Painting robot sim")
|
||||||
|
COLORS = [
|
||||||
|
"black",
|
||||||
|
"yellow",
|
||||||
|
"red",
|
||||||
|
"blue"
|
||||||
|
]
|
||||||
|
|
||||||
|
def color_handler(unused_addr, c):
|
||||||
|
if c in COLORS:
|
||||||
|
t.pencolor(c)
|
||||||
|
|
||||||
def coordinate_handler(unused_addr, x, y, z, roll, pitch, yaw):
|
def coordinate_handler(unused_addr, x, y, z, roll, pitch, yaw):
|
||||||
|
prev_size = t.pensize
|
||||||
t.pen(pensize=z)
|
t.pen(pensize=z)
|
||||||
if z <= 0:
|
if z <= 0:
|
||||||
t.penup()
|
t.penup()
|
||||||
else:
|
else:
|
||||||
t.pendown()
|
t.pendown()
|
||||||
|
if prev_size == 0:
|
||||||
|
t.dot()
|
||||||
t.goto(x, y)
|
t.goto(x, y)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -26,6 +38,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
dispatcher = Dispatcher()
|
dispatcher = Dispatcher()
|
||||||
dispatcher.map("/tcp_coordinates", coordinate_handler)
|
dispatcher.map("/tcp_coordinates", coordinate_handler)
|
||||||
|
dispatcher.map("/color", color_handler)
|
||||||
|
|
||||||
server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcher)
|
server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcher)
|
||||||
print(f"Serving on {server.server_address}")
|
print(f"Serving on {server.server_address}")
|
||||||
|
|||||||
57
rot.py
Normal file
57
rot.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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))
|
||||||
Reference in New Issue
Block a user