#! /usr/bin/env python3 import asyncio from monome import Monome, create_serialosc_connection class Hello(Monome): def __init__(self): super().__init__('/hello') def grid_key(self, x, y, s): self.led_row(0, y, [s] * 8) self.led_col(x, 0, [s] * 8) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.async(create_serialosc_connection(Hello, loop=loop)) loop.run_forever()
from hello import Hello class HelloPage(monome.Page, Hello): def __init__(self, manager): monome.Page.__init__(self, manager) Hello.__init__(self) def ready(self): monome.Page.ready(self) Hello.ready(self) class ExamplePages(monome.SumPageManager): def __init__(self): super().__init__([ FadersPage(self), LightsPage(self), LifePage(self), HelloPage(self), ]) loop = asyncio.get_event_loop() asyncio. async (monome.create_serialosc_connection(ExamplePages, loop=loop)) try: loop.run_forever() except KeyboardInterrupt: print('kthxbye')
def cleanup(): yield from asyncio.sleep(0.2) if __name__ == "__main__": from concurrent.futures import ThreadPoolExecutor loop = asyncio.get_event_loop() loop.set_default_executor(ThreadPoolExecutor(100)) # create clock # coro = loop.create_datagram_endpoint(clocks.FooClock, local_addr=('127.0.0.1', 9000)) # transport, clock = loop.run_until_complete(coro) clock = clocks.InaccurateTempoClock(90) # create synth coro = loop.create_datagram_endpoint(synths.Renoise, local_addr=("127.0.0.1", 0), remote_addr=("127.0.0.1", 8001)) transport, renoise = loop.run_until_complete(coro) coro = monome.create_serialosc_connection(lambda: Parc(clock, renoise)) serialosc = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: for apps in serialosc.app_instances.values(): for app in apps: app.disconnect() loop.run_until_complete(cleanup()) print("kthxbye")
self.faders[x] = asyncio. async (self.fade_to( x, self.row_to_value(y))) def value_to_row(self, value): return sorted([i for i in range(self.height)], key=lambda i: abs(self.row_values[i] - value))[0] def row_to_value(self, row): return self.row_values[self.height - 1 - row] @asyncio.coroutine def fade_to(self, x, new_value): while self.values[x] != new_value: if self.values[x] < new_value: self.values[x] += 1 else: self.values[x] -= 1 col = [ 0 if c > self.value_to_row(self.values[x]) else 1 for c in range(self.height) ] col.reverse() self.led_col(x, 0, col) yield from asyncio.sleep(1 / 100) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio. async (monome.create_serialosc_connection(Faders), loop=loop) loop.run_forever()
asyncio. async (self.animate()) def grid_key(self, x, y, s): if s == 1: self.led_set(x, y, s) def disconnect(self, *args): self.alive = False super().disconnect(*args) async def animate(self): while self.alive: for i in range(self.height): row = [random.randint(0, 1) for i in range(self.width)] for j in range(3): self.led_row(0, i, [0] * self.width) await asyncio.sleep(1 / 30) self.led_row(0, i, row) await asyncio.sleep(1 / 30) for i in reversed(range(self.height)): row = [random.randint(0, 1) for i in range(self.width)] self.led_row(0, i, row) await asyncio.sleep(1 / 20) await asyncio.sleep(2) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio. async (monome.create_serialosc_connection(Lights), loop=loop) loop.run_forever()
#! /usr/bin/env python3 # # test for automatic varibright->monobright conversion of messages # try changing varibright to True for smooth brightness transition # import asyncio import monome class Monobright(monome.Monome): def __init__(self): super().__init__('/hello', varibright=False) @asyncio.coroutine def light(self, x, y): for i in range(16): self.led_level_set(x, y, i) yield from asyncio.sleep(0.1) def grid_key(self, x, y, s): if s == 1: asyncio. async (self.light(x, y)) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio. async (monome.create_serialosc_connection(Monobright, loop=loop)) loop.run_forever()
self.bridge_port = bridge_port self.app_host = app_host self.app_port = app_port self.app_prefix = app_prefix def ready(self): asyncio.async(self.init_gate()) @asyncio.coroutine def init_gate(self): # there is no remote_addr=(self.app_host, self.app_port) # because some endpoint implementations (oscP5) are pretty careless # about their source ports transport, protocol = yield from self.loop.create_datagram_endpoint( lambda: Gate(self.app_prefix, self), local_addr=(self.bridge_host, self.bridge_port), ) self.gate = protocol def grid_key(self, x, y, s): self.gate.grid_key(x, y, s) if __name__ == '__main__': loop = asyncio.get_event_loop() coro = monome.create_serialosc_connection({ '*': lambda: Bridge(bridge_port=8080, app_port=8000, app_prefix='/rove'), }, loop=loop) loop.run_until_complete(coro) loop.run_forever()
for i in range(self.speed * speed): new_pos = yield from self.clock.sync() except asyncio.CancelledError: self.play_row[x] = 0 self.pipe() self.led_col(x, 0, [0] * self.height) if __name__ == '__main__': loop = asyncio.get_event_loop() # create clock #coro = loop.create_datagram_endpoint(clocks.FooClock, local_addr=('127.0.0.1', 9000)) #transport, clock = loop.run_until_complete(coro) clock = clocks.InaccurateTempoClock(100) # create synth coro = loop.create_datagram_endpoint(synths.Renoise, local_addr=('127.0.0.1', 0), remote_addr=('127.0.0.1', 8001)) transport, renoise = loop.run_until_complete(coro) coro = monome.create_serialosc_connection(lambda: Flin(clock, renoise, 0)) serialosc = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: for apps in serialosc.app_instances.values(): for app in apps: app.disconnect() print('kthxbye')
def ready(self): monome.Page.ready(self) Life.ready(self) from hello import Hello class HelloPage(monome.Page, Hello): def __init__(self, app): monome.Page.__init__(self, app) Hello.__init__(self) def ready(self): monome.Page.ready(self) Hello.ready(self) class ExamplePages(monome.Pages): def __init__(self): super().__init__([ FadersPage(self), LightsPage(self), LifePage(self), HelloPage(self), ], monome.PageCorner.bottom_right) loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(ExamplePages, loop=loop)) try: loop.run_forever() except KeyboardInterrupt: print('kthxbye')
def ready(self): asyncio. async (self.init_gate()) @asyncio.coroutine def init_gate(self): # there is no remote_addr=(self.app_host, self.app_port) # because some endpoint implementations (oscP5) are pretty careless # about their source ports transport, protocol = yield from self.loop.create_datagram_endpoint( lambda: Gate(self.app_prefix, self), local_addr=(self.bridge_host, self.bridge_port), ) self.gate = protocol def grid_key(self, x, y, s): self.gate.grid_key(x, y, s) if __name__ == '__main__': loop = asyncio.get_event_loop() coro = monome.create_serialosc_connection( { '*': lambda: Bridge(bridge_port=8080, app_port=8000, app_prefix='/rove' ), }, loop=loop) loop.run_until_complete(coro) loop.run_forever()
#! /usr/bin/env python3 import asyncio from monome import Monome, create_serialosc_connection class Hello(Monome): def __init__(self): super().__init__('/hello') def grid_key(self, x, y, s): self.led_row(0, y, [s] * 8) self.led_col(x, 0, [s] * 8) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio. async (create_serialosc_connection(Hello, loop=loop)) loop.run_forever()
asyncio.async(self.animate()) def grid_key(self, x, y, s): if s == 1: self.led_set(x, y, s) def disconnect(self, *args): self.alive = False super().disconnect(*args) @asyncio.coroutine def animate(self): while self.alive: for i in range(self.height): row = [random.randint(0, 1) for i in range(self.width)] for j in range(3): self.led_row(0, i, [0] * self.width) yield from asyncio.sleep(1 / 30) self.led_row(0, i, row) yield from asyncio.sleep(1 / 30) for i in reversed(range(self.height)): row = [random.randint(0, 1) for i in range(self.width)] self.led_row(0, i, row) yield from asyncio.sleep(1 / 20) yield from asyncio.sleep(2) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(Lights), loop=loop) loop.run_forever()
from lights import Lights class LightsPart(monome.Section, Lights): def __init__(self, splitter, size, offset): monome.Section.__init__(self, splitter, size, offset) Lights.__init__(self) def ready(self): monome.Section.ready(self) Lights.ready(self) class ExampleSplitter(monome.Splitter): def __init__(self): super().__init__([ FadersPart(self, size=(8, 8), offset=(0, 0)), LightsPart(self, size=(8, 8), offset=(8, 0)), ]) loop = asyncio.get_event_loop() asyncio. async (monome.create_serialosc_connection(ExampleSplitter, loop=loop)) try: loop.run_forever() except KeyboardInterrupt: print('kthxbye')
Faders.__init__(self) def ready(self): monome.Section.ready(self) Faders.ready(self) from lights import Lights class LightsPart(monome.Section, Lights): def __init__(self, splitter, size, offset): monome.Section.__init__(self, splitter, size, offset) Lights.__init__(self) def ready(self): monome.Section.ready(self) Lights.ready(self) class ExampleSplitter(monome.Splitter): def __init__(self): super().__init__([ FadersPart(self, size=(8,8), offset=(0,0)), LightsPart(self, size=(8,8), offset=(8,0)), ]) loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(ExampleSplitter, loop=loop)) try: loop.run_forever() except KeyboardInterrupt: print('kthxbye')
def grid_key(self, x, y, s): self.send('/{}/grid/key'.format(self.prefix), x, y, s) class Bridge(monome.Monome): def __init__(self, loop=None): super().__init__('/rove-bridge') if loop is None: loop = asyncio.get_event_loop() self.loop = loop def ready(self): asyncio. async (self.init_gate()) @asyncio.coroutine def init_gate(self): transport, protocol = yield from self.loop.create_datagram_endpoint( lambda: Gate('/rove', self), local_addr=('127.0.0.1', 8080), remote_addr=('127.0.0.1', 8000)) self.gate = protocol def grid_key(self, x, y, s): self.gate.grid_key(x, y, s) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio. async (monome.create_serialosc_connection(Bridge), loop=loop) loop.run_forever()
def grid_key(self, x, y, s): self.send('/{}/grid/key'.format(self.prefix), x, y, s) class Bridge(monome.Monome): def __init__(self, loop=None): super().__init__('/rove-bridge') if loop is None: loop = asyncio.get_event_loop() self.loop = loop def ready(self): asyncio.async(self.init_gate()) @asyncio.coroutine def init_gate(self): transport, protocol = yield from self.loop.create_datagram_endpoint( lambda: Gate('/rove', self), local_addr=('127.0.0.1', 8080), remote_addr=('127.0.0.1', 8000) ) self.gate = protocol def grid_key(self, x, y, s): self.gate.grid_key(x, y, s) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(Bridge), loop=loop) loop.run_forever()
#! /usr/bin/env python3 # # test for automatic varibright->monobright conversion of messages # try changing varibright to True for smooth brightness transition # import asyncio import monome class Monobright(monome.Monome): def __init__(self): super().__init__('/hello', varibright=False) @asyncio.coroutine def light(self, x, y): for i in range(16): self.led_level_set(x, y, i) yield from asyncio.sleep(0.1) def grid_key(self, x, y, s): if s == 1: asyncio.async(self.light(x, y)) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(Monobright, loop=loop)) loop.run_forever()
self.values = [random.randint(0, FADERS_MAX_VALUE) for f in range(self.width)] self.faders = [asyncio.async(self.fade_to(f, 0)) for f in range(self.width)] def grid_key(self, x, y, s): if s == 1: self.faders[x].cancel() self.faders[x] = asyncio.async(self.fade_to(x, self.row_to_value(y))) def value_to_row(self, value): return sorted([i for i in range(self.height)], key=lambda i: abs(self.row_values[i] - value))[0] def row_to_value(self, row): return self.row_values[self.height - 1 - row] @asyncio.coroutine def fade_to(self, x, new_value): while self.values[x] != new_value: if self.values[x] < new_value: self.values[x] += 1 else: self.values[x] -= 1 col = [0 if c > self.value_to_row(self.values[x]) else 1 for c in range(self.height)] col.reverse() self.led_col(x, 0, col) yield from asyncio.sleep(1/100) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(Faders), loop=loop) loop.run_forever()
#! /usr/bin/env python3 import asyncio import monome class GridStudies(monome.Monome): def __init__(self): super().__init__('/monome') def grid_key(self, x, y, s): print("key:", x, y, s) self.led_level_set(x, y, s*15) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.async(monome.create_serialosc_connection(GridStudies)) loop.run_forever()
@asyncio.coroutine def cleanup(): yield from asyncio.sleep(0.2) if __name__ == '__main__': from concurrent.futures import ThreadPoolExecutor loop = asyncio.get_event_loop() loop.set_default_executor(ThreadPoolExecutor(100)) # create clock #coro = loop.create_datagram_endpoint(clocks.FooClock, local_addr=('127.0.0.1', 9000)) #transport, clock = loop.run_until_complete(coro) clock = clocks.InaccurateTempoClock(90) # create synth coro = loop.create_datagram_endpoint(synths.Renoise, local_addr=('127.0.0.1', 0), remote_addr=('127.0.0.1', 8001)) transport, renoise = loop.run_until_complete(coro) coro = monome.create_serialosc_connection(lambda: Parc(clock, renoise)) serialosc = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: for apps in serialosc.app_instances.values(): for app in apps: app.disconnect() loop.run_until_complete(cleanup()) print('kthxbye')