pub struct TickTime {
pub ticks: i64,
pub tpq: u32,
}Expand description
Fields§
§ticks: i64Tick offset, interpreted at this value’s tpq resolution.
tpq: u32Resolution in ticks per quarter note; must be non-zero.
Implementations§
Source§impl TickTime
impl TickTime
Sourcepub fn new(ticks: i64, tpq: u32) -> Result<Self, MidiError>
pub fn new(ticks: i64, tpq: u32) -> Result<Self, MidiError>
Creates a time at tpq resolution, failing with MidiError::ZeroTpq
when tpq is zero.
Sourcepub fn from_quarters(quarters: i64) -> Self
pub fn from_quarters(quarters: i64) -> Self
Builds a time of whole quarter notes at unit resolution (tpq == 1).
Sourcepub fn mul_int(self, factor: i64) -> Self
pub fn mul_int(self, factor: i64) -> Self
Scales the tick count by an integer factor, keeping the resolution.
Sourcepub fn mul_ratio(
self,
numerator: i64,
denominator: i64,
) -> Result<Self, MidiError>
pub fn mul_ratio( self, numerator: i64, denominator: i64, ) -> Result<Self, MidiError>
Scales the tick count by numerator / denominator, failing with
MidiError::InvalidRatio when denominator is zero.
Sourcepub fn div_ratio(
self,
numerator: i64,
denominator: i64,
) -> Result<Self, MidiError>
pub fn div_ratio( self, numerator: i64, denominator: i64, ) -> Result<Self, MidiError>
Scales the tick count by denominator / numerator, failing with
MidiError::InvalidRatio when numerator is zero.
Sourcepub fn rebase(self, new_tpq: u32) -> Result<Self, MidiError>
pub fn rebase(self, new_tpq: u32) -> Result<Self, MidiError>
Re-expresses this time at new_tpq resolution without rounding.
Fails with MidiError::ZeroTpq when new_tpq is zero, or
MidiError::InexactRebase when the conversion would not be exact.
Sourcepub fn quantize(self, new_tpq: u32) -> Self
pub fn quantize(self, new_tpq: u32) -> Self
Re-expresses this time at new_tpq resolution, rounding to the nearest
tick. A zero new_tpq is clamped to unit resolution.
Sourcepub fn as_rational(self) -> (i64, i64)
pub fn as_rational(self) -> (i64, i64)
Returns the time as a (ticks, tpq) rational in quarter notes.
Sourcepub fn as_f64_quarters(self) -> f64
pub fn as_f64_quarters(self) -> f64
Returns the time as a floating-point count of quarter notes.