-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide helpers to get I/O buffers in OnAudioBuffer handlers #56
base: master
Are you sure you want to change the base?
Changes from 4 commits
e885e27
2696998
69e534e
7f03693
3c3ef1a
c63b539
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
use crate::{decode_user_data, encode_user_data, Hz}; | ||
use reaper_low::raw::audio_hook_register_t; | ||
use reaper_low::raw::{audio_hook_register_t, ReaSample}; | ||
use reaper_low::{firewall, raw}; | ||
|
||
use std::fmt; | ||
use std::fmt::Debug; | ||
use std::os::raw::c_int; | ||
use std::ptr::{null_mut, NonNull}; | ||
use std::slice::{from_raw_parts_mut}; | ||
|
||
/// Consumers need to implement this trait in order to be called back in the real-time audio thread. | ||
/// | ||
|
@@ -58,7 +59,35 @@ impl AudioHookRegister { | |
|
||
/// Returns the current number of output channels. | ||
pub fn output_nch(&self) -> u32 { | ||
unsafe { self.0.as_ref() }.input_nch as u32 | ||
unsafe { self.0.as_ref() }.output_nch as u32 | ||
} | ||
|
||
/// Get access to the underlying samples of an output channel | ||
pub fn output_channel_samples(&self, ch: usize, args: &OnAudioBufferArgs) -> Option<&mut [ReaSample]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing the The final signature in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try it this way and update the PR. |
||
unsafe { | ||
if let Some(get_buffer) = self.0.as_ref().GetBuffer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I know, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, I'll change it. |
||
let ptr = get_buffer(true, ch as i32); | ||
if ptr != null_mut() { | ||
return Some(from_raw_parts_mut(ptr, args.len as usize)); | ||
} | ||
} | ||
} | ||
|
||
None | ||
} | ||
|
||
/// Get access to the underlying samples of an input channel | ||
pub fn input_channel_samples(&self, ch: usize, args: &OnAudioBufferArgs) -> Option<&mut [ReaSample]> { | ||
unsafe { | ||
if let Some(get_buffer) = self.0.as_ref().GetBuffer { | ||
let ptr = get_buffer(false, ch as i32); | ||
if ptr != null_mut() { | ||
return Some(from_raw_parts_mut(ptr, args.len as usize)); | ||
} | ||
} | ||
} | ||
|
||
None | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One goal of the medium-level API is to not change the naming too much. It would be more in line with the other code to have only one method
get_buffer()
and introduce aBufferKind
enum to distinguish between input and output buffer (built analogously to e.g. enumRecordArmMode
inmisc_enums.rs
).Another goal is to use consistent data types. Therefore I would prefer
u32
as channel type instead ofusize
(input_nch()
andoutput_nch()
both returnu32
values).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, will change accordingly.