Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding add/sub method for Time struct #185

Open
alexandru0-dev opened this issue Feb 9, 2023 · 0 comments
Open

adding add/sub method for Time struct #185

alexandru0-dev opened this issue Feb 9, 2023 · 0 comments

Comments

@alexandru0-dev
Copy link

Adding add and sub methods to Time, would be useful for calculating seek times for playbacks

My temporary solution:

// symphonia-core/src/units.rs

impl Time {
// ...

    pub fn add(self, other: Self) -> Self {
        Time {
            seconds: self.seconds + other.seconds,
            frac: self.frac + other.frac
        }
    }

    pub fn sub(self, other: Self) -> Self {
        // check for underflow
        let seconds = self.seconds.checked_sub(other.seconds).unwrap_or(0);
        let mut frac = self.frac - other.frac;
        if frac < 0.0 {
            frac = 0.0
        }
        Time {
            seconds,
            frac
        }
    }

... 
}

feel free to share opinions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant