Hi, i want to create a music loop sequence machine .is there a simpler way to create a sequencer (looping function) using JUST conditions and actions or will javascript be needed. If so, how would the code be added to Gdevelop? Thanks so much !!
function track() {
//instruments and their sounds
const kick = new Tone.Player('./Samples/kick-tape.wav').toMaster();
const snare = new Tone.Player('./Samples/snare-tape.wav').toMaster();
const hihat = new Tone.Player('./Samples/hihat-808.wav').toMaster();
const clap = new Tone.Player('./Samples/clap-tape.wav').toMaster();
let index = 0; //counter
//play/pause button
const pow = document.querySelector('.powerButton').addEventListener('click', playpause);
Tone.Transport.scheduleRepeat(rep, '8n');
function playpause() {
Tone.Transport.toggle();
event.target.classList.toggle('powerPush');
}
//clear button
var actButs = document.getElementsByClassName('allButs');
const clr = document.querySelector('.clearButton').addEventListener('click', clear);
function clear() {
[].forEach.call(actButs, function(e) {
e.classList.remove('active');
});
event.target.classList.toggle('clearPush');
}
//drum selection
const buts = document.querySelectorAll('.allButs');
for (i = 0; i < buts.length; ++i) {
buts[i].addEventListener('click', toggle);
}
function toggle() {
event.target.classList.toggle('active');
}
//looping function
function rep(){
let step = (index % 8) + 1;
console.log(step);
let kickIn = document.querySelector(`.kickButs input:nth-child(${step})`);
if (kickIn.classList.contains('active')) {
kick.start();
}
let snareIn = document.querySelector(`.snareButs input:nth-child(${step})`);
if (snareIn.classList.contains('active')) {
snare.start();
}
let hihatIn = document.querySelector(`.hihatButs input:nth-child(${step})`);
if (hihatIn.classList.contains('active')) {
hihat.start();
}
let clapIn = document.querySelector(`.clapButs input:nth-child(${step})`);
if (clapIn.classList.contains('active')) {
clap.start();
}
//dot counter functionality
let dotCounter = document.querySelector(`.dot:nth-child(${step})`); //light up counter when beat is on it
dotCounter.classList.add('dotOn');
if (step != 1) {
dotKill = document.querySelector(`.dot:nth-child(${step - 1})`); //remove class of previously lit button
dotKill.classList.remove('dotOn');
} else {
dotCounter = document.querySelector(`.dot:nth-child(${8})`); //if first button is lit, dim the last button
dotCounter.classList.remove('dotOn');
}
console.log(step);
index++;
}
//tempo
const tempoSlider = document.querySelector('.tempoSlide');
const tempoTrack = document.querySelector('.tempoNum');
tempoSlider.addEventListener('input', tempoOut);
function tempoOut() {
tempoTrack.innerHTML = tempoSlider.value;
Tone.Transport.bpm.value = tempoSlider.value;
}
//volume
const volSlide = document.querySelector('.volumeSlide');
const volTrack = document.querySelector('.volumeNum');
volSlide.addEventListener('input', volOut);
function volOut() {
volTrack.innerHTML = `${volSlide.value} dB`;
Tone.Master.volume.value = volSlide.value;
}
}
track();