pub struct ScalaScale { /* private fields */ }Expand description
A scale parsed from a Scala .scl file.
The stored degrees follow this crate’s convention rather than Scala’s: the
implicit 1/1 unison is made explicit at index 0, and the final entry of
the file — the interval the scale repeats at — is held separately as the
period instead of being a degree. So a 12-note file yields
12 degrees plus a period, and degrees()[0] is always 1/1.
Implementations§
Source§impl ScalaScale
impl ScalaScale
Sourcepub fn parse(contents: &str) -> Result<Self>
pub fn parse(contents: &str) -> Result<Self>
Parses the contents of a .scl file.
Both ratio and cents degrees are accepted. Lines beginning with ! are
comments; the first non-comment line is the description, the second is
the degree count, and the rest are degrees.
Sourcepub fn parse_bytes(bytes: &[u8]) -> Result<Self>
pub fn parse_bytes(bytes: &[u8]) -> Result<Self>
Parses the raw bytes of a .scl file.
The Scala format is defined as latin-1 (ISO-8859-1), which music21’s
scale.scala module states explicitly, and 73 of the ~3900 files it
ships are not valid UTF-8. Bytes are therefore decoded as latin-1 rather
than as UTF-8, so accented characters in description lines survive
instead of becoming replacement characters. Degree lines are ASCII in
either reading, so numbers are unaffected.
This crate does no file IO of its own, so read the file yourself:
use music21_rs::ScalaScale;
let bytes = std::fs::read("partch_43.scl")?;
let scale = ScalaScale::parse_bytes(&bytes)?;Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Returns the scale’s description line.
Sourcepub fn degrees(&self) -> &[ScalaDegree]
pub fn degrees(&self) -> &[ScalaDegree]
Returns the degrees of one period, starting with 1/1.
Sourcepub fn period(&self) -> ScalaDegree
pub fn period(&self) -> ScalaDegree
Returns the interval the scale repeats at.
This is usually an octave, but need not be — Bohlen-Pierce repeats at
3/1, and non-octave scales are common in the Scala archive.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the scale has no degrees.
A Scala file may declare zero degrees — the archive’s xxx.scl does,
and music21 reads it as a scale with no pitches.
Sourcepub fn ratio_at(&self, index: IntegerType) -> FloatType
pub fn ratio_at(&self, index: IntegerType) -> FloatType
Returns the frequency ratio above the root for a degree index.
Indices outside one period wrap, shifting by the period for each wrap. Negative indices run below the root.
A scale with no degrees has nothing to wrap through, so every index
returns the root ratio of 1.0.
Sourcepub fn cents_above_root(&self, index: IntegerType) -> FloatType
pub fn cents_above_root(&self, index: IntegerType) -> FloatType
Returns the cents above the root for a degree index.
Note this is absolute distance from the scale root, unlike
TuningSystem::cents_at, which reports
deviation from equal temperament.
Sourcepub fn frequency_at(&self, root_hz: FloatType, index: IntegerType) -> FloatType
pub fn frequency_at(&self, root_hz: FloatType, index: IntegerType) -> FloatType
Returns the frequency in hertz for a degree index, given a root pitch.
A Scala scale fixes no absolute pitch, so the root is supplied by the caller.
Trait Implementations§
Source§impl Clone for ScalaScale
impl Clone for ScalaScale
Source§fn clone(&self) -> ScalaScale
fn clone(&self) -> ScalaScale
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScalaScale
impl Debug for ScalaScale
Source§impl Display for ScalaScale
impl Display for ScalaScale
Source§impl FromStr for ScalaScale
impl FromStr for ScalaScale
Source§impl PartialEq for ScalaScale
impl PartialEq for ScalaScale
Source§fn eq(&self, other: &ScalaScale) -> bool
fn eq(&self, other: &ScalaScale) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ScalaScale
Auto Trait Implementations§
impl Freeze for ScalaScale
impl RefUnwindSafe for ScalaScale
impl Send for ScalaScale
impl Sync for ScalaScale
impl Unpin for ScalaScale
impl UnsafeUnpin for ScalaScale
impl UnwindSafe for ScalaScale
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