pub enum Ratio {
Rational {
numerator: UnsignedIntegerType,
denominator: UnsignedIntegerType,
},
Root {
base: UnsignedIntegerType,
numerator: UnsignedIntegerType,
denominator: UnsignedIntegerType,
},
}Expand description
An exact interval as a tuning table writes one: a ratio of whole numbers, or a root of one.
A root is how an equal division is exact: a step of twelve-tone equal
temperament is 2^(1/12), and one of Bohlen-Pierce 3^(1/13). Neither is
a fraction, which is why this is not a FractionType; a rational one
converts to that with Ratio::to_fraction, and to a Monzo with
Ratio::monzo.
Variants§
Rational
numerator / denominator.
Fields
numerator: UnsignedIntegerTypeThe number on top.
denominator: UnsignedIntegerTypeThe number below.
Root
base^(numerator / denominator).
Fields
base: UnsignedIntegerTypeThe number a root is taken of.
numerator: UnsignedIntegerTypeThe power it is raised to.
denominator: UnsignedIntegerTypeWhich root is taken.
Implementations§
Source§impl Ratio
impl Ratio
Sourcepub const fn new(
numerator: UnsignedIntegerType,
denominator: UnsignedIntegerType,
) -> Self
pub const fn new( numerator: UnsignedIntegerType, denominator: UnsignedIntegerType, ) -> Self
numerator / denominator.
Sourcepub const fn root(
base: UnsignedIntegerType,
numerator: UnsignedIntegerType,
denominator: UnsignedIntegerType,
) -> Self
pub const fn root( base: UnsignedIntegerType, numerator: UnsignedIntegerType, denominator: UnsignedIntegerType, ) -> Self
base^(numerator / denominator).
Sourcepub fn to_fraction(self) -> Option<FractionType>
pub fn to_fraction(self) -> Option<FractionType>
The ratio as a FractionType: None for a root, and for a ratio
too wide for one.
Sourcepub fn monzo(self) -> Result<Monzo>
pub fn monzo(self) -> Result<Monzo>
The ratio’s prime exponents. Errors on a root, whose exponents are not
whole, and on a ratio with a prime past the ones Monzo carries.
Sourcepub fn with_octaves(self, octaves: UnsignedIntegerType) -> Self
pub fn with_octaves(self, octaves: UnsignedIntegerType) -> Self
The interval raised by octaves periods: octaves for a ratio, and
whole powers of its base for a root.
Trait Implementations§
impl Copy for Ratio
Source§impl<'de> Deserialize<'de> for Ratio
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Ratio
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>,
impl Eq for Ratio
impl StructuralPartialEq for Ratio
Auto Trait Implementations§
impl Freeze for Ratio
impl RefUnwindSafe for Ratio
impl Send for Ratio
impl Sync for Ratio
impl Unpin for Ratio
impl UnsafeUnpin for Ratio
impl UnwindSafe for Ratio
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