|
| 1 | +===== |
| 2 | +aiosc |
| 3 | +===== |
| 4 | + |
| 5 | +This is an experimental minimalistic Open Sound Control (OSC) communication |
| 6 | +module which uses asyncio for network operations and is compatible with the |
| 7 | +asyncio event loop. |
| 8 | + |
| 9 | +Installation |
| 10 | +============ |
| 11 | + |
| 12 | +aiosc requires at least Python 3.4. It can be installed using pip:: |
| 13 | + |
| 14 | + pip3 install aiosc |
| 15 | + pip3 install --user aiosc |
| 16 | + |
| 17 | +Usage |
| 18 | +===== |
| 19 | + |
| 20 | +To send an OSC message just use ``aiosc.send``: |
| 21 | + |
| 22 | +.. code-block:: python |
| 23 | +
|
| 24 | + import asyncio |
| 25 | + import aiosc |
| 26 | +
|
| 27 | + loop = asyncio.get_event_loop() |
| 28 | + loop.run_until_complete( |
| 29 | + aiosc.send(('127.0.0.1', 9000), '/hello', 'world') |
| 30 | + ) |
| 31 | +
|
| 32 | +To implement an OSC server with ``aiosc`` you should create an UDP endpoint |
| 33 | +using ``aiosc.OSCProtocol`` as the protocol. ``OSCProtocol`` can be subclassed |
| 34 | +or directly constructed with a dictionary mapping OSC address patterns to |
| 35 | +handler methods for incoming messages: |
| 36 | + |
| 37 | +.. code-block:: python |
| 38 | +
|
| 39 | + def protocol_factory(): |
| 40 | + osc = aiosc.OSCProtocol({ |
| 41 | + '//*': lambda addr, path, *args: print(addr, path, args) |
| 42 | + }) |
| 43 | + return osc |
| 44 | +
|
| 45 | + loop = asyncio.get_event_loop() |
| 46 | + coro = loop.create_datagram_endpoint(protocol_factory, local_addr=('127.0.0.1', 9000)) |
| 47 | + transport, protocol = loop.run_until_complete(coro) |
| 48 | +
|
| 49 | + loop.run_forever() |
| 50 | +
|
| 51 | +For more examples, see ``examples/``. |
| 52 | + |
| 53 | +OSC address patterns |
| 54 | +==================== |
| 55 | + |
| 56 | +``aiosc`` dispatches messages to handler methods using glob-style address |
| 57 | +pattern matching as described in the OSC 1.0 specification. The ``//`` operator |
| 58 | +from OSC 1.1 preliminary specification is also supported. |
| 59 | + |
| 60 | +Examples: |
| 61 | + |
| 62 | +* ``/hello/world`` matches ``/hello/world``. |
| 63 | +* ``/hello/*`` matches ``/hello/world`` and ``/hello/sarah``. |
| 64 | +* ``/{hello,goodbye}//world`` matches ``/hello/world`` and ``/goodbye/cruel/world``. |
| 65 | +* ``//*`` matches any address. |
| 66 | + |
| 67 | +Notes |
| 68 | +===== |
| 69 | + |
| 70 | +Bundles are not yet supported. |
| 71 | + |
| 72 | +Contrary to most OSC implementations, OSC data types are picked from the |
| 73 | +preliminary spec documented in Features and Future of Open Sound Control |
| 74 | +version 1.1 for NIME paper. For example, 'I' typetag is decoded to Impulse |
| 75 | +(aka "bang") which is passed around as ``aiosc.Impulse`` singleton. |
| 76 | + |
| 77 | +Suggestions, bug reports, issues and/or pull requests are, of course, welcome. |
| 78 | + |
| 79 | +License |
| 80 | +======= |
| 81 | + |
| 82 | +Copyright (c) 2014 Artem Popov <artfwo@gmail.com> |
| 83 | + |
| 84 | +aiosc is licensed under the MIT license, please see LICENSE file for details. |
0 commit comments