Time miscalculation fix (#343)

Times being converted to BarsBeatsSixteenths have the potential to miscalculate due to an extended floating point number within the function.

Example of error:
https://jsfiddle.net/timboie/1vztuhz1/

Fix validation:
https://jsfiddle.net/timboie/6e7d31t3/

Any further testing is appreciated

Fixes #342
This commit is contained in:
timothyboie 2018-05-15 07:10:10 -07:00 committed by Yotam Mann
parent e39e392791
commit 4cd88ab1eb

View file

@ -111,6 +111,7 @@ define(["Tone/core/Tone", "Tone/type/TimeBase", "Tone/type/Frequency"], function
Tone.Time.prototype.toBarsBeatsSixteenths = function(){
var quarterTime = this._beatsToUnits(1);
var quarters = this.valueOf() / quarterTime;
quarters = parseFloat(quarters.toFixed(4));
var measures = Math.floor(quarters / this._getTimeSignature());
var sixteenths = (quarters % 1) * 4;
quarters = Math.floor(quarters) % this._getTimeSignature();