Skip to content

Instantly share code, notes, and snippets.

View walmik's full-sized avatar

Walmik Deshpande walmik

View GitHub Profile
const _ = require('lodash');
const scribble = require('scribbletune');
const setOfNotes = scribble
.scale('C3 lydian')
.concat(scribble.scale('C4 lydian')); // or simply scribble.scale('C3 major') OR manually set the notes
const pattern = 'x__[xx]x_x_'.repeat(8); // or a simple one 'x___'.repeat(4)
const count = pattern.replace(/[^x]/g, '').length;
const notes = [];
for (let i = 0; i < count; i++) {
const pickOne = arr =>
arr.length > 1 ? arr[Math.round(Math.random())] : arr[0];
const dice = () => !!Math.round(Math.random());
const getProgFactory = ({ T, P, D }) => {
return (count = 4) => {
const chords = [];
// Push root/tonic
chords.push(pickOne(T));
@walmik
walmik / scribble-drummer.js
Last active July 19, 2019 20:22
This a simple script that will create a few MIDI files with a slight variation each time you run it with nodejs on the terminal
// Make sure you have Node version 8+ installed locally and you have run `npm install scribbletune` before running this script
const scribble = require('scribbletune');
const ptn = 'xxxx'.repeat(7);
const A = 'xxx[x[RR]]';
const B = 'xx[x[RR]][x[RR]]';
const C = 'x-[x[RR]]';
const kick = scribble.clip({
pattern: ptn + A + ptn + B + ptn + A + ptn + C,
notes: 'c4',
const scribble = require('scribbletune');
const chords = scribble.getChordsByProgression('C4 minor', 'ii III ii v'); //i III ii v
const notes = [];
let pattern = '';
chords.split(' ').forEach((c, i) => {
const chord = scribble.chord(c);
if (i % 2 !== 0) {
// use 2 quarter notes
notes.push(chord[0]);
@walmik
walmik / riff.js
Last active October 22, 2019 13:50
Create a commonly used dance music riff using just Scribbletune
const scribble = require('scribbletune');
const getRandomPattern = function(count = 8) {
let str = '[x-]R';
for (let i = 1; i < count; i++) {
str += Math.round(Math.random()) ? '[x-]R' : 'R[x-]';
}
return str;
};
@walmik
walmik / webaudio-seq.js
Created February 27, 2018 07:35
Code snippet to load a couple of wave files (from disc) and play em in a sequence
window.onload = init;
var context;
var bufferLoader;
function BufferLoader(context, urlList, callback) {
this.context = context;
this.urlList = urlList;
this.onload = callback;
this.bufferList = new Array();
this.loadCount = 0;
@walmik
walmik / double-check.js
Created October 29, 2013 02:46
Given an array of integers and an integer return true if any 2 integers of the array add up to a number equal to the integer For example: fn ( [2,1,3,4], 4 ); should return true
function doubleCheck(arr, intgr) {
var bool = false;
arr = arr.sort(function(a,b) {return a-b;});
console.log(arr);
while(arr.length) {
var num = arr.shift();
for(var i=0; i<arr.length; i++) {
console.log('iteration' + arr[i]);
if(num + arr[i] === intgr) {
return true;