gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js tone js bpm frame speed step sequencer
- User
html css js tone js bpm frame speed step sequencer
- Assistant
html css js tone js bpm frame speed step sequencer
Creating a basic step sequencer using HTML, CSS, JavaScript combined with Tone.js for audio synthesis is a great project. Below is a simple example of a step sequencer where you can:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Step Sequencer with Tone.js</title>
<style>
body {
font-family: Arial, sans-serif;
background: #222;
color: #eee;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
h1 {
margin-bottom: 10px;
}
#controls {
margin-bottom: 20px;
}
label {
margin-right: 10px;
}
#bpm {
width: 60px;
}
#sequencer {
display: grid;
grid-template-columns: repeat(16, 30px);
grid-gap: 4px;
}
.step {
width: 30px;
height: 30px;
background: #444;
border-radius: 4px;
cursor: pointer;
user-select: none;
transition: background 0.2s;
}
.step.active {
background: #1abc9c;
}
.step.playing {
box-shadow: 0 0 8px #f39c12;
}
button {
background: #1abc9c;
border: none;
padding: 8px 15px;
color: #222;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
margin-left: 10px;
transition: background 0.3s;
}
button:hover {
background: #16a085;
}
</style>
</head>
<body>
<h1>Simple Step Sequencer</h1>
<div id="controls">
<label for="bpm">BPM:</label>
<input type="number" id="bpm" min="40" max="240" value="120" />
<button id="startStop">Start</button>
</div>
<div id="sequencer"></div>
<script src="https://cdn.jsdelivr.net/npm/tone/build/Tone.min.js"></script>
<script>
const steps = 16;
const sequencer = document.getElementById('sequencer');
const bpmInput = document.getElementById('bpm');
const startStopBtn = document.getElementById('startStop');
// Create step buttons
const stepButtons = [];
for (let i = 0; i < steps; i++) {
const step = document.createElement('div');
step.classList.add('step');
step.dataset.index = i;
step.addEventListener('click', () => {
step.classList.toggle('active');
});
sequencer.appendChild(step);
stepButtons.push(step);
}
// Setup Tone.js synth
const synth = new Tone.Synth({
oscillator: {
type: "square"
},
envelope: {
attack: 0.01,
decay: 0.1,
sustain: 0.3,
release: 0.2
}
}).toDestination();
// Setup Tone.Transport for timing
Tone.Transport.bpm.value = bpmInput.value;
let index = 0;
let isPlaying = false;
function repeat(time) {
// Highlight the current step
stepButtons.forEach((step, i) => {
step.classList.toggle('playing', i === index);
});
// If step is active, trigger synth
if (stepButtons[index].classList.contains('active')) {
// Use Tone.js to play note on 16th notes timing
synth.triggerAttackRelease("C4", "16n", time);
}
index = (index + 1) % steps;
}
startStopBtn.addEventListener('click', async () => {
if (!isPlaying) {
// Tone.js requires user interaction to start the audio context
await Tone.start();
Tone.Transport.scheduleRepeat(repeat, "16n");
Tone.Transport.start();
isPlaying = true;
startStopBtn.textContent = 'Stop';
} else {
Tone.Transport.stop();
Tone.Transport.cancel();
stepButtons.forEach(step => step.classList.remove('playing'));
index = 0;
isPlaying = false;
startStopBtn.textContent = 'Start';
}
});
bpmInput.addEventListener('input', () => {
const bpm = parseInt(bpmInput.value);
if (bpm >= 40 && bpm <= 240) {
Tone.Transport.bpm.value = bpm;
}
});
</script>
</body>
</html>
Tone.Transport schedules a repeat callback (repeat) every 16th note.If you want to add multiple rows for different sounds, or different instruments, or even sequence patterns, let me know! This is a solid base for a classic step sequencer.
Not yet included in a published release.