Skip to main content

Minimal OSC parser and server for CircuitPython and CPython

Project description

Introduction

Documentation Status Discord Build Status Code Style: Black

Minimal OSC parser, server, and client for CircuitPython and CPython

Open Sound Control 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:

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install circuitpython-microosc

To install system-wide (this may be required in some cases):

sudo pip3 install circuitpython-microosc

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .env/bin/activate
pip3 install circuitpython-microosc

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install microosc

Or the following command to update an existing version:

circup update

Usage Example

import time, os, wifi, socketpool
import microosc

UDP_HOST = "224.0.0.1"  # multicast UDP
UDP_PORT = 5000

ssid = os.getenv("CIRCUITPY_WIFI_SSID")
password = os.getenv("CIRCUITPY_WIFI_PASSWORD")

print("connecting to WiFi", ssid)
wifi.radio.connect(ssid, password)

socket_pool = socketpool.SocketPool(wifi.radio)

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("\t\tmsg:", msg.addr, msg.args),  # prints all messages
    "/1/fader": fader_handler,
    "/filter1": fader_handler,
}

osc_server = micro_osc.Server(socket_pool, UDP_HOST, UDP_PORT, dispatch_map)

print("MicroOSC server started on ", UDP_HOST, UDP_PORT)

last_time = time.monotonic()

while True:

    osc_server.poll()

    if time.monotonic() - last_time > 1.0:
        last_time = time.monotonic()
        print(f"waiting {last_time:.2f}")

References

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

circuitpython-microosc-0.3.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

circuitpython_microosc-0.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file circuitpython-microosc-0.3.tar.gz.

File metadata

  • Download URL: circuitpython-microosc-0.3.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for circuitpython-microosc-0.3.tar.gz
Algorithm Hash digest
SHA256 1cdc71f5dff7a9de4030d86ac3b186aa4e9c397fe9ff06876e40a4f826612f3b
MD5 c5479397cb45716a81de96cb4892d43d
BLAKE2b-256 c2f39b6f410eed3c833f894c82cb54ef182a1b0fca2d11362783d274462e76d2

See more details on using hashes here.

File details

Details for the file circuitpython_microosc-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for circuitpython_microosc-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d896bcdf4838a892c2cc9ca54ca1611265b0fcc0d7c2ebbb6285860586ee4409
MD5 76053d78ccdb8c2b42fcb29c52025961
BLAKE2b-256 e912a39dedcf3fecfc2b444226419f949772957f5e5f90ee62fc4bf09b4861d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page