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_rs::{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", "E-", "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", "E-", "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.

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

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.

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

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, so the scale closes on B# rather than C. Taking it from the realized pitches would read the answer off already-simplified output and lose that.

music21’s own behaviour for a cycle wider than an octave is erratic — ["P5", "P5"] returns pitches an octave above the tonic it was given, and it mutates the caller’s interval list in place. Neither is reproduced here: the cycle is closed at the octave above the last pitch and the input is left alone.

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-, and the major-scale sieve gives a major scale.

music21’s SieveScale also takes an eld (elementary displacement) to scale the widths for non-semitone steps. Only the default of one semitone is supported here, since the crate has no microtonal step type to widen to.

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 pitches(&self) -> Result<Vec<Pitch>>

Returns the pitches of one pass through the cycle, starting at the tonic.

Trait Implementations§

Source§

impl Clone for StepScale

Source§

fn clone(&self) -> StepScale

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.