You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
2 years ago
|
import csv
|
||
|
import time
|
||
|
from pythonosc.udp_client import SimpleUDPClient
|
||
|
|
||
|
class Loop:
|
||
|
|
||
|
index = 0
|
||
|
|
||
|
def __init__(self, seq: list, bpm: int, ip="127.0.0.1", port=1337):
|
||
|
self.seq = seq
|
||
|
self.bpm = bpm
|
||
|
self.client = SimpleUDPClient(ip, port)
|
||
|
|
||
|
def read(self):
|
||
|
with open('seq.csv', newline='') as f:
|
||
|
self.seq = [step for step in csv.DictReader(f)]
|
||
|
|
||
|
|
||
|
def process(self, step):
|
||
|
commands = [command for command in step.values()]
|
||
|
self.client.send_message('/seq', commands)
|
||
|
for key, value in step.items():
|
||
|
print(value, end=' ')
|
||
|
print('')
|
||
|
|
||
|
def main(self):
|
||
|
while True:
|
||
|
self.read()
|
||
|
try:
|
||
|
self.process(self.seq[self.index])
|
||
|
except IndexError:
|
||
|
self.index = 0
|
||
|
self.process(self.seq[self.index])
|
||
|
self.index = self.index + 1 if self.index < len(self.seq) - 1 else 0
|
||
|
time.sleep(60/self.bpm/4)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
with open('seq.csv', newline='') as f:
|
||
|
sequence = [step for step in csv.DictReader(f)]
|
||
|
loop = Loop(sequence, 120)
|
||
|
loop.main()
|