total-serialism icon indicating copy to clipboard operation
total-serialism copied to clipboard

Convert duration values to ms

Open tmhglnd opened this issue 5 years ago • 1 comments
trafficstars

An enhancement to the Translate library of a method that converts various duration values from different platforms to a corresponding millisecond value based on a set tempo.

example

const TL = require('total-serialism').Translate;

TL.setTempo(120);
//=> set tempo to 120 beats per minute

var rhythm = [8n, 4n, 16n];
TL.toTime(rhythm)
//=> [ 250, 500, 125 ]

But could also work with division notation

const TL = require('total-serialism').Translate;

TL.setTempo(120);
//=> set tempo to 120 beats per minute

var rhythm = ['1/8', '1/4', '1/16'];
TL.toTime(rhythm)
//=> [ 250, 500, 125 ]

Or with floating point ratio values

const TL = require('total-serialism').Translate;

TL.setTempo(120);
//=> set tempo to 120 beats per minute

var rhythm = [0.125, 0.25, 0.0625];
TL.toTime(rhythm)
//=> [ 250, 500, 125 ]

tmhglnd avatar Mar 22 '20 13:03 tmhglnd

Not yet possible with one function that works for all, but there are now several translate methods for different types of input. Using the Time Value Syntax of Cycling'74's MaxMSP

// format: TL.func(<Array>, <bpm>)

TL.divisionToMs(['1/4', ['1/8', ['3/16', '1/4']], '1/6', '2'], 100);
//=> [ 600, [ 300, [ 450, 600 ] ], 400, 4800 ] 
// Alias: TL.dtoms()

TL.ratioToMs([0.25, [0.125, [0.1875, 0.25]], 0.1667, 2], 100);
//=> [ 600, [ 300, [ 450, 600 ] ], 400.08, 4800 ] 
// Alias: TL.rtoms()

TL.timevalueToMs(['4n', ['8nt', ['16nd', '2nd']], '32n', '3m'], 100);
//=> [ 600, [ 200, [ 225, 1800 ] ], 75, 7200 ] 
// Alias. TL.ttoms()

tmhglnd avatar Nov 28 '21 13:11 tmhglnd