Skip to main content

ScalaScale

Struct ScalaScale 

Source
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

Source

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.

Source

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)?;
Source

pub fn description(&self) -> &str

Returns the scale’s description line.

Source

pub fn degrees(&self) -> &[ScalaDegree]

Returns the degrees of one period, starting with 1/1.

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of degrees in one period.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ScalaScale

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 ScalaScale

Source§

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

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

impl Display for ScalaScale

Source§

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

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

impl FromStr for ScalaScale

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(contents: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for ScalaScale

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ScalaScale

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.