Skip to content

Instantly share code, notes, and snippets.

Avatar

Walmik Deshpande walmik

View GitHub Profile
View random-chord-progressions.js
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++) {
View chord-progressions.js
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 Jul 19, 2019
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
View scribble-drummer.js
// 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',
View simpleMelody.js
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 Oct 22, 2019
Create a commonly used dance music riff using just Scribbletune
View riff.js
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 Feb 27, 2018
Code snippet to load a couple of wave files (from disc) and play em in a sequence
View webaudio-seq.js
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 Oct 29, 2013
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
View double-check.js
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;
You can’t perform that action at this time.