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

Remove Duration runtime constructor errors #93

Open
bwetherfield opened this issue Oct 9, 2018 · 6 comments
Open

Remove Duration runtime constructor errors #93

bwetherfield opened this issue Oct 9, 2018 · 6 comments

Comments

@bwetherfield
Copy link
Member

bwetherfield commented Oct 9, 2018

At present let badDur: Duration = 1/>31 causes an error, because 31 is not a power of 2.

Proposed eradication of these errors: A constructor of the following form.

init(_ numerator: Beats, _ power: Power) {
    self.beats = numerator
    self.denominator = pow(2, power)
}

where Power may be implemented as Int as Subdivision is now.

@bwetherfield
Copy link
Member Author

This has the added bonus that technically a breve/double-whole-note is now possible with power = -1...

@jsbean
Copy link
Member

jsbean commented Oct 9, 2018

I really like this. I used the other way as it is more immediately intuitive (I personally don't think of rhythmic subdivision values by their power of two). Perhaps for now, we could keep both.

Wanna open a PR which adds:

extension Duration {
    init(_ numerator: Beats, power: Power) { ... }
}

Note: power argument label extant.

You will have to add a Power struct which is a wrapper for Int, with a failable (or crashing) initializer. Maybe look into using the NewType protocol in Structure/DataStructures.

If only Swift had dependent types!

Nevermind, misunderstood. This would be an excellent idea! And no new types needed.

@jsbean
Copy link
Member

jsbean commented Oct 9, 2018

Re: dependent types: very interesting project: https://github.com/silt-lang/silt

@jsbean
Copy link
Member

jsbean commented Oct 9, 2018

It might actually make things easier down the line if the power was the actual stored value. See ProportionTree, etc. where a bunch of decoding of powers has to take place. Perhaps that could be simplified with this approach.

@bwetherfield
Copy link
Member Author

Interesting. Yes trying to make sense of it at the moment!

@bwetherfield
Copy link
Member Author

ProportionTree that is

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