Skip to main content

Clock

Struct Clock 

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

Named clock with a ClockDomain and a ClockChart, the unit of clock math in this crate.

A clock converts between Instants and ClockIndexes, and mints the kernel Tick / Expr forms that carry a clock index across the runtime.

§Examples

use sim_kernel::Symbol;
use sim_lib_stream_clock::{Clock, ClockChart, ClockIndex};

let clock = Clock::frame(Symbol::new("audio"), 48_000)?;
assert!(matches!(clock.chart(), ClockChart::Frames { frames_per_second: 48_000 }));
let instant = clock.instant_for_index(ClockIndex::new(48_000))?;
assert_eq!(instant.numerator(), 1);
assert_eq!(instant.denominator(), 1);

Implementations§

Source§

impl Clock

Source

pub fn frame(id: Symbol, frames_per_second: u64) -> Result<Self>

Builds a frame clock in the ClockDomain::Sample domain.

Returns an error when frames_per_second is zero.

Source

pub fn frame_with_domain( id: Symbol, domain: ClockDomain, frames_per_second: u64, ) -> Result<Self>

Builds a frame clock in an explicit domain.

Returns an error when domain is ClockDomain::MidiTick (which requires a MIDI chart) or when frames_per_second is zero.

Source

pub fn midi(id: Symbol, tpq: u32, tempo_map: TempoMap) -> Result<Self>

Builds a MIDI clock in the ClockDomain::MidiTick domain.

Returns an error when tpq (ticks per quarter note) is zero.

Source

pub fn id(&self) -> &Symbol

Returns the clock’s identifying symbol.

Source

pub fn domain(&self) -> ClockDomain

Returns the clock’s domain.

Source

pub fn chart(&self) -> &ClockChart

Returns the clock’s timing chart.

Source

pub fn index_for_instant(&self, instant: Instant) -> Result<IndexConversion>

Converts instant to this clock’s index, reporting whether the result is exact via the returned IndexConversion.

Returns an error when the conversion arithmetic overflows or the index does not fit in a u64.

Source

pub fn instant_for_index(&self, index: ClockIndex) -> Result<Instant>

Converts a clock index back to its Instant.

Returns an error when the conversion arithmetic overflows.

Source

pub fn tick_for_index(&self, cx: &mut Cx, index: ClockIndex) -> Result<Tick>

Interns index as datum content and returns the kernel Tick that carries it on this clock.

The clock index is stored as a datum node referenced by content, so kernel events keep carrying only Tick values. Returns an error when interning into the datum store fails.

Source

pub fn index_expr(&self, index: ClockIndex) -> Expr

Builds the codec Expr extension form encoding index on this clock.

Trait Implementations§

Source§

impl Clone for Clock

Source§

fn clone(&self) -> Clock

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 Clock

Source§

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

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

impl Eq for Clock

Source§

impl PartialEq for Clock

Source§

fn eq(&self, other: &Clock) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Clock

Auto Trait Implementations§

§

impl Freeze for Clock

§

impl RefUnwindSafe for Clock

§

impl Send for Clock

§

impl Sync for Clock

§

impl Unpin for Clock

§

impl UnsafeUnpin for Clock

§

impl UnwindSafe for Clock

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.