Skip to main content

Temperament

Struct Temperament 

Source
pub struct Temperament { /* private fields */ }
Expand description

A regular temperament: a period, some generators, and a mapping onto primes.

The mapping says how many periods and how many of each generator every prime of the subgroup is worth. Everything else — how wide a ratio comes out, whether a comma vanishes, which scales the generator makes — is read off that.

The number of rows is the temperament’s Temperament::rank: one for the period plus one for each generator. Rank 2 is the common case and the only one where moments of symmetry mean anything, since those come of stacking a single generator.

use music21_rs::tuningsystem::{Monzo, Temperament};

// Porcupine, from its own infobox: three generators to a fourth.
let porcupine = Temperament::from_mapping(1, &[-3, -5], 163.6, &[2, 3, 5])?;
assert!(porcupine.tempers_out(&Monzo::from_ratio(250, 243)?));
assert_eq!(porcupine.pattern(7)?.to_string(), "1L 6s");
assert_eq!(porcupine.rank(), 2);

Implementations§

Source§

impl Temperament

Source

pub fn from_mapping( periods_per_equave: UnsignedIntegerType, generator_steps: &[IntegerType], generator_cents: FloatType, primes: &[IntegerType], ) -> Result<Self>

Builds a rank-2 temperament from the mapping line the literature publishes.

periods_per_equave and generator_steps are the two halves of the wiki’s 1; 1 4 10: one period to the octave, then how many generators each prime after the first is worth. primes is the subgroup, whose first prime is the equave — usually 2, but 3.5.7 repeats at a tritave. A subgroup need not be every prime up to its largest: mavila is written over 2.3.5.11, with no 7 in it.

Source

pub fn from_mapping_rows( periods_per_equave: UnsignedIntegerType, generator_rows: &[&[IntegerType]], generator_cents: &[FloatType], primes: &[IntegerType], ) -> Result<Self>

Builds a temperament of any rank from one mapping row per generator.

Each row says how many of that generator each prime after the equave is worth, so every row is one shorter than the subgroup. Marvel’s two rows over 2.3.5.7.11 are 1 0 2 -1 and 0 1 2 -3, tuned to a fifth and a major third.

The period row is not asked for, because the generators already decide it: whatever they leave over has to be made up in whole periods. Errors when it cannot be — when some prime needs a fraction of a period, which means the generators and the mapping do not go together.

Source

pub fn from_published( periods_per_equave: UnsignedIntegerType, generator_steps: &[IntegerType], generator_cents: FloatType, primes: &[IntegerType], ) -> Result<Self>

Builds a rank-2 temperament from a published mapping, taking the generator either way round.

A generator and its inverse inside the period reach the same notes — a fifth up and a fourth down are the same chain — so a mapping written for one of them and a tuning quoted for the other describe one temperament and only look inconsistent. Sources do mix the two: the Xenharmonic Wiki’s Mabilic and trismegistus gives the mapping 1; -15 -3 5, which wants a generator of 672.8 cents, beside a tuning of 526.7, which wants 1; 15 3 -5.

So this tries the mapping as written, and failing that tries it negated against the inverse generator. Temperament::from_mapping is the strict reading and stays strict; reach for that when the caller knows which way round it meant. The error reported on failure is the one from the mapping as written, since that is what the caller handed over.

Source

pub fn rank(&self) -> usize

How many rows the mapping has: one for the period, one per generator.

Two is the usual case, and the only one where a moment of symmetry means anything.

Source

pub fn primes(&self) -> &[IntegerType]

The primes the temperament is written over, its subgroup.

Source

pub fn equave(&self) -> IntegerType

The prime the temperament repeats at — 2 for an octave, 3 for a tritave.

Source

pub fn equave_cents(&self) -> FloatType

How wide the equave is, in cents.

Source

pub fn repeats_at_the_octave(&self) -> bool

Whether the temperament repeats at the octave, as most do.

Source

pub fn period_map(&self) -> &[IntegerType]

How many periods each prime is worth, in the subgroup’s own order.

Source

pub fn generator_map(&self) -> &[Vec<IntegerType>]

How many of each generator every prime is worth, one row per generator.

Source

pub fn periods_per_equave(&self) -> IntegerType

How many periods there are to an equave.

Source

pub fn period_cents(&self) -> FloatType

The period, in cents.

Source

pub fn generator_cents(&self) -> &[FloatType]

Each generator’s width, in cents.

Source

pub fn map(&self, interval: &Monzo) -> Result<Vec<IntegerType>>

How many periods and how many of each generator interval comes to.

The answer is one number per mapping row, the period’s first. Errors on an interval using a prime outside the subgroup, since the temperament has said nothing about it — reading that as nought steps would be an answer it has not got.

Source

pub fn cents(&self, interval: &Monzo) -> Result<FloatType>

How wide interval comes out once tempered, in cents.

Source

pub fn error_cents(&self, interval: &Monzo) -> Result<FloatType>

How far off just interval sounds here, in cents; positive is sharp.

Source

pub fn tempers_out(&self, comma: &Monzo) -> bool

Whether comma vanishes — no periods and no generators at all.

A comma using a prime the subgroup has not got is not tempered out; the temperament has said nothing about it either way.

Source

pub fn mos(&self, notes: UnsignedIntegerType) -> Result<MosScale>

The scale of notes notes to an equave that this generator makes.

The count is notes per equave, the way the literature counts them.

A temperament with more than one period to the equave repeats its pattern in each, so the scale this returns covers one period and the count has to divide by Temperament::periods_per_equave — augmented has three periods, and its 3L 3s is one large and one small step in each of them. Errors on a count that does not divide, on a rank other than 2, and where MosScale::new does.

Source

pub fn pattern(&self, notes: UnsignedIntegerType) -> Result<Mos>

The step pattern of notes notes to the equave.

This is what a temperament’s published MOS list names. It is the pattern of one period repeated in each, so augmented’s two-note period over three periods is 3L 3s and not 1L 1s.

Source

pub fn moments( &self, most: UnsignedIntegerType, ) -> Result<Vec<UnsignedIntegerType>>

Every note count to the equave, up to most, that makes a moment of symmetry.

This is the temperament’s list of MOS scales, and it starts lower than a published one does: a two- or three-note moment is real but nobody bothers writing it down.

Source

pub fn subgroup_name(&self) -> String

The subgroup written the way the literature writes it, 2.3.5.11.

Trait Implementations§

Source§

impl Clone for Temperament

Source§

fn clone(&self) -> Temperament

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 Temperament

Source§

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

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

impl<'de> Deserialize<'de> for Temperament

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 Temperament

Source§

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

Writes the subgroup, the mapping rows and the generators, as an infobox does.

Source§

impl PartialEq for Temperament

Source§

fn eq(&self, other: &Temperament) -> 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 Temperament

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 Temperament

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.