pub fn audio_reg_hardware_hook_add<T>(
        &mut self,
        callback: Box<T>,
    ) -> ReaperFunctionResult<RegistrationHandle<T>>
    where
        T: OnAudioBuffer + 'static,
    {
        // Create thin pointer of callback before making it a trait object (for being able to
        // restore the original callback later).
        let callback_thin_ptr: NonNull<T> = callback.as_ref().into();
        // Create owned audio hook register and make it own the callback (as user data)
        let register = OwnedAudioHookRegister::new(callback);
        // Store it in memory.  Although we keep it here, conceptually it's owned by REAPER, so we
        // should not access it while being registered.
        let reaper_ptr = self.audio_hook_registers.keep(register);
        // Register the low-level audio hook register at REAPER
        unsafe { self.audio_reg_hardware_hook_add_unchecked(reaper_ptr)? };
        // Return a handle which the consumer can use to unregister
        let handle = RegistrationHandle::new(callback_thin_ptr, reaper_ptr.cast());
        Ok(handle)
    }
/// Registers an audio hook register.
///
/// This allows you to get called back in the real-time audio thread before and after REAPER's
/// processing. You should be careful with this because you are entering real-time world.
///
/// This function returns a handle which you can use to unregister the audio hook register at
/// any time via [`audio_reg_hardware_hook_remove()`] (from the main thread).
///
/// # Errors
///
/// Returns an error if the registration failed.
///
/// # Example
///
/// ```no_run
/// # let mut session = reaper_medium::ReaperSession::default();
/// use reaper_medium::{
///     ControlSurface, OnAudioBuffer, OnAudioBufferArgs,
///     Reaper, RealTimeAudioThreadScope, MidiInputDeviceId
/// };
///
/// struct MyOnAudioBuffer {
///     counter: u64,
///     reaper: Reaper<RealTimeAudioThreadScope>,
/// }
///
/// impl OnAudioBuffer for MyOnAudioBuffer {
///     fn call(&mut self, args: OnAudioBufferArgs) {
///         // Mutate some own state (safe because we are the owner)
///         if self.counter % 100 == 0 {
///             println!("Audio hook callback counter: {}\n", self.counter);
///         }
///         self.counter += 1;
///         // Read some MIDI events
///         self.reaper.get_midi_input(MidiInputDeviceId::new(0), |input| -> Option<()> {
///             for event in input?.get_read_buf().enum_items(0) {
///                 println!("Received MIDI event {:?}", event);
///             }
///             Some(())
///         });
///     }
/// }
///
/// session.audio_reg_hardware_hook_add(Box::new(MyOnAudioBuffer {
///     counter: 0,
///     reaper: session.create_real_time_reaper()
/// }));
/// # Ok::<_, Box<dyn std::error::Error>>(())
/// ```
///
/// [`audio_reg_hardware_hook_remove()`]: #method.audio_reg_hardware_hook_remove
Registers an audio hook register.
This allows you to get called back in the real-time audio thread before and after REAPER's
processing. You should be careful with this because you are entering real-time world.

This function returns a handle which you can use to unregister the audio hook register at
any time via [`audio_reg_hardware_hook_remove()`] (from the main thread).
Registers an audio hook register . This allows you to get called back in the real - time audio thread before and after REAPER ' s processing . You should be careful with this because you are entering real - time world . This function returns a handle which you can use to unregister the audio hook register at any time via [ ` audio_reg_hardware_hook_remove () ` ] ( from the main thread ) .
pub fn audio_reg_hardware_hook_add<T>(
        &mut self,
        callback: Box<T>,
    ) -> ReaperFunctionResult<RegistrationHandle<T>>
    where
        T: OnAudioBuffer + 'static,
    {
        // Create thin pointer of callback before making it a trait object (for being able to
        // restore the original callback later).
        let callback_thin_ptr: NonNull<T> = callback.as_ref().into();
        // Create owned audio hook register and make it own the callback (as user data)
        let register = OwnedAudioHookRegister::new(callback);
        // Store it in memory.  Although we keep it here, conceptually it's owned by REAPER, so we
        // should not access it while being registered.
        let reaper_ptr = self.audio_hook_registers.keep(register);
        // Register the low-level audio hook register at REAPER
        unsafe { self.audio_reg_hardware_hook_add_unchecked(reaper_ptr)? };
        // Return a handle which the consumer can use to unregister
        let handle = RegistrationHandle::new(callback_thin_ptr, reaper_ptr.cast());
        Ok(handle)
    }
pub fn audio_reg_hardware_hook_add < T > ( & mut self , callback : Box < T > , ) -> ReaperFunctionResult < RegistrationHandle < T > > where T : OnAudioBuffer + ' static , { // Create thin pointer of callback before making it a trait object (for being able to // restore the original callback later). let callback_thin_ptr : NonNull < T > = callback . as_ref ( ) . into ( ) ; // Create owned audio hook register and make it own the callback (as user data) let register = OwnedAudioHookRegister :: new ( callback ) ; // Store it in memory.  Although we keep it here, conceptually it's owned by REAPER, so we // should not access it while being registered. let reaper_ptr = self . audio_hook_registers . keep ( register ) ; // Register the low-level audio hook register at REAPER unsafe { self . audio_reg_hardware_hook_add_unchecked ( reaper_ptr ) ? } ; // Return a handle which the consumer can use to unregister let handle = RegistrationHandle :: new ( callback_thin_ptr , reaper_ptr . cast ( ) ) ; Ok ( handle ) }
Registers an audio hook register.
Registers an audio hook register .
&mut self
callback
Box<T>
&mut self
callback
Box<T>
errors
Returns an error if the registration failed.
Returns an error if the registration failed .
example
None
let mut session = reaper_medium::reapersession::default();
use reaper_medium::{
ControlSurface, OnAudioBuffer, OnAudioBufferArgs,
Reaper, RealTimeAudioThreadScope, MidiInputDeviceId
}.

struct MyOnAudioBuffer {
counter: u64,
reaper: Reaper,
}

impl OnAudioBuffer for MyOnAudioBuffer {
fn call(&mut self, args: OnAudioBufferArgs) {
Mutate some own state (safe because we are the owner)
if self.counter % 100 == 0 {
println!("Audio hook callback counter: {}\n", self.counter);
}
self.counter += 1;
Read some MIDI events
self.reaper.get_midi_input(MidiInputDeviceId::new(0), |input| -> Option<()> {
for event in input?.get_read_buf().enum_items(0) {
println!("Received MIDI event {:?}", event);
}
Some(())
});
}
}

session.audio_reg_hardware_hook_add(Box::new(MyOnAudioBuffer {
counter: 0,
reaper: session.create_real_time_reaper()
})).
use reaper_medium :: { ControlSurface OnAudioBuffer OnAudioBufferArgs Reaper RealTimeAudioThreadScope MidiInputDeviceId } . struct MyOnAudioBuffer { counter : u64 reaper : Reaper } impl OnAudioBuffer for MyOnAudioBuffer { fn call ( &mut self args : OnAudioBufferArgs ) { Mutate some own state ( safe because we are the owner ) if self . counter % 100 == 0 { println! ( " Audio hook callback counter : {} \ n " self . counter ) ; } self . counter + = 1 ; Read some MIDI events self . reaper . get_midi_input ( MidiInputDeviceId :: new ( 0 ) |input| - > Option< () > { for event in input? . get_read_buf () . enum_items ( 0 ) { println! ( " Received MIDI event { : ? } " event ) ; } Some (( )) } ) ; } } session . audio_reg_hardware_hook_add ( Box :: new ( MyOnAudioBuffer { counter : 0 reaper : session . create_real_time_reaper () } )) .
ok::<_, box<dyn std::error::error>>(())
None