aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-12-21 22:46:55 -0500
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-12-21 22:46:55 -0500
commita1823d3f9568aac9eeafc91e444744906440ded8 (patch)
treef1c63f72458095a2322d0def48ba7ecdde689845 /src/utils.rs
parent09b01cef6389b1354073c2846303d027e4a73043 (diff)
downloadit2midi-a1823d3f9568aac9eeafc91e444744906440ded8.tar.xz
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.
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs14
1 files changed, 14 insertions, 0 deletions
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<u8> for Rational
fn from(v: u8) -> Self { Rational::from_int(v as i64) }
}
+impl From<Rational> 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}}