Code Monkey home page Code Monkey logo

total-serialism's Introduction

Total Serialism

A Toolbox full of Algorithmic Composition methods

๐Ÿ™ Support Total Serialism by becoming a Patron

Visit the Total Serialism Documentation for interactive examples.

total-serialism is a set of methods used for procedurally generating and transforming number sequences (mainly in the form of arrays). This library does not output anything else then numbers, but can therefore be nicely integrated with frameworks like P5js, ToneJS, Node4Max, Hydra and any other javascript based project you want to generate arrays for. For examples with P5 see In Action. This library focusses mainly on algorithmic composition of music, but is absolutely not limited to only that and will be useful for any project that involves generation and manipulation of arrays and numbers. The library is a result of my research in algorithmic composition, livecoding and electronic music and was first prototyped with Max/MSP in the Mercury livecoding environment. It is now also used in the web based Mercury Playground

This library is a work in progress. I'm always interested in receiving inspiration, suggestions, enhancements, literature and more. Feel free to file an issue here or make a pull request and I will gladly look into it!

๐Ÿ“‹ Table of Content

๐Ÿ‘พ Newest features

Binary & Spacing

Generative rhythmical patterns of 1's and 0's by converting a number to binary or using the integer value as spacing between onsets

const Gen = require('total-serialism').Generative;

Gen.binary(358);
//=> [1, 0, 1, 1, 0, 0, 1, 1, 0]

Gen.space(2, 3, 2)
//=> [1, 0, 1, 0, 0, 1, 0]

n-Order Markov Chain

This is an identical approach to the MarkovChain while also offering the possibility of training to create n-order chains. In theory, longer chains preserve the original structure of the model, but won't generate as diverse outputs. Thanks to James Bradbury

const Rand = require('total-serialism').Stochastic;

let pattern = [1, 2, 3, 1, 2, 4, 1, 2, 5, 2, 3, 4];
// make a MarkovChain instance and optionally train with array
// an optional second argument sets the order of the markov (default=2)
let markov = new Rand.DeepMarkov(pattern, 2);

// view the transition table (stored as Map())
// Keys are stored as stringis derived via JSON.stringify()
console.log(markov.table);
// Map(7) {
//   '[1,2]' => [ 3, 4, 5 ],
//   '[2,3]' => [ 1, 4 ],
//   '[3,1]' => [ 2 ],
//   '[2,4]' => [ 1 ],
//   '[4,1]' => [ 2 ],
//   '[2,5]' => [ 2 ],
//   '[5,2]' => [ 3 ]
// }

// set the state of the model used as initial value
markov.state([1, 2]);

// generate an array of 10 values 
markov.chain(10);
// => [ 2, 3, 1, 2, 5, 2, 3, 4, 1, 2 ]

Chord progressions

Generate chord progressions as 2d-array's of semitones from an array of Roman Numerals and an optional root note.

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

// Convert a chord progression from roman numerals to semitones
TL.chordsFromNumerals(['I', 'IIm', 'IVsus2', 'V7', 'VIm9'], 'c');
// => [[ 0, 4, 7 ],
//     [ 2, 5, 9 ],
//     [ 5, 7, 0 ],
//     [ 7, 11, 2, 5 ],
//     [ 9, 0, 4, 7, 11 ]] 

Support for n-dimensional arrays

Most of the transform, translate and utility functions now support calculations with n-dimensional arrays.

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

TL.noteToMidi(['c4', ['eb4', 'g4', 'a4'], ['a3', 'f4']]);
//=> [ 60, [ 63, 67, 69 ], [ 57, 65 ] ] 

Mod.clone(['c', ['e', 'g']], ['4', '5', '#3']);
//=> [ 'c4', [ 'e4', 'g4' ], 'c5', [ 'e5', 'g5' ], 'c#3', [ 'e#3', 'g#3' ] ]

TL.relativeToMidi([[-12, -9, -5], [0, 4, 7], [2, 5, 9]], 'c4');
//=> [ [ 36, 39, 43 ], [ 48, 52, 55 ], [ 50, 53, 57 ] ] 

Stat.compare(['c', ['e', 'g']], ['c', ['e', 'g']]);
//=> true 

Mod.flatten([1, [2, 3, [ 4 ], 5], 6]);
//=> [ 1, 2, 3, 4, 5, 6 ] 

Mod.lookup([0, [1, 1, [2, 3], 0], 2], ['c4', 'e4', 'f4', 'g4']);
//=> [ 'c4', [ 'e4', 'e4', [ 'f4', 'g4' ], 'c4' ], 'f4' ] 

cellular automaton

Generate an Elementary Cellular Automaton class. This is an one dimensional array (collection of cells) with states that are either dead or alive (0/1). By following a set of rules the next generation is calculated for every cell based on its neighbouring cells.

const Algo = require('total-serialism').Algorithmic;
const Rand = require('total-serialism').Stochastic;

let ca = new Algo.Automaton();
// feed with 40 randomly generated values 0-1
ca.feed(Rand.coin(40));
// set the rule with a decimal representation
ca.rule(120);
// generate the next generation and store in array
let gen = ca.next();

// create multiple generations in a forloop
let gens = [];
for (let i=0; i<10; i++){
	gens.push(ca.next());
}
Util.draw(gens);

//  โ–ˆโ–ˆ  โ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆ  โ–ˆโ–ˆโ–ˆ โ–ˆ    โ–ˆ  โ–ˆโ–ˆ    โ–ˆ โ–ˆโ–ˆ
// โ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆ  โ–ˆโ–ˆโ–ˆ  โ–ˆโ–ˆ โ–ˆ โ–ˆ โ–ˆโ–ˆ โ–ˆ    โ–ˆ โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ
//    โ–ˆโ–ˆ โ–ˆ โ–ˆ โ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆ โ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆ    โ–ˆโ–ˆ โ–ˆโ–ˆ   โ–ˆ  
//    โ–ˆโ–ˆโ–ˆ โ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆ โ–ˆโ–ˆ  โ–ˆโ–ˆ โ–ˆ   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ   โ–ˆ 
//    โ–ˆ โ–ˆโ–ˆ โ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆ โ–ˆ  โ–ˆ    โ–ˆโ–ˆ   โ–ˆ
// โ–ˆ   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  โ–ˆ      โ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆ โ–ˆ  โ–ˆ   โ–ˆโ–ˆโ–ˆ   
//  โ–ˆ  โ–ˆ     โ–ˆโ–ˆ  โ–ˆ     โ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆ  โ–ˆ  โ–ˆ โ–ˆโ–ˆ  
//   โ–ˆ  โ–ˆ    โ–ˆโ–ˆโ–ˆ  โ–ˆ     โ–ˆโ–ˆ   โ–ˆโ–ˆ โ–ˆ  โ–ˆ  โ–ˆโ–ˆโ–ˆโ–ˆ 
//    โ–ˆ  โ–ˆ   โ–ˆ โ–ˆโ–ˆ  โ–ˆ    โ–ˆโ–ˆโ–ˆ  โ–ˆโ–ˆโ–ˆ โ–ˆ  โ–ˆ โ–ˆ  โ–ˆโ–ˆ
// โ–ˆ   โ–ˆ  โ–ˆ   โ–ˆโ–ˆโ–ˆโ–ˆ  โ–ˆ   โ–ˆ โ–ˆโ–ˆ โ–ˆ โ–ˆโ–ˆ โ–ˆ  โ–ˆ โ–ˆ โ–ˆโ–ˆ

Scale tuning

Use the new TL.Scala() class to import a .scl file (Scala tuning format) to work with custom tuning systems apart from the Western 12-TET (Equal Temperament) tuning or use one of the tunings from a database with over 5000 tunings from Stichting Huygens-Fokker.

const { Scala } = require('total-serialism').Translate;

// Create an instance of a Scala class
let scl = new Scala();

scl.scalaToFreq([60, 63, 67, 69, 72, 81, 36, 48]);
//=> [ 261.63, 311.13, 392.00, 440.00, 523.25, 880.00, 65.41, 130.81 ]

// Get the entire list of names from the library
scl.names;
// [ '05-19',
//   '05-22',
//   '05-24',
//   '06-41',
//   '07-19',
//   '07-31',
//   '07-37',
//   '08-11',
//   '08-13',
//   '08-19', ... and 5000 more]

Random clave patterns

Use the Rand.clave() to generate binary beats with clave patterns

const { clave } = require('total-serialism').Stochastic;

clave(16, 4);
//=> [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1 ] 
//=> โ–ˆ   โ–ˆ โ–ˆ   โ–ˆ  โ–ˆ โ–ˆ

clave(16, 3, 1);
//=> [ 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1 ] 
//=> โ–ˆ  โ–ˆ  โ–ˆโ–ˆ  โ–ˆ โ–ˆ  โ–ˆ

๐Ÿš€ Install

Install in node_modules

$ npm install total-serialism
// entire package
const Srl = require('total-serialism');

// subset of library
const Gen = require('total-serialism').Generative;

// specific methods
const { spread, fill } = require('total-serialism').Generative;

Import es5 version

// entire package
const Srl = require('total-serialism/build/ts.es5.js');
// subset of library
const Algo = require('total-serialism/build/ts.es5.js').Algorithmic;

Include in html

Include latest or specific version of bundled minified es5 through url in index.html

<script src="https://unpkg.com/total-serialism/build/ts.es5.min.js"></script>

<script src="https://unpkg.com/[email protected]/build/ts.es5.min.js"></script>

Use in a html <script> like so:

// entire package
const Srl = TotalSerialism;
// subset of library
const Rand = TotalSerialism.Stochastic;

๐Ÿ”ญ Content

The library consists of a few subsets:

  • Generative : Basic methods that generate arrays of number sequences, such as methods that generate an ascending array of numbers evenly spread between a low and high value.
  • Algorithmic : These are also generative methods, but are in general more complex algorithms, such as a euclidean rhythm generator, lindenmayer string expansion, cellular automaton, fibonacci sequence, pisano periods and more.
  • Stochastic : Methods for procedurally generating number sequences based on various types of randomness, such as white noise (uniformly distributed), rolling a die, flipping a coin and more. Also includes a n-order Markov Chain.
  • Transform : Methods that transform arrays. Think of methods such as reversing, palindrome, duplicating, inversing, interleaving and more.
  • Statistic : A set of methods from Statistics and Probability Theory that allow for analysis of number sequences for statistical purposes. For example getting the average value or the most common value from an array.
  • Translate : Translate between different notation systems and tunings with Scala. For example convert midi values to frequency, or note names to midi integers. Or use a relative semitone notation system and convert to midi. Map values in an Array to a specified scale, and output the relative values in the specified scale, root and octave.
  • Utility : Basic arithmetic and methods necessary to run functions in the libraries above. But can also be of help in your own algorithmic processes.

๐Ÿ“Ÿ Usage

The entire library

const TS = require('total-serialism');

// function calls look like:
TS.Generative.spread(4);
TS.Stochastic.random(4);

Or an individual section

const Gen  = require('total-serialism').Generative;
const Algo = require('total-serialism').Algorithmic;
const Mod  = require('total-serialism').Transform;
const Rand = require('total-serialism').Stochastic;
const Util = require('total-serialism').Utility;

// function calls look like:
Gen.spread(4);
Rand.random(4);

Or an individual function

const { spread } = require('total-serialism').Generative;
const { random } = require('total-serialism').Stochastic;

// function calls look like:
spread(4);
random(4);

It's also possible to expose entire subsets to the main package

// expose multiple sub-libraries to the main package with
const TS = require('total-serialism');
Object.assign(TS, TS.Generative, TS.Stochastic);

// function calls look like:
TS.spread(4);
TS.random(4);

Or expose entire subsets to the global namespace. (not recommended, this can lead to name collisions with other functions/packages)

// expose multiple sub-libraries to the global scope
const TS = require('total-serialism');
Object.assign(globalThis, TS.Generative, TS.Stochastic);

// function calls look like:
spread(4);
random(4);
// etc...

๐ŸŽฎ In Action with p5

The following links redirect to p5.js sketches coded in the p5 browser editor. These sketches demonstrate some of the methods from this library, used in both sound (for algorithmic compositions with p5.Sound) and visuals. The sketches use the bundled minified version of this package included via the script in the html. See install for instructions on how to include the version in the index.html and script.

โœจ Inspiration & Bibliography

This library is inspired by the composition techniques named Serialism and Total Serialism. The technique approaches the parameters that make up a piece of music as individual series of values. These parameters are (but not limited to) pitch, duration/rhythm and velocity/dynamics.

Serialism originated from the twelve-tone technique, described in 1919 by Josef Hauer in his published work "Law of the twelve tones". This technique starts out with a randomly ordered set of the twelve chromatic notes. From there on out you can apply transformations on this set, such as reverse/retrograde, inverse, transpose, and combinations between those.

For many of the functions programmed much inspiration was gained from Laurie Spiegels paper on "Manipulation of Musical Patterns" (1981) in which she suggests to "extract a basic "library" consisting of the most elemental transformations which have consistently been successfully used on musical patterns, a basic group of "tried-and-true" musical manipulations." Specifically the stretch and expand methods were inspired by Laurie Spiegels writings in this paper. Stretch is a method that is "inserting a smooth ramp between discretely separated values" and expand is an interpretation of "Extension beyond that which already exists in such a way as to preserve continuity with it, to project from it"

The euclidean rhythm generator was inspired by the famous paper by Godfried Toussaint.

The clave rhythm generator was inspired by another paper by Godfried Toussaint.

Inspiration for the sequencing also came from the Live Coding scene and current programming languages available such as Tidal, Extempore, SonicPi and more. In Live Coding the Serialism technique is very common when programming music. In many cases the rhythms, melodies, and other musical expressions are expressed in arrays that are iterated based on the timing of the system.

The inspiration for usage of Integer Sequences came from composers such as Iannis Xenakis, who used the fibonacci formula in his piece Nomos Alpha and referred to the technique as Fibonacci Motion. Also Xenakis referred to the usuage of set theory for composition as Symbolic Music.

The Online Encyclopedia of Integer Sequences is a great resource for number sequences that can be derived from a wide variety of mathematical functions. A famous sequence is the Fibonacci sequence. An interesting approach used with integer sequences in algorithmic composition is applying a modulo operation. For the fibonacci sequence this results in the Pisano periods.

The Hexadecimal rhythm generator was inspired by a workshop by Steven Yi at the International Conference on Live Coding 2020 at the University of Limerick, Ireland.

Some methods from the Transformational and Stochastic library are inspired by objects or functions in the Max/MSP programming environment. Such as the urn, spread and spreadInclusive methods.

The collatz conjecture algorithm was inspired by a Numberphile and Coding Train video on youtube. The conjecture allows for very organic graphs when drawing the even-odd numbers in sequence as small rotations in angles of lines.

The Infinity Series is based on the work by composer Per Nรธrgรฅrd. The method takes its name from the endlessly self-similar nature of the resulting musical material, comparable to fractal geometry. Mathematically, the infinity series is an integer sequence. A great explanation can be found here:

Some other interesting resources and papers that have been used for some of the methods within this library.

๐Ÿค“ Missing Something?

This library is a work in progress, and I'm always interested to receive inspiration, suggestions, enhancements, literature and more. Feel free to file an issue here and I will gladly look into it!

๐Ÿ”‹ Powered By

Total Serialism is a result of research in algorithmic composition with the Mercury live coding environment.

๐Ÿ“„ License

The MIT License

Copyright (c) 2020 Timo Hoogland

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

total-serialism's People

Contributors

dependabot[bot] avatar jamesb93 avatar tmhglnd avatar toledomer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

total-serialism's Issues

Don't wrap chordsFromNumerals output by default

All generated chords are currently wrapped within one octave to keep chords close together. But this is not always ideal, so this could be added as an option or done manually with the Util.wrap() method.

Export and import transition table as json for Markov and DeepMarkov

For the normal Markov this will be quite straight forward, for the DeepMarkov it needs some translation because that class uses the Map object. Below some code that should be implemented from https://stackoverflow.com/questions/29085197/how-do-you-json-stringify-an-es6-map:

// when exporting
JSON.stringify(markov.table, replacer);

// when importing
markov.table = JSON.parse(inputJSON, reviver);

// function for stringifying the Map output to store as json
function replacer(key, value) {
	if (value instanceof Map) {
		return {
			type: 'Map',
			value: [ ...value ],
		};
	} else {
		return value;
	}
}

// function for parsing a stringified Map output stored as json
function reviver(key, value) {
	if (typeof value === 'object' && value !== null) {
		if (value.type === 'Map') {
			return new Map(value.value);
		}
	}
	return value;
}

Hexachordal Rotation

This feature will implement the Hexachordal Rotation, or Rotational Arrays, an technique used by Stravinsky in the 1950's. This operation involves partitioning a twelve-tone series into hexachords (labeled ฮฑ [alpha] and ฮฒ [beta]) and then rotating each hexachord by moving the first pitch to the end until five additional permutations are created. To create commonality among hexachords, these two arrays of rotated hexachords are then transposed in order to retain the original first pitches of the hexachords (labeled ฮณ [gamma] and ฮด [delta]).

Further reading:

example:

ฮฑ                       ฮฒ
    Eb E  Bb Ab A  D    C  B  C# F# G  F
I   E  Bb Ab A  D  Eb   B  C# F# G  F  C
II  Bb Ab A  D  Eb E    C# F# G  F  C  B
III Ab A  D  Eb E  Bb   F# G  F  C  B  C#
IV  A  D  Eb E  Bb Ab   G  F  C  B  C# F#
V   D  Eb E  Bb Ab A    F  C  B  C# F# G

ฮณ                       ฮด
    Eb E  Bb Ab A  D    C  B  C# F# G  F
I   Eb A  G  Ab Db D    C  D  G  Ab Gb Db
II  Eb Db D  G  Ab A    C  F  Gb Fb Cb Bb
III Eb E  A  Bb B  F    C  Db Cb Gb F  G
IV  Eb Ab A  Bb E  D    C  Bb F  Fb Gb Cb
V   Eb E  F  B  A  Bb   C  G  Gb Ab Db D

Figure 1. Rotational array of the prime form of the row for Movements

Method for repeating items from array

A method that repeats every item from an array a specified amount of times:

const Mod = require('total-serialism').Transform;

let myArr = [5 7 12 24]
myArr = Mod.repeat(myArr 4);
console.log(myArr);
//=> [ 5 5 5 5 7 7 7 7 12 12 12 12 24 24 24 24 ]

Markov Chain

Add a markov-chain set of methods to the library. Probably easiest in the form of a class that can learn and generate through seperate methods.

Some ideas:

const Algo = require('total-serialism').Algorithmic;
let myMarkov = Algo.markov();
// => make an instance of a markov-chain

myMarkov.train([0, 1, 1, 2, 1, 3, 2, 3, 1, 3, 0]);
// => train the Markov Chain with an array of values

myMarkov.next();
// => generates the next value

let values = myMarkov.generate(12);
// => generates 12 values as an array

Add Per Nรธrgรฅrd's infinity series

New generative method for infinity series of Per Nรธrgรฅrd:

Some background:
https://oeis.org/A004718
https://en.wikipedia.org/wiki/Per_N%C3%B8rg%C3%A5rd
https://www.lawtonhall.com/blog/2019/9/9/per-nrgrds-infinity-series#:~:text=Coding%20the%20Infinity%20Series

Typescript implementation:
https://github.com/tablesandwaves/tblswvs.js/blob/main/src/melody.ts#L194

What should the function be called?
infinitySeries(), perNorgard(), norgard(), infSeries()

Is argument number of iterations?
infinitySeries(<num-iterations>, [<germinal-interval>])

Method and expected output:

Generative.norgard(0, [0, 1]);
// => [ 0 ]

Generative.norgard(5, [0, 1]);
// => [ 0, 1, -1, 2, 1, 0, -2, 3, -1, 2, 0, 1, 2, -1, -3, 4, 1, 0, -2, 3, 0, 1, -1, 2, -2, 3, 1, 0, 3, -2, -4, 5 ]

List methods on 2D lists

Allow list transformations on 2D or even 3D lists by applying a recursive list processing for deeper dimensions.

Gen.fill() should accept single array as argument

Instead of providing seperate arguments per fill value it should also accept an array and generate from there:

Original with separate arguments

Gen.fill(10, 2, 15, 3, 20, 4);
//=> [ 10, 10, 15, 15, 15, 20, 20, 20, 20 ] 

When using an array it returns [ 0 ]

Gen.fill([10, 20, 2, 15, 3, 20, 4]);
//=> [ 0 ] 

This should actually result in

Gen.fill([10, 20, 2, 15, 3, 20, 4]);
//=> [ 10, 10, 15, 15, 15, 20, 20, 20, 20 ] 

Build this for importing with a script tag

Hello,

Nice looking library. I was wondering if you could build a bundled version of this that could be used on codepen for teaching purposes. This would usually work but I realized that's just an access point to the other files.

Find closest Chord inversion

Find a method and program a function that finds the best inversion for a chord with the most notes being close together given another chord as input (or maybe even 2 chords where the other chords should sit in between).

Make invert() work with notename strings

The invert() method from the Translate category only works with numbers at the moment. It would be interesting to see if there is a way to make it work with notenames like c4 e5 g#3 etc.

Expand with statistical methods

This library should include methods like:

const Stat = require('total-serialism').Statistical;

Stat.max()
//=> return the highest value from an array (possibly also works with note-names)
Stat.min()
//=> return the lowest value from an array (possibly also works with note-names)
Stat.mean()
//=> return the avarage value from an array (possible also works with note-names)
Stat.median()
//=> return the median from an array (possible also works with note-names)
Stat.mode()
//=> return the mode from an array (possible also works with note-names)

Convert duration values to ms

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 ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.