Skip to main content

EventBatch

Struct EventBatch 

Source
pub struct EventBatch<'a> { /* private fields */ }
Expand description

A batch of events over a specific timeframe in samples.

This is what is produced by the EventBatcher iterator, i.e. the iterator returned by the InputEvents::batch method.

Implementations§

Source§

impl<'a> EventBatch<'a>

Source

pub fn events(&self) -> InputEventsIter<'a> ⓘ

Returns all events in this batch.

Source

pub fn first_sample(&self) -> usize

Returns the index of the first sample in this batch.

This is used to locate the start of the batch when processing a block of samples.

Source

pub fn next_batch_first_sample(&self) -> Option<usize>

Returns the index of the first sample in the next batch.

This is used to locate the end of the batch when processing a block of samples.

If there is no next batch (i.e. if this is the last batch), then this returns None, indicating that this batch extends to the end of the sample block that is being processed.

Source

pub fn sample_bounds(&self) -> (Bound<usize>, Bound<usize>)

Returns the batch’s bounds as a pair of sample index bounds, which can be directly used for indexing into a slice.

This is equivalent to indexing with:

  • first_sample..next_batch_first_sample if there is a next batch;
  • or first_sample.. if this is the last batch.
§Example
use clack_common::events::io::EventBatch;
let slice: &[f32] = /* ... */
let batch: EventBatch = /* ... */

// Easily get the subslice matching this event batch's bounds.
let subslice = &slice[batch.sample_bounds()];

// Using sample_bounds is equivalent to doing this:
let manual_subslice = match batch.next_batch_first_sample() {
    Some(next_batch_first_sample) => &slice[batch.first_sample()..next_batch_first_sample],
    None => &slice[batch.first_sample()..]
};

assert_eq!(subslice, manual_subslice)

Auto Trait Implementations§

§

impl<'a> !Send for EventBatch<'a>

§

impl<'a> !Sync for EventBatch<'a>

§

impl<'a> Freeze for EventBatch<'a>

§

impl<'a> RefUnwindSafe for EventBatch<'a>

§

impl<'a> Unpin for EventBatch<'a>

§

impl<'a> UnsafeUnpin for EventBatch<'a>

§

impl<'a> UnwindSafe for EventBatch<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.