Skip to main content

ScoreCorrector

Struct ScoreCorrector 

Source
pub struct ScoreCorrector { /* private fields */ }
Expand description

A score being corrected, part by part: music21’s ScoreCorrector.

use music21_rs::omr::correctors::ScoreCorrector;
use music21_rs::tinynotation::from_tiny_notation;
use music21_rs::{Stream, StreamKind};

// The third bar is a quarter short.
let part = from_tiny_notation("4/4 c4 d e f g a b c' d'4 e' f'")?;
let mut score = Stream::with_kind(StreamKind::Score);
score.insert(0.0, part);

let mut corrector = ScoreCorrector::new(score)?;
assert_eq!(corrector.single_parts()[0].incorrect_measures(), [2]);
corrector.run()?;
assert_eq!(corrector.single_parts()[0].hashed_notes()[2], "PPPP");

Implementations§

Source§

impl ScoreCorrector

Source

pub fn new(score: Stream) -> Result<Self>

A corrector for a score: each part’s measures hashed and those not filling the bar of the score’s first time signature flagged.

§Errors

A measure of voices that cannot be chordified.

Source

pub fn score(&self) -> &Stream

The score, as corrected so far.

Source

pub fn into_score(self) -> Stream

The score, as corrected so far, given back.

Source

pub fn single_parts(&self) -> &[SinglePart]

The parts being corrected: music21’s singleParts.

Source

pub fn single_part_mut(&mut self, part: usize) -> &mut SinglePart

One part, to run its horizontal model on its own.

Source

pub fn all_hashes(&self) -> Vec<&[String]>

Every part’s measure rhythms: music21’s getAllHashes.

Source

pub fn all_incorrect_measures(&self) -> Vec<&[usize]>

Every part’s flagged measures: music21’s getAllIncorrectMeasures.

Source

pub fn find_incorrect_measures( &mut self, part: usize, run_fast: bool, ) -> Result<&[usize]>

Flags a part’s measures whose notes do not fill their bar, and gives them back: music21’s getIncorrectMeasureIndices. With run_fast, every bar is that of the first measure’s time signature, or of 4/4 where none is in force; without, each measure’s own.

§Errors

Without run_fast, a measure with no time signature in force, which music21 fails on.

Source

pub fn run_horizontal_correction_model( &mut self, ) -> Vec<Vec<MeasureRelationship>>

Every part’s horizontal model: music21’s runHorizontalCorrectionModel.

Source

pub fn vertical_probability_dist(&mut self) -> Result<&[Vec<FloatType>]>

For each part, the share of its measures whose rhythm is like that of the measure at the same place in each part, as music21 counts likeness: music21’s verticalProbabilityDist. Worked out once and kept.

§Errors

Parts of different lengths, or one with no measures, which music21 fails on.

The measure at the same place in another part most likely to correct a flagged one: of the parts whose measure there is not flagged, the one most likely misread as it by its changes, times how often the two parts’ rhythms are alike, the first of those as likely: music21’s runVerticalSearch.

§Errors

As Self::vertical_probability_dist, or a measure of voices that cannot be chordified.

Source

pub fn run_vertical_correction_model( &mut self, ) -> Result<Vec<Vec<MeasureRelationship>>>

Self::run_vertical_search for every flagged measure of every part: music21’s runVerticalCorrectionModel.

§Errors

As Self::run_vertical_search.

Source

pub fn substitute_measure( &mut self, source_measure: usize, source_part: usize, destination_measure: usize, destination_part: usize, ) -> Result<()>

Puts the contents of one measure in another’s place, the notes keeping the pitches the replaced measure’s notes had, in order, as far as they go: music21’s substituteOneMeasureContentsForAnother.

As music21 does, everything is appended one after another, a measure’s right barline and its voices included: a barline ends up inside the measure, and voices one after another rather than together. Spanners naming the replaced measure’s notes name nothing afterwards. A measure put in its own place is emptied, as music21 empties it before copying from it.

§Errors

A pitch whose accidental cannot be written again from its modifier.

§Panics

A part or measure past the last.

Source

pub fn generate_corrected_score( &mut self, horizontal: &[Vec<MeasureRelationship>], vertical: &[Vec<MeasureRelationship>], ) -> Result<PriorsIntegrationScore>

Corrects each flagged measure both models found a correction for, from the horizontal model’s measure where it is more likely, and from the vertical model’s otherwise, then hashes each part’s measures again: music21’s generateCorrectedScore. Corrections are made in turn, so a measure corrected may correct another after it.

§Errors

A measure of voices that cannot be chordified.

Source

pub fn run(&mut self) -> Result<PriorsIntegrationScore>

Corrects the score by both models: music21’s run and runPriorModel. The score corrected is Self::score.

§Errors

As Self::run_vertical_correction_model.

Trait Implementations§

Source§

impl Clone for ScoreCorrector

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 ScoreCorrector

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.