Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Lifetime of (SysEx)Event #114

Open
Boscop opened this issue Dec 29, 2019 · 0 comments
Open

Lifetime of (SysEx)Event #114

Boscop opened this issue Dec 29, 2019 · 0 comments
Labels

Comments

@Boscop
Copy link
Member

Boscop commented Dec 29, 2019

I was writing a VST for a HW synth to convert CCs to SysEx automation and vice-versa (while letting irrelevant msgs through unchanged).
Due to the lifetime on Event/SysExEvent.payload I couldn't just map incoming msgs to outgoing msgs, but had to push those msgs that should be mapped to SysEx to a separate vec, and then send that one afterwards (so I have two calls to send_buffer.send_events, one for the filtered input events and one for the payloads vec mapped to SysExEvents).
But I want to preserve the ordering between the input and output msgs, i.e. not change the order of the param automation.
So this requires being able to return SysExEvents where the payload's lifetime comes from a vec outside of the mapping closure.
But currently it's not possible, I get:

error: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
note: ...so that closure can access payloads
note: first, the lifetime cannot outlive the lifetime '_ as defined on the body at 336:44...
note: but, the lifetime must be valid for the method call at 336:17...
note: ...so that a type/lifetime parameter is in scope

The lifetime that the incoming events have comes from this:

vst-rs/src/api.rs

Lines 454 to 457 in d7d5b6f

#[allow(clippy::needless_lifetimes)]
pub fn events<'a>(&'a self) -> impl Iterator<Item = ::event::Event<'a>> {
self.events_raw().iter().map(|ptr| unsafe { **ptr }.into())
}

Any thoughts what the best approach would be, to make this kind of use case more convenient?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants