Rust Audio

How to use LV2 Patch message atoms in rust-lv2

I need my lv2 plugin to receive patch messages from the host. Very similar to the sampler example in the lv2book. Another example is a-fluidsynth of Ardour. Look here for the relevant part in the Ardour source.

I am a little bit stuck with it. I can receive atom messages in my rust-lv2 plugin, but I am a little puzzled how to unwrap the patch messages.

My (simplified) run function as of now looks like this (basically taken from the rust-lv2 book):

fn run(&mut self, ports: &mut Ports, _: &mut ()) {
    let mut offset: usize = 0;

    let control_sequence = ports
        .control
        .read(self.urids.atom.sequence, self.urids.unit.beat).unwrap();

    for (timestamp, message) in control_sequence {
        let timestamp: usize = match timestamp.as_frames() {
            Some(ts) => ts as usize,
            None => continue
        };

        println!("message recieved");

        // now what?
    }
}

I see the “message received” output when the host sends a LV2_PATCH__Set but I can’t seem to retrieve the information out of it.

I tried to set up the URIs for the patch message and have them in my URID collection like


#[uri("http://lv2plug.in/ns/ext/patch#Set")]
pub struct PatchSet;

#[derive(URIDCollection)]
pub struct URIDs {
    atom: AtomURIDCollection,
    patch_set: URID<PatchSet>,
    unit: UnitURIDCollection,
}

But then when I try to read it like

if let Some(_) = message.read(self.urids.patch_set, ()) {
    println!("LV2_PATCH__Set recieved")
}

The compiler says the trait 'lv2::lv2_atom::scalar::ScalarAtom; is not implemented for 'PatchSet'

Now the questions:

  1. Is this already supposed to work, or would I need to add something to rust-lv2 to make it work?
  2. Do I need to implement some trait (like lv2_atom::Atom) for the Patch* struct?
  3. If so, would it make sense to do that in rust-lv2?

I it takes some work on rust-lv2 to archive this, just give me some hints where to start. Then I will try to do it.

I’ve figured out something in the meantime. I’ll put the progject on GitHub soon for further discussion.

Now I put the project on GitHub. See the announcement.

The Atom communication from the host to the plugin now works. The way back is still somwhat troublesome.

@Janonard
This here should IMO go into rust-lv2: https://github.com/johannes-mueller/sonarigo/blob/master/sonarigo-lv2/src/lv2_stuff.rs

Want a PR?