gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
chiptune sequencer share html
- User
chiptune sequencer share html
- Assistant
chiptune sequencer share html
Certainly! Here's a simple example of a Chiptune sequencer made with HTML, CSS, and JavaScript. This example uses the Web Audio API to produce square wave tones (typical in chiptune music) and allows you to toggle steps in a basic 8-step sequencer for 3 different notes.
You can save the following code as chiptune_sequencer.html and open it in your browser to start creating simple chip-style sequences.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chiptune Sequencer</title>
<style>
body {
font-family: monospace, monospace;
background: #111;
color: #0f0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding: 20px;
}
h1 {
margin-bottom: 10px;
}
.sequencer {
display: grid;
grid-template-columns: repeat(8, 40px);
grid-gap: 5px;
margin-bottom: 20px;
}
.step {
width: 40px;
height: 40px;
background: #222;
border: 2px solid #0f0;
cursor: pointer;
transition: background 0.3s;
}
.step.active {
background: #0f0;
}
.step.playing {
border-color: #ff0;
box-shadow: 0 0 10px #ff0;
}
.row-label {
text-align: right;
padding-right: 10px;
line-height: 40px;
user-select: none;
}
.row-container {
display: flex;
align-items: center;
margin-bottom: 5px;
}
button {
background: #222;
color: #0f0;
border: 2px solid #0f0;
padding: 10px 20px;
font-size: 1rem;
cursor: pointer;
margin-bottom: 20px;
transition: background 0.3s;
}
button:hover {
background: #0f0;
color: #111;
}
</style>
</head>
<body>
<h1>Simple Chiptune Sequencer</h1>
<div id="sequencer-container"></div>
<button id="play-btn">Play</button>
<script>
// Configuration
const numSteps = 8;
const numRows = 3;
// Frequencies for 3 notes typical for chiptune (C4, E4, G4 range)
const noteFreqs = [261.63, 329.63, 392.00]; // C4, E4, G4
// Sequencer state: a 2D array of booleans (rows x steps)
const sequencerState = Array.from({ length: numRows }, () =>
Array(numSteps).fill(false)
);
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Create the sequencer grid UI
const container = document.getElementById('sequencer-container');
const rows = ['C4', 'E4', 'G4'];
rows.forEach((label, rowIndex) => {
const rowDiv = document.createElement('div');
rowDiv.classList.add('row-container');
const rowLabel = document.createElement('div');
rowLabel.classList.add('row-label');
rowLabel.textContent = label;
rowDiv.appendChild(rowLabel);
const sequencerRow = document.createElement('div');
sequencerRow.classList.add('sequencer');
for (let step = 0; step < numSteps; step++) {
const stepDiv = document.createElement('div');
stepDiv.classList.add('step');
stepDiv.dataset.row = rowIndex;
stepDiv.dataset.step = step;
stepDiv.addEventListener('click', () => {
sequencerState[rowIndex][step] = !sequencerState[rowIndex][step];
stepDiv.classList.toggle('active');
});
sequencerRow.appendChild(stepDiv);
}
rowDiv.appendChild(sequencerRow);
container.appendChild(rowDiv);
});
let isPlaying = false;
let currentStep = 0;
let intervalId;
function playStep(step) {
// Animate the playing column
document.querySelectorAll('.step.playing').forEach(el => {
el.classList.remove('playing');
});
for (let row = 0; row < numRows; row++) {
const stepDiv = document.querySelector(
`.step[data-row="${row}"][data-step="${step}"]`
);
stepDiv.classList.add('playing');
if (sequencerState[row][step]) {
playNote(noteFreqs[row]);
}
}
}
function playNote(frequency) {
const osc = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
osc.type = 'square'; // Typical chiptune waveform
osc.frequency.value = frequency;
gainNode.gain.setValueAtTime(0.1, audioCtx.currentTime);
osc.connect(gainNode);
gainNode.connect(audioCtx.destination);
osc.start();
// Stop after a short duration
osc.stop(audioCtx.currentTime + 0.15);
// Fade out quickly to avoid clicks
gainNode.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + 0.15);
}
function playSequence() {
if (!isPlaying) {
isPlaying = true;
currentStep = 0;
intervalId = setInterval(() => {
playStep(currentStep);
currentStep = (currentStep + 1) % numSteps;
}, 300); // 300ms per step (~200 BPM)
} else {
isPlaying = false;
clearInterval(intervalId);
// Remove playing highlight
document.querySelectorAll('.step.playing').forEach(el => {
el.classList.remove('playing');
});
}
playBtn.textContent = isPlaying ? 'Stop' : 'Play';
}
const playBtn = document.getElementById('play-btn');
playBtn.addEventListener('click', () => {
// Resume AudioContext on user interaction if needed
if (audioCtx.state === 'suspended') {
audioCtx.resume().then(() => playSequence());
} else {
playSequence();
}
});
</script>
</body>
</html>
Let me know if you want a more advanced version or specific features!
Not yet included in a published release.