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
impl StepScale
Sourcepub fn cyclical(tonic: Pitch, steps: &[&str]) -> Result<Self>
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.
Sourcepub fn octave_repeating(tonic: Pitch, steps: &[&str]) -> Result<Self>
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.
Sourcepub fn sieve(tonic: Pitch, expression: &str) -> Result<Self>
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.
Sourcepub fn degree_count(&self) -> usize
pub fn degree_count(&self) -> usize
Returns the number of steps, which is one fewer than the pitch count.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StepScale
impl RefUnwindSafe for StepScale
impl Send for StepScale
impl Sync for StepScale
impl Unpin for StepScale
impl UnsafeUnpin for StepScale
impl UnwindSafe for StepScale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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