Skip to main content

WindowedAnalysis

Struct WindowedAnalysis 

Source
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

Source

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.

Source

pub fn minimum_windows(&self) -> &[Stream]

The quarter-note measures every window is made of.

Source

pub fn window_count(&self) -> usize

How many quarter-note measures there are.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WindowedAnalysis

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.