Interpolated Probability Drums

by yotammann

HTML

<script src="https://tonejs.github.io/CDN/r6/Tone.min.js"></script>
<script src="https://tonejs.github.io/build/Tone.js"></script>
<!-- <script src="https://tonejs.github.io/Logo/build/Waveform.js"></script> -->
<div>

</div>

JavaScript

var synth = new Tone.Synth({
	'oscillator.type' : 'sawtooth2',
  envelope : {
  	attack : 0.01,
    decay : 0.2,
    sustain : 0
  }
}).toMaster()

var notes = ["C4", "D4", "E4", "F#4", "G4", "A4", "B4"]
var noteIndex = 0

function pickRandom(){
	var nextRandom = Math.floor(Math.random() * notes.length)
  if (nextRandom !== noteIndex){
    return nextRandom
  } else {
  	return pickRandom()
  }
}

var loop = new Tone.Loop(function(time){
	var value = notes[noteIndex]
  noteIndex = pickRandom()
	synth.triggerAttack(value, time)
}, 0.1).start()


Tone.Transport.start()