pub fn measure_slices(
tree: &TimespanTree<'_>,
start: FloatType,
end: FloatType,
time_points: Option<&[FloatType]>,
) -> Vec<MeasureSlice>Expand description
The stretch of tree from start to end cut wherever a timespan
starts or stops, each slice with where it starts from start, how
long it lasts, and what sounds there: music21’s measureSlices.
time_points hands over the tree’s all_time_points where many
measures are cut from one tree.
use music21::analysis::reduce_chords::measure_slices;
use music21::tinynotation::from_tiny_notation;
use music21::tree::{Flatten, as_timespans};
let line = from_tiny_notation("4/4 c2 e4 g")?;
let tree = as_timespans(&line, Flatten::Flat, None);
let slices = measure_slices(&tree, 1.0, 4.0, None);
let cuts: Vec<(f64, f64)> = slices
.iter()
.map(|slice| (slice.offset, slice.quarter_length))
.collect();
assert_eq!(cuts, [(0.0, 1.0), (1.0, 1.0), (2.0, 1.0)]);
assert_eq!(slices[1].pitches[0].name_with_octave(), "E4");