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
Sure! I can help you create a basic step sequencer using HTML, CSS, and JavaScript with Tone.js for sound generation. The sequencer will allow you to control the BPM (speed), and step through frames (steps) for a pattern like a 6-step sequencer.
Here’s a simple example:
<!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;
background: #222;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem;
height: 100vh;
}
h1 {
margin-bottom: 1rem;
}
.sequencer {
display: flex;
gap: 10px;
margin-bottom: 1rem;
}
.step {
width: 50px;
height: 50px;
background: #444;
border-radius: 5px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
user-select: none;
transition: background-color 0.3s, transform 0.2s;
}
.step.active {
background: #0f0;
}
.step.playing {
transform: scale(1.2);
border: 2px solid #0f0;
}
.controls {
margin-bottom: 1rem;
}
label {
margin-right: 8px;
}
input[type="range"] {
width: 150px;
}
button {
padding: 0.5rem 1rem;
font-weight: bold;
background: #0f0;
border: none;
border-radius: 5px;
cursor: pointer;
color: #222;
transition: background-color 0.3s;
}
button:hover {
background: #0c0;
}
</style>
</head>
<body>
<h1>6-Step Sequencer (Tone.js)</h1>
<div class="sequencer" id="sequencer">
<!-- Steps will be generated here -->
</div>
<div class="controls">
<label for="bpm">BPM:</label>
<input id="bpm" type="range" min="60" max="180" value="120" />
<span id="bpmVal">120</span>
</div>
<button id="playBtn">Play</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.39/Tone.min.js"></script>
<script>
const stepsCount = 6;
const sequencer = document.getElementById('sequencer');
const bpmSlider = document.getElementById('bpm');
const bpmVal = document.getElementById('bpmVal');
const playBtn = document.getElementById('playBtn');
// Create the steps UI
const steps = [];
for (let i = 0; i < stepsCount; i++) {
const stepEl = document.createElement('div');
stepEl.classList.add('step');
stepEl.textContent = i + 1;
stepEl.dataset.step = i;
sequencer.appendChild(stepEl);
steps.push(stepEl);
stepEl.addEventListener('click', () => {
stepEl.classList.toggle('active');
});
}
// Tone.js synth
const synth = new Tone.Synth().toDestination();
// Sequencer state
let currentStep = 0;
let isPlaying = false;
let intervalId = null;
// Update BPM display and Tone.Transport BPM
bpmSlider.addEventListener('input', () => {
bpmVal.textContent = bpmSlider.value;
Tone.Transport.bpm.value = bpmSlider.value;
});
// Initialize Tone.Transport BPM
Tone.Transport.bpm.value = bpmSlider.value;
// Play / Pause function
function playSequencer() {
if (!isPlaying) {
if (Tone.context.state !== 'running') {
Tone.context.resume();
}
currentStep = 0;
isPlaying = true;
playBtn.textContent = 'Pause';
// Start the Tone.Transport and schedule repeat
Tone.Transport.scheduleRepeat(repeat, "8n"); // 8th notes
Tone.Transport.start();
} else {
isPlaying = false;
playBtn.textContent = 'Play';
Tone.Transport.stop();
Tone.Transport.cancel();
steps.forEach(s => s.classList.remove('playing'));
}
}
playBtn.addEventListener('click', playSequencer);
function repeat(time) {
// Remove playing class from all
steps.forEach((step) => step.classList.remove('playing'));
const stepEl = steps[currentStep];
stepEl.classList.add('playing');
if (stepEl.classList.contains('active')) {
// Play a note - you can choose your own notes here
// For simplicity, play C4 on all active steps
synth.triggerAttackRelease("C4", "8n", time);
}
currentStep++;
if (currentStep >= stepsCount) currentStep = 0;
}
</script>
</body>
</html>
synth.triggerAttackRelease("C4", "8n", time);stepsCount and updating the layout.If you want me to help with a more complex sequencer (multiple instruments, patterns, etc.), just let me know!
Not yet included in a published release.