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
impl Temperament
Sourcepub fn from_mapping(
periods_per_equave: UnsignedIntegerType,
generator_steps: &[IntegerType],
generator_cents: FloatType,
primes: &[IntegerType],
) -> Result<Self>
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.
Sourcepub fn from_mapping_rows(
periods_per_equave: UnsignedIntegerType,
generator_rows: &[&[IntegerType]],
generator_cents: &[FloatType],
primes: &[IntegerType],
) -> Result<Self>
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.
Sourcepub fn from_published(
periods_per_equave: UnsignedIntegerType,
generator_steps: &[IntegerType],
generator_cents: FloatType,
primes: &[IntegerType],
) -> Result<Self>
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.
Sourcepub fn rank(&self) -> usize
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.
Sourcepub fn primes(&self) -> &[IntegerType] ⓘ
pub fn primes(&self) -> &[IntegerType] ⓘ
The primes the temperament is written over, its subgroup.
Sourcepub fn equave(&self) -> IntegerType
pub fn equave(&self) -> IntegerType
The prime the temperament repeats at — 2 for an octave, 3 for a tritave.
Sourcepub fn equave_cents(&self) -> FloatType
pub fn equave_cents(&self) -> FloatType
How wide the equave is, in cents.
Sourcepub fn repeats_at_the_octave(&self) -> bool
pub fn repeats_at_the_octave(&self) -> bool
Whether the temperament repeats at the octave, as most do.
Sourcepub fn period_map(&self) -> &[IntegerType] ⓘ
pub fn period_map(&self) -> &[IntegerType] ⓘ
How many periods each prime is worth, in the subgroup’s own order.
Sourcepub fn generator_map(&self) -> &[Vec<IntegerType>]
pub fn generator_map(&self) -> &[Vec<IntegerType>]
How many of each generator every prime is worth, one row per generator.
Sourcepub fn periods_per_equave(&self) -> IntegerType
pub fn periods_per_equave(&self) -> IntegerType
How many periods there are to an equave.
Sourcepub fn period_cents(&self) -> FloatType
pub fn period_cents(&self) -> FloatType
The period, in cents.
Sourcepub fn generator_cents(&self) -> &[FloatType] ⓘ
pub fn generator_cents(&self) -> &[FloatType] ⓘ
Each generator’s width, in cents.
Sourcepub fn map(&self, interval: &Monzo) -> Result<Vec<IntegerType>>
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.
Sourcepub fn cents(&self, interval: &Monzo) -> Result<FloatType>
pub fn cents(&self, interval: &Monzo) -> Result<FloatType>
How wide interval comes out once tempered, in cents.
Sourcepub fn error_cents(&self, interval: &Monzo) -> Result<FloatType>
pub fn error_cents(&self, interval: &Monzo) -> Result<FloatType>
How far off just interval sounds here, in cents; positive is sharp.
Sourcepub fn tempers_out(&self, comma: &Monzo) -> bool
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.
Sourcepub fn mos(&self, notes: UnsignedIntegerType) -> Result<MosScale>
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.
Sourcepub fn pattern(&self, notes: UnsignedIntegerType) -> Result<Mos>
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.
Sourcepub fn moments(
&self,
most: UnsignedIntegerType,
) -> Result<Vec<UnsignedIntegerType>>
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.
Sourcepub fn subgroup_name(&self) -> String
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
impl Clone for Temperament
Source§fn clone(&self) -> Temperament
fn clone(&self) -> Temperament
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 Temperament
impl Debug for Temperament
Source§impl<'de> Deserialize<'de> for Temperament
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Temperament
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Temperament
impl Display for Temperament
Source§impl PartialEq for Temperament
impl PartialEq for Temperament
Source§impl Serialize for Temperament
Available on crate feature serde only.
impl Serialize for Temperament
serde only.impl StructuralPartialEq for Temperament
Auto Trait Implementations§
impl Freeze for Temperament
impl RefUnwindSafe for Temperament
impl Send for Temperament
impl Sync for Temperament
impl Unpin for Temperament
impl UnsafeUnpin for Temperament
impl UnwindSafe for Temperament
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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