Skip to main content

pitch_to_dynamic

Function pitch_to_dynamic 

Source
pub fn pitch_to_dynamic(stream: &Stream) -> Result<Vec<(FloatType, usize)>>
Expand description

Each pitch of each note and chord of a stream flattened, with each dynamic it sounds under – the dynamic’s place in SHORT_NAMES, from pppppp at nought to ffffff – one pair for each: music21’s ActivityMatch.pitchToDynamic. A dynamic holds from its offset to the next dynamic’s, the last to the end of the stream, and a note starting just where one dynamic ends and the next begins sounds under both. music21 reads where a dynamic ends as its offset plus its length in Python’s arithmetic, which rounds a sum of an offset in quarters and a length in thirds, so a note on a third of a beat can fall just after the end and sound under the next dynamic alone; this reads them so too.

§Errors

A stream with no notes or chords, or no dynamics, or a dynamic not one of SHORT_NAMES, such as sfz, which music21 cannot place either.