Rename Buffer::with_raw_vec to set_slices
This commit is contained in:
parent
11d9476a5f
commit
19be530ba3
6 changed files with 24 additions and 24 deletions
|
@ -117,7 +117,7 @@ impl<'a> Buffer<'a> {
|
|||
/// The stored slices must point to live data when this object is passed to the plugins' process
|
||||
/// function. The rest of this object also assumes all channel lengths are equal. Panics will
|
||||
/// likely occur if this is not the case.
|
||||
pub unsafe fn with_raw_vec(&mut self, update: impl FnOnce(&mut Vec<&'a mut [f32]>)) {
|
||||
pub unsafe fn set_slices(&mut self, update: impl FnOnce(&mut Vec<&'a mut [f32]>)) {
|
||||
update(&mut self.output_slices);
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ mod miri {
|
|||
let mut real_buffers = vec![vec![0.0; 512]; 2];
|
||||
let mut buffer = Buffer::default();
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
let (first_channel, other_channels) = real_buffers.split_at_mut(1);
|
||||
*output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
|
||||
})
|
||||
|
@ -159,7 +159,7 @@ mod miri {
|
|||
let mut real_buffers = vec![vec![0.0; 512]; 2];
|
||||
let mut buffer = Buffer::default();
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
let (first_channel, other_channels) = real_buffers.split_at_mut(1);
|
||||
*output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
|
||||
})
|
||||
|
|
|
@ -1788,7 +1788,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
wrapper
|
||||
.output_buffer
|
||||
.borrow_mut()
|
||||
.with_raw_vec(|output_slices| {
|
||||
.set_slices(|output_slices| {
|
||||
output_slices.resize_with(bus_config.num_output_channels as usize, || &mut [])
|
||||
});
|
||||
|
||||
|
@ -1812,7 +1812,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
Buffer::default,
|
||||
);
|
||||
for buffer in aux_input_buffers.iter_mut() {
|
||||
buffer.with_raw_vec(|channel_slices| {
|
||||
buffer.set_slices(|channel_slices| {
|
||||
channel_slices
|
||||
.resize_with(bus_config.aux_input_busses.num_channels as usize, || {
|
||||
&mut []
|
||||
|
@ -1827,7 +1827,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
Buffer::default,
|
||||
);
|
||||
for buffer in aux_output_buffers.iter_mut() {
|
||||
buffer.with_raw_vec(|channel_slices| {
|
||||
buffer.set_slices(|channel_slices| {
|
||||
channel_slices
|
||||
.resize_with(bus_config.aux_output_busses.num_channels as usize, || {
|
||||
&mut []
|
||||
|
@ -1989,7 +1989,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
// flags?
|
||||
let mut output_buffer = wrapper.output_buffer.borrow_mut();
|
||||
let mut buffer_is_valid = false;
|
||||
output_buffer.with_raw_vec(|output_slices| {
|
||||
output_buffer.set_slices(|output_slices| {
|
||||
// Buffers for zero-channel plugins like note effects should always be allowed
|
||||
buffer_is_valid = output_slices.is_empty();
|
||||
|
||||
|
@ -2095,7 +2095,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
|
||||
// If the host passes weird data then we need to be very sure that there are
|
||||
// no dangling references to previous data
|
||||
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut []));
|
||||
buffer.set_slices(|slices| slices.fill_with(|| &mut []));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2113,7 +2113,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
));
|
||||
}
|
||||
|
||||
buffer.with_raw_vec(|slices| {
|
||||
buffer.set_slices(|slices| {
|
||||
for (channel_slice, channel_storage) in
|
||||
slices.iter_mut().zip(storage.iter_mut())
|
||||
{
|
||||
|
@ -2148,12 +2148,12 @@ impl<P: ClapPlugin> Wrapper<P> {
|
|||
|
||||
// If the host passes weird data then we need to be very sure that there are
|
||||
// no dangling references to previous data
|
||||
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut []));
|
||||
buffer.set_slices(|slices| slices.fill_with(|| &mut []));
|
||||
continue;
|
||||
}
|
||||
|
||||
let block_len = block_end - block_start;
|
||||
buffer.with_raw_vec(|slices| {
|
||||
buffer.set_slices(|slices| {
|
||||
for (channel_idx, channel_slice) in slices.iter_mut().enumerate() {
|
||||
*channel_slice = std::slice::from_raw_parts_mut(
|
||||
(*(*host_output).data32.add(channel_idx)).add(block_start)
|
||||
|
|
|
@ -325,7 +325,7 @@ impl Cpal {
|
|||
];
|
||||
let mut buffer = Buffer::default();
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
// Pre-allocate enough storage, the pointers are set in the data callback because
|
||||
// `channels` will have been moved between now and the next callback
|
||||
output_slices.resize_with(channels.len(), || &mut []);
|
||||
|
@ -344,7 +344,7 @@ impl Cpal {
|
|||
// Things may have been moved in between callbacks, so these pointers need to be set up
|
||||
// again on each invocation
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
for (output_slice, channel) in output_slices.iter_mut().zip(channels.iter_mut())
|
||||
{
|
||||
// SAFETY: `channels` is no longer used directly after this, and it outlives
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Backend for Dummy {
|
|||
];
|
||||
let mut buffer = Buffer::default();
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
// SAFETY: `channels` is no longer used directly after this
|
||||
*output_slices = channels
|
||||
.iter_mut()
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Backend for Jack {
|
|||
|
||||
let mut buffer = Buffer::default();
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
output_slices.resize_with(self.outputs.lock().len(), || &mut []);
|
||||
})
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ impl Backend for Jack {
|
|||
|
||||
// And the buffer's slices need to point to the JACK output ports
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
buffer.set_slices(|output_slices| {
|
||||
for (output_slice, output) in output_slices.iter_mut().zip(outputs.iter_mut()) {
|
||||
// SAFETY: This buffer is only read from after in this callback, and the
|
||||
// reference passed to `cb` cannot outlive that function call
|
||||
|
|
|
@ -402,7 +402,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
|
|||
self.inner
|
||||
.output_buffer
|
||||
.borrow_mut()
|
||||
.with_raw_vec(|output_slices| {
|
||||
.set_slices(|output_slices| {
|
||||
output_slices
|
||||
.resize_with(bus_config.num_output_channels as usize, || &mut [])
|
||||
});
|
||||
|
@ -429,7 +429,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
|
|||
Buffer::default,
|
||||
);
|
||||
for buffer in aux_input_buffers.iter_mut() {
|
||||
buffer.with_raw_vec(|channel_slices| {
|
||||
buffer.set_slices(|channel_slices| {
|
||||
channel_slices.resize_with(
|
||||
bus_config.aux_input_busses.num_channels as usize,
|
||||
|| &mut [],
|
||||
|
@ -444,7 +444,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
|
|||
Buffer::default,
|
||||
);
|
||||
for buffer in aux_output_buffers.iter_mut() {
|
||||
buffer.with_raw_vec(|channel_slices| {
|
||||
buffer.set_slices(|channel_slices| {
|
||||
channel_slices.resize_with(
|
||||
bus_config.aux_output_busses.num_channels as usize,
|
||||
|| &mut [],
|
||||
|
@ -1324,7 +1324,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
|
|||
// we'll skip the process function.
|
||||
let mut output_buffer = self.inner.output_buffer.borrow_mut();
|
||||
let mut buffer_is_valid = false;
|
||||
output_buffer.with_raw_vec(|output_slices| {
|
||||
output_buffer.set_slices(|output_slices| {
|
||||
// Buffers for zero-channel plugins like note effects should always be allowed
|
||||
buffer_is_valid = output_slices.is_empty();
|
||||
|
||||
|
@ -1416,7 +1416,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
|
|||
|
||||
// If the host passes weird data then we need to be very sure that there are
|
||||
// no dangling references to previous data
|
||||
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut []));
|
||||
buffer.set_slices(|slices| slices.fill_with(|| &mut []));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1435,7 +1435,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
|
|||
));
|
||||
}
|
||||
|
||||
buffer.with_raw_vec(|slices| {
|
||||
buffer.set_slices(|slices| {
|
||||
for (channel_slice, channel_storage) in
|
||||
slices.iter_mut().zip(storage.iter_mut())
|
||||
{
|
||||
|
@ -1470,12 +1470,12 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
|
|||
|
||||
// If the host passes weird data then we need to be very sure that there are
|
||||
// no dangling references to previous data
|
||||
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut []));
|
||||
buffer.set_slices(|slices| slices.fill_with(|| &mut []));
|
||||
continue;
|
||||
}
|
||||
|
||||
let block_len = block_end - block_start;
|
||||
buffer.with_raw_vec(|slices| {
|
||||
buffer.set_slices(|slices| {
|
||||
for (channel_idx, channel_slice) in slices.iter_mut().enumerate() {
|
||||
*channel_slice = std::slice::from_raw_parts_mut(
|
||||
(*(*host_output).buffers.add(channel_idx)).add(block_start)
|
||||
|
|
Loading…
Add table
Reference in a new issue