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

Tone.Time.valueOf #205

Closed
JackCA opened this issue Feb 28, 2017 · 3 comments
Closed

Tone.Time.valueOf #205

JackCA opened this issue Feb 28, 2017 · 3 comments

Comments

@JackCA
Copy link
Contributor

JackCA commented Feb 28, 2017

Thought it might be a good idea to have a valueOf method on Tone.Time objects so that the following would evaluate correctly:

screenshot 2017-02-27 21 38 04

What do you think? I will offer to implement again or you can run with it.

You could probably just alias it to toTicks

🎵

@tambien
Copy link
Contributor

tambien commented Feb 28, 2017

I think eval is the same as valueOf.

Tone.Time('0:0:1').eval() will give you the current value in whatever units is the default type of that class, so Tone.Frequency('4n').eval() is the same as Tone.Frequency('4n').toFrequency() and Tone.TransportTime('4n').eval() is the same as Tone.TransportTime('4n').toTicks()

Might be interesting to include some comparison operators like gt, lt, etc.

@tambien tambien closed this as completed Feb 28, 2017
@JackCA
Copy link
Contributor Author

JackCA commented Feb 28, 2017

@tambien the difference being that valueOf is automatically invoked when doing comparisons. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf

I very easily worked around this by just using toTicks during the comparison but I think it's pretty common to implement valueOf when it makes sense for things that are often compared.

implementing the individual comparison functions on the objects themselves seems interesting, but not sure what advantage over valueOf is especially considering the difference in effort to implement/maintain.

Anyways, thanks for hearing me out and offering your thoughts.

🤘

@tambien
Copy link
Contributor

tambien commented Feb 28, 2017

@JackCA oh interesting! I wasn't aware that valueOf has this special property.

So probably the easiest route is just to alias eval with valueOf and it would hopefully work pretty seamlessly. I think eval is preferable over toTicks since, it will adapt to all of the classes which implement specific types like TransportTime and Frequency. Plus that fact that toTicks is quantized to the PPQ while eval doesn't have this limitation.

Feel free to send a PR. Just make sure it's on the dev branch. And a couple of validation tests would be much appreciated.

@tambien tambien reopened this Feb 28, 2017
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