pub struct Expander { /* private fields */ }Expand description
music21’s repeat.Expander: a part’s repeats read once, to be played
out whole – which is Stream::expand_repeats – or a step at a time.
The steps work on a stream of measures given them and hand back a new one; where music21 strips the repeat barline off a measure of the stream it was given, the crate leaves that stream as it was.
use music21::bar::{Barline, RepeatDirection};
use music21::repeat::Expander;
use music21::{Duration, Note, Stream, StreamKind};
let mut part = Stream::with_kind(StreamKind::Part);
for number in 1..=3 {
let mut measure = Stream::with_kind(StreamKind::Measure);
measure.set_number(number);
measure.push(Note::from_name("C4")?.with_duration(Duration::whole()));
if number == 2 {
measure.set_left_barline(Some(Barline::repeat(RepeatDirection::Start, None)));
measure.set_right_barline(Some(Barline::repeat(RepeatDirection::End, Some(3))));
}
part.insert(f64::from(number - 1) * 4.0, measure);
}
let expander = Expander::new(&part)?;
assert!(expander.repeat_bars_are_coherent()?);
assert_eq!(expander.measure_map()?, [0, 1, 1, 1, 2]);
assert_eq!(expander.measure_map_numbers()?, ["1", "2", "2a", "2b", "3"]);Implementations§
Source§impl Expander
impl Expander
Sourcepub fn new(part: &Stream) -> Result<Self>
pub fn new(part: &Stream) -> Result<Self>
The repeats of part’s measures, read: music21’s Expander(part),
which is refused where the part has no measures.
Sourcepub fn measure_map(&self) -> Result<Vec<usize>>
pub fn measure_map(&self) -> Result<Vec<usize>>
For each measure played, which measure of the part it plays, by its
place among them: music21’s measureMap.
A measure is found by its number and suffix, and by its number alone where no measure of the part has both, as music21 finds it; one renumbered after a jump past the part’s last number has neither, and is refused.
Sourcepub fn measure_map_numbers(&self) -> Result<Vec<String>>
pub fn measure_map_numbers(&self) -> Result<Vec<String>>
The number and suffix of each measure played: music21’s
measureMap(returnType='measureNumber').
Sourcepub fn find_innermost_repeat_indices(measures: &Stream) -> Vec<usize>
pub fn find_innermost_repeat_indices(measures: &Stream) -> Vec<usize>
The places among measures’ measures of the first passage closed
by a repeat barline, from the last start before it, or from the
first measure where there is none: music21’s
findInnermostRepeatIndices. Empty where no repeat closes.
Sourcepub fn process_innermost_repeat_bars(
measures: &Stream,
repeat_indices: Option<&[usize]>,
repeat_times: Option<u32>,
expansion_only: bool,
) -> Result<Stream>
pub fn process_innermost_repeat_bars( measures: &Stream, repeat_indices: Option<&[usize]>, repeat_times: Option<u32>, expansion_only: bool, ) -> Result<Stream>
measures with its innermost repeated passage played out, every
other measure kept as it stands: music21’s
processInnermostRepeatBars. Called again on what it gives, it
plays out the next passage.
repeat_indices plays out exactly those measures instead, and
repeat_times plays them that many times rather than as often as
the closing barline says; expansion_only hands back the measures
played out and nothing else. The measures are laid end to end in a
stream of measures’ own kind; one played again is numbered with
a, b and on.
Sourcepub fn repeat_expression_index(
measures: &Stream,
kind: RepeatExpressionKind,
) -> Vec<usize>
pub fn repeat_expression_index( measures: &Stream, kind: RepeatExpressionKind, ) -> Vec<usize>
The places among measures’ measures of those holding a mark of
kind, once for each such mark: music21’s getRepeatExpressionIndex
asked for one class of mark. Empty where there is none.
Sourcepub fn is_expandable(&self) -> Result<Option<bool>>
pub fn is_expandable(&self) -> Result<Option<bool>>
Whether the repeats can be played out: music21’s isExpandable,
which is None where there is nothing to play out, and false
where the repeat barlines do not pair up, the endings do not follow
on from each other, or a da capo or dal segno lacks the fine,
coda or segno it names.
Sourcepub fn repeat_bars_are_coherent(&self) -> Result<bool>
pub fn repeat_bars_are_coherent(&self) -> Result<bool>
Whether every repeat barline pairs up with another: music21’s
repeatBarsAreCoherent. An end with no start before it is taken to
go back to the beginning; a right barline marking a start is
refused.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Expander
impl Freeze for Expander
impl RefUnwindSafe for Expander
impl Send for Expander
impl Sync for Expander
impl Unpin for Expander
impl UnsafeUnpin for Expander
impl UnwindSafe for Expander
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more