total-serialism
Advanced tools
Comparing version 1.3.1 to 1.4.1
@@ -28,3 +28,3 @@ //============================================================================== | ||
function hexBeat(hex="8"){ | ||
if (!hex.isNaN){ hex = hex.toString(); } | ||
if (!hex.isNaN){ hex = hex.toString(); } | ||
var a = []; | ||
@@ -87,2 +87,34 @@ for (i in hex){ | ||
} | ||
} | ||
} | ||
// Lindemayer String expansion | ||
// a recursive fractal algorithm to generate botanic (and more) | ||
// Default rule is 1 -> 10, 0 -> 1, where 1=A and 0=B | ||
// Rules are specified as a JS object consisting of strings or arrays | ||
// | ||
// @param {String} -> the axiom (the start) | ||
// @param {Int} -> number of generations | ||
// @param {Object} -> production rules | ||
// @return {String/Array} -> axiom determins string or array output | ||
// | ||
function linden(axiom=[1], iteration=3, rules={1: [1, 0], 0: [1]}){ | ||
axiom = (typeof axiom === 'number')? [axiom] : axiom; | ||
let asString = typeof axiom === 'string'; | ||
let res; | ||
for(let n=0; n<iteration; n++){ | ||
res = (asString)? "" : []; | ||
for(ch in axiom){ | ||
let char = axiom[ch]; | ||
let rule = rules[char]; | ||
if(rule){ | ||
res = (asString)? res + rule : res.concat(rule); | ||
}else{ | ||
res = (asString)? res + char : res.concat(char); | ||
} | ||
} | ||
axiom = res; | ||
} | ||
return res; | ||
} | ||
exports.linden = linden; |
@@ -129,16 +129,27 @@ //============================================================================== | ||
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)); | ||
// Generate a list of 12 semitones | ||
// then shuffle the list based on a random seed | ||
// | ||
// @return {Array} -> twelve-tone series | ||
// | ||
function twelveTone(){ | ||
return shuffle(Gen.spread(12)); | ||
} | ||
exports.twelveTone = twelveTone; | ||
var vals = []; | ||
for (var i=0; i<hi-lo; i++){ | ||
vals.push(i+lo); | ||
} | ||
vals = shuffle(vals); | ||
// Work in progress | ||
// 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; | ||
// return vals.slice(0, len); | ||
// } | ||
// exports.urn = urn; |
{ | ||
"name": "total-serialism", | ||
"version": "1.3.1", | ||
"version": "1.4.1", | ||
"description": "A set of methods for the generation and transformation of number sequences useful in algorithmic composition", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
100
README.md
@@ -9,13 +9,14 @@ # Total Serialism | ||
- [Generative Methods](#generative-methods) | ||
- [Algorithmic Methods](#algorithmic-methods) | ||
- [Stochastic Methods](#stochastic-methods) | ||
- [Transformative Methods](#transformative-methods) | ||
- [Missing Something?](#missing-something) | ||
- [Inspiration & Further Reading](#inspiration--further-reading) | ||
- [Missing Something?](#missing-something) | ||
- [License](#license) | ||
## Content | ||
# 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` : More complex methods to generate number sequences, such as euclidean rhythm generation, lindenmayer string expansion, fibonacci sequence, pisano periods and more. | ||
- `Algorithmic` : These are also generative methods, but are in general more complex algorithms, such as euclidean rhythm generation, lindenmayer string expansion, fibonacci sequence, pisano periods and more. | ||
- `Transform` : Methods that transform the array in some fashion. Think of methods such as reversing, palindrome, duplicating, inversing, interleaving and more. | ||
@@ -25,9 +26,27 @@ - `Stochastic` : Methods for procedurally generating number sequences based on various types of randomness, such as white noise (evenly distributed), rolling dice, flipping a coin and more. | ||
## Install | ||
# Newest features | ||
Generate Twelve-tone sequences | ||
```js | ||
// generate a twelve-tone series, influenced by the random seed | ||
// basically the same as: Mod.shuffle(Gen.spread(12)); | ||
Rand.twelveTone(); //=> [11, 0, 8, 2, 4, 9, 1, 6, 3, 5, 7, 10] | ||
``` | ||
Generate Lindenmayer system sequences | ||
```js | ||
// Cantor set as 0's and 1's in an array ruleset | ||
Algo.linden(1, 3, {1: [1, 0, 1], 0: [0, 0, 0]}); | ||
//=> [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1] | ||
``` | ||
# Install | ||
``` | ||
$ npm install total-serialism | ||
``` | ||
## Usage | ||
# Usage | ||
@@ -49,5 +68,5 @@ The entire library | ||
## Examples | ||
# Examples | ||
### Generative Methods | ||
## Generative Methods | ||
@@ -70,6 +89,10 @@ ```js | ||
### Algorithmic Methods | ||
## Algorithmic Methods | ||
```js | ||
const Algo = require('total-serialism').Algorithmic; | ||
``` | ||
### Euclidean Rhythm Generator | ||
```js | ||
// generate a euclidean rhythm evenly spacing n-beats amongst n-steps | ||
@@ -79,7 +102,11 @@ Algo.euclid(16, 9, 1); | ||
// inspired by Godfried Toussaints famous paper "The Euclidean Algorithm Generates Traditional Musical Rhythms" | ||
``` | ||
### Hexadecimal Rhythm Generator | ||
```js | ||
// 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 | ||
// inspired by Steven Yi's implementation in CSound Live Coding | ||
``` | ||
@@ -89,5 +116,44 @@ | ||
### Stochastic Methods | ||
### Lindenmayer String Expansion | ||
```js | ||
// Koch curve | ||
Algo.linden('F', 2, {F: 'F+F-F-F+F'}); | ||
//=> 'F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F' | ||
// Cantor set | ||
Algo.linden('A', 3, {A: 'ABA', B: 'BBB'}); | ||
//=> 'ABABBBABABBBBBBBBBABABBBABA' | ||
// Sierpinski Triangle | ||
Algo.linden('F-G-G', 1, {'F': 'F−G+F+G−F', 'G' : 'GG'}); | ||
//=> 'F−G+F+G−F-GG-GG' | ||
``` | ||
### L-System return Array with Ints | ||
```js | ||
Algo.linden(); | ||
//default => [1, 0, 1, 1, 0] | ||
// Cantor set as 0's and 1's in an array ruleset | ||
Algo.linden(1, 3, {1: [1, 0, 1], 0: [0, 0, 0]}); | ||
//=> [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1] | ||
// Set more complex rules for generating semitones for example | ||
var complexRules = { | ||
0: [0, 3, 7], | ||
3: [-1, 0], | ||
7: [12, 19, 0], | ||
12: [12, 0, 0, 5], | ||
5: [0, -3, 0] | ||
} | ||
Algo.linden(0, 2, complexRules); | ||
//=> [0, 3, 7, -1, 0, 12, 19, 0, -1, 0, 3, 7, 12, 0, 0, 5, 19, 0, 3, 7] | ||
``` | ||
## Stochastic Methods | ||
```js | ||
const Rand = require('total-serialism').Stochastic; | ||
@@ -112,5 +178,9 @@ | ||
Rand.shuffle([0, 5, 7, 12]); //=> [7, 5, 0, 12] | ||
// generate a twelve-tone series, influenced by the random seed | ||
// basically the same as: Mod.shuffle(Gen.spread(12)); | ||
Rand.twelveTone(); //=> [11, 0, 8, 2, 4, 9, 1, 6, 3, 5, 7, 10] | ||
``` | ||
### Transformative Methods | ||
## Transformative Methods | ||
@@ -159,3 +229,3 @@ ```js | ||
## Inspiration & Further Reading | ||
# Inspiration & Further Reading | ||
@@ -170,3 +240,3 @@ 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/dynamic*. | ||
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. | ||
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. | ||
@@ -191,7 +261,7 @@ - [Serialism on Wikipedia](https://en.wikipedia.org/wiki/Serialism) | ||
## Missing Something? | ||
# 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](https://github.com/tmhglnd/total-serialism/issues) and I will gladly look into it! | ||
## License | ||
# License | ||
@@ -198,0 +268,0 @@ The MIT License |
@@ -16,4 +16,13 @@ | ||
- test for negative values | ||
- test for strings vs numbers | ||
*/ | ||
var complexRules = { | ||
0: [0, 3, 7], | ||
3: [-1, 0], | ||
7: [12, 19, 0], | ||
12: [12, 0, 0, 5], | ||
5: [0, -3, 0] | ||
} | ||
testSerial(); | ||
@@ -24,3 +33,3 @@ testGen(); | ||
testMod(); | ||
testTranslate(); | ||
// testTranslate(); | ||
testUtil(); | ||
@@ -64,2 +73,16 @@ | ||
test("Algo.hexBeat(573);"); | ||
test("Algo.linden()"); | ||
// koch curve | ||
test("Algo.linden('F', 2, {F: 'F+F-F-F+F'})"); | ||
// cantor set | ||
test("Algo.linden('A', 3, {A: 'ABA', B: 'BBB'})"); | ||
// cantor set as 0's and 1's in an array ruleset | ||
test("Algo.linden(1, 3, {1: [1, 0, 1], 0: [0, 0, 0]})"); | ||
// Sierpinski Triangle | ||
test("Algo.linden('F-G-G', 1, {'F': 'F−G+F+G−F', 'G' : 'GG'})"); | ||
// usage with integers and arrays | ||
test("Algo.linden([1, 0, 1], 3, {0: [1], 1: [0, 1]})"); | ||
// more complex rules for semitone melodies (see above for rules) | ||
test("Algo.linden(0, 3, complexRules)"); | ||
} | ||
@@ -98,2 +121,9 @@ | ||
test("Rand.shuffle([0, 5, 7, 12])"); | ||
test("Rand.seed(4923)"); | ||
test("Rand.twelveTone()"); | ||
test("Rand.twelveTone()"); | ||
test("Rand.seed(4923)"); | ||
test("Rand.twelveTone()"); | ||
} | ||
@@ -282,2 +312,2 @@ | ||
console.log("====================================\n"); | ||
} | ||
} |
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
50554
1293
266