Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created July 18, 2017 12:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobus1998/30f56dd1b1f199a3f9ee2282023ba19b to your computer and use it in GitHub Desktop.
Save kobus1998/30f56dd1b1f199a3f9ee2282023ba19b to your computer and use it in GitHub Desktop.
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