Skip to main content

KeyAnalyzer

Struct KeyAnalyzer 

Source
pub struct KeyAnalyzer<'a> {
    pub window_size: usize,
    pub weight_algorithm: fn(FloatType, IntegerType) -> FloatType,
    /* private fields */
}
Expand description

The keys of a stream’s measures, read one measure at a time and then smoothed by the measures around each: music21’s KeyAnalyzer.

A measure is read as every part’s measure at that place, by the Aarden-Essen profile music21’s analyze('key') uses, and a measure with no notes has no reading. Each reading is then given the readings of the window_size measures either side, each weighed by weight_algorithm at its distance, and the key scoring best is the measure’s.

use music21_rs::analysis::floating_key::KeyAnalyzer;
use music21_rs::tinynotation::from_tiny_notation;

let line = from_tiny_notation("4/4 c4 e g c' c e g c' g b d' g d f# a d'")?;
let analyzer = KeyAnalyzer::new(&line)?;
let keys: Vec<String> = analyzer
    .run()?
    .iter()
    .map(|key| key.tonic_pitch_name_with_case())
    .collect();
assert_eq!(keys, ["C", "C", "G", "G"]);

Fields§

§window_size: usize

How many measures either side of each are taken into account. Four by default; fewer for music that changes key often.

§weight_algorithm: fn(FloatType, IntegerType) -> FloatType

How a neighbour’s reading is weighed at its distance in measures.

Implementations§

Source§

impl<'a> KeyAnalyzer<'a>

Source

pub fn new(stream: &'a Stream) -> Result<Self>

An analyzer of a stream of measures, or of a score whose first part is in measures, which says how many there are.

§Errors

A stream with no measures in it.

Source

pub fn measure_count(&self) -> usize

How many measures are read.

Source

pub fn raw_key_by_measure(&self) -> Vec<Option<Vec<KeyEstimate>>>

Every measure’s reading on its own, nothing for a measure with no notes: music21’s getRawKeyByMeasure.

Source

pub fn interpretation_by_measure( &self, index: usize, ) -> Option<Vec<(String, FloatType)>>

A measure’s reading as each key’s name with case and its coefficient, best first: music21’s getInterpretationByMeasure.

Source

pub fn smooth_interpretation_by_measure(&self) -> Result<Vec<Key>>

The key of every measure that has a reading, smoothed by its neighbours’: music21’s smoothInterpretationByMeasure. A measure with no reading has no key, and is left out. Each measure is smoothed by its neighbours’ own readings, not their smoothed ones.

§Errors

A best reading that names no key.

Source

pub fn run(&self) -> Result<Vec<Key>>

Every measure’s key, smoothed: music21’s run.

§Errors

As KeyAnalyzer::smooth_interpretation_by_measure.

Trait Implementations§

Source§

impl<'a> Clone for KeyAnalyzer<'a>

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<'a> Debug for KeyAnalyzer<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for KeyAnalyzer<'a>

§

impl<'a> RefUnwindSafe for KeyAnalyzer<'a>

§

impl<'a> Send for KeyAnalyzer<'a>

§

impl<'a> Sync for KeyAnalyzer<'a>

§

impl<'a> Unpin for KeyAnalyzer<'a>

§

impl<'a> UnsafeUnpin for KeyAnalyzer<'a>

§

impl<'a> UnwindSafe for KeyAnalyzer<'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> 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.