gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js tone js bpm speed step sequencer
- User
html css js tone js bpm speed step sequencer
- Assistant
html css js tone js bpm speed step sequencer
Certainly! Below is a simple example of a step sequencer built with HTML, CSS, and JavaScript using the Tone.js library. It includes controls for BPM (tempo) and step speed, and a grid of buttons to toggle steps on/off for a single drum sound (kick). You can extend this to multiple sounds or more complex instruments.
<!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: 2rem;
}
h1 {
margin-bottom: 0.5rem;
}
.sequencer {
display: grid;
grid-template-columns: repeat(16, 40px);
grid-gap: 6px;
margin: 1rem 0;
}
.step {
width: 40px;
height: 40px;
background: #444;
border-radius: 4px;
cursor: pointer;
transition: background 0.2s;
}
.step.active {
background: #0f0;
}
.step.playing {
box-shadow: 0 0 10px #0f0;
}
.controls {
margin-top: 1rem;
display: flex;
gap: 20px;
align-items: center;
}
label {
font-size: 14px;
}
input[type="range"] {
width: 150px;
}
button {
padding: 0.5rem 1rem;
background: #0f0;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
color: #222;
transition: background 0.3s;
}
button:hover {
background: #0c0;
}
</style>
</head>
<body>
<h1>Step Sequencer (Kick Drum)</h1>
<div class="sequencer" id="sequencer">
<!-- Steps will be created by JS -->
</div>
<div class="controls">
<label for="bpm">BPM: <span id="bpmValue">120</span></label>
<input type="range" id="bpm" min="60" max="200" value="120" />
<button id="playBtn">Play</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/tone@14.7.77/build/Tone.min.js"></script>
<script>
const stepsCount = 16;
const sequencerEl = document.getElementById('sequencer');
const playBtn = document.getElementById('playBtn');
const bpmSlider = document.getElementById('bpm');
const bpmDisplay = document.getElementById('bpmValue');
// Create step buttons
let steps = [];
for(let i = 0; i < stepsCount; i++) {
const step = document.createElement('div');
step.classList.add('step');
step.dataset.index = i;
sequencerEl.appendChild(step);
steps.push(step);
}
// Step active states
let activeSteps = new Array(stepsCount).fill(false);
steps.forEach((step, i) => {
step.addEventListener('click', () => {
activeSteps[i] = !activeSteps[i];
step.classList.toggle('active', activeSteps[i]);
});
});
// Kick drum synth using Tone.js
const kick = new Tone.MembraneSynth().toDestination();
// Tone.js Transport setup
Tone.Transport.bpm.value = bpmSlider.value;
Tone.Transport.loop = true;
Tone.Transport.loopStart = 0;
Tone.Transport.loopEnd = '1m'; // 1 measure loop (4/4)
let currentStep = 0;
function scheduleStep(time) {
// Highlight current step
steps.forEach((step, i) => {
step.classList.toggle('playing', i === currentStep);
});
// Play kick if step is active
if(activeSteps[currentStep]) {
kick.triggerAttackRelease('C2', '8n', time);
}
currentStep = (currentStep + 1) % stepsCount;
}
// Schedule repeat every 16th note
Tone.Transport.scheduleRepeat(scheduleStep, '16n');
// Play button control
playBtn.addEventListener('click', async () => {
if(Tone.Transport.state !== 'started') {
await Tone.start();
Tone.Transport.start();
playBtn.textContent = 'Pause';
} else {
Tone.Transport.pause();
playBtn.textContent = 'Play';
steps.forEach(step => step.classList.remove('playing'));
currentStep = 0;
}
});
// BPM slider control
bpmSlider.addEventListener('input', () => {
const bpm = +bpmSlider.value;
Tone.Transport.bpm.value = bpm;
bpmDisplay.textContent = bpm;
});
</script>
</body>
</html>
Tone.Player.Let me know if you'd like me to help with more complex features!