Interpolated Probability Drums
by yotammann
HTML
<script src="https://tonejs.github.io/build/Tone.js"></script>
<!-- <script src="https://tonejs.github.io/Logo/build/Waveform.js"></script> -->
<input id="kick" type = "range" min="0" max="100">
<input id="snare" type = "range" min="0" max="100">
JavaScript
var kit = new Tone.MultiPlayer({
"kick" : "https://tonejs.github.io/examples/audio/505/kick.mp3",
"snare" : "https://tonejs.github.io/examples/audio/505/snare.mp3",
"hh" : "https://tonejs.github.io/examples/audio/505/hh.mp3"
}, function(){
Tone.Transport.start()
}).toMaster()
var kickProbability = new Tone.CtrlInterpolate([
[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]
])
var snareProbability = new Tone.CtrlInterpolate([
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]
])
//var snareProbability = [0, 0, 0.8, 0]
//var hhProbability = [0.25, 0.25, 0.4, 0.25]
var pattern = new Tone.Pattern(function(time, index){
if (Math.random() < kickProbability.value[index]){
kit.start("kick", time)
}
if (Math.random() < snareProbability.value[index]){
kit.start("snare", time)
}
//if (Math.random() < hhProbability[index]){
// kit.start("hh", time)
//}
}, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 'up').start()
pattern.interval = 0.125
document.querySelector('#kick').addEventListener('input',function(e){
kickProbability.index = parseInt(e.target.value)/100
})
document.querySelector('#snare').addEventListener('input',function(e){
snareProbability.index = parseInt(e.target.value)/100
})
//loop.probability = 0.5