pub struct MusicalTime { /* private fields */ }Expand description
Musical time in units of beats + super-beats.
Note this value is always positive.
Implementations§
Source§impl MusicalTime
impl MusicalTime
Sourcepub fn new(beats: u32, super_beats: u32) -> Self
pub fn new(beats: u32, super_beats: u32) -> Self
beats- The time in musical beats.super_beats- The number of super-beats (after the time inself.beats) (Note this value will be constrained to the range[0, 508,032,000)).
A “super-beat” is a unit of time equal to 1 / 508,032,000 of a beat. This number was chosen
because it is nicely divisible by a whole slew of factors including 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 24, 32, 64, 128, 256, 512, and 1920, as well as common sampling
rates such as 22050, 24000, 44100, 48000, 88200, 96000, 176400, and 192000. This ensures that
any recording of note data in this format will always be at-least sample-accurate.
Sourcepub fn super_beats(&self) -> u32
pub fn super_beats(&self) -> u32
The number of super-beats (after the time in self.beats()).
A “super-beat” is a unit of time equal to 1 / 508,032,000 of a beat. This number was chosen
because it is nicely divisible by a whole slew of factors including 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 24, 32, 64, 128, 256, 512, and 1920, as well as common sampling
rates such as 22050, 24000, 44100, 48000, 88200, 96000, 176400, and 192000. This ensures that
any recording of note data in this format will always be at-least sample-accurate.
This value will always be in the range [0, 508,032,000).
Sourcepub fn from_beats(beats: u32) -> Self
pub fn from_beats(beats: u32) -> Self
beats- The time in musical beats.
Sourcepub fn from_half_beats(beats: u32, half_beats: u32) -> Self
pub fn from_half_beats(beats: u32, half_beats: u32) -> Self
beats- The time in musical beats.half_beats- The number of half-beats (after the timebeats). This will be constrained to the range[0, 1].
Sourcepub fn from_quarter_beats(beats: u32, quarter_beats: u32) -> Self
pub fn from_quarter_beats(beats: u32, quarter_beats: u32) -> Self
beats- The time in musical beats.quarter_beats- The number of quarter-beats (after the timebeats). This will be constrained to the range[0, 3].
Sourcepub fn from_eighth_beats(beats: u32, eighth_beats: u32) -> Self
pub fn from_eighth_beats(beats: u32, eighth_beats: u32) -> Self
beats- The time in musical beats.eighth_beats- The number of eighth-beats (after the timebeats). This will be constrained to the range[0, 7].
Sourcepub fn from_sixteenth_beats(beats: u32, sixteenth_beats: u32) -> Self
pub fn from_sixteenth_beats(beats: u32, sixteenth_beats: u32) -> Self
beats- The time in musical beats.sixteenth_beats- The number of sixteenth-beats (after the timebeats). This will be constrained to the range[0, 15].
Sourcepub fn from_32nd_beats(beats: u32, _32nd_beats: u32) -> Self
pub fn from_32nd_beats(beats: u32, _32nd_beats: u32) -> Self
beats- The time in musical beats._32nd_beats- The number of 32nd-beats (after the timebeats). This will be constrained to the range[0, 31].
Sourcepub fn from_64th_beats(beats: u32, _64th_beats: u32) -> Self
pub fn from_64th_beats(beats: u32, _64th_beats: u32) -> Self
beats- The time in musical beats._64th_beats- The number of 64th-beats (after the timebeats). This will be constrained to the range[0, 63].
Sourcepub fn from_128th_beats(beats: u32, _128th_beats: u32) -> Self
pub fn from_128th_beats(beats: u32, _128th_beats: u32) -> Self
beats- The time in musical beats._128th_beats- The number of 128th-beats (after the timebeats). This will be constrained to the range[0, 127].
Sourcepub fn from_third_beats(beats: u32, third_beats: u32) -> Self
pub fn from_third_beats(beats: u32, third_beats: u32) -> Self
beats- The time in musical beats.third_beats- The number of third-beats (after the timebeats). This will be constrained to the range[0, 2].
Sourcepub fn from_fifth_beats(beats: u32, fifth_beats: u32) -> Self
pub fn from_fifth_beats(beats: u32, fifth_beats: u32) -> Self
beats- The time in musical beats.fifth_beats- The number of fifth-beats (after the timebeats). This will be constrained to the range[0, 4].
Sourcepub fn from_sixth_beats(beats: u32, fifth_beats: u32) -> Self
pub fn from_sixth_beats(beats: u32, fifth_beats: u32) -> Self
beats- The time in musical beats.sixth_beats- The number of sixth-beats (after the timebeats). This will be constrained to the range[0, 5].
Sourcepub fn from_seventh_beats(beats: u32, seventh_beats: u32) -> Self
pub fn from_seventh_beats(beats: u32, seventh_beats: u32) -> Self
beats- The time in musical beats.seventh_beats- The number of seventh-beats (after the timebeats). This will be constrained to the range[0, 6].
Sourcepub fn from_ninth_beats(beats: u32, ninth_beats: u32) -> Self
pub fn from_ninth_beats(beats: u32, ninth_beats: u32) -> Self
beats- The time in musical beats.ninth_beats- The number of ninth-beats (after the timebeats). This will be constrained to the range[0, 8].
Sourcepub fn from_tenth_beats(beats: u32, tenth_beats: u32) -> Self
pub fn from_tenth_beats(beats: u32, tenth_beats: u32) -> Self
beats- The time in musical beats.tenth_beats- The number of tenth-beats (after the timebeats). This will be constrained to the range[0, 9].
Sourcepub fn from_twelth_beats(beats: u32, twelth_beats: u32) -> Self
pub fn from_twelth_beats(beats: u32, twelth_beats: u32) -> Self
beats- The time in musical beats.twelth_beats- The number of twelth-beats (after the timebeats). This will be constrained to the range[0, 11].
Sourcepub fn from_24th_beats(beats: u32, _24th_beats: u32) -> Self
pub fn from_24th_beats(beats: u32, _24th_beats: u32) -> Self
beats- The time in musical beats._24th_beats- The number of 24th-beats (after the timebeats). This will be constrained to the range[0, 23].
Sourcepub fn from_beats_f64(beats: f64) -> Self
pub fn from_beats_f64(beats: f64) -> Self
Get the corresponding musical time from the number of beats (as an f64).
Note that this conversion is NOT lossless.
If beats is negative, then a MusicalTime of 0 will be returned instead.
Sourcepub fn as_beats_f64(&self) -> f64
pub fn as_beats_f64(&self) -> f64
Convert the corresponding musical time in units of beats (as an f64 value).
Note that this conversion is NOT lossless.
This is useful for displaying notes in UI.
pub fn snap_to_nearest_beat(&self) -> MusicalTime
Sourcepub fn snap_to_nearest_whole_beats(&self, beats: u32) -> MusicalTime
pub fn snap_to_nearest_whole_beats(&self, beats: u32) -> MusicalTime
Snap to the nearest multiple of whole beats.
pub fn snap_to_nearest_fractional_beat<const DIVISOR: u32>(&self) -> MusicalTime
pub fn snap_to_nearest_half_beat(&self) -> MusicalTime
pub fn snap_to_nearest_quarter_beat(&self) -> MusicalTime
pub fn snap_to_nearest_eigth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_sixteenth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_32nd_beat(&self) -> MusicalTime
pub fn snap_to_nearest_64th_beat(&self) -> MusicalTime
pub fn snap_to_nearest_128th_beat(&self) -> MusicalTime
pub fn snap_to_nearest_third_beat(&self) -> MusicalTime
pub fn snap_to_nearest_fifth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_sixth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_seventh_beat(&self) -> MusicalTime
pub fn snap_to_nearest_ninth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_tenth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_twelth_beat(&self) -> MusicalTime
pub fn snap_to_nearest_24th_beat(&self) -> MusicalTime
Sourcepub fn num_fractional_beats<const DIVISOR: u32>(&self) -> u32
pub fn num_fractional_beats<const DIVISOR: u32>(&self) -> u32
The number of fractional-beats after self.beats() (floored to
the nearest fractional-beat).
This will always be in the range [0, DIVISOR - 1].
Sourcepub fn num_half_beats(&self) -> u32
pub fn num_half_beats(&self) -> u32
The number of half-beats after self.beats() (floored to
the nearest half-beat).
This will always be in the range [0, 1].
Sourcepub fn num_quarter_beats(&self) -> u32
pub fn num_quarter_beats(&self) -> u32
The number of quarter-beats after self.beats() (floored to
the nearest quarter-beat).
This will always be in the range [0, 3].
Sourcepub fn num_eigth_beats(&self) -> u32
pub fn num_eigth_beats(&self) -> u32
The number of eigth-beats after self.beats() (floored to
the nearest eigth-beat).
This will always be in the range [0, 7].
Sourcepub fn num_sixteenth_beats(&self) -> u32
pub fn num_sixteenth_beats(&self) -> u32
The number of sixteenth-beats after self.beats() (floored to
the nearest sixteenth-beat).
This will always be in the range [0, 15].
Sourcepub fn num_32nd_beats(&self) -> u32
pub fn num_32nd_beats(&self) -> u32
The number of 32nd-beats after self.beats() (floored to
the nearest 32nd-beat).
This will always be in the range [0, 31].
Sourcepub fn num_64th_beats(&self) -> u32
pub fn num_64th_beats(&self) -> u32
The number of 128th-beats after self.beats() (floored to
the nearest 64th-beat).
This will always be in the range [0, 63].
Sourcepub fn num_128th_beats(&self) -> u32
pub fn num_128th_beats(&self) -> u32
The number of 64th-beats after self.beats() (floored to
the nearest 128th-beat).
This will always be in the range [0, 127].
Sourcepub fn num_third_beats(&self) -> u32
pub fn num_third_beats(&self) -> u32
The number of third-beats after self.beats() (floored to
the nearest third-beat).
This will always be in the range [0, 2].
Sourcepub fn num_fifth_beats(&self) -> u32
pub fn num_fifth_beats(&self) -> u32
The number of fifth-beats after self.beats() (floored to
the nearest fifth-beat).
This will always be in the range [0, 4].
Sourcepub fn num_sixth_beats(&self) -> u32
pub fn num_sixth_beats(&self) -> u32
The number of sixth-beats after self.beats() (floored to
the nearest sixth-beat).
This will always be in the range [0, 5].
Sourcepub fn num_seventh_beats(&self) -> u32
pub fn num_seventh_beats(&self) -> u32
The number of seventh-beats after self.beats() (floored to
the nearest seventh-beat).
This will always be in the range [0, 6].
Sourcepub fn num_ninth_beats(&self) -> u32
pub fn num_ninth_beats(&self) -> u32
The number of ninth-beats after self.beats() (floored to
the nearest ninth-beat).
This will always be in the range [0, 8].
Sourcepub fn num_tenth_beats(&self) -> u32
pub fn num_tenth_beats(&self) -> u32
The number of tenth-beats after self.beats() (floored to
the nearest tenth-beat).
This will always be in the range [0, 9].
Sourcepub fn num_twelth_beats(&self) -> u32
pub fn num_twelth_beats(&self) -> u32
The number of twelth-beats after self.beats() (floored to
the nearest twelth-beat).
This will always be in the range [0, 11].
Sourcepub fn num_24th_beats(&self) -> u32
pub fn num_24th_beats(&self) -> u32
The number of 24th-beats after self.beats() (floored to
the nearest 24th-beat).
This will always be in the range [0, 23].
Sourcepub fn to_seconds(&self, bpm: f64) -> Seconds
pub fn to_seconds(&self, bpm: f64) -> Seconds
Convert to the corresponding time in Seconds.
Note that this conversion is NOT lossless.
Sourcepub fn to_nearest_frame_round(
&self,
bpm: f64,
sample_rate: SampleRate,
) -> Frames
pub fn to_nearest_frame_round( &self, bpm: f64, sample_rate: SampleRate, ) -> Frames
Convert to the corresponding discrete Frames. This will be rounded to the nearest sample.
Note that this conversion is NOT lossless.
Note that this must be re-calculated after recieving a new SampleRate.
Sourcepub fn to_nearest_frame_floor(
&self,
bpm: f64,
sample_rate: SampleRate,
) -> Frames
pub fn to_nearest_frame_floor( &self, bpm: f64, sample_rate: SampleRate, ) -> Frames
Convert to the corresponding discrete Frames. This will be floored to the nearest sample.
Note that this conversion is NOT lossless.
Note that this must be re-calculated after recieving a new SampleRate.
Sourcepub fn to_nearest_frame_ceil(&self, bpm: f64, sample_rate: SampleRate) -> Frames
pub fn to_nearest_frame_ceil(&self, bpm: f64, sample_rate: SampleRate) -> Frames
Convert to the corresponding discrete Frames. This will be ceil-ed to the nearest sample.
Note that this conversion is NOT lossless.
Note that this must be re-calculated after recieving a new SampleRate.
Sourcepub fn to_sub_frames(&self, bpm: f64, sample_rate: SampleRate) -> (Frames, f64)
pub fn to_sub_frames(&self, bpm: f64, sample_rate: SampleRate) -> (Frames, f64)
Convert to the corresponding discrete Frames floored to the nearest sample,
while also returning the fractional sub-sample part.
Note that this conversion is NOT lossless.
Note that this must be re-calculated after recieving a new SampleRate.
Sourcepub fn to_nearest_super_frame_round(&self, bpm: f64) -> SuperFrames
pub fn to_nearest_super_frame_round(&self, bpm: f64) -> SuperFrames
Convert to the corresponding discrete SuperFrames. This will be rounded to the nearest super-frame.
Note that this conversion is NOT lossless.
Sourcepub fn to_nearest_super_frame_floor(&self, bpm: f64) -> SuperFrames
pub fn to_nearest_super_frame_floor(&self, bpm: f64) -> SuperFrames
Convert to the corresponding discrete SuperFrames. This will be floored to the nearest super-frame.
Note that this conversion is NOT lossless.
Sourcepub fn to_nearest_super_frame_ceil(&self, bpm: f64) -> SuperFrames
pub fn to_nearest_super_frame_ceil(&self, bpm: f64) -> SuperFrames
Convert to the corresponding discrete SuperFrames. This will be ceil-ed to the nearest super-frame.
Note that this conversion is NOT lossless.
Sourcepub fn to_sub_super_frames(&self, bpm: f64) -> (SuperFrames, f64)
pub fn to_sub_super_frames(&self, bpm: f64) -> (SuperFrames, f64)
Convert to the corresponding discrete SuperFrames floored to the nearest super-frame,
while also returning the fractional sub-super-frame part.
Note that this conversion is NOT lossless.
Sourcepub fn checked_sub(self, rhs: MusicalTime) -> Option<MusicalTime>
pub fn checked_sub(self, rhs: MusicalTime) -> Option<MusicalTime>
Try subtracting rhs from self. This will return None if the resulting value
is negative due to rhs being larger than self (overflow).
Trait Implementations§
Source§impl Add for MusicalTime
impl Add for MusicalTime
Source§impl AddAssign for MusicalTime
impl AddAssign for MusicalTime
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl Clone for MusicalTime
impl Clone for MusicalTime
Source§fn clone(&self) -> MusicalTime
fn clone(&self) -> MusicalTime
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MusicalTime
impl Debug for MusicalTime
Source§impl Default for MusicalTime
impl Default for MusicalTime
Source§impl From<AtomicMusicalTime> for MusicalTime
impl From<AtomicMusicalTime> for MusicalTime
Source§fn from(value: AtomicMusicalTime) -> Self
fn from(value: AtomicMusicalTime) -> Self
Source§impl From<MusicalTime> for AtomicMusicalTime
impl From<MusicalTime> for AtomicMusicalTime
Source§fn from(value: MusicalTime) -> Self
fn from(value: MusicalTime) -> Self
Source§impl Hash for MusicalTime
impl Hash for MusicalTime
Source§impl Mul<u32> for MusicalTime
impl Mul<u32> for MusicalTime
Source§impl MulAssign<u32> for MusicalTime
impl MulAssign<u32> for MusicalTime
Source§fn mul_assign(&mut self, other: u32)
fn mul_assign(&mut self, other: u32)
*= operation. Read more