Rust bindings - median
Still a work in progress so, use at your own risk, but here is some Rust code that exposes the max-sdk as a rust -sys library and also adds some higher level constructs for creating externals and interacting with the sdk.
https://github.com/Cycling74/median/tree/develop/median
Here is a very basic code example, implementing a Max external.
use median::{
atom::Atom, builder::MaxWrappedBuilder, max_sys::t_atom_long, object::MaxObj, post,
symbol::SymbolRef, wrapper::*,
};
median::external! {
pub struct Example;
impl MaxObjWrapped<Example> for Example {
fn new(builder: &mut dyn MaxWrappedBuilder<Self>) -> Self {
let _ = builder.add_inlet(median::inlet::MaxInlet::Proxy);
Self
}
}
impl Example {
#[bang]
pub fn bang(&self) {
let i = median::inlet::Proxy::get_inlet(self.max_obj());
median::object_post!(self.max_obj(), "bang from inlet {}", i);
}
#[int]
pub fn int(&self, v: t_atom_long) {
let i = median::inlet::Proxy::get_inlet(self.max_obj());
post!("int {} from inlet {}", v, i);
}
#[list]
pub fn list(&self, atoms: &[Atom]) {
post!("got list with length {}", atoms.len());
}
#[any]
pub fn baz(&self, sel: &SymbolRef, atoms: &[Atom]) {
post!("got any with sel {} and length {}", sel, atoms.len());
}
}
}
Amazing, thanks! I was just wondering yesterday if anyone had tried this.