Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct Server {
- pub(crate) handle: libaudioverse_sys::LavHandle,
- block_callback: Option<Box<Box<'static + FnMut(f64)>>>,
- impl Server {
- /// Set the callback to be called per block of synthesized audio
- pub fn set_block_callback<F>(&mut self, callback: F) -> Result<()>
- where
- F: 'static + FnMut(f64),
- {
- let cb: Box<Box<'static + FnMut(f64)>> = Box::new(Box::new(callback));
- let cb_ptr = Box::into_raw(cb);
- self.block_callback = Some(unsafe { Box::from_raw(cb_ptr) });
- check(unsafe {
- libaudioverse_sys::Lav_serverSetBlockCallback(
- self.handle,
- Some(callback_handler),
- cb_ptr as *mut _,
- )
- })?;
- Ok(())
- }
- // actual usage:
- let server = ...; // construct a server
- ...
- let environment = ...;
- let source = SourceNode::new(&server, &environment);
- let cb = |_: f64| {
- let (x, y) = ...; // compute the next position of the source, referencing other variables created after server is constructed
- source.position().set(x, y);
- };
- // trying to set this callback leads to lifetime errors
- server.set_block_callback(cb)
Add Comment
Please, Sign In to add comment