Skip to main content

pitch_attribute_count

Function pitch_attribute_count 

Source
pub fn pitch_attribute_count<K: PartialEq>(
    stream: &Stream,
    attribute: impl Fn(&Pitch) -> K,
) -> Result<Vec<(K, usize)>>
Expand description

How often each value of some property of a stream’s pitches comes, in the order each value is first met: music21’s pitchAttributeCount, with the property a function of the pitch rather than the name of one.

The pitches are music21’s Stream.pitches: those of every note, chord, chord symbol and pitched member of a percussion chord, through every nested stream, in the order the streams hold them. A key’s pitches are not among them.

use music21_rs::analysis::pitch_analysis::pitch_attribute_count;
use music21_rs::tinynotation::from_tiny_notation;

let line = from_tiny_notation("4/4 c4 d c e")?;
let counts = pitch_attribute_count(&line, |pitch| pitch.name())?;
assert_eq!(counts, [("C".to_string(), 2), ("D".to_string(), 1), ("E".to_string(), 1)]);

§Errors

A chord symbol whose notes cannot be worked out.