Created
July 18, 2017 12:26
-
-
Save kobus1998/30f56dd1b1f199a3f9ee2282023ba19b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scribble = require('scribbletune') | |
const _ = require('lodash') | |
function randomInt (min, max) { | |
return Math.floor((Math.random() * max) + min) | |
} | |
function createPattern () { | |
let choices = ['x', '_'] | |
let pattern = '' | |
for (let i = 1; i < 64; i++) { | |
pattern += choices[Math.floor(Math.random()*choices.length)] | |
} | |
return pattern | |
} | |
function generateName (length) { | |
let chars = [], token = '' | |
let abc = ['a', 'b', 'c', 'd', 'e', 'f', | |
'g', 'h', 'i', 'j', 'k', 'l', | |
'm', 'n', 'o', 'p', 'q', 'r', | |
's', 't', 'u', 'v', 'w', 'x', | |
'y', 'z'] | |
let abcUp = abc.map(function(x){ return x.toUpperCase() }) | |
let nums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] | |
chars = chars.concat(abc, abcUp, nums) | |
for (let i = 1; i < length; i++) { | |
token += chars[randomInt(0, chars.length)] | |
} | |
return token | |
} | |
const notes = ['g', 'b', 'b', 'c', 'd', 'e', 'f'] | |
const scales = scribble.scales | |
const randomNote = _.shuffle(notes)[0] | |
const randomScale = _.shuffle(scales)[0] | |
for (let i = 1; i < 100; i++) { | |
let shuffle | |
if (randomInt(-1, 2) === 1) { | |
shuffle = true | |
} else { | |
shuffle = false | |
} | |
let midi = scribble.clip({ | |
notes: scribble.scale(randomNote, randomScale, randomInt(0, 8)), // this works too ['c3', 'd3', 'e3', 'f3', 'g3', 'a3', 'b3'] | |
pattern: createPattern(), | |
shuffle: true | |
}) | |
let name = generateName(16) | |
scribble.midi(midi, `./random-songs/${name}.mid`) | |
console.log(`Created midi with the name: ${name}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment