Skip to content

Commit

Permalink
replace BufferView trait with IntoBlocks and BlockIterator traits
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Mar 9, 2024
1 parent 66db666 commit 1182220
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 143 deletions.
2 changes: 1 addition & 1 deletion examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Processor for GainProcessor {
fn reset(&mut self) {}

fn process(&mut self, buffers: Buffers, events: Events) {
let buffer = buffers.collect::<BufferMut>().unwrap();
let mut buffer = buffers.collect::<BufferMut>().unwrap();
for (mut buffer, events) in buffer.split_at_events(events) {
for event in events {
match event.data {
Expand Down
30 changes: 26 additions & 4 deletions src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use std::marker::PhantomData;
use std::ops::{Index, IndexMut, Range};
use std::{array, slice};

mod buffer_view;
pub mod collect;
pub mod iter;

pub use buffer_view::{BufferView, Offset};

use crate::events::Events;
use collect::FromBuffers;
use iter::IntoSamples;
use iter::{BlockIterator, IntoBlocks, IntoSamples};

#[derive(Copy, Clone, Eq, PartialEq)]
pub enum BufferType {
Expand Down Expand Up @@ -137,6 +135,14 @@ impl<'a, 'b> Buffers<'a, 'b> {
pub fn samples<'c>(&'c mut self) -> iter::SamplesIter<'a, 'c> {
self.reborrow().into_samples()
}

#[inline]
pub fn split_at_events<'c, 'e>(
&'c mut self,
events: Events<'e>,
) -> iter::SplitAtEvents<'e, iter::BlocksIter<'a, 'c>> {
self.reborrow().into_blocks().split_at_events(events)
}
}

impl<'a, 'b> IntoIterator for Buffers<'a, 'b> {
Expand Down Expand Up @@ -334,6 +340,14 @@ impl<'a, 'b> Buffer<'a, 'b> {
pub fn samples(&self) -> iter::SampleIter<'a, 'b> {
self.into_samples()
}

#[inline]
pub fn split_at_events<'e>(
&self,
events: Events<'e>,
) -> iter::SplitAtEvents<'e, iter::BlockIter<'a, 'b>> {
self.into_blocks().split_at_events(events)
}
}

impl<'a, 'b> Index<usize> for Buffer<'a, 'b> {
Expand Down Expand Up @@ -501,6 +515,14 @@ impl<'a, 'b> BufferMut<'a, 'b> {
pub fn samples<'c>(&'c mut self) -> iter::SampleIterMut<'a, 'c> {
self.reborrow().into_samples()
}

#[inline]
pub fn split_at_events<'c, 'e>(
&'c mut self,
events: Events<'e>,
) -> iter::SplitAtEvents<'e, iter::BlockIterMut<'a, 'c>> {
self.reborrow().into_blocks().split_at_events(events)
}
}

impl<'a, 'b> Index<usize> for BufferMut<'a, 'b> {
Expand Down
113 changes: 0 additions & 113 deletions src/buffers/buffer_view.rs

This file was deleted.

Loading

0 comments on commit 1182220

Please sign in to comment.