diff --git a/chroma_case/Partition.py b/chroma_case/Partition.py index 02a2359..0e00fbd 100644 --- a/chroma_case/Partition.py +++ b/chroma_case/Partition.py @@ -20,22 +20,20 @@ class Partition: self.__notes = notes - def play(self, output_lambda:Callable[[str, tuple[int, int, int], int], None]): + async def play(self, output_lambda:Callable[[str, tuple[int, int, int], int], None]): now = datetime.datetime.now() tasks_to_wait = [] for note in self.__notes: tasks_to_wait.append( asyncio.create_task( - lambda: asyncio.wait( - run_at( - now + datetime.timedelta(milliseconds= note.get_start_time()), - output_lambda( - note.get_key(), - note.get_color(), - note.get_duration() - ) + run_at( + now + datetime.timedelta(milliseconds= note.get_start_time()), + output_lambda( + note.get_key(), + note.get_color(), + note.get_duration() ) ) ) ) - asyncio.wait(tasks_to_wait) + await asyncio.wait(tasks_to_wait) diff --git a/chroma_case/__pycache__/Partition.cpython-39.pyc b/chroma_case/__pycache__/Partition.cpython-39.pyc index d87e69c..a3a1445 100644 Binary files a/chroma_case/__pycache__/Partition.cpython-39.pyc and b/chroma_case/__pycache__/Partition.cpython-39.pyc differ diff --git a/main.py b/main.py index e4901e1..15121f2 100644 --- a/main.py +++ b/main.py @@ -3,16 +3,22 @@ from chroma_case.Note import Note import asyncio import sys -def printing(key, color, duration): +async def printing(key, color, duration): print(f"key: {key}, c:{color} for {duration / 1000}s") + await asyncio.sleep(duration / 1000) + print(f"end of {key}") -def main(): - n = Note("fa", (0, 255, 0), 1000, 1000) - p = Partition("test", [n]) +async def main(): + n = Note("fa", (0, 255, 0), 1000, 7000) - p.play(printing) + p = Partition("test", + [n, + Note("fa#", (234, 255, 0), 3000, 2000)] + ) + + await p.play(printing) return 0