Using monome with the Rust programming language

As part of a bigger project, I’ve been working on a Rust crate (rust name for libraries) to use Grid and Arc devices via serialosc in the Rust programming language.

It’s now feature complete. It has the following features and characteristics:

  • Enumerating devices, and connecting to multiple devices (of different or the same type) on the same host at the same time
  • Using standard and custom port for serialosc
  • Receiving plug/unplug events
  • All the standard OSC methods, with an API that is a tad higher level sometimes (for example, there is a method to set all the leds on a grid, appropriately converted to map calls if they are not setting intensity and are just on/off)
  • Support for arc and grid of various sizes, tilt sensors, encoder buttons
  • Portable on all OSes (Windows/Linux/Mac, ARM, x86, x86-64 and probably more, but this is what I tested), including the Bela platform, which I’m using for this project
  • it uses asynchronous and event-driven networking primitives on all platforms (using tokio), and lock-free message queues (using crossbeam) for optimum performances in soft or hard real-time environment.
  • A minimal number of dynamic allocations (but I can probably remove the remaining ones)
  • Complete documentation for every little attribute or method of the API
  • A variety of examples for various devices and features (accelerators, device enumeration, arc, grid, etc.)
  • Continuous integration and some unit tests (with and without device, so that it can run on travis containers.

Rust is a system programming language originally created by Mozilla (where I work), however it’s now in the hand of a strong community. It puts emphasis on performance, reliability, and productivity, and can be used for the same type of tasks than you would use C or C++. It’s very well suited for embedded and/or real-time audio work, and can target all operating systems and a lot of SOCs, with the ability to very easily cross-compile to other targets.

A variety of crates to work with audio are available through the package manager, such as very easy access to the low level audio input/output library used by Firefox, which is intended for use in low-latency scenarios, or various bits of DSP, lock-free data structures, and audio encoding and decoding that are essential to quickly build robust applications.

I’ve written a blog post at https://blog.paul.cx/post/monome-rs-1.0/ that has a bit more info about the library, including how to use it and how to contribute.

19 Likes

Super excited about this! I came across this project several months ago and I think I was able to get the gradient example working? I tried setting up a new project with the enumerate.rs example from github and get here:

$ RUST_LOG=debug cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target\debug\enumerate.exe`
[2019-07-14T19:11:33Z DEBUG tokio_reactor] adding I/O source: 0
[2019-07-14T19:11:33Z DEBUG tokio_reactor::background] starting background reactor
[2019-07-14T19:11:33Z DEBUG tokio_reactor::registration] scheduling Write for: 0
[2019-07-14T19:11:33Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:33Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:33Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:34Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:34Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:34Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:34Z DEBUG tokio_reactor] dropping I/O source: 0
Found 1 devices.
Device 0: m1000636: grid (12897). Setting it up:
[2019-07-14T19:11:34Z DEBUG tokio_reactor] adding I/O source: 4194304
[2019-07-14T19:11:34Z DEBUG tokio_reactor::registration] scheduling Write for: 0
[2019-07-14T19:11:34Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-07-14T19:11:34Z DEBUG tokio_reactor::registration] scheduling Read for: 0

and then it hangs. No errors from serialoscd running in the foreground. I’m on Windows 10, the grid is the most recent edition, bought last year. I am able to use monome_sum in Max 7.

Can you share your source code? Or is it one of the example programs that hang?

1 Like

Yes, the enumerate.rs example, though it’s working now! I believe I already had restarted serialoscd and replugged the grid several times, but restarted serialoscd again and this time it ran. I feel like I’ve had this kind of thing happen on Windows with every language I’ve tried (Node, Python, Supercollider) so I suspect it is on the serialosc end? Probably need to go back and digest some Windows setup help threads (or try the prerelease build from the the thread across the way).

1 Like

I was looking to implement this, glad to see someone did it first :slight_smile:

1 Like