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();
//what is retrigger?
snare.retrigger = true;
var val1= D2;
var val2= "D4";

var chain = new Tone.CtrlMarkov({
val1.toString(): "D4",
"D4": "D2"
//"E2": ["D2","F2"],
//"F2": [{value:"E2",probability:0.4},{value:"G2", probability:0.4},{value:"A2", probability:0.1},{value:"E2", probability:0.1}],
//"F4": [{value:"F2",probability:0.4},{value:"A2", probability:0.4},{value:"E2", probability:0.1},{value:"B2", probability:0.1}],
//"G4": ["F4","B4"],
//"B4":[{value:"G4",probability:0.8},{value:"F4", probability:0.2}]
//snare:"B2"

});

var synth = new Tone.FMSynth().toMaster();

//set beginning
chain.value = val1;

//play 70 notes
for (var i=0;i<70;i++){
//schedule them all
synth.triggerAttackRelease(chain.value,0.1,i*0.4);
//get the next state in the Markov chain
chain.next();
console.log(chain.value)
}