JSFiddle - React, Tailwind, and code Playground
by Eve Weinberg
HTML
<script src="https://tonejs.github.io/CDN/r6/Tone.js"></script>
JavaScript
var snareUrl = "https://tonejs.github.io/Tone.js/examples/audio/505/snare.mp3";
var snare = new Tone.Player(snareUrl).toMaster();
var faster = 0
var Gotfaster =0.5
//what is retrigger?
snare.retrigger = true;
var var1 = "D1";
var var2 = "D2";
var var3 = "D3";
var obj = {};
// fill the object with the data using the object[property]
obj[var1] = var2; // this is equal to obj.D1 = "D2"
obj[var2] = [ var2, var3 ]; // this is equal to obj.D2 = [ "D1", "D3" ]
obj[var3] = var1; // this is equal to obj.D3 = "D1"
var chain = new Tone.CtrlMarkov({obj});
//var chain = new Tone.CtrlMarkov({
//"C2": "E2",
//"E2": "G2",
//"G2": "C3",
//"C3": "E3",
//"E3": "B3",
//"B3": "C4",
//"C4": "E4",
//"E4": "D2",
//"D2": "C2"
//});
var synth = new Tone.FMSynth().toMaster();
//set beginning
chain.value = obj[var1];
//play 70 notes
for (var i=0;i<70;i++){
if (faster <.5){
Gotfaster = 0.5-faster
} else{
Gotfaster=.09
}
//schedule them all, note, time, velocity
synth.triggerAttackRelease(chain.value,0.2,i*(Gotfaster));
//get the next state in the Markov chain
chain.next();
console.log(chain.value)
faster = faster+.0044
//console.log("faster "+ faster)
//console.log("Gotfaster "+ Gotfaster)
}