Skip to main content

Scale

Struct Scale 

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

A named scale realized from a tonic pitch.

use music21_rs::{Pitch, Scale, ScaleType};

let scale = Scale::new(ScaleType::Octatonic, Pitch::from_name("C4")?);
let names: Vec<String> = scale.pitches()?.iter().map(|p| p.name()).collect();

assert_eq!(names, ["C", "D", "E-", "F", "G-", "A-", "A", "B", "C"]);

Implementations§

Source§

impl Scale

Source

pub fn roman_numeral(&self, degree: u8) -> Result<RomanNumeral>

The roman numeral on a degree of this scale: music21’s romanNumeral, the triad that degree carries read against the major key of the tonic, whatever its case would say.

Source

pub fn tune(&self, stream: &mut Stream) -> Result<()>

Moves every note and chord of a stream onto this scale: music21’s tune. A pitch whose name, or any enharmonic of it within two accidentals, is a name of the scale’s octave from the tonic becomes that scale pitch in its own octave, spelled as it was where the scale pitch has such a spelling; a pitch the scale has no name for is left alone. Nested streams are tuned too.

Source

pub fn scala_data(&self) -> Result<ScalaScale>

This scale written as a Scala file writes one: music21’s getScalaData, each degree as the cents above the tonic, with the interval the scale closes on as the period.

Source

pub fn new(scale_type: ScaleType, tonic: Pitch) -> Self

Builds a scale of the given type on a tonic.

Source

pub fn from_pitches(pitches: &[Pitch]) -> Result<Self>

A scale given by the notes of one octave of it rather than by a name: music21’s ConcreteScale(pitches=[...]).

The first pitch is the tonic, the steps are the intervals between neighbours, and the scale closes back on the octave, so the notes repeat an octave higher as any scale’s do.

Source

pub fn descending(&self) -> Scale

This scale as it sounds coming down, which for most is itself.

Source

pub fn pitches_descending(&self) -> Result<Vec<Pitch>>

The scale coming down: highest note first, through the collection it uses descending.

Source

pub fn pitches_between_descending( &self, minimum: &Pitch, maximum: &Pitch, ) -> Result<Vec<Pitch>>

A range of the scale coming down, highest note first.

Source

pub fn is_custom(&self) -> bool

Whether this scale was given by its notes rather than by a name.

Source

pub fn set_tonic(&mut self, tonic: Pitch)

Moves the scale to a new tonic, keeping its pattern of steps.

Source

pub fn derive_ranked_by( &self, pitches: &[Pitch], limit: Option<usize>, comparison: DegreeComparison, ) -> Result<Vec<(usize, Scale)>>

The scales of this pattern that contain the most of pitches, best first: music21’s deriveRanked on the scale rather than on the type, which is what a scale given by its notes has to use.

Source

pub fn degree_count(&self) -> usize

Returns the number of distinct degrees: music21’s getDegreeMaxUnique, seven for a major scale and twelve for the chromatic.

Source

pub fn scale_type(&self) -> ScaleType

Returns the scale type.

Source

pub fn tonic(&self) -> &Pitch

Returns the tonic pitch.

Source

pub fn pitches(&self) -> Result<Vec<Pitch>>

Returns the pitches of one octave, from the tonic through its octave.

The result has degree_count() + 1 entries, since the closing octave is included the way music21’s getPitches includes it.

A tonic with no octave is realized in octave 4, which is what music21 does: the scale on a bare G runs G4 A4 B-4 C5 …. The tonic itself keeps its own spelling — Scale::tonic still has no octave — because the octave belongs to the realization and not to the scale.

Source

pub fn realized_tonic(&self) -> Pitch

The tonic as the scale sounds it: music21’s getTonic, which is the tonic in octave 4 when it was given without one.

Source

pub fn relative_major(&self) -> Result<Scale>

The major scale written with the same key signature as this one: music21’s getRelativeMajor.

A mode is written with the signature of the major scale it is a rotation of, so D dorian is C major and E minor is G major. Only the seven-note modes have one.

Source

pub fn relative_minor(&self) -> Result<Scale>

The minor scale written with the same key signature: music21’s getRelativeMinor.

Source

pub fn parallel_major(&self) -> Scale

The major scale on the same tonic: music21’s getParallelMajor.

Source

pub fn parallel_minor(&self) -> Scale

The minor scale on the same tonic: music21’s getParallelMinor.

Source

pub fn named_degrees(&self) -> Option<Vec<IntegerType>>

The degree each of this scale’s notes stands on, in order from the tonic, where those are not simply the notes counted off.

Only a named pattern can say so — a collection given by its notes is counted — and only one of them does: see ScaleType::ascending_degrees.

Source

pub fn pitch_on_degree(&self, degree: IntegerType) -> Result<Option<Pitch>>

Returns the pitch standing on a one-based scale degree, or nothing where the scale has no such degree.

Degree 1 is the tonic. Every other degree is read within the one octave the scale is realized in, so the eighth degree is the tonic again and not the octave above it, and the zeroth and the negative degrees count back round from the top. That is music21’s pitchFromDegree, which asks its interval network for the node the degree names and gets one of the nodes it has.

A scale that names its degrees has only the ones it names: Rag Asawari’s ascent has no third, and answers nothing when asked for one rather than handing back the note that would be third in line.

Source

pub fn pitch_at_degree(&self, degree: IntegerType) -> Result<Pitch>

The pitch standing on a one-based scale degree, which the scale is expected to have: Self::pitch_on_degree is the one that says when it does not.

Source

pub fn pitches_between( &self, minimum: &Pitch, maximum: &Pitch, ) -> Result<Vec<Pitch>>

Returns every pitch of the scale from minimum up to maximum, inclusive: music21’s getPitches given a range.

The scale is realized from the tonic in whatever octave puts it at or below the bottom of the range, then walked upward, so asking a C major scale for E-5 to G-7 starts at E5 — the first scale pitch that is not below the bottom — and not at a respelled E-5.

Source

pub fn is_realizable(&self) -> bool

Whether the pattern can be walked at all.

A collection given by its notes may rise and fall back to where it began — A4 B4 C4 D4 E4 F4 G4 A4 does — and a pattern that goes nowhere cannot be realized over a range, however many times it is walked. music21 says so as well, out of the network it walks.

Source

pub fn octave_duplicating(&self) -> bool

Whether the pattern repeats at the octave: music21’s octaveDuplicating. Every named scale does, and one given by its notes need not — a collection spanning two octaves before it comes back to its tonic is a pattern two octaves long.

Source

pub fn final_pitch(&self) -> Result<Pitch>

The note the scale comes to rest on, as it sounds: music21’s getTonic, which is the fourth degree of a plagal mode.

Source

pub fn dominant(&self) -> Result<Pitch>

The reciting tone: music21’s getDominant.

Source

pub fn leading_tone(&self) -> Result<Pitch>

The seventh degree raised or lowered to sit a semitone below the final: music21’s getLeadingTone, which in a minor scale is not the seventh degree the scale itself has.

Source

pub fn derive_by_degree(&self, degree: usize, pitch: &Pitch) -> Result<Scale>

Returns the scale of the same type on which pitch is the given degree: music21’s deriveByDegree, so the major scale with E as its fifth is A major. The pitch keeps its spelling; a pitch without an octave is read in octave 4, as music21 reads it, so the new tonic has one.

Source

pub fn transpose(&self, interval: &Interval) -> Result<Scale>

Returns the same scale type on the tonic transposed by interval.

Source

pub fn chord(&self) -> Result<Chord>

Returns one octave of the scale as a chord, tonic through octave: music21’s getChord.

Source

pub fn pitches_from_scale_degrees( &self, degrees: &[usize], ) -> Result<Vec<Pitch>>

Returns the pitches at the given degrees within one octave of the tonic: music21’s pitchesFromScaleDegrees, which realizes tonic through octave once and so silently drops a degree beyond the octave.

Source

pub fn pitches_from_scale_degrees_between( &self, degrees: &[usize], minimum: &Pitch, maximum: &Pitch, ) -> Result<Vec<Pitch>>

Every pitch of the named degrees between two pitches: music21’s pitchesFromScaleDegrees given a range, so the third and seventh of C major from c2 to c6 are D2 G2 D3 G3 D4 G4 D5 G5.

Source

pub fn interval_between_degrees( &self, start: usize, end: usize, ) -> Result<Interval>

Returns the interval from one degree to another, both folded into the first octave the way music21’s pitchFromDegree folds them, so degree 9 of a seven-note scale is degree 2 and the interval from 2 to 9 is a unison.

Source

pub fn is_next( &self, other: &Pitch, origin: &Pitch, steps: usize, ) -> Result<bool>

Returns whether other is the scale pitch steps degrees above origin, compared by name so the octave does not matter: music21’s isNext.

Source

pub fn match_pitches( &self, pitches: &[Pitch], ) -> Result<(Vec<Pitch>, Vec<Pitch>)>

Splits pitches into those whose names the scale contains and those it does not: music21’s match. The matched list carries the scale’s own pitches, realized from the tonic in octave 4 when it has none, and the unmatched list carries the pitches as given.

Source

pub fn match_pitches_by( &self, pitches: &[Pitch], comparison: DegreeComparison, ) -> Result<(Vec<Pitch>, Vec<Pitch>)>

The same, saying how a pitch is matched against a degree.

Both lists hold the pitches as given rather than the scale’s own — music21 hands its targets straight back — except that one with no octave is heard in octave 4, since that is where the scale sounds.

Source

pub fn find_missing(&self, pitches: &[Pitch]) -> Result<Vec<Pitch>>

Returns the scale pitches, tonic through octave, whose pitch classes none of pitches has: music21’s findMissing, so C major against C E G is D4 F4 A4 B4.

Source

pub fn solfeg( &self, pitch: &Pitch, variant: SolfegVariant, chromatic: bool, ) -> Result<String>

Returns the solfège syllable for a pitch, do through ti with the chromatic inflections (di, ra, …): music21’s solfeg. Without chromatic the plain syllable of the degree is returned whatever the accidental. Errors for degrees past seven and alterations past a double sharp or flat.

Source

pub fn degree_of_by( &self, pitch: &Pitch, comparison: DegreeComparison, ) -> Result<Option<usize>>

Returns the one-based degree matching a pitch under the given comparison, or None when the scale does not have it.

Source

pub fn degrees_of_by( &self, pitch: &Pitch, comparison: DegreeComparison, ) -> Result<Vec<usize>>

Every one-based degree the pitch stands on.

A scale may name the same note twice — Rag Marwa’s A is both its fifth degree and its seventh, since the pattern dips before it closes — and music21 chooses between them at random. The choosing is left to the caller; this says what there is to choose from.

Source

pub fn degree_of(&self, pitch: &Pitch) -> Result<Option<usize>>

Returns the one-based degree whose pitch name matches, ignoring octave, or None when the pitch is not in the scale.

Source

pub fn degree_of_pitch_class(&self, pitch: &Pitch) -> Result<Option<usize>>

Returns the one-based degree whose pitch class matches, so F- finds the E of C major.

Source

pub fn next_pitch_above(&self, origin: &Pitch, steps: usize) -> Result<Pitch>

Returns the scale pitch steps degrees above origin. A pitch outside the scale first moves to the nearest scale pitch above it.

Source

pub fn next_pitch_beside( &self, origin: &Pitch, steps: IntegerType, below: bool, ) -> Result<Pitch>

The same, told which side of a pitch outside the scale to start from: music21’s getNeighbor, where naming a side means stepping the whole way from the neighbour on it rather than counting the move onto the scale as one of the steps.

Source

pub fn next_pitch_below(&self, origin: &Pitch, steps: usize) -> Result<Pitch>

Returns the scale pitch steps degrees below origin. A pitch outside the scale first moves to the nearest scale pitch below it.

Source

pub fn degree_and_accidental_of( &self, pitch: &Pitch, ) -> Result<(usize, Option<Accidental>)>

Returns the degree a pitch sits on together with the accidental that separates it from the scale’s own spelling of that degree, so E- in C major is degree three with a flat. Errors when no degree shares the pitch’s letter.

Source

pub fn places_of(&self, origin: &Pitch) -> Result<usize>

How many places in this scale’s realization stand on origin.

A scale may name the same note twice: Rag Marwa’s D- is both the note above its tonic and the one it passes through coming down from the octave, and where the next note is depends on which of them is meant. music21 chooses between them at random — the choosing is the caller’s, and Self::next_pitch_below_from takes it.

Source

pub fn next_pitch_below_from( &self, origin: &Pitch, steps: usize, place: usize, ) -> Result<Pitch>

The note steps below origin, read as the place-th of the places this scale stands that note on. See Self::places_of.

Source

pub fn next_pitch_above_from( &self, origin: &Pitch, steps: usize, place: usize, ) -> Result<Pitch>

The note steps above origin, read the same way.

Trait Implementations§

Source§

impl Clone for Scale

Source§

fn clone(&self) -> Scale

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 Scale

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Scale

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Scale

Source§

fn eq(&self, other: &Scale) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Scale

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Scale

Auto Trait Implementations§

§

impl Freeze for Scale

§

impl RefUnwindSafe for Scale

§

impl Send for Scale

§

impl Sync for Scale

§

impl Unpin for Scale

§

impl UnsafeUnpin for Scale

§

impl UnwindSafe for Scale

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.