html chiptune tracker bpm patterns rows per pattern synth per instrument custom osc volume detune adsr filter noise share song shortcuts loop "/#" no demo
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
It looks like you want an HTML-based chiptune tracker with the following features:
BPM control
Patterns with rows per pattern
Multiple instruments each with their own synth
Custom oscillator per instrument
Volume, detune, ADSR envelope, filter, noise controls per instrument
Ability to share songs (e.g., via URL)
Keyboard shortcuts
Loop playback
Support for pattern editing using e.g. "/#" commands or shortcuts
No demo sounds auto-started (no autoplay/demo)
I can help you with a basic prototype or a starter code base that implements a simplified chiptune tracker with these core features. It won't be a full featured DAW/tracker in one go, but it will give a foundation on which you can build.
Here's a concise but extensible Web Audio + HTML/JS tracker example skeleton:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>HTML Chiptune Tracker</title>
<style>
body { font-family: monospace; background: #222; color: #eee; }
#tracker { display: flex; gap: 1rem; }
.pattern, .instruments { background: #333; padding: 1rem; border-radius: 5px; }
table { border-collapse: collapse; }
td, th { border: 1px solid #555; padding: 0.2rem 0.4rem; text-align: center; }
input[type=number], select { font-family: monospace; background: #222; color: #eee; border: 1px solid #555; border-radius: 3px; width: 4rem; }
button { background: #444; border: none; padding: 0.5rem 1rem; color: #eee; border-radius: 3px; cursor: pointer; }
button:hover { background: #666; }
</style>
</head>
<body>
<h1>HTML Chiptune Tracker</h1>
<div>
BPM: <input id="bpm" type="number" value="120" min="40" max="300" />
Rows per Pattern: <input id="rowsPerPattern" type="number" value="16" min="4" max="64" />
Instruments: <input id="instrumentsCount" type="number" value="3" min="1" max="8" />
<button id="initBtn">Initialize</button>
</div>
<div id="tracker">
<div class="pattern">
<h2>Pattern Editor</h2>
<table id="patternTable" tabindex="0"></table>
<button id="playBtn">Play / Stop</button>
<button id="loopBtn">Toggle Loop</button>
</div>
<div class="instruments">
<h2>Instruments</h2>
<div id="instrumentsContainer"></div>
</div>
</div>
<p>
Shortcuts:<br/>
- Arrow keys move selection<br/>
- Numbers 1-8 choose instrument note<br/>
- Space toggles play/stop<br/>
- L toggles loop<br/>
- / and # can be used for effects (not implemented in this demo)<br/>
</p>
<script>
(() => {
const AudioCtx = window.AudioContext || window.webkitAudioContext;
const audioCtx = new AudioCtx();
let playing = false;
let loop = false;
let intervalId = null;
// Tracker state
let bpm = 120;
let rowsPerPattern = 16;
let instrumentCount = 3;
let tempoInterval = null;
let currentRow = 0;
let notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
let semitoneMap = {
'C': 0, 'C#':1,'D':2,'D#':3,'E':4,'F':5,'F#':6,'G':7,'G#':8,'A':9,'A#':10,'B':11
};
// Storage for pattern:
// pattern[row][instrument] = {note: 'C4', vol: 1, detune: 0, ...}
let pattern = [];
// Instruments with synth params
let instruments = [];
// Selected cell [row, instrument]
let selectedCell = [0,0];
// Create default blank pattern
function createEmptyPattern() {
pattern = [];
for(let r=0; r<rowsPerPattern; r++) {
let row = [];
for(let i=0; i<instrumentCount; i++) {
row.push({note:null, vol:1, detune:0, osc:'square', adsr: {a:0.01, d:0.1, s:0.5, r:0.3}, filter: null, noise:false});
}
pattern.push(row);
}
}
// Create instruments default
function createDefaultInstruments() {
instruments = [];
for(let i=0; i<instrumentCount; i++) {
instruments.push({
osc: 'square', // 'square','sawtooth','triangle','sine','custom'
vol: 0.5,
detune: 0,
adsr: {a:0.01,d:0.1,s:0.5,r:0.3},
filter: {type:'lowpass', freq:1200, q:1},
noise: false
});
}
}
// Frequency calc for notes
function noteToFreq(note) {
// e.g. note = C4, A4=440Hz
if(!note) return null;
let match = note.match(/^([A-G]#?)(\d)$/);
if(!match) return null;
let pitch = match[1];
let octave = +match[2];
let semitone = semitoneMap[pitch];
if(semitone === undefined) return null;
let n = (octave-4)*12 + semitone;
return 440 * Math.pow(2, n/12);
}
// Create oscillator with settings from instrument
function createOscillator(inst, freq) {
if(inst.noise) {
// Noise instead of oscillator
let bufferSize = audioCtx.sampleRate;
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;
}
let noiseSource = audioCtx.createBufferSource();
noiseSource.buffer = buffer;
noiseSource.loop = true;
return noiseSource;
} else {
let osc = audioCtx.createOscillator();
if(inst.osc === 'custom') {
// Example custom waveform - a simple pulse wave
let real = new Float32Array([0, 1, 0.5, 0.2]);
let imag = new Float32Array(real.length);
let wave = audioCtx.createPeriodicWave(real, imag);
osc.setPeriodicWave(wave);
} else {
osc.type = inst.osc;
}
osc.frequency.value = freq;
osc.detune.value = inst.detune;
return osc;
}
}
// Play a step row of notes
function playRow(row) {
if(row >= pattern.length) return;
let now = audioCtx.currentTime;
let rowTime = 60/(bpm*4); // 16th note duration approx, adjust for your speed
for(let i=0; i<instrumentCount; i++) {
let noteData = pattern[row][i];
if(noteData.note) {
let freq = noteToFreq(noteData.note);
if(freq) {
let inst = instruments[i];
let osc = createOscillator(inst, freq);
let gainNode = audioCtx.createGain();
gainNode.gain.setValueAtTime(0, now);
// ADSR
let adsr = inst.adsr;
gainNode.gain.linearRampToValueAtTime(inst.vol*noteData.vol, now + adsr.a);
gainNode.gain.linearRampToValueAtTime(inst.vol*noteData.vol*adsr.s, now + adsr.a + adsr.d);
gainNode.gain.setTargetAtTime(0, now + rowTime - adsr.r, adsr.r);
// Filter (optional)
let filterNode = null;
if(inst.filter) {
filterNode = audioCtx.createBiquadFilter();
filterNode.type = inst.filter.type;
filterNode.frequency.setValueAtTime(inst.filter.freq, now);
filterNode.Q.setValueAtTime(inst.filter.q, now);
}
osc.connect(filterNode || gainNode);
if(filterNode) filterNode.connect(gainNode);
gainNode.connect(audioCtx.destination);
osc.start(now);
osc.stop(now + rowTime);
osc.onended = () => {
gainNode.disconnect();
if(filterNode) filterNode.disconnect();
osc.disconnect();
};
}
}
}
}
// Draw pattern table
function drawPattern() {
let table = document.getElementById('patternTable');
table.innerHTML = '';
// header row
let thead = document.createElement('thead');
let headerRow = document.createElement('tr');
let thEmpty = document.createElement('th');
thEmpty.textContent = '#';
headerRow.appendChild(thEmpty);
for(let i=0; i<instrumentCount; i++) {
let th = document.createElement('th');
th.textContent = 'Inst ' + (i+1);
headerRow.appendChild(th);
}
thead.appendChild(headerRow);
table.appendChild(thead);
let tbody = document.createElement('tbody');
for(let r=0; r<rowsPerPattern; r++) {
let tr = document.createElement('tr');
let numTd = document.createElement('td');
numTd.textContent = r+1;
tr.appendChild(numTd);
for(let i=0; i<instrumentCount; i++) {
let td = document.createElement('td');
let note = pattern[r][i].note || '';
td.textContent = note;
if(selectedCell[0] === r && selectedCell[1] === i)
td.style.background = '#666';
tr.appendChild(td);
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
}
// Draw instruments
function drawInstruments() {
let container = document.getElementById('instrumentsContainer');
container.innerHTML = '';
instruments.forEach((inst, i) => {
let div = document.createElement('div');
div.style.border = '1px solid #555';
div.style.padding = '0.5rem';
div.style.marginBottom = '0.5rem';
let html = `
<h3>Instrument ${i+1}</h3>
<label>Oscillator:
<select data-inst="${i}" class="osc-select">
<option value="square" ${inst.osc==='square'?'selected':''}>Square</option>
<option value="sawtooth" ${inst.osc==='sawtooth'?'selected':''}>Sawtooth</option>
<option value="triangle" ${inst.osc==='triangle'?'selected':''}>Triangle</option>
<option value="sine" ${inst.osc==='sine'?'selected':''}>Sine</option>
<option value="custom" ${inst.osc==='custom'?'selected':''}>Custom</option>
</select>
</label><br/>
<label>Volume: <input type="range" data-inst="${i}" class="vol" min="0" max="1" step="0.01" value="${inst.vol}" /></label><br/>
<label>Detune: <input type="range" data-inst="${i}" class="detune" min="-1200" max="1200" step="1" value="${inst.detune}" /></label><br/>
<fieldset>
<legend>ADSR</legend>
<label>A: <input type="number" min="0" max="1" step="0.01" class="adsr-a" data-inst="${i}" value="${inst.adsr.a}" /></label><br/>
<label>D: <input type="number" min="0" max="1" step="0.01" class="adsr-d" data-inst="${i}" value="${inst.adsr.d}" /></label><br/>
<label>S: <input type="number" min="0" max="1" step="0.01" class="adsr-s" data-inst="${i}" value="${inst.adsr.s}" /></label><br/>
<label>R: <input type="number" min="0" max="1" step="0.01" class="adsr-r" data-inst="${i}" value="${inst.adsr.r}" /></label><br/>
</fieldset>
<fieldset>
<legend>Filter</legend>
<label>Type:
<select class="filter-type" data-inst="${i}">
<option value="lowpass" ${inst.filter?.type==='lowpass'?'selected':''}>Lowpass</option>
<option value="highpass" ${inst.filter?.type==='highpass'?'selected':''}>Highpass</option>
<option value="bandpass" ${inst.filter?.type==='bandpass'?'selected':''}>Bandpass</option>
<option value="none" ${!inst.filter ? 'selected' : ''}>None</option>
</select>
</label><br/>
<label>Frequency: <input type="number" min="20" max="20000" step="1" class="filter-freq" data-inst="${i}" value="${inst.filter?.freq || 0}" /></label><br/>
<label>Q: <input type="number" min="0" max="20" step="0.1" class="filter-q" data-inst="${i}" value="${inst.filter?.q || 0}" /></label><br/>
</fieldset>
<label>Noise: <input type="checkbox" data-inst="${i}" class="noise" ${inst.noise ? 'checked' : ''} /></label>
`;
div.innerHTML = html;
container.appendChild(div);
});
// Add event listeners to inputs
container.querySelectorAll('select.osc-select').forEach(el => el.addEventListener('change', e => {
let idx = +e.target.dataset.inst;
instruments[idx].osc = e.target.value;
}));
container.querySelectorAll('input.vol').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
instruments[idx].vol = +e.target.value;
}));
container.querySelectorAll('input.detune').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
instruments[idx].detune = +e.target.value;
}));
container.querySelectorAll('input.adsr-a').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
instruments[idx].adsr.a = +e.target.value;
}));
container.querySelectorAll('input.adsr-d').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
instruments[idx].adsr.d = +e.target.value;
}));
container.querySelectorAll('input.adsr-s').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
instruments[idx].adsr.s = +e.target.value;
}));
container.querySelectorAll('input.adsr-r').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
instruments[idx].adsr.r = +e.target.value;
}));
container.querySelectorAll('select.filter-type').forEach(el => el.addEventListener('change', e => {
let idx = +e.target.dataset.inst;
let val = e.target.value;
if(val === 'none') {
instruments[idx].filter = null;
} else {
if(!instruments[idx].filter) instruments[idx].filter = {type:'lowpass', freq:1200, q:1};
instruments[idx].filter.type = val;
}
}));
container.querySelectorAll('input.filter-freq').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
if(instruments[idx].filter) instruments[idx].filter.freq = +e.target.value;
}));
container.querySelectorAll('input.filter-q').forEach(el => el.addEventListener('input', e => {
let idx = +e.target.dataset.inst;
if(instruments[idx].filter) instruments[idx].filter.q = +e.target.value;
}));
container.querySelectorAll('input.noise').forEach(el => el.addEventListener('change', e => {
let idx = +e.target.dataset.inst;
instruments[idx].noise = e.target.checked;
}));
}
// Handle keyboard shortcuts for editing pattern
function handlePatternInput(e) {
// Only react if patternTable is focused
// We map numbers 1-8 to notes, arrow keys to move, space to play/stop
// For demo simplicity we use a fixed octave and notes 1-8 map to C to G notes
if(!document.activeElement || document.activeElement.id !== 'patternTable') return;
const notesMap = ['C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5'];
switch(e.key) {
case 'ArrowDown':
selectedCell[0] = (selectedCell[0] +1) % rowsPerPattern;
e.preventDefault();
break;
case 'ArrowUp':
selectedCell[0] = (selectedCell[0] -1 + rowsPerPattern) % rowsPerPattern;
e.preventDefault();
break;
case 'ArrowRight':
selectedCell[1] = (selectedCell[1] +1) % instrumentCount;
e.preventDefault();
break;
case 'ArrowLeft':
selectedCell[1] = (selectedCell[1] -1 + instrumentCount) % instrumentCount;
e.preventDefault();
break;
case ' ':
togglePlay();
e.preventDefault();
break;
case 'l':
case 'L':
toggleLoop();
e.preventDefault();
break;
case '/':
case '#':
// for future effects support
alert('Effects support not implemented yet');
e.preventDefault();
break;
default:
if(e.key >= '1' && e.key <= '8') {
let noteIdx = +e.key -1;
pattern[selectedCell[0]][selectedCell[1]].note = notesMap[noteIdx];
e.preventDefault();
} else if(e.key === '0' || e.key.toLowerCase() === 'x') {
// clear note
pattern[selectedCell[0]][selectedCell[1]].note = null;
e.preventDefault();
}
break;
}
drawPattern();
}
// Play or stop looped playback
function togglePlay() {
if(playing) stopPlay();
else startPlay();
}
function startPlay() {
if(audioCtx.state === 'suspended') audioCtx.resume();
playing = true;
currentRow = 0;
document.getElementById('playBtn').textContent = 'Stop';
let msPerRow = (60000 / bpm) / 4; // 16ths based
intervalId = setInterval(() => {
playRow(currentRow);
currentRow++;
if(currentRow >= rowsPerPattern) {
if(loop) currentRow = 0;
else {
stopPlay();
}
}
}, msPerRow);
}
function stopPlay() {
playing = false;
document.getElementById('playBtn').textContent = 'Play';
if(intervalId) clearInterval(intervalId);
intervalId = null;
}
function toggleLoop() {
loop = !loop;
document.getElementById('loopBtn').textContent = loop ? 'Loop: ON' : 'Loop: OFF';
}
// Share song - serializing pattern and instruments into URL hash
function updateHash() {
let state = {
bpm,
rowsPerPattern,
instrumentCount,
pattern,
instruments
};
let s = btoa(unescape(encodeURIComponent(JSON.stringify(state))));
location.hash = s;
}
function loadFromHash() {
if(location.hash.length>1) {
try {
let s = decodeURIComponent(escape(atob(location.hash.substring(1))));
let state = JSON.parse(s);
bpm = state.bpm || bpm;
rowsPerPattern = state.rowsPerPattern || rowsPerPattern;
instrumentCount = state.instrumentCount || instrumentCount;
pattern = state.pattern || pattern;
instruments = state.instruments || instruments;
// Set inputs
document.getElementById('bpm').value = bpm;
document.getElementById('rowsPerPattern').value = rowsPerPattern;
document.getElementById('instrumentsCount').value = instrumentCount;
drawPattern();
drawInstruments();
} catch(e) {
console.warn('Failed to load pattern from URL hash', e);
}
}
}
// Initialize
document.getElementById('initBtn').addEventListener('click', () => {
bpm = +document.getElementById('bpm').value;
rowsPerPattern = +document.getElementById('rowsPerPattern').value;
instrumentCount = +document.getElementById('instrumentsCount').value;
createEmptyPattern();
createDefaultInstruments();
drawPattern();
drawInstruments();
});
document.getElementById('playBtn').addEventListener('click', togglePlay);
document.getElementById('loopBtn').addEventListener('click', toggleLoop);
document.getElementById('patternTable').addEventListener('keydown', handlePatternInput);
// Update hash on changes (debounced)
function debounce(func, wait=1000) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
}
function onChangeUpdateHash() {
bpm = +document.getElementById('bpm').value;
rowsPerPattern = +document.getElementById('rowsPerPattern').value;
instrumentCount = +document.getElementById('instrumentsCount').value;
updateHash();
}
document.getElementById('bpm').addEventListener('input', debounce(onChangeUpdateHash));
document.getElementById('rowsPerPattern').addEventListener('input', debounce(onChangeUpdateHash));
document.getElementById('instrumentsCount').addEventListener('input', debounce(onChangeUpdateHash));
// Save on instrument changes as well
document.getElementById('instrumentsContainer').addEventListener('input', debounce(updateHash));
document.getElementById('instrumentsContainer').addEventListener('change', debounce(updateHash));
// Save on pattern edits (rows) - listen on patternTable keydown as well
document.getElementById('patternTable').addEventListener('keydown', debounce(updateHash));
// Init on load
window.addEventListener('load', () => {
loadFromHash();
if(pattern.length === 0) {
createEmptyPattern();
createDefaultInstruments();
drawPattern();
drawInstruments();
}
document.getElementById('loopBtn').textContent = loop ? 'Loop: ON' : 'Loop: OFF';
});
})();
</script>
</body>
</html>
Features in this example:
You initialize pattern by number of rows and instruments.
Manually enter notes 1-8 keys which maps to C-D-E-F-G-A-B-C notes.
Pattern table is keyboard navigable with arrow keys.
Play/Stop and Loop toggle buttons.
Each instrument has controls to adjust oscillator waveform, volume, detune, ADSR envelope, filter params, noise toggle.
Plays notes with Web Audio API using configured synth per instrument.
Pattern and instrument data serialized as JSON in Base64 stored in URL hash to share via URL.
Keyboard shortcuts for play/stop, loop toggle.
No demo playback on page load - user must press play.
/ and # keys show placeholders for future effects support.
Clean monospace styled UI.
How to use:
Adjust BPM, rows per pattern and instruments count, click Initialize
Click pattern table and use arrow keys to move cursor.
Press number keys 1-8 to enter notes on instrument columns.
Use instrument panel to tweak osc, volume, detune, envelope, filter, noise.
Use play button to play pattern.
Use loop toggle for repeat playback.
Share the current song by sharing the URL with the hash.
This is a good baseline for a chiptune tracker you can extend with:
Advanced note input (note names)
Patterns chaining
Effect column support with /, # commands
Custom oscillators via partials or user waveforms
UI improvements etc.
If you want I can help you extend features further or build a better UI! Just ask.