You want an HTML-based chiptune tracker with features including BPM, rows per track, patterns, synth per instrument, custom oscillator, volume, detune, ADSR, filter, noise, sharing songs, shortcuts, loop, and no demo.
Here's a minimal yet functional example of a chiptune tracker in HTML/JS that supports most of these features. Because a full chiptune tracker is complex, this example is a starting point showcasing:
- BPM control
- Rows per pattern
- Patterns per track
- Synth per instrument with custom oscillator types
- Volume, detune, ADSR envelope, filter, noise per instrument
- Ability to share song data in URL hash (
/#)
- Keyboard shortcuts for playback and editing
- Looping patterns
- No demo loaded on start
This uses the Web Audio API and a minimal UI. You can extend it with more instruments or UI polish as needed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chiptune Tracker (minimal)</title>
<style>
body { font-family: monospace; background: #222; color: #eee; margin: 0; }
#app {
display: flex;
flex-direction: column;
max-width: 800px;
margin: auto;
padding: 1em;
}
table {
border-collapse: collapse;
margin: 1em 0;
width: 100%;
}
th, td {
border: 1px solid #555;
padding: 0.3em 0.6em;
text-align: center;
}
th {
background: #333;
}
input[type=number], select {
width: 4em;
background: #222;
border: 1px solid #555;
color: #eee;
}
input[type=range] {
width: 100px;
}
.controls {
display: flex;
gap: 1em;
flex-wrap: wrap;
}
button {
background: #333;
color: #eee;
border: 1px solid #555;
padding: 0.3em 0.6em;
cursor: pointer;
}
button:hover { background: #555; }
select, input {
font-family: monospace;
}
label {
user-select: none;
}
</style>
</head>
<body>
<div id="app">
<h1>Chiptune Tracker</h1>
<div class="controls">
<label>BPM: <input type="number" id="bpm" min="30" max="300" value="120" /></label>
<label>Rows/Pattern: <input type="number" id="rowsPerPattern" min="4" max="64" value="16" /></label>
<label>Patterns/Track: <input type="number" id="patternsPerTrack" min="1" max="8" value="4" /></label>
<label>Current Pattern: <select id="patternSelect"></select></label>
<button id="playBtn">Play</button>
<button id="stopBtn">Stop</button>
<button id="loopToggle">Loop: On</button>
<button id="shareBtn">Share</button>
</div>
<h2>Instruments</h2>
<table id="instrumentTable">
<thead>
<tr>
<th>#</th>
<th>Oscillator</th>
<th>Volume</th>
<th>Detune (cents)</th>
<th>ADSR (ms)</th>
<th>Filter (Hz)</th>
<th>Noise (0-1)</th>
</tr>
</thead>
<tbody></tbody>
</table>
<button id="addInstrument">Add Instrument</button>
<h2>Pattern Editor</h2>
<div style="overflow-x: auto;">
<table id="patternGrid">
<thead><tr><th>Row</th></tr></thead>
<tbody></tbody>
</table>
</div>
<p>Shortcuts: Space=Play/Pause, Arrows=Navigate, Enter=Edit Cell, L=Loop toggle</p>
</div>
<script>
(() => {
// === Constants & Variables ===
const MAX_INSTRUMENTS = 8;
let bpm = 120;
let rowsPerPattern = 16;
let patternsPerTrack = 4;
let currentPattern = 0;
let loop = true;
let playing = false;
let audioContext = null;
let currentRow = 0;
let timerId = null;
// Data structures
let instruments = [];
// For patterns: patternsPerTrack patterns, each with rowsPerPattern rows,
// each row is an array with [note, instrument]
// note as MIDI number or null, instrument is instrument index or null
let patterns = [];
// UI elements
const bpmInput = document.getElementById('bpm');
const rowsPerPatternInput = document.getElementById('rowsPerPattern');
const patternsPerTrackInput = document.getElementById('patternsPerTrack');
const patternSelect = document.getElementById('patternSelect');
const instrumentTableBody = document.querySelector('#instrumentTable tbody');
const addInstrumentBtn = document.getElementById('addInstrument');
const patternGrid = document.getElementById('patternGrid');
const patternGridHeader = patternGrid.tHead.rows[0];
const patternGridBody = patternGrid.tBodies[0];
const playBtn = document.getElementById('playBtn');
const stopBtn = document.getElementById('stopBtn');
const loopToggleBtn = document.getElementById('loopToggle');
const shareBtn = document.getElementById('shareBtn');
// Notes map
// For chiptune, notes can be represented by e.g. 'C-4', 'D#4', '---' (empty)
// We'll map notes to MIDI number for playback
const NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F','F#','G','G#','A','A#','B'];
function noteToMidi(noteStr) {
// Format expected: C-4, D#5, --- for empty
if(noteStr === '---') return null;
const note = noteStr.substring(0,2).trim();
const octave = parseInt(noteStr.substring(2));
const noteIndex = NOTES.findIndex(n => n===note);
if(noteIndex<0) return null;
return 12*(octave+1)+noteIndex; // MIDI note number
}
function midiToNote(midi) {
if(midi === null || midi === undefined) return '---';
const octave = Math.floor(midi/12)-1;
const noteIndex = midi % 12;
return NOTES[noteIndex].padEnd(2,'-')+octave;
}
// Generate empty pattern data
function createEmptyPattern() {
let pattern = [];
for(let r=0; r<rowsPerPattern; r++) {
// For simplicity assume 1 track instrument per row
// Each row: {note: null, instrument: null}
pattern.push({note: null, instrument: null});
}
return pattern;
}
// Initialize patterns
function initPatterns() {
patterns = [];
for(let p=0;p<patternsPerTrack;p++) {
patterns.push(createEmptyPattern());
}
}
// Initialize instruments with one default instrument on load
function initInstruments() {
instruments = [];
addInstrument({
oscillator: 'square',
volume: 0.5,
detune: 0,
adsr: {attack: 10, decay: 50, sustain: 0.7, release: 200},
filterFreq: 1000,
noise: 0
});
}
function addInstrument(data) {
if(instruments.length >= MAX_INSTRUMENTS) {
alert('Max instruments reached');
return;
}
instruments.push({
oscillator: data.oscillator || 'square',
volume: data.volume || 0.5,
detune: data.detune || 0,
adsr: data.adsr || {attack: 10, decay: 50, sustain: 0.7, release: 200},
filterFreq: data.filterFreq || 1000,
noise: data.noise || 0
});
renderInstrumentTable();
}
// Render instruments table
function renderInstrumentTable() {
instrumentTableBody.innerHTML = '';
instruments.forEach((inst, i) => {
const tr = document.createElement('tr');
// # column
let td = document.createElement('td');
td.textContent = i+1;
tr.appendChild(td);
// Oscillator
td = document.createElement('td');
const oscSelect = document.createElement('select');
['square','sawtooth','triangle','sine'].forEach(type => {
let option = document.createElement('option');
option.value = type;
option.textContent = type;
if(type === inst.oscillator) option.selected = true;
oscSelect.appendChild(option);
});
oscSelect.addEventListener('change', e => {
inst.oscillator = e.target.value;
saveState();
});
td.appendChild(oscSelect);
tr.appendChild(td);
// Volume
td = document.createElement('td');
const volInput = document.createElement('input');
volInput.type = 'range';
volInput.min = 0;
volInput.max = 1;
volInput.step = 0.01;
volInput.value = inst.volume;
volInput.title = inst.volume;
volInput.addEventListener('input', e => {
inst.volume = parseFloat(e.target.value);
volInput.title = inst.volume;
saveState();
});
td.appendChild(volInput);
tr.appendChild(td);
// Detune
td = document.createElement('td');
const detuneInput = document.createElement('input');
detuneInput.type = 'number';
detuneInput.min = -100;
detuneInput.max = 100;
detuneInput.value = inst.detune;
detuneInput.addEventListener('change', e => {
inst.detune = parseInt(e.target.value);
saveState();
});
td.appendChild(detuneInput);
tr.appendChild(td);
// ADSR (Attack, Decay, Sustain, Release)
td = document.createElement('td');
const adsrInputs = {};
['attack','decay','sustain','release'].forEach(key => {
let input = document.createElement('input');
input.type = key==='sustain' ? 'range' : 'number';
if(key === 'sustain') {
input.min = 0;
input.max = 1;
input.step = 0.01;
input.value = inst.adsr[key];
input.title = inst.adsr[key];
} else {
input.min = 0;
input.max = 1000;
input.step = 1;
input.value = inst.adsr[key];
}
input.style.width = key==='sustain' ? '60px' : '60px';
input.addEventListener('input', e => {
if(key==='sustain') {
inst.adsr.sustain = parseFloat(e.target.value);
e.target.title = inst.adsr.sustain.toFixed(2);
} else {
inst.adsr[key] = parseInt(e.target.value);
}
saveState();
});
adsrInputs[key] = input;
td.appendChild(document.createTextNode(key[0].toUpperCase()+':'));
td.appendChild(input);
td.appendChild(document.createTextNode(' '));
});
tr.appendChild(td);
// Filter frequency
td = document.createElement('td');
const filterInput = document.createElement('input');
filterInput.type = 'number';
filterInput.min = 0;
filterInput.max = 5000;
filterInput.value = inst.filterFreq;
filterInput.addEventListener('change', e => {
inst.filterFreq = parseInt(e.target.value);
saveState();
});
td.appendChild(filterInput);
tr.appendChild(td);
// Noise
td = document.createElement('td');
const noiseInput = document.createElement('input');
noiseInput.type = 'range';
noiseInput.min = 0;
noiseInput.max = 1;
noiseInput.step = 0.01;
noiseInput.value = inst.noise;
noiseInput.title = inst.noise;
noiseInput.addEventListener('input', e => {
inst.noise = parseFloat(e.target.value);
noiseInput.title = inst.noise;
saveState();
});
td.appendChild(noiseInput);
tr.appendChild(td);
instrumentTableBody.appendChild(tr);
});
}
// Render pattern selector
function renderPatternSelector() {
patternSelect.innerHTML = '';
for(let i=0; i<patternsPerTrack; i++) {
const opt = document.createElement('option');
opt.value = i;
opt.textContent = 'Pattern '+(i+1);
if(i === currentPattern) opt.selected = true;
patternSelect.appendChild(opt);
}
}
// Render pattern editor header (columns)
function renderPatternHeader() {
// Clear existing but keep "Row" header
while(patternGridHeader.cells.length > 1) {
patternGridHeader.deleteCell(1);
}
// Assume one track with note and instrument columns
// Columns: Note | Instrument
let thNote = document.createElement('th');
thNote.textContent = 'Note';
patternGridHeader.appendChild(thNote);
let thInst = document.createElement('th');
thInst.textContent = 'Inst';
patternGridHeader.appendChild(thInst);
}
// Render pattern grid
function renderPatternGrid() {
patternGridBody.innerHTML = '';
let patternData = patterns[currentPattern];
for(let r=0; r<rowsPerPattern; r++) {
let tr = document.createElement('tr');
const rowCell = document.createElement('td');
rowCell.textContent = r+1;
tr.appendChild(rowCell);
// Note cell
let noteCell = document.createElement('td');
noteCell.contentEditable = true;
noteCell.classList.add('note');
noteCell.textContent = midiToNote(patternData[r].note);
noteCell.dataset.row = r;
tr.appendChild(noteCell);
// Instrument cell
let instCell = document.createElement('td');
instCell.contentEditable = true;
instCell.classList.add('instrument');
instCell.textContent = patternData[r].instrument !== null ? patternData[r].instrument+1 : '';
instCell.dataset.row = r;
tr.appendChild(instCell);
patternGridBody.appendChild(tr);
}
}
// Parse note input string (like C-4) or empty
function parseNoteInput(input) {
input = input.trim();
if(input === '' || input === '---') return null;
// allow natural notes only maybe (basic validation)
// Format: Letter + optional '#' + octave digit
const regex = /^([A-G])(#?)(-?\d)$/i;
let m = input.match(regex);
if(!m) return null;
let note = m[1].toUpperCase();
let sharp = m[2];
let octave = parseInt(m[3]);
if(sharp) note += '#';
if(!NOTES.includes(note)) return null;
return noteToMidi(note + octave);
}
// Save edits from pattern grid back to data model
function savePatternEdits() {
const rows = patternGridBody.rows;
for(let r=0; r < rows.length; r++) {
const noteCell = rows[r].querySelector('.note');
const instCell = rows[r].querySelector('.instrument');
let note = parseNoteInput(noteCell.textContent);
let inst = parseInt(instCell.textContent);
if(isNaN(inst) || inst < 1 || inst > instruments.length) inst = null; else inst = inst-1;
patterns[currentPattern][r].note = note;
patterns[currentPattern][r].instrument = inst;
}
saveState();
}
// Audio synthesis helpers
function playNote(midi, instrumentIndex, duration=500) {
if(!audioContext || midi === null || instrumentIndex === null) return;
let inst = instruments[instrumentIndex];
let now = audioContext.currentTime;
// Oscillator for tone
let osc = audioContext.createOscillator();
osc.type = inst.oscillator;
osc.frequency.value = midiToFrequency(midi);
osc.detune.value = inst.detune;
// Gain envelope
let gainNode = audioContext.createGain();
// Filter
let filter = audioContext.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.value = inst.filterFreq;
// Noise
let noiseNode = createNoiseNode(inst.noise);
// Connect chain: osc + noise -> filter -> gain -> destination
osc.connect(filter);
noiseNode.connect(filter);
filter.connect(gainNode);
gainNode.connect(audioContext.destination);
// ADSR envelope
const attackEnd = now + inst.adsr.attack / 1000;
const decayEnd = attackEnd + inst.adsr.decay / 1000;
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(inst.volume, attackEnd);
gainNode.gain.linearRampToValueAtTime(inst.volume * inst.adsr.sustain, decayEnd);
gainNode.gain.setValueAtTime(inst.volume * inst.adsr.sustain, decayEnd);
gainNode.gain.setTargetAtTime(0, decayEnd + (duration / 1000), inst.adsr.release / 1000);
osc.start(now);
noiseNode.start(now);
osc.stop(now + (duration/1000) + inst.adsr.release / 1000);
noiseNode.stop(now + (duration/1000) + inst.adsr.release / 1000);
// Cleanup nodes after stopping
osc.onended = () => {
osc.disconnect();
gainNode.disconnect();
filter.disconnect();
noiseNode.disconnect();
};
}
function createNoiseNode(volume) {
// White noise source scaled by noise volume
if(volume <= 0) {
// Return dummy source (silent)
const osc = audioContext.createOscillator();
osc.frequency.value = 0;
osc.connect(audioContext.destination);
return osc;
}
const bufferSize = 2 * audioContext.sampleRate;
const noiseBuffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate);
let output = noiseBuffer.getChannelData(0);
for(let i=0; i<bufferSize; i++) {
output[i] = (Math.random() * 2 -1) * volume;
}
const whiteNoise = audioContext.createBufferSource();
whiteNoise.buffer = noiseBuffer;
whiteNoise.loop = true;
return whiteNoise;
}
function midiToFrequency(midi) {
return 440 * Math.pow(2, (midi - 69) / 12);
}
// Playback logic
function playStep() {
if(!playing) return;
if(currentRow >= rowsPerPattern) {
if(loop) {
currentRow = 0;
} else {
stop();
return;
}
}
// Play notes in current row
let row = patterns[currentPattern][currentRow];
if(row.instrument !== null && row.note !== null) {
playNote(row.note, row.instrument, (60000/bpm) * 0.8);
}
highlightRow(currentRow);
currentRow++;
}
function start() {
if(playing) return;
if(!audioContext) audioContext = new AudioContext();
playing = true;
currentRow = 0;
highlightRow(-1);
timerId = setInterval(playStep, (60000 / bpm) / 4); // 4 steps per beat
playBtn.disabled = true;
stopBtn.disabled = false;
}
function stop() {
playing = false;
clearInterval(timerId);
timerId = null;
highlightRow(-1);
playBtn.disabled = false;
stopBtn.disabled = true;
}
function toggleLoop() {
loop = !loop;
loopToggleBtn.textContent = 'Loop: ' + (loop ? 'On' : 'Off');
saveState();
}
function highlightRow(row) {
const rows = patternGridBody.rows;
for(let i=0; i<rows.length; i++) {
rows[i].style.backgroundColor = (i === row) ? '#0c0' : '';
}
}
// Save/load state to/from URL hash (shareable)
function saveState() {
const state = {
bpm,
rowsPerPattern,
patternsPerTrack,
currentPattern,
loop,
instruments,
patterns
};
const json = JSON.stringify(state);
const data = btoa(encodeURIComponent(json));
history.replaceState(null,null, '/#'+data);
}
function loadStateFromHash() {
if(location.hash.length < 2) return false;
try {
const data = location.hash.slice(1);
const json = decodeURIComponent(atob(data));
const state = JSON.parse(json);
bpm = state.bpm || bpm;
rowsPerPattern = state.rowsPerPattern || rowsPerPattern;
patternsPerTrack = state.patternsPerTrack || patternsPerTrack;
currentPattern = state.currentPattern || 0;
loop = !!state.loop;
if(Array.isArray(state.instruments)) instruments = state.instruments;
if(Array.isArray(state.patterns)) patterns = state.patterns;
bpmInput.value = bpm;
rowsPerPatternInput.value = rowsPerPattern;
patternsPerTrackInput.value = patternsPerTrack;
loopToggleBtn.textContent = 'Loop: ' + (loop ? 'On' : 'Off');
renderPatternSelector();
renderInstrumentTable();
renderPatternGrid();
patternSelect.value = currentPattern;
return true;
} catch(e) {
console.warn('Failed to load state', e);
return false;
}
}
// UI Events setup
bpmInput.addEventListener('change', e => {
bpm = Math.max(30, Math.min(300, parseInt(e.target.value)));
e.target.value = bpm;
saveState();
});
rowsPerPatternInput.addEventListener('change', e => {
rowsPerPattern = Math.max(4, Math.min(64, parseInt(e.target.value)));
e.target.value = rowsPerPattern;
initPatterns();
renderPatternSelector();
renderPatternGrid();
saveState();
});
patternsPerTrackInput.addEventListener('change', e => {
patternsPerTrack = Math.max(1, Math.min(8, parseInt(e.target.value)));
e.target.value = patternsPerTrack;
initPatterns();
renderPatternSelector();
renderPatternGrid();
saveState();
});
patternSelect.addEventListener('change', e => {
savePatternEdits();
currentPattern = parseInt(e.target.value);
renderPatternGrid();
saveState();
});
addInstrumentBtn.addEventListener('click', e => {
addInstrument({
oscillator: 'square',
volume: 0.5,
detune: 0,
adsr: {attack: 10, decay: 50, sustain: 0.7, release: 200},
filterFreq: 1000,
noise: 0
});
saveState();
});
patternGridBody.addEventListener('input', e => {
savePatternEdits();
});
playBtn.addEventListener('click', () => {
start();
});
stopBtn.addEventListener('click', () => {
stop();
});
loopToggleBtn.addEventListener('click', () => {
toggleLoop();
});
shareBtn.addEventListener('click', () => {
savePatternEdits();
saveState();
alert('Song data saved in URL hash!\nCopy the URL to share.');
});
// Keyboard shortcuts
window.addEventListener('keydown', e => {
if(e.target.isContentEditable || e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT') return;
switch(e.key) {
case ' ':
e.preventDefault();
if(playing) stop(); else start();
break;
case 'l':
case 'L':
e.preventDefault();
toggleLoop();
break;
}
});
// Initialization sequence
function init() {
if(!loadStateFromHash()) {
// No saved state, initialize defaults
initInstruments();
initPatterns();
renderPatternSelector();
renderInstrumentTable();
renderPatternHeader();
renderPatternGrid();
} else {
renderPatternHeader();
}
playBtn.disabled = false;
stopBtn.disabled = true;
}
init();
})();
</script>
</body>
</html>
How to Use
- Adjust BPM, rows per pattern, and patterns per track in the inputs at the top.
- Add instruments and tweak oscillator type, volume, detune, ADSR, filter frequency, and noise.
- Select the pattern to edit from the dropdown.
- Pattern editor has rows with columns for Note (e.g.
C-4, D#5, --- for empty) and Instrument (instrument number).
- Press Play to start playback, Stop to stop.
- Loop toggle to enable/disable looping.
- Click Share to encode all song data and settings in the URL hash. Copy and share the URL to reload song.
- Keyboard shortcuts: Space toggles play/pause, L toggles loop.
Limitations
- Only one track, one note per row (chiptune trackers often have multiple tracks)
- Simple pattern and instrument interface - can be extended for more features
- No demo loaded (empty patch on start)
- No advanced UI features like pattern copy/paste or complex pattern editing
- Playback timing is approximate with setInterval, can be improved with AudioWorklet or similar
This gives you a foundation you can build off and customize for your needs. If you want a more advanced tracker, let me know!