gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js tone js bpm speed frame (6∻) step sequencer
- User
html css js tone js bpm speed frame (6∻) step sequencer
- Assistant
html css js tone js bpm speed frame (6∻) step sequencer
Creating a simple step sequencer with HTML, CSS, and JavaScript using Tone.js is a great project! Below is a basic example of a 6-step sequencer that plays a simple synth note at a given BPM. You can toggle each step on/off, adjust BPM, and the sequencer will run accordingly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>6-Step Sequencer with Tone.js</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 30px;
background: #222;
color: white;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
margin-bottom: 20px;
}
.sequencer {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.step {
width: 50px;
height: 50px;
background: #444;
border-radius: 5px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
user-select: none;
font-weight: bold;
font-size: 1.2rem;
color: #bbb;
transition: background-color 0.2s;
}
.step.active {
background: #0f0;
color: #000;
font-weight: 900;
}
.step.playing {
box-shadow: 0 0 10px 3px yellow;
}
.controls {
margin-top: 15px;
display: flex;
align-items: center;
gap: 10px;
}
input[type=number] {
padding: 5px;
width: 60px;
font-size: 1rem;
border-radius: 4px;
border: none;
outline: none;
text-align: center;
}
button {
padding: 8px 15px;
font-size: 1rem;
border: none;
border-radius: 6px;
cursor: pointer;
background: #0a0;
color: white;
transition: background-color 0.3s;
}
button:hover {
background: #0d0;
}
</style>
</head>
<body>
<h1>6-Step Sequencer (Tone.js)</h1>
<div class="sequencer" id="sequencer">
<!-- Steps generated by JS -->
</div>
<div class="controls">
<label for="bpm">BPM:</label>
<input type="number" id="bpm" min="40" max="300" value="120" />
<button id="startStopBtn">Start</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/tone@14.8.39/build/Tone.min.js"></script>
<script>
// Variables
const stepsCount = 6;
let sequenceSteps = new Array(stepsCount).fill(false);
let currentStep = 0;
let isPlaying = false;
// DOM Elements
const sequencerEl = document.getElementById('sequencer');
const bpmInput = document.getElementById('bpm');
const startStopBtn = document.getElementById('startStopBtn');
// Create synth sound
const synth = new Tone.Synth({
oscillator: {
type: "triangle"
},
envelope: {
attack: 0.01,
decay: 0.2,
sustain: 0.3,
release: 1
}
}).toDestination();
// Create GUI steps buttons
for (let i = 0; i < stepsCount; i++) {
const step = document.createElement('div');
step.classList.add('step');
step.textContent = i + 1;
step.dataset.index = i;
step.addEventListener('click', () => {
sequenceSteps[i] = !sequenceSteps[i];
step.classList.toggle('active', sequenceSteps[i]);
});
sequencerEl.appendChild(step);
}
// Tone.js Transport Setup
Tone.Transport.scheduleRepeat(repeat, "16n"); // sixteenth note step
// Function called each step
function repeat(time) {
if (!isPlaying) return;
// Remove playing class from previous steps
document.querySelectorAll('.step').forEach((el, i) => {
el.classList.toggle('playing', i === currentStep);
});
// Play sound if step is active
if (sequenceSteps[currentStep]) {
// Trigger synth note - simple C4 note
synth.triggerAttackRelease("C4", "8n", time);
}
currentStep = (currentStep + 1) % stepsCount;
}
// Start / Stop button handler
startStopBtn.addEventListener('click', async () => {
if (!isPlaying) {
// Start Tone Transport (this requires user interaction)
await Tone.start();
Tone.Transport.bpm.value = parseInt(bpmInput.value);
currentStep = 0;
isPlaying = true;
Tone.Transport.start();
startStopBtn.textContent = "Stop";
} else {
isPlaying = false;
Tone.Transport.stop();
document.querySelectorAll('.step').forEach(el => el.classList.remove('playing'));
startStopBtn.textContent = "Start";
}
});
// Update BPM live when changed
bpmInput.addEventListener('change', () => {
let bpm = parseInt(bpmInput.value);
if (bpm < 40) bpm = 40;
if (bpm > 300) bpm = 300;
bpmInput.value = bpm;
Tone.Transport.bpm.value = bpm;
});
</script>
</body>
</html>
.html file.If you'd like to expand this, you can:
Let me know if you want help with any advanced feature!
Not yet included in a published release.