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: usizeHow 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) -> FloatTypeHow a neighbour’s reading is weighed at its distance in measures.
Implementations§
Source§impl<'a> KeyAnalyzer<'a>
impl<'a> KeyAnalyzer<'a>
Sourcepub fn new(stream: &'a Stream) -> Result<Self>
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.
Sourcepub fn measure_count(&self) -> usize
pub fn measure_count(&self) -> usize
How many measures are read.
Sourcepub fn raw_key_by_measure(&self) -> Vec<Option<Vec<KeyEstimate>>>
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.
Sourcepub fn interpretation_by_measure(
&self,
index: usize,
) -> Option<Vec<(String, FloatType)>>
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.
Sourcepub fn smooth_interpretation_by_measure(&self) -> Result<Vec<Key>>
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.
Trait Implementations§
Source§impl<'a> Clone for KeyAnalyzer<'a>
impl<'a> Clone for KeyAnalyzer<'a>
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> 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