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>
impl<'a> EventBatch<'a>
Sourcepub fn events(&self) -> InputEventsIter<'a> ⓘ
pub fn events(&self) -> InputEventsIter<'a> ⓘ
Returns all events in this batch.
Sourcepub fn first_sample(&self) -> usize
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.
Sourcepub fn next_batch_first_sample(&self) -> Option<usize>
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.
Sourcepub fn sample_bounds(&self) -> (Bound<usize>, Bound<usize>)
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_sampleif 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)