init: scorometer from poc

This commit is contained in:
GitBluub
2022-12-18 00:52:49 +09:00
parent 56fdadc705
commit 3891ad9dfd
20 changed files with 448 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import asyncio, datetime
from typing import Callable
from .Note import Note
async def wait_until(dt):
# sleep until the specified datetime
now = datetime.datetime.now()
await asyncio.sleep((dt - now).total_seconds())
async def run_at(dt, coro):
await wait_until(dt)
return await coro
class Partition:
def __init__(self, name:str, notes:list[Note]) -> None:
self.__name = name
self.__notes = notes
async def play(self, output_lambda:Callable[[object], None]):
now = datetime.datetime.now()
tasks_to_wait = []
for note in self.__notes:
tasks_to_wait.append(
asyncio.create_task(
run_at(
now + datetime.timedelta(milliseconds= note.get_start_time()),
output_lambda(note.get_data())
)
)
)
await asyncio.wait(tasks_to_wait)