Skip to main content

dynamics_in_force

Function dynamics_in_force 

Source
pub fn dynamics_in_force(stream: &Stream) -> Vec<Option<usize>>
Expand description

The dynamic each element of a stream stands under: for every element Stream::leaves lists, the position in that list of the dynamic in force where it stands, or None where no dynamic is.

A dynamic is in force from where it stands until the next, the last until the end of the stream, which is music21’s extendDuration; a note before the first dynamic stands under none, and of two dynamics at one offset the later-listed is the one in force. This is the search realize_volume realizes against, for a caller that keeps something of its own beside each element.

use music21_rs::{volume::dynamics_in_force, Dynamic, Note, Stream};

let mut stream = Stream::new();
stream.insert(0.0, Note::from_name("G3")?);
stream.insert(1.0, Dynamic::new("ff"));
stream.insert(1.0, Note::from_name("G3")?);
assert_eq!(dynamics_in_force(&stream), [None, Some(1), Some(1)]);