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 shortcuts loop "/#" no demo
- Assistant
You want an HTML-based chiptune tracker with features including:
- BPM control
- Rows per track
- Patterns
- Rows per pattern
- Synth per instrument with custom oscillator options
- Volume, detune, ADSR envelope, filter, noise controls
- Sharing (e.g. via URL hash "/#")
- Keyboard shortcuts
- Looping
- No demo (a clean, basic tracker, not just a demo)
Below is a starter implementation of a very minimal chiptune tracker in a single HTML file that meets your core requirements. It uses Web Audio API, supports multiple patterns & instruments with basic synth parameters (oscillator type, volume, detune, ADSR, filter, noise), BPM control, rows, looping, keyboard shortcuts, and URL-based sharing via a JSON-encoded state in the hash fragment.
This is NOT a full-fledged tracker with a polished UI (e.g. piano roll or waveform editor), but it’s a functional foundation you can extend and improve.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Minimal HTML Chiptune Tracker</title> <style> body { font-family: monospace; background: #111; color: #eee; margin: 0; padding: 0; } #tracker { display: grid; grid-template-columns: 1fr 2fr 1fr; height: 100vh; } #left, #center, #right { padding: 10px; overflow: auto; box-sizing: border-box; } #left { background: #222; } #center { background: #111; } #right { background: #222; } table { border-collapse: collapse; } td, th { border: 1px solid #333; padding: 2px 5px; text-align: center; user-select:none; } .cell { cursor: pointer; } .active-cell { background: #3399ff; color: #fff; } input, select, button { width: 100%; margin: 5px 0; box-sizing: border-box; background: #222; border: 1px solid #555; color: #eee; padding: 5px; } input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; } label { display: block; margin-top: 10px; } #patternName { width: 100%; background: #222; border: 1px solid #555; color: #eee; padding: 5px; } button { cursor: pointer; } #log { font-size: 0.8em; height: 160px; overflow: auto; background: #111; border: 1px solid #333; padding: 5px; } .note { color: #6f9; } .rest { color: #555; } #footer { text-align:center; font-size:0.8em; padding:5px; background:#222; } </style> </head> <body> <div id="tracker"> <div id="left"> <h3>Controls</h3> <label>BPM <input type="number" id="bpm" value="120" min="30" max="300" /></label> <label>Rows per Track <input type="number" id="rowsPerTrack" value="16" min="4" max="64" /></label> <label>Patterns <input type="number" id="patternsCount" value="4" min="1" max="16" /></label> <label>Rows per Pattern <input type="number" id="rowsPerPattern" value="16" min="4" max="64" /></label> <button id="newPatternBtn">New Pattern</button> <button id="playBtn">▶️ Play</button> <button id="stopBtn">⏹ Stop</button> <button id="saveBtn">💾 Save URL</button> <button id="loadBtn">📂 Load URL</button> <button id="clearBtn">🗑 Clear</button> <hr /> <h3>Loop</h3> <label><input type="checkbox" id="loopCheckbox" checked /> Loop Pattern</label> </div> <div id="center"> <h3>Patterns</h3> <div id="patternsList"></div> <h3>Track Editor</h3> <div id="trackEditor"></div> </div> <div id="right"> <h3>Instrument Settings</h3> <label>Instrument: <select id="instrumentSelect"></select> </label> <label>Oscillator: <select id="oscillatorType"> <option value="square">Square</option> <option value="sawtooth">Sawtooth</option> <option value="triangle">Triangle</option> <option value="sine">Sine</option> </select> </label> <label>Volume: <input type="range" id="volume" min="0" max="1" step="0.01" value="0.5"/></label> <label>Detune (cents): <input type="number" id="detune" min="-1200" max="1200" step="1" value="0"/></label> <label>Attack (s): <input type="number" id="attack" min="0" max="2" step="0.01" value="0.01"/></label> <label>Decay (s): <input type="number" id="decay" min="0" max="2" step="0.01" value="0.1"/></label> <label>Sustain (0-1): <input type="number" id="sustain" min="0" max="1" step="0.01" value="0.4"/></label> <label>Release (s): <input type="number" id="release" min="0" max="2" step="0.01" value="0.2"/></label> <label>Filter Cutoff (Hz): <input type="number" id="filterCutoff" min="20" max="20000" step="1" value="1500"/></label> <label>Noise Volume: <input type="range" id="noiseVolume" min="0" max="1" step="0.01" value="0"/></label> <button id="addInstrumentBtn">➕ Add Instrument</button> </div> </div> <div id="footer"> Shortcuts: ←/→ Select pattern | ↑/↓ Select row | Space Play/Stop | E Edit cell | L Toggle loop </div> <script> (() => { const AudioContext = window.AudioContext || window.webkitAudioContext; const ctx = new AudioContext(); // ----- State ----- // Default constants const NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']; const NOTE_TO_FREQ = (note, octave) => { const noteIndex = NOTES.indexOf(note); if (noteIndex === -1) return null; // A4 = 440 Hz (Octave 4) const semitonesFromA4 = noteIndex - 9 + (octave - 4) * 12; return 440 * Math.pow(2, semitonesFromA4 / 12); }; // Initial parameters let state = { bpm: 120, rowsPerTrack: 16, patternsCount: 4, rowsPerPattern: 16, loop: true, patterns: [], // array of patterns currentPattern: 0, currentRow: 0, playing: false, instruments: [], tempoTimeMs: 0, }; // Pattern structure: // { // name: string, // tracks: [ [row, {note:str, octave:int, instrument:int, volume:0-1, detune:int, ...}] ] per track, // } // We'll allow 4 tracks per pattern for simplicity. const MAX_TRACKS = 4; const EMPTY_CELL = null; // Current editing position let currentTrack = 0; let currentRow = 0; // --------- UI Elements --------- const bpmInput = document.getElementById('bpm'); const rowsPerTrackInput = document.getElementById('rowsPerTrack'); const patternsCountInput = document.getElementById('patternsCount'); const rowsPerPatternInput = document.getElementById('rowsPerPattern'); const patternsListDiv = document.getElementById('patternsList'); const trackEditorDiv = document.getElementById('trackEditor'); const playBtn = document.getElementById('playBtn'); const stopBtn = document.getElementById('stopBtn'); const saveBtn = document.getElementById('saveBtn'); const loadBtn = document.getElementById('loadBtn'); const newPatternBtn = document.getElementById('newPatternBtn'); const clearBtn = document.getElementById('clearBtn'); const loopCheckbox = document.getElementById('loopCheckbox'); // Instrument controls const instrumentSelect = document.getElementById('instrumentSelect'); const oscillatorTypeSelect = document.getElementById('oscillatorType'); const volumeSlider = document.getElementById('volume'); const detuneInput = document.getElementById('detune'); const attackInput = document.getElementById('attack'); const decayInput = document.getElementById('decay'); const sustainInput = document.getElementById('sustain'); const releaseInput = document.getElementById('release'); const filterCutoffInput = document.getElementById('filterCutoff'); const noiseVolumeInput = document.getElementById('noiseVolume'); const addInstrumentBtn = document.getElementById('addInstrumentBtn'); // --- Helpers --- function clamp(num, min, max) { return Math.min(Math.max(num, min), max); } // Create empty pattern function createEmptyPattern(name = 'Pattern') { const tracks = []; for (let t = 0; t < MAX_TRACKS; t++) { const track = []; for (let r = 0; r < state.rowsPerPattern; r++) { track.push(EMPTY_CELL); } tracks.push(track); } return { name, tracks, }; } // Initialize state function initState() { // Initialize patterns if empty or count changed while (state.patterns.length < state.patternsCount) { state.patterns.push(createEmptyPattern(`Pattern ${state.patterns.length+1}`)); } if(state.patterns.length > state.patternsCount) state.patterns.length = state.patternsCount; if(state.instruments.length === 0){ state.instruments.push(makeDefaultInstrument()); } currentTrack = 0; currentRow = 0; state.currentPattern = 0; renderPatternsList(); renderTrackEditor(); renderInstrumentSettings(); } // Default instrument: square wave, moderate envelope function makeDefaultInstrument() { return { oscillatorType: 'square', volume: 0.5, detune: 0, attack: 0.01, decay: 0.1, sustain: 0.4, release: 0.2, filterCutoff: 1500, noiseVolume: 0, name: 'Default', }; } // Frequency for note string like C#4 function freqFromNote(note) { if(!note) return null; // note format: e.g. "C#4", "A3", or "rest" if(note.toLowerCase() === 'rest') return null; const matches = note.match(/^([A-G]#?)(-?\d)$/); if(!matches) return null; const [_, pitch, octaveStr] = matches; const octave = parseInt(octaveStr); return NOTE_TO_FREQ(pitch, octave); } // Convert frequency to MIDI note number?? // Not needed for now. // Play a note function playNote(noteStr, instrumentIndex, durationSec=0.3) { if(!noteStr || noteStr.toLowerCase() === 'rest') return; const inst = state.instruments[instrumentIndex]; if(!inst) return; const freq = freqFromNote(noteStr); if(!freq) return; const now = ctx.currentTime; // Noise node if noiseVolume > 0 let noiseNode; if(inst.noiseVolume > 0) { const bufferSize = ctx.sampleRate * durationSec; const buffer = ctx.createBuffer(1, bufferSize, ctx.sampleRate); const data = buffer.getChannelData(0); for(let i=0; i<bufferSize; i++) data[i] = (Math.random()*2-1)*inst.noiseVolume; noiseNode = ctx.createBufferSource(); noiseNode.buffer = buffer; } // Oscillator const osc = ctx.createOscillator(); osc.type = inst.oscillatorType; osc.frequency.setValueAtTime(freq, now); osc.detune.setValueAtTime(inst.detune, now); // Gain for envelope + volume const gainNode = ctx.createGain(); // Filter const filterNode = ctx.createBiquadFilter(); filterNode.type = 'lowpass'; filterNode.frequency.setValueAtTime(inst.filterCutoff, now); // Connect nodes: osc > filter > gain osc.connect(filterNode); filterNode.connect(gainNode); // If noise enabled: noiseNode > gain > filterNode also to gainNode if(noiseNode) { noiseNode.connect(gainNode); } gainNode.connect(ctx.destination); // ADSR envelope const attackEnd = now + inst.attack; gainNode.gain.setValueAtTime(0, now); gainNode.gain.linearRampToValueAtTime(inst.volume, attackEnd); gainNode.gain.linearRampToValueAtTime(inst.volume * inst.sustain, attackEnd + inst.decay); // Sustain const sustainEnd = attackEnd + inst.decay + durationSec; gainNode.gain.setValueAtTime(inst.volume * inst.sustain, sustainEnd); // Release gainNode.gain.linearRampToValueAtTime(0, sustainEnd + inst.release); osc.start(now); osc.stop(sustainEnd + inst.release); if(noiseNode){ noiseNode.start(now); noiseNode.stop(sustainEnd + inst.release); } } // --- Render Pattern List --- function renderPatternsList() { patternsListDiv.innerHTML = ''; state.patterns.forEach((pat, i) => { const btn = document.createElement('button'); btn.textContent = `${i+1}: ${pat.name}`; btn.style.backgroundColor = (i === state.currentPattern) ? '#3399ff' : '#444'; btn.style.color = 'white'; btn.style.margin = '2px'; btn.onclick = () => { state.currentPattern = i; currentRow = 0; renderPatternsList(); renderTrackEditor(); }; patternsListDiv.appendChild(btn); }); } // --- Render Track Editor --- function renderTrackEditor() { trackEditorDiv.innerHTML = ''; const pat = state.patterns[state.currentPattern]; if(!pat) return; const table = document.createElement('table'); const thead = document.createElement('thead'); const thr = document.createElement('tr'); thr.appendChild(document.createElement('th')); // for row # col for(let t=0;t<MAX_TRACKS;t++){ const th = document.createElement('th'); th.textContent = `Trk ${t+1}`; thr.appendChild(th); } thead.appendChild(thr); table.appendChild(thead); const tbody = document.createElement('tbody'); for(let r=0; r < state.rowsPerPattern; r++) { const tr = document.createElement('tr'); const rowlabel = document.createElement('td'); rowlabel.textContent = r+1; tr.appendChild(rowlabel); for(let t=0;t<MAX_TRACKS;t++){ const td = document.createElement('td'); td.classList.add('cell'); if(r === currentRow && t === currentTrack) { td.classList.add('active-cell'); } const cellData = pat.tracks[t][r]; td.textContent = cellData ? cellData.note : 'rest'; td.title = '(Click to edit)'; td.onclick = () => { currentTrack = t; currentRow = r; renderTrackEditor(); editCell(currentTrack, currentRow); }; tr.appendChild(td); } tbody.appendChild(tr); } table.appendChild(tbody); trackEditorDiv.appendChild(table); } // --- Edit cell: prompt for note and instrument --- function editCell(track, row) { const pat = state.patterns[state.currentPattern]; let cell = pat.tracks[track][row]; if(!cell) cell = {}; const notePrompt = prompt('Enter note (e.g. C4, D#5, rest):', cell.note || 'rest'); if(notePrompt === null) return; // cancel const note = notePrompt.trim(); if(note !== 'rest' && !/^([A-G]#?)-?\d$/.test(note)) { alert('Invalid note. Format: C4, D#5, rest'); return; } let instrumentIndex = cell.instrument; if(instrumentIndex === undefined) instrumentIndex = 0; const instNames = state.instruments.map((i,n) => `${n}: ${i.name || 'Unnamed'}`).join('\n'); const instPrompt = prompt('Instrument number:\n' + instNames, instrumentIndex); if(instPrompt === null) return; let instNum = parseInt(instPrompt); if(isNaN(instNum) || instNum<0 || instNum>=state.instruments.length){ alert('Invalid instrument number'); return; } pat.tracks[track][row] = { note, instrument: instNum }; renderTrackEditor(); } // --- Play Pattern Sequencer --- let schedulerTimer = null; let nextNoteTime = 0; // time for next note in seconds let currentPlayRow = 0; function nextNote(){ const interval = 60 / state.bpm / 4; // 16th note steps approx, so each row = quarter note / rows? nextNoteTime += interval; } // Actually we'll treat rows as steps that divide 4 quarter notes per beat into rowsPerPattern parts function scheduleNote(row){ const pat = state.patterns[state.currentPattern]; if(!pat) return; // Play notes on all tracks for this row for(let t=0; t<MAX_TRACKS;t++){ const cell = pat.tracks[t][row]; if(cell){ playNote(cell.note, cell.instrument); } } } function scheduler() { if (!state.playing) return; const now = ctx.currentTime; if(nextNoteTime <= now) { scheduleNote(currentPlayRow); currentPlayRow++; if(currentPlayRow >= state.rowsPerPattern) { if(state.loop) currentPlayRow = 0; else { stopPlayback(); return; } } const interval = 60 / state.bpm / 4; nextNoteTime += interval; } schedulerTimer = setTimeout(scheduler, 25); } function startPlayback() { if(ctx.state === 'suspended') { ctx.resume(); } if(state.playing) return; state.playing = true; currentPlayRow = 0; nextNoteTime = ctx.currentTime + 0.05; scheduler(); } function stopPlayback() { state.playing = false; if(schedulerTimer) { clearTimeout(schedulerTimer); schedulerTimer = null; } } // --- Event Listeners --- bpmInput.addEventListener('change', () => { let val = parseInt(bpmInput.value); if(isNaN(val) || val < 30) val = 30; if(val > 300) val = 300; bpmInput.value = val; state.bpm = val; }); rowsPerTrackInput.addEventListener('change', () => { let val = parseInt(rowsPerTrackInput.value); if(isNaN(val) || val < 4) val = 4; if(val > 64) val = 64; rowsPerTrackInput.value = val; state.rowsPerTrack = val; }); patternsCountInput.addEventListener('change', () => { let val = parseInt(patternsCountInput.value); if(isNaN(val) || val < 1) val = 1; if(val > 16) val = 16; patternsCountInput.value = val; state.patternsCount = val; initState(); }); rowsPerPatternInput.addEventListener('change', () => { let val = parseInt(rowsPerPatternInput.value); if(isNaN(val) || val < 4) val = 4; if(val > 64) val = 64; rowsPerPatternInput.value = val; state.rowsPerPattern = val; // resize rows in patterns state.patterns.forEach(p => { p.tracks.forEach(track => { const oldLen = track.length; if(val > oldLen){ for(let i=oldLen; i<val; i++){ track.push(EMPTY_CELL); } } else if (val < oldLen){ track.length = val; } }); }); renderTrackEditor(); }); newPatternBtn.onclick = () => { const newName = prompt('New pattern name:', `Pattern ${state.patterns.length+1}`); if(newName === null) return; const pat = createEmptyPattern(newName); state.patterns.push(pat); state.patternsCount = state.patterns.length; patternsCountInput.value = state.patternsCount; state.currentPattern = state.patterns.length-1; renderPatternsList(); renderTrackEditor(); }; playBtn.onclick = () => { startPlayback(); }; stopBtn.onclick = () => { stopPlayback(); }; clearBtn.onclick = () => { if(confirm('Clear ALL patterns and instruments?')){ state.patterns = []; state.instruments = []; state.patternsCount = 1; state.rowsPerPattern = 16; state.bpm = 120; bpmInput.value = 120; patternsCountInput.value = 1; rowsPerPatternInput.value = 16; initState(); } }; loopCheckbox.onchange = () => { state.loop = loopCheckbox.checked; }; saveBtn.onclick = () => { const serial = btoa(unescape(encodeURIComponent(JSON.stringify(state)))); const url = location.origin + location.pathname + "/#" + serial; prompt('Save or share this URL:', url); }; loadBtn.onclick = () => { const hash = location.hash.slice(1); if (!hash) { alert('No saved data in URL hash!'); return; } try { const json = decodeURIComponent(escape(atob(hash))); const newState = JSON.parse(json); Object.assign(state, newState); bpmInput.value = state.bpm; rowsPerTrackInput.value = state.rowsPerTrack; patternsCountInput.value = state.patternsCount; rowsPerPatternInput.value = state.rowsPerPattern; loopCheckbox.checked = state.loop; initState(); } catch(e){ alert('Failed to load data from URL'); console.error(e); } }; // Instrument controls handling function renderInstrumentSettings(){ instrumentSelect.innerHTML = ''; state.instruments.forEach((i, idx) => { const opt = document.createElement('option'); opt.value = idx; opt.textContent = `${idx}: ${i.name || 'Unnamed'}`; instrumentSelect.appendChild(opt); }); instrumentSelect.value = 0; setInstrumentInputs(state.instruments[0]); } function setInstrumentInputs(inst) { oscillatorTypeSelect.value = inst.oscillatorType; volumeSlider.value = inst.volume; detuneInput.value = inst.detune; attackInput.value = inst.attack; decayInput.value = inst.decay; sustainInput.value = inst.sustain; releaseInput.value = inst.release; filterCutoffInput.value = inst.filterCutoff; noiseVolumeInput.value = inst.noiseVolume; } function updateInstrumentFromInput(idx) { const inst = state.instruments[idx]; if(!inst) return; inst.oscillatorType = oscillatorTypeSelect.value; inst.volume = parseFloat(volumeSlider.value); inst.detune = parseInt(detuneInput.value); inst.attack = parseFloat(attackInput.value); inst.decay = parseFloat(decayInput.value); inst.sustain = parseFloat(sustainInput.value); inst.release = parseFloat(releaseInput.value); inst.filterCutoff = parseInt(filterCutoffInput.value); inst.noiseVolume = parseFloat(noiseVolumeInput.value); } instrumentSelect.onchange = () => { const idx = parseInt(instrumentSelect.value); if(state.instruments[idx]){ setInstrumentInputs(state.instruments[idx]); } }; [oscillatorTypeSelect, volumeSlider, detuneInput, attackInput, decayInput, sustainInput, releaseInput, filterCutoffInput, noiseVolumeInput].forEach(e => { e.onchange = () => { const idx = parseInt(instrumentSelect.value); if(!isNaN(idx)){ updateInstrumentFromInput(idx); } }; }); addInstrumentBtn.onclick = () => { const name = prompt('Name for new instrument?', `Inst ${state.instruments.length}`); if(name === null) return; const newInst = makeDefaultInstrument(); newInst.name = name; state.instruments.push(newInst); renderInstrumentSettings(); }; // Keyboard shortcuts window.addEventListener('keydown', (e)=>{ if(e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT' || e.target.isContentEditable) return; switch(e.key){ case 'ArrowLeft': state.currentPattern = (state.currentPattern -1 +state.patternsCount) % state.patternsCount; currentRow=0; renderPatternsList(); renderTrackEditor(); e.preventDefault(); break; case 'ArrowRight': state.currentPattern = (state.currentPattern +1) % state.patternsCount; currentRow=0; renderPatternsList(); renderTrackEditor(); e.preventDefault(); break; case 'ArrowUp': currentRow = (currentRow -1 + state.rowsPerPattern) % state.rowsPerPattern; renderTrackEditor(); e.preventDefault(); break; case 'ArrowDown': currentRow = (currentRow +1) % state.rowsPerPattern; renderTrackEditor(); e.preventDefault(); break; case ' ': if(state.playing) stopPlayback(); else startPlayback(); e.preventDefault(); break; case 'e': case 'E': editCell(currentTrack, currentRow); e.preventDefault(); break; case 'l': case 'L': state.loop = !state.loop; loopCheckbox.checked = state.loop; e.preventDefault(); break; } }); // --- Load from URL hash on load --- function loadFromHash(){ const hash = location.hash.slice(1); if(!hash) return false; try { const json = decodeURIComponent(escape(atob(hash))); const newState = JSON.parse(json); Object.assign(state, newState); bpmInput.value = state.bpm; rowsPerTrackInput.value = state.rowsPerTrack; patternsCountInput.value = state.patternsCount; rowsPerPatternInput.value = state.rowsPerPattern; loopCheckbox.checked = state.loop; initState(); return true; } catch(e){ console.warn('Failed to load from URL hash', e); return false; } } // Initialize UI if(!loadFromHash()){ initState(); } })(); </script> </body> </html>
Usage
- Adjust BPM, pattern rows, patterns count from the controls on the left.
- Use the Patterns section to select current pattern.
- The editor grid in the center shows 4 tracks and rows per pattern. Click a cell or press
Eto edit a note (format: C4, D#5, rest). - Pick instrument per note (prompt) when editing a note.
- Manage instruments on the right side, set oscillator, ADSR, volume etc. Add instruments using
Add Instrumentbutton. - Play / stop pronunciation with the buttons or
spacekey. - Navigate rows with arrow keys, left/right to switch pattern.
- Save your song as an encoded URL with the
Save URLbutton. Load a song by pasting an encoded URL and clickingLoad URL. - Toggle looping with the checkbox or
Lkey.
Notes
- This is a minimal starting point built to your spec. Many features can be improved, extended, or replaced with richer UI.
- Sound quality is basic. It uses Web Audio oscillators with fixed frequency notes and ADSR envelope.
- Noise is simulated by adding buffered noise samples mixed with the oscillator.
- Sharing is done via JSON string encoded in base64 stored in the URL hash. This is simple, not very efficient, but functional.
- The pattern editor is simple text-based but can be expanded with better input methods and visual cues.
If you want me to help extend or improve any part (e.g. piano roll UI, pattern chaining, saving files), 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.