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

Calculating a midi note #8

Open
TeXitoi opened this issue Jul 22, 2021 · 3 comments
Open

Calculating a midi note #8

TeXitoi opened this issue Jul 22, 2021 · 3 comments

Comments

@TeXitoi
Copy link

TeXitoi commented Jul 22, 2021

Is your feature request related to a problem? Please describe.

I need to calculate a Note, but there is no way to do any calculation as the enum is opaque. Now, I use transmute:

https://github.com/TeXitoi/midi-grid/blob/master/src/main.rs#L195-L196

Describe the solution you'd like

impl core::ops::Add<Rhs = u8> for Note;
impl core::ops::Sub<Rhs = u8> for Note;

What about overflow? Saturating? Modulo? Panic?

Describe alternatives you've considered

transmute

impl From<U7> for Note;

Additional context

Thanks for this crate, was able to make a midi keyboard within an hour! https://github.com/TeXitoi/midi-grid

When we agree on the design, I can implement it if you want.

@btrepp
Copy link
Collaborator

btrepp commented Jul 22, 2021

Hi

Glad it helps. :). From u7 makes the most sense for me. Consumer of API can build a u7 how they want.

I think it wasn't implemented just because implementation and tests may have taken some time. Which I didn't need when I initially wrote it :)

@TeXitoi
Copy link
Author

TeXitoi commented Jul 22, 2021

OK, I'll try to do a PR when I have a bit of time. Thanks.

@btrepp
Copy link
Collaborator

btrepp commented May 29, 2024

For those who stumble upon this. still just was never implemented.

It would look something like

impl From<U7> for Note {
    fn from(value: U7) -> Note {
        //either massive match or transmute here
    }
}

It' only doesn't exist because it was a bit tedious to write out (eg safest is a big. match) and I didn't have the immediate need. In my use case I had a known set of midi notes, so from button presses I created the enum (safest, statically verified).

So I didn't have the use-case for calculation, hence not implemented. It's a relatively straight forward PR though.

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

2 participants