Skip to main content

voice_leading_quartet_positions

Function voice_leading_quartet_positions 

Source
pub fn voice_leading_quartet_positions(
    stream: &Stream,
    options: QuartetOptions,
) -> Vec<(FloatType, [usize; 4])>
Expand description

Where the four notes of every quartet iterate_all_voice_leading_quartets finds stand in the stream: each quartet as the offset it is found at and the positions in Stream::leaves of its v1n1, v1n2, v2n1 and v2n2, in that order. This is the walk itself, for a caller that keeps something of its own beside each note and wants that back rather than a copy of the pitch; the offset is what music21’s reverse walks backwards by, since a voice held through has its notes start earlier.

use music21_rs::{voiceleading::{voice_leading_quartet_positions, QuartetOptions}, Note, Stream, StreamKind};

let mut upper = Stream::with_kind(StreamKind::Part);
upper.insert(0.0, Note::from_name("C5")?);
upper.insert(1.0, Note::from_name("D5")?);
let mut lower = Stream::with_kind(StreamKind::Part);
lower.insert(0.0, Note::from_name("C4")?);
lower.insert(1.0, Note::from_name("B3")?);
let mut score = Stream::with_kind(StreamKind::Score);
score.insert(0.0, upper);
score.insert(0.0, lower);
assert_eq!(voice_leading_quartet_positions(&score, QuartetOptions::default()), [(1.0, [0, 1, 2, 3])]);