pub struct WindowedAnalysis { /* private fields */ }Expand description
A stream cut into windows of a quarter note each, ready to have an
analysis run over windows of any number of them: music21’s
WindowedAnalysis.
music21 hands each window to an analysis object’s process; here the
analysis is a function of the window, and a window is a stream of the
quarter-note measures it spans, put end to end. A window holding nothing
the analysis can use is the analysis’s to answer for, as an Option or
a Result.
use music21_rs::analysis::{KeyProfile, estimate_key_of_stream};
use music21_rs::analysis::windowed::{WindowType, WindowedAnalysis};
use music21_rs::tinynotation::from_tiny_notation;
let line = from_tiny_notation("4/4 c4 e g c' f a c' f'")?;
let windowed = WindowedAnalysis::new(&line)?;
assert_eq!(windowed.window_count(), 8);
let keys = windowed.analyze(4, WindowType::Overlap, |window| {
estimate_key_of_stream(KeyProfile::KrumhanslSchmuckler, window)
.map(|estimates| estimates[0].key().tonic_pitch_name_with_case())
});
assert_eq!(keys.first(), Some(&Some("C".to_string())));
assert_eq!(keys.last(), Some(&Some("F".to_string())));Implementations§
Source§impl WindowedAnalysis
impl WindowedAnalysis
Sourcepub fn new(stream: &Stream) -> Result<Self>
pub fn new(stream: &Stream) -> Result<Self>
Cuts a stream into measures of one quarter note, a note running past
a barline tied into the next: music21’s getMinimumWindowStream. A
stream holding parts is flattened first, its parts sounding as one.
§Errors
A stream that cannot be put into measures.
Sourcepub fn minimum_windows(&self) -> &[Stream]
pub fn minimum_windows(&self) -> &[Stream]
The quarter-note measures every window is made of.
Sourcepub fn window_count(&self) -> usize
pub fn window_count(&self) -> usize
How many quarter-note measures there are.
Sourcepub fn analyze<T>(
&self,
window_size: usize,
window_type: WindowType,
analysis: impl FnMut(&Stream) -> T,
) -> Vec<T>
pub fn analyze<T>( &self, window_size: usize, window_type: WindowType, analysis: impl FnMut(&Stream) -> T, ) -> Vec<T>
The analysis run over every window of window_size quarters, in
order: music21’s analyze, its answers without the colours.
Sourcepub fn process<T>(
&self,
min_window: Option<usize>,
max_window: Option<usize>,
step: WindowStep,
window_type: WindowType,
include_total_window: bool,
analysis: impl FnMut(&Stream) -> T,
) -> Result<Vec<(usize, Vec<T>)>>
pub fn process<T>( &self, min_window: Option<usize>, max_window: Option<usize>, step: WindowStep, window_type: WindowType, include_total_window: bool, analysis: impl FnMut(&Stream) -> T, ) -> Result<Vec<(usize, Vec<T>)>>
The analysis run over windows of each size from min_window to
max_window quarters, stepping by step, each size with its
answers: music21’s process. A size left out is the whole stream,
and with include_total_window the whole stream is always among
the sizes.
§Errors
Multiplying by less than two, which never grows.
Trait Implementations§
Source§impl Clone for WindowedAnalysis
impl Clone for WindowedAnalysis
Auto Trait Implementations§
impl Freeze for WindowedAnalysis
impl RefUnwindSafe for WindowedAnalysis
impl Send for WindowedAnalysis
impl Sync for WindowedAnalysis
impl Unpin for WindowedAnalysis
impl UnsafeUnpin for WindowedAnalysis
impl UnwindSafe for WindowedAnalysis
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more