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

Convert duration values to ms #3

Open
tmhglnd opened this issue Mar 22, 2020 · 1 comment
Open

Convert duration values to ms #3

tmhglnd opened this issue Mar 22, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@tmhglnd
Copy link
Owner

tmhglnd commented Mar 22, 2020

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 tmhglnd added the enhancement New feature or request label Mar 22, 2020
@tmhglnd
Copy link
Owner Author

tmhglnd commented Nov 28, 2021

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant