-
Notifications
You must be signed in to change notification settings - Fork 33
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
Set HDR_SPEED #13
Set HDR_SPEED #13
Conversation
* Added setTicks functionality on File object * Added tests for valid & invalid input
I have 2 implementations for this which I ve put in a jsbin (in case you wanna take a look) http://jsbin.com/wiwuhayuze/1/edit?js,console |
} | ||
|
||
this.HDR_SPEED = String.fromCharCode((num/256), num%256); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also use buffers and do the same as follows:
var speed = new Buffer(2);
speed.writeInt16BE(num);
this.HDR_SPEED = String.fromCharCode(speed[0], speed[1]);
I did not use this Buffer
based approach directly as we are exporting the module for the browser as well. But this seems like the least hacky way so far.
Hi @dingram Did you need some more changes to this PR? |
I ve made the change and moved the input validation but I m not sure what is the range for the valid input. Is it 1 to 65536? |
I need it for the specific error message. |
var c = config || {}; | ||
if (c.ticks && typeof c.ticks !== 'number' || c.ticks <= 0 || c.ticks >= (1 << 15)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably do:
if (c.ticks) {
if (typeof c.ticks !== 'number') {
throw new Error('Ticks per beat must be a number');
}
if (c.ticks <=0 || c.ticks >= (1 << 15)) {
throw new Error('Ticks per beat must be between 1 and 32767');
}
this.ticks = Math.floor(c.ticks);
} else {
this.ticks = 128;
}
in order to have clear error messages for different types of errors... and also to ensure that the number of ticks is an integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about nesting if
s but I guess it s fine in this scenario.
Hi Dave, do you have any further requirements in this PR? Apart from that, I had a question. I have a node module that depends on Thanks! |
Allow number of ticks per beat to be set.
Middle C is C4 in this library. |
To use this function: