From a1823d3f9568aac9eeafc91e444744906440ded8 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Wed, 21 Dec 2022 22:46:55 -0500 Subject: Convert tempo effects. Introducing an it2midi-specific swing on/off command to aid real bpm calculation when legacy swing technique is used in the file. --- src/utils.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index cbe9716..0fc4328 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,5 @@ use std::ops::*; +use std::fmt::{Debug, Formatter, Error}; #[derive(Copy, Clone)] pub struct Rational @@ -15,6 +16,14 @@ impl Default for Rational fn default() -> Rational { Rational::from_int(0) } } +impl Debug for Rational +{ + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> + { + f.write_fmt(format_args!("{}/{}", self.n, self.d)) + } +} + impl Add for Rational { type Output = Self; @@ -70,6 +79,11 @@ impl From for Rational fn from(v: u8) -> Self { Rational::from_int(v as i64) } } +impl From for f64 +{ + fn from(v: Rational) -> Self { v.n as f64 / v.d as f64 } +} + impl Rational { fn from_int(v: i64) -> Rational {Rational{n: v, d: 1}} -- cgit v1.2.3