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 new( description: impl Into<String>, degrees: Vec<ScalaDegree>, period: ScalaDegree, ) -> Self

A scale from its parts: a description, the degrees with the unison at index 0, and the interval it repeats at.

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 written_cents(&self) -> Vec<FloatType> ⓘ

The cents of every degree the file writes: music21’s getCentsAboveTonic.

The unison is left out and the period is the last of them, which is how a .scl file writes a scale — twelve lines for a twelve-tone scale, the last of them the octave. cents_above_root is the other reading, the cents of an index counted from the root.

Source

pub fn written_degrees(&self) -> Vec<ScalaDegree>

The degrees a .scl file writes for this scale: every degree above the unison, and the period last. A scale with no degrees writes none.

Source

pub fn adjacent_cents(&self) -> Vec<FloatType> ⓘ

The width of each step in cents: music21’s getAdjacentCents.

One width per degree the file writes, the first being the step off the unison and the last the step that closes the period.

Source

pub fn from_written_cents( description: impl Into<String>, cents: &[FloatType], ) -> Self

A scale from the cents of every degree a file writes, the period last: the reverse of written_cents.

Source

pub fn from_adjacent_cents( description: impl Into<String>, widths: &[FloatType], ) -> Self

A scale from the width of each step, in cents: music21’s setAdjacentCents.

The last width closes the period, so [100.0; 12] is twelve-tone equal temperament.

Source

pub fn interval_sequence(&self) -> Result<Vec<Interval>>

Each step of the scale as an interval: music21’s getIntervalSequence.

A step is measured in cents and an interval counts semitones, which ChromaticInterval counts fractionally — so a step of 137 cents is a second a little over a third of a semitone wide, and says so.

Source

pub fn from_interval_sequence( description: impl Into<String>, steps: &[Interval], ) -> Self

A scale from an interval per step: music21’s setIntervalSequence.

Source

pub fn file_string(&self, file_name: Option<&str>) -> String

The text of a .scl file for this scale: music21’s getFileString.

The name is written as the first comment where one is given, as the archive’s own files write it. A degree that was read as a ratio is written back as that ratio — both spellings are Scala, and only this one reads back as the scale it came from; music21 keeps cents alone and so cannot.

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) -> 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 ScalaScale

Source§

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

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

impl<'de> Deserialize<'de> for ScalaScale

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for ScalaScale

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

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.