html chiptune tracker bpm rows per tracks patterns rows per pattern synth per instrument…
- User
html chiptune tracker bpm rows per tracks patterns rows per pattern synth per instrument custom osc volume detune adsr filter noise share song shortcuts loop "/#" no demo
- Assistant
It looks like you're looking to create or understand an HTML-based chiptune tracker (a music tracker interface suitable for making chiptune music) that supports features like:
- BPM control
- Rows per track
- Patterns and rows per pattern
- Synth per instrument with custom oscillator settings
- Volume, detune, ADSR envelope, filter and noise controls
- Ability to share the song (via URL fragment like "/#")
- Keyboard shortcuts
- Looping
- No demo mode
Below is a brief explanation of these features and a minimal example outline of an HTML + JS chiptune tracker that covers key parts to get you started.
What is a Chiptune Tracker?
A tracker is a kind of sequencer interface that shows patterns as rows and columns with notes and commands, typical for chiptunes/music with limited channels.
- BPM (Beats Per Minute): Controls tempo
- Rows per Pattern: Number of rows/steps in the pattern
- Patterns: A sequence of note rows
- Synth per instrument: each instrument has its own sound generating parameters
- Custom oscillator: oscillator waveform like square, sawtooth, triangle, noise
- Volume, detune, ADSR (Attack, Decay, Sustain, Release), filter, noise: synth parameters
- Share Song: Save song state in URL fragment or similar
- Keyboard shortcuts: navigate, play, stop, add notes, etc.
- Loop: Play song looping
Recommended Libraries
- For audio synthesis: the Web Audio API is standard.
- For oscillator types, you can use native oscillators or simulate custom oscillators.
- For UI, basic HTML + CSS + JS is enough.
- Use
requestAnimationFrameorsetTimeoutfor playback timing.
Minimal Example Outline
Below is the skeleton of a simple chiptune tracker implementing some of those features.
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Simple Chiptune Tracker</title> <style> body { font-family: monospace; background:#121212; color:#ddd; } .tracker { display: grid; grid-template-columns: repeat(4, 80px); gap: 4px; margin: 1rem; } .cell { padding: 4px; border: 1px solid #333; text-align: center; cursor:pointer; } .cell.selected { background: #444; } button { margin: 0.5rem; } input[type=range] { width: 100px; } </style> </head> <body> <h1>Simple Chiptune Tracker</h1> <div> BPM: <input type="number" id="bpm" value="125" min="30" max="300" /> Rows/Pattern: <input type="number" id="rowsPerPattern" value="16" min="4" max="64" /> </div> <div> <button id="playBtn">Play</button> <button id="stopBtn">Stop</button> <button id="loopBtn">Loop: Off</button> </div> <div id="tracker" class="tracker"></div> <h2>Instrument</h2> <div> Oscillator: <select id="oscType"> <option value="square">Square</option> <option value="sawtooth">Sawtooth</option> <option value="triangle">Triangle</option> <option value="sine">Sine</option> <option value="noise">Noise</option> </select> </div> <div> Volume: <input type="range" id="volume" min="0" max="1" step="0.01" value="0.5" /> </div> <div> Detune: <input type="range" id="detune" min="-100" max="100" step="1" value="0" /> </div> <div> ADSR (ms) A: <input type="number" id="attack" value="10" min="0" max="1000" /> D: <input type="number" id="decay" value="50" min="0" max="1000" /> S: <input type="number" id="sustain" value="0.8" min="0" max="1" step="0.01" /> R: <input type="number" id="release" value="100" min="0" max="1000" /> </div> <h2>Sharing</h2> <button id="shareBtn">Share Song (copy URL)</button> <script> // Constants const notes = ["C-4", "C#4", "D-4", "D#4", "E-4", "F-4", "F#4", "G-4", "G#4", "A-4", "A#4", "B-4", "C-5"]; const noteFrequencies = { "C-4": 261.63, "C#4": 277.18, "D-4": 293.66, "D#4": 311.13, "E-4": 329.63, "F-4": 349.23, "F#4": 369.99, "G-4": 392.00, "G#4": 415.30, "A-4": 440.00, "A#4": 466.16, "B-4": 493.88, "C-5": 523.25 }; let audioCtx = new (window.AudioContext || window.webkitAudioContext)(); let isPlaying = false; let loop = false; let currentRow = 0; let timerId; let bpmInput = document.getElementById("bpm"); let rowsPerPatternInput = document.getElementById("rowsPerPattern"); let trackerDiv = document.getElementById("tracker"); let playBtn = document.getElementById("playBtn"); let stopBtn = document.getElementById("stopBtn"); let loopBtn = document.getElementById("loopBtn"); // Synth instrument settings let instrument = { oscType: "square", volume: 0.5, detune: 0, attack: 0.01, decay: 0.05, sustain: 0.8, release: 0.1, noise: false }; let rowsPerPattern = parseInt(rowsPerPatternInput.value); let tracks = 4; // Number of tracks // Pattern data [pattern][row][track] => note string or null // For simplicity, 1 pattern only here let pattern = []; for(let r=0; r<rowsPerPattern; r++){ let row = []; for(let t=0; t<tracks; t++){ row.push(null); } pattern.push(row); } // UI setup function function buildTracker(){ trackerDiv.innerHTML = ""; rowsPerPattern = parseInt(rowsPerPatternInput.value); pattern.length = 0; for(let r=0; r<rowsPerPattern; r++){ let row = []; for(let t=0; t<tracks; t++){ row.push(null); } pattern.push(row); } for(let r=0; r<rowsPerPattern; r++){ for(let t=0; t<tracks; t++){ let cell = document.createElement("div"); cell.classList.add("cell"); cell.dataset.row = r; cell.dataset.track = t; cell.textContent = "---"; cell.addEventListener("click", () => { cycleNote(cell); }); trackerDiv.appendChild(cell); } } } // Cycle note on click (empty -> C-4 -> D-4 -> ... -> empty) function cycleNote(cell){ let r = parseInt(cell.dataset.row); let t = parseInt(cell.dataset.track); let current = pattern[r][t]; let index = current ? notes.indexOf(current) : -1; index++; if(index >= notes.length){ index = -1; // empty } pattern[r][t] = index === -1 ? null : notes[index]; cell.textContent = pattern[r][t] || "---"; } // Audio play note function with ADSR envelope function playNote(freq, time, duration){ if(instrument.noise){ // Noise oscillator let bufferSize = audioCtx.sampleRate * duration; let buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate); let data = buffer.getChannelData(0); for(let i=0; i<bufferSize; i++){ data[i] = (Math.random() * 2 - 1) * instrument.volume; } let noiseSource = audioCtx.createBufferSource(); noiseSource.buffer = buffer; let gainNode = audioCtx.createGain(); gainNode.gain.setValueAtTime(0, time); // ADSR gainNode.gain.linearRampToValueAtTime(instrument.volume, time + instrument.attack); gainNode.gain.linearRampToValueAtTime(instrument.volume * instrument.sustain, time + instrument.attack + instrument.decay); gainNode.gain.setValueAtTime(instrument.volume * instrument.sustain, time + duration - instrument.release); gainNode.gain.linearRampToValueAtTime(0, time + duration); noiseSource.connect(gainNode).connect(audioCtx.destination); noiseSource.start(time); noiseSource.stop(time + duration); return; } let osc = audioCtx.createOscillator(); let gainNode = audioCtx.createGain(); osc.type = instrument.oscType; osc.frequency.setValueAtTime(freq, time); osc.detune.setValueAtTime(instrument.detune, time); gainNode.gain.setValueAtTime(0, time); gainNode.gain.linearRampToValueAtTime(instrument.volume, time + instrument.attack); gainNode.gain.linearRampToValueAtTime(instrument.volume * instrument.sustain, time + instrument.attack + instrument.decay); gainNode.gain.setValueAtTime(instrument.volume * instrument.sustain, time + duration - instrument.release); gainNode.gain.linearRampToValueAtTime(0, time + duration); osc.connect(gainNode).connect(audioCtx.destination); osc.start(time); osc.stop(time + duration); } // Playback loop update function playLoop(){ if(!isPlaying) return; let bpm = parseInt(bpmInput.value); let rowDuration = 60 / bpm / 4; // quarter note divided into 4 rows let now = audioCtx.currentTime; let scheduleTime = now + 0.1; // small delay to avoid glitches for(let t=0; t<tracks; t++){ let note = pattern[currentRow][t]; if(note){ playNote(noteFrequencies[note], scheduleTime, rowDuration * 0.9); } } // Highlight row in UI highlightRow(currentRow); currentRow++; if(currentRow >= rowsPerPattern){ if(loop) currentRow = 0; else { stop(); return; } } timerId = setTimeout(playLoop, rowDuration * 1000); } // Highlight the current row function highlightRow(row){ document.querySelectorAll(".cell").forEach(cell=>{ if(parseInt(cell.dataset.row) === row){ cell.style.backgroundColor = "#2277ee"; } else { cell.style.backgroundColor = ""; } }); } // Start playback function play(){ if(isPlaying) return; if(audioCtx.state === "suspended"){ audioCtx.resume(); } isPlaying = true; currentRow = 0; playLoop(); } // Stop playback function stop(){ isPlaying = false; clearTimeout(timerId); highlightRow(-1); } // Loop toggle loopBtn.onclick = () => { loop = !loop; loopBtn.textContent = "Loop: " + (loop ? "On" : "Off"); } // Update instrument settings when inputs change document.getElementById("oscType").onchange = (e) => { instrument.oscType = e.target.value; instrument.noise = e.target.value === "noise"; }; document.getElementById("volume").oninput = (e) => instrument.volume = parseFloat(e.target.value); document.getElementById("detune").oninput = (e) => instrument.detune = parseInt(e.target.value); document.getElementById("attack").oninput = (e) => instrument.attack = parseInt(e.target.value) / 1000; document.getElementById("decay").oninput = (e) => instrument.decay = parseInt(e.target.value) / 1000; document.getElementById("sustain").oninput = (e) => instrument.sustain = parseFloat(e.target.value); document.getElementById("release").oninput = (e) => instrument.release = parseInt(e.target.value) / 1000; // Play & Stop button events playBtn.onclick = play; stopBtn.onclick = stop; // Rows per pattern change redraw tracker rowsPerPatternInput.onchange = buildTracker; // Share song (serialize pattern and instrument in URL hash) document.getElementById("shareBtn").onclick = () => { let song = { bpm: bpmInput.value, rowsPerPattern: rowsPerPatternInput.value, pattern: pattern, instrument: instrument }; let encoded = encodeURIComponent(btoa(JSON.stringify(song))); let shareUrl = location.origin + location.pathname + "/#" + encoded; navigator.clipboard.writeText(shareUrl).then(() => { alert("URL copied to clipboard!"); }); } // Load from URL on page load function loadFromURL(){ let hash = location.hash.slice(1); if(!hash) return; try{ let decoded = atob(decodeURIComponent(hash)); let song = JSON.parse(decoded); bpmInput.value = song.bpm; rowsPerPatternInput.value = song.rowsPerPattern; instrument = song.instrument; // Set instrument inputs document.getElementById("oscType").value = instrument.oscType; document.getElementById("volume").value = instrument.volume; document.getElementById("detune").value = instrument.detune; document.getElementById("attack").value = instrument.attack * 1000; document.getElementById("decay").value = instrument.decay * 1000; document.getElementById("sustain").value = instrument.sustain; document.getElementById("release").value = instrument.release * 1000; // Load pattern, reassign rows if size changed pattern = song.pattern; rowsPerPattern = parseInt(rowsPerPatternInput.value); buildTracker(); // Fill cells with notes document.querySelectorAll(".cell").forEach(cell=>{ let r = parseInt(cell.dataset.row); let t = parseInt(cell.dataset.track); if(pattern[r] && pattern[r][t]){ cell.textContent = pattern[r][t]; } else { cell.textContent = "---"; } }); }catch(e){ console.warn("Failed to load pattern from URL", e); } } // Initialize buildTracker(); loadFromURL(); </script> </body> </html>
Suggested Features You Can Add/Improve:
- Keyboard shortcuts for navigation and note edit
- More tracks and multiple patterns with pattern order list
- Better UI with pattern/track/row headers
- Effects commands (arpeggio, tremolo, pitch bend)
- Filter and more synth controls beyond ADSR and detune
- Save/load files (e.g. JSON export/import)
- Visual waveform displays
- More precise timing scheduling using Web Audio API's scheduling
How To Use
- Click cells to cycle notes.
- Set BPM and rows per pattern.
- Choose oscillator type (noise included).
- Adjust volume, detune, ADSR envelope.
- Click "Play" to hear the pattern play row by row.
- Click "Loop" to toggle loop on/off.
- Click "Share Song" to get a URL encoding the current song that you can share.
- Open that URL to reload the pattern.
If you'd like me to help build specific features or deeper functionality or want a ready-made library recommendation, just ask!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →