Skip to main content

label_beat_depth

Function label_beat_depth 

Source
pub fn label_beat_depth(part: &mut Stream) -> Result<()>
Expand description

Marks each note and rest of a part’s measures with a lyric of a star for every level of the metrical hierarchy starting where it does: music21’s labelBeatDepth. The depths are beat_depths’.

use music21_rs::analysis::metrical::label_beat_depth;
use music21_rs::stream::StreamElement;
use music21_rs::tinynotation::from_tiny_notation;

let mut part = from_tiny_notation("4/4 c8 c c c c c c c")?;
label_beat_depth(&mut part)?;
let stars: Vec<String> = part
    .leaves()
    .into_iter()
    .filter_map(|(_, element)| match element {
        StreamElement::Note(note) => {
            Some(note.lyrics().iter().map(|lyric| lyric.text()).collect())
        }
        _ => None,
    })
    .collect();
assert_eq!(stars, ["****", "*", "**", "*", "***", "*", "**", "*"]);

§Errors

As beat_depths, or a chord symbol to mark, which carries no lyric here.