Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
todbot committed Aug 20, 2023
1 parent d731cdb commit ef28264
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
27 changes: 27 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ Introduction
Minimal OSC parser and server for CircuitPython and CPython


`Open Sound Control <https://opensoundcontrol.stanford.edu/>`_ is an efficient data transport
encoding/protocol for real-time performance messages for music or other similar endeavors.
The OSC byte encoding is designed to be semi-human readable and efficient enough for
UDP packet transmission.

OSC Messages are defined by an "OSC Address" (e.g. "/1/faderA") and optional "OSC Arguments",
one or more possible of several data types (e.g. float32 or int32). OSC doesn't pre-define
specific OSC Addresses, it is up the the sender and receiver to agree upon them.

This "MicroOSC" library is a minimal UDP receiver ("OSC Server") and parser of OSC packets.
The MicroOSC UDP receiver supports both unicast and multicast UDP on both CircuitPython and CPython.


Requirements
============

To run this library you will need one of:

* CircuitPython board with native ``wifi`` support, like those based on ESP32-S2, ESP32-S3, etc.
* Desktop Python (CPython) computer

To send OSC messages, you will need an OSC UDP sender (aka "OSC client").
Some easy-to-use OSC clients are:

* `TouchOSC <https://hexler.net/touchosc>`_
* `OSCSend for Ableton Live <https://www.ableton.com/en/packs/connection-kit/>`_

Dependencies
=============
This driver depends on:
Expand Down
2 changes: 2 additions & 0 deletions examples/microosc_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
print("connecting to WiFi", ssid)
wifi.radio.connect(ssid, password)


def fader_handler(msg):
"""Used to handle 'fader' OscMsgs, printing it as a '*' text progress bar
:param OscMsg msg: message with one required float32 value
"""
print(msg.addr, "*" * int(20 * msg.args[0])) # make a little bar chart


dispatch_map = {
"/": lambda msg: print("/:", msg.addr, msg.args), # prints all messages
"/1/fader": fader_handler,
Expand Down
11 changes: 7 additions & 4 deletions examples/microosc_simpletest_cpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
UDP_HOST = sys.argv[1]
UDP_PORT = int(sys.argv[2])

last_velocity=0
last_velocity = 0 # pylint: disable=invalid-name


def note_handler(msg):
"""Used to handle 'Note1' and 'Velocity1' OscMsgs from Ableton Live.
Live's "OscSend" plugin sends two OSC Packets for every MIDI note.
This function reconctructs that into a single print().
:param OscMsg msg: message with one required int32 value
"""
global last_velocity
global last_velocity # pylint: disable=global-statement
if msg.addr == "/Note1":
if last_velocity != 0:
print("NOTE ON ", msg.args[0], last_velocity)
Expand All @@ -33,6 +35,7 @@ def note_handler(msg):
elif msg.addr == "/Velocity1":
last_velocity = msg.args[0]


def fader_handler(msg):
"""Used to handle 'fader' OscMsgs, printing it as a '*' text progress bar
:param OscMsg msg: message with one required float32 value
Expand All @@ -44,8 +47,8 @@ def fader_handler(msg):
# matches all messages
"/": lambda msg: print("\t\tmsg:", msg.addr, msg.args),
# maches how Live's OSC MIDI Send plugin works
'/Note1' : note_handler,
'/Velocity1' : note_handler,
"/Note1": note_handler,
"/Velocity1": note_handler,
# /1/fader3 matches how TouchOSC sends faders ,"/1" is screen, "fader3" is 3rd fader
"/1/fader": fader_handler,
"/filter1": fader_handler,
Expand Down

0 comments on commit ef28264

Please sign in to comment.