total-serialism
Advanced tools
Comparing version 1.2.1 to 1.3.1
@@ -17,2 +17,3 @@ //============================================================================== | ||
const Transform = require('./lib/transform.js'); | ||
const Translate = require('./lib/translate.js'); | ||
const Utility = require('./lib/utility.js'); | ||
@@ -26,3 +27,4 @@ // const Dict = require('./lib/dict.js'); | ||
exports.Transform = Transform; | ||
exports.Translate = Translate; | ||
exports.Utility = Utility; | ||
// exports.Dict = Dict; |
@@ -11,5 +11,8 @@ //============================================================================== | ||
// credits: | ||
// - euclid() function based on paper by Godfried Toussaint | ||
// - euclid() based on paper by Godfried Toussaint | ||
// http://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf | ||
// and code from https://github.com/brianhouse/bjorklund | ||
// - hexBeat() inspired by Steven Yi's implementation in the csound | ||
// livecode environment from https://github.com/kunstmusik/csound-live-code | ||
// and here https://kunstmusik.github.io/learn-hex-beats/ | ||
//============================================================================== | ||
@@ -19,2 +22,20 @@ | ||
// A hexadecimal rhythm generator. Generates values of 0 and 1 | ||
// based on the input of a hexadecimal character string | ||
// | ||
// @param {String} -> hexadecimal characters (0 t/m f) | ||
// @return {Array} -> rhythm | ||
// | ||
function hexBeat(hex="8"){ | ||
if (!hex.isNaN){ hex = hex.toString(); } | ||
var a = []; | ||
for (i in hex){ | ||
var binary = parseInt("0x"+hex[i]).toString(2); | ||
var padding = binary.padStart(4, '0'); | ||
a = a.concat(padding.split('').map(x => Number(x))); | ||
} | ||
return a; | ||
} | ||
exports.hexBeat = hexBeat; | ||
// A euclidean rhythm generator. Generates values of 0 and 1 | ||
@@ -21,0 +42,0 @@ // distributed based on the common denominator after division |
@@ -16,2 +16,3 @@ //============================================================================== | ||
var seedrandom = require('seedrandom'); | ||
var Gen = require('./gen-basic'); | ||
// local pseudorandom number generator | ||
@@ -71,2 +72,15 @@ var rng = seedrandom(); | ||
// generate a list of random integer values | ||
// but the next random value is within a limited range of the previous value | ||
// | ||
// @param {Int} -> length of output array | ||
// @param {Number} -> minimum range (optional, default=null) | ||
// @param {Number} -> maximum range (optional, default=null) | ||
// @return {Array} | ||
// function drunk(len=1, lo=null, hi=null, start=0){ | ||
// len = Math.max(1, Math.abs(len)); | ||
// } | ||
// exports.drunk = drunk; | ||
// generate a list of random integer values 0 or 1 | ||
@@ -115,2 +129,18 @@ // like a coin toss, heads/tails | ||
} | ||
exports.shuffle = shuffle; | ||
exports.shuffle = shuffle; | ||
function urn(len=1, lo=len, hi=0){ | ||
// swap if lo > hi | ||
if (lo > hi){ var t=lo, lo=hi, hi=t; } | ||
// len is positive and minimum of 1 | ||
len = Math.max(1, Math.abs(len)); | ||
var vals = []; | ||
for (var i=0; i<hi-lo; i++){ | ||
vals.push(i+lo); | ||
} | ||
vals = shuffle(vals); | ||
return vals.slice(0, len); | ||
} | ||
exports.urn = urn; |
@@ -71,3 +71,4 @@ //============================================================================== | ||
// add 1 or more values to an array, preserves listlength | ||
// add 1 or more values to an array, | ||
// preserves listlength of first argument | ||
// arguments are applied sequentially | ||
@@ -93,3 +94,4 @@ // | ||
// subtract 1 or more values from an array, preserves listlength | ||
// subtract 1 or more values from an array | ||
// preserves listlength of first argument | ||
// arguments are applied sequentially | ||
@@ -116,3 +118,4 @@ // | ||
// multiply 1 or more values from an array, preserves listlength | ||
// multiply 1 or more values from an array | ||
// preserves listlength of first argument | ||
// arguments are applied sequentially | ||
@@ -139,3 +142,4 @@ // | ||
// divide 1 or more values from an array, preserves listlength | ||
// divide 1 or more values from an array | ||
// preserves listlength of first argument | ||
// arguments are applied sequentially | ||
@@ -142,0 +146,0 @@ // |
{ | ||
"name": "total-serialism", | ||
"version": "1.2.1", | ||
"version": "1.3.1", | ||
"description": "A set of methods for the generation and transformation of number sequences useful in algorithmic composition", | ||
@@ -32,3 +32,4 @@ "main": "index.js", | ||
"transformation", | ||
"permutation" | ||
"permutation", | ||
"hexbeat" | ||
], | ||
@@ -42,4 +43,5 @@ "author": "Timo Hoogland", | ||
"dependencies": { | ||
"seedrandom": "^3.0.5" | ||
"seedrandom": "^3.0.5", | ||
"tonal": "^2.2.2" | ||
} | ||
} |
@@ -67,2 +67,19 @@ # Total Serialism | ||
### Algorithmic Methods | ||
```js | ||
const Algo = require('total-serialism').Algorithmic; | ||
// generate a euclidean rhythm evenly spacing n-beats amongst n-steps | ||
Algo.euclid(16, 9, 1); | ||
//=> [0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1] | ||
// inspired by Godfried Toussaints famous paper "The Euclidean Algorithm Generates Traditional Musical Rhythms" | ||
// generate a hexadecimal rhythm based on a hexadecimal string (0-f) | ||
Algo.hexBeat('a9d2'); | ||
//=> [1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0] | ||
// inspired by Steven Yi's implementation in CSound | ||
``` | ||
- [Learn hex beats](https://kunstmusik.github.io/learn-hex-beats/) | ||
### Stochastic Methods | ||
@@ -144,2 +161,4 @@ | ||
The euclidean rhythm generator was inspired by the famous paper by Godfried Toussaint and the hexadecimal rhythm generator was inspired by Steven Yi's implementation in the CSound livecoding environment and a workshop given by him during the ICLC 2020 in Limerick. | ||
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 comming when programming the music. In many cases the rhythms, melodies, and more are expressed in some form of arrays that is iterated through based on the timing of the system. | ||
@@ -159,2 +178,8 @@ | ||
- [Godfried Toussaint - The Euclidean Algorithm Generates Traditional Musical Rhythms](http://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf) | ||
- [Steven Yi - Hexadecimal Beat](https://github.com/kunstmusik/csound-live-code/blob/master/doc/hexadecimal_beats.md) | ||
- [Bernhard Wagner - Rhythmic Patterns As Binary Numbers](http://bernhardwagner.net/musings/RPABN.html) | ||
## Missing Something? | ||
@@ -161,0 +186,0 @@ |
@@ -7,2 +7,3 @@ | ||
const Rand = require("../index").Stochastic; | ||
const TsL = require("../index").Translate; | ||
const Util = require("../index").Utility; | ||
@@ -23,2 +24,3 @@ | ||
testMod(); | ||
testTranslate(); | ||
testUtil(); | ||
@@ -57,2 +59,7 @@ | ||
test("Algo.euclid(16, 9, 1)"); | ||
test("Algo.hexBeat();"); | ||
test("Algo.hexBeat('f898');"); | ||
test("Algo.hexBeat('a9d2');"); | ||
test("Algo.hexBeat(573);"); | ||
} | ||
@@ -190,2 +197,40 @@ | ||
function testTranslate(){ | ||
pagebreak("Translate"); | ||
test("TsL.midiToNote(48);"); | ||
test("TsL.mton([60, 67, 72]);"); | ||
test("TsL.noteToMidi('c2');"); | ||
test("TsL.noteToMidi(['c2','d2','f#2']);"); | ||
test("TsL.ntom(['f-1','bb3','g#2']);"); | ||
test("TsL.midiToFreq(60);"); | ||
test("TsL.mtof([60, 67, 72]);"); | ||
test("TsL.noteToFreq('c2');"); | ||
test("TsL.noteToFreq(['c2','d2','f#2']);"); | ||
test("TsL.ntof(['f-1','bb3','g###2']);"); | ||
test("TsL.midiToNote(Mod.palindrome(Gen.spread(3, 48, 60)));"); | ||
test("TsL.semiToMidi(0);"); | ||
test("TsL.semiToMidi([0, 2, 7, -3, -12, 12]);"); | ||
test("TsL.stom([0, 2, 7, -3, -12, 12], 3);"); | ||
test("TsL.semiToFreq(0);"); | ||
test("TsL.semiToFreq([0, 2, 7, -3, -12, 12]);"); | ||
test("TsL.stof([0, 2, 7, -3, -12, 12], 3);"); | ||
test("TsL.midiToSemi(48);"); | ||
test("TsL.midiToSemi([48, 50, 55, 45, 36, 60]);"); | ||
test("TsL.mtos([48, 50, 55, 45, 36, 60], 3);"); | ||
test("TsL.scaleNames();"); | ||
test("TsL.setScale('harmonic minor', 'd');"); | ||
test("TsL.setScale('prometheus', 'A#');"); | ||
test("TsL.setScale('minor pentatonic', 'd');"); | ||
test("TsL.getScale();"); | ||
} | ||
function testUtil(){ | ||
@@ -192,0 +237,0 @@ pagebreak("Utility"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46773
14
1225
196
2
+ Addedtonal@^2.2.2
+ Addedtonal@2.2.2(transitive)
+ Addedtonal-array@2.2.2(transitive)
+ Addedtonal-chord@2.2.2(transitive)
+ Addedtonal-dictionary@2.2.2(transitive)
+ Addedtonal-distance@2.2.2(transitive)
+ Addedtonal-interval@2.2.2(transitive)
+ Addedtonal-key@2.2.2(transitive)
+ Addedtonal-note@2.2.2(transitive)
+ Addedtonal-pcset@2.2.2(transitive)
+ Addedtonal-roman-numeral@2.2.2(transitive)
+ Addedtonal-scale@2.2.2(transitive)