Skip to main content

Expander

Struct Expander 

Source
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

Source

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.

Source

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.

Source

pub fn measure_map_numbers(&self) -> Result<Vec<String>>

The number and suffix of each measure played: music21’s measureMap(returnType='measureNumber').

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Expander

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expander

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.