Skip to main content

StepScale

Struct StepScale 

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

A scale built by walking a cycle of intervals from a tonic.

use music21::{Pitch, StepScale};

let tonic = Pitch::from_name("C4")?;
let cyclical = StepScale::cyclical(tonic.clone(), &["m3", "M3"])?;
let names: Vec<String> = cyclical.pitches()?.iter().map(|p| p.name()).collect();
assert_eq!(names, ["C", "Eb", "G"]);

let repeating = StepScale::octave_repeating(tonic, &["m3", "M3"])?;
let names: Vec<String> = repeating.pitches()?.iter().map(|p| p.name()).collect();
assert_eq!(names, ["C", "Eb", "G", "C"]);

Interval implements neither PartialEq nor Hash, so neither is derived here; compare realized pitches instead.

Implementations§

Source§

impl StepScale

Source

pub fn cyclical(tonic: Pitch, steps: &[&str]) -> Result<Self>

Builds music21’s CyclicalScale: the intervals walked once, no closing.

A cycle of whole semitones adding up to 1, 2, 3, 4, 6 or 12 semitones comes back to its tonic within an octave, and is repeated to fill the octave with its last step spelled to land on the tonic, so it repeats there: ["M3"] is M3 M3 d4, and ["m2"] is twelve steps.

An empty list defaults to a single m2, as music21 does.

Source

pub fn cyclical_of(tonic: Pitch, steps: Vec<Interval>) -> Result<Self>

The same from intervals already in hand, which is the only way to give a step that has no name: one measured in cents.

Source

pub fn octave_repeating(tonic: Pitch, steps: &[&str]) -> Result<Self>

Builds music21’s OctaveRepeatingScale: the intervals plus a closing interval that completes the octave, where they do not reach it already.

An empty list defaults to a single m2, as music21 does.

Steps that come to twelve semitones close on the tonic: the last one is respelled to land on its octave, so M3 M3 M3 is M3 M3 d4. Otherwise the closing interval is the complement of the interval sum, which is how music21 derives it — not the interval between the last realized pitch and the octave. The two differ in spelling whenever realization respells a degree: three m2 steps from C sum to dd4, whose complement is AA5, not the major sixth from the E- the walk reaches. A note the walk reaches on the tonic’s place is spelled as the tonic, so that scale still ends on C.

A cycle wider than an octave is closed at the octave above its last pitch: ["P5", "P5"] is C4 G4 D5 C6.

Source

pub fn octave_repeating_of(tonic: Pitch, steps: Vec<Interval>) -> Result<Self>

The same from intervals already in hand.

Source

pub fn sieve(tonic: Pitch, expression: &str) -> Result<Self>

Builds music21’s SieveScale from a Xenakis sieve expression.

The sieve’s interval widths become the cycle, which music21 then treats as a CyclicalScale — so "3@0" from C is C E- F# A C, and the major-scale sieve gives a major scale.

The widths are counted in semitones; Self::sieve_by counts them in anything else.

Source

pub fn sieve_by(tonic: Pitch, expression: &str, eld: FloatType) -> Result<Self>

The same with the sieve’s unit said: music21’s eld, the elementary displacement, in semitones. A sieve of every integer counted in twos is a whole-tone scale, and counted in halves is a scale of quarter tones.

Source

pub fn tonic(&self) -> &Pitch

Returns the tonic pitch.

Source

pub fn steps(&self) -> &[Interval]

Returns the step intervals, including any closing interval.

Source

pub fn degree_count(&self) -> usize

Returns the number of steps, which is one fewer than the pitch count.

Source

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

The same cycle as a Scale, which is what answers everything a scale is asked past its own notes: a range of them, the degree a note stands on, the note beside another.

Source

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

Returns the pitches of one pass through the cycle, starting at the tonic. Each step is spelled with at most one accidental, as music21’s interval network spells it, and a scale that repeats at the octave ends on its tonic’s name. A tonic with no octave gives pitches with none.

Trait Implementations§

Source§

impl Clone for StepScale

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 StepScale

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.