Struct Cents
pub struct Cents(/* private fields */);Expand description
An interval in cents, a hundredth of a semitone: any finite value, sign allowed.
use sound_to_patch::units::Cents;
let detune = Cents::new(-7.0)?;
assert!(Cents::new(f64::INFINITY).is_err());Implementations§
§impl Cents
impl Cents
pub fn to_ratio(self) -> Result<f64, RangeError>
pub fn to_ratio(self) -> Result<f64, RangeError>
Returns the frequency ratio 2^(c / 1200).
use sound_to_patch::units::Cents;
assert_eq!(Cents::new(1200.0)?.to_ratio()?, 2.0);§Errors
Returns a RangeError beyond ±1 200 000 cents, a conservative cap
that keeps the ratio finite and nonzero.
pub fn from_ratio(ratio: f64) -> Result<Cents, RangeError>
pub fn from_ratio(ratio: f64) -> Result<Cents, RangeError>
Converts a frequency ratio: c = 1200 * log2(ratio). The result can
lie beyond the cap of Cents::to_ratio: f64::MAX gives about
1 228 800 cents.
§Errors
Returns a RangeError for a ratio of zero or less, or one that is
not finite.
Trait Implementations§
impl Copy for Cents
§impl<'de> Deserialize<'de> for Cents
impl<'de> Deserialize<'de> for Cents
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Cents, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Cents, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl FromStr for Cents
impl FromStr for Cents
§type Err = ParseUnitError
type Err = ParseUnitError
The associated error which can be returned from parsing.
§impl PartialOrd for Cents
impl PartialOrd for Cents
§impl Serialize for Cents
impl Serialize for Cents
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Spread for Cents
impl StructuralPartialEq for Cents
Auto Trait Implementations§
impl Freeze for Cents
impl RefUnwindSafe for Cents
impl Send for Cents
impl Sync for Cents
impl Unpin for Cents
impl UnsafeUnpin for Cents
impl UnwindSafe for Cents
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> ClampCast for Twhere
T: PartialOrd + Copy + 'static,
impl<T> ClampCast for Twhere
T: PartialOrd + Copy + 'static,
fn clamp_cast<O>(self) -> O
impl<T> CloneAny for 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>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> ⓘ
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 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> ⓘ
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