It looks like you want an HTML chiptune tracker with features including:
- BPM (tempo control)
- Patterns and rows per pattern
- Multiple instruments with synth per instrument
- Custom oscillators
- Volume, detune, ADSR envelope, filter, noise controls per instrument
- Ability to share the song via URL or shortcut
- Looping functionality
- No demo sounds or extraneous content included
Here is a minimal yet functional HTML + JavaScript chiptune tracker prototype implementing these core features. It uses the Web Audio API synthesizer and supports patterns, rows, instruments, BPM, and basic ADSR/filter controls. The data can be serialized to the URL hash for sharing and reloaded.
Features implemented in this example
- BPM control
- Configurable rows per pattern (fixed here for simplicity, can be expanded)
- Multiple instruments (with synth oscillator choice: square, sawtooth, sine, custom)
- Volume, detune, ADSR envelope, filter frequency control per instrument
- Noise on/off per instrument
- Basic pattern editor grid
- Playback looping
- Share song state encoded in URL hash (using JSON + base64)
- Shortcuts for playback start/stop (space), navigation (arrows)
How to use
- Click the cells to input notes (C4=60 MIDI standard)
- Use dropdowns and sliders below for instrument settings
- Press spacebar to toggle playback loop
- URL hash updates automatically on changes, share URL to share song
- Reload page with URL to reload composition
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simple HTML Chiptune Tracker</title>
<style>
body { font-family: monospace, monospace; background: #222; color: #eee; margin: 0; padding: 0; }
h1 {text-align:center;}
#tracker { display: grid; grid-template-columns: repeat(17, 3em); margin: 0 auto; }
#tracker .header { background: #444; font-weight: bold; text-align: center; }
#tracker .cell {
border: 1px solid #555;
text-align: center;
cursor: pointer;
user-select: none;
line-height: 2em;
font-size: 0.9rem;
}
#tracker .cell.active { background: #177; color: #def; font-weight: bold; }
#tracker .cell.note { color: #7f7; }
#tracker .cell.empty { color: #444; }
#controls {
max-width: 600px;
margin: 1em auto;
background: #333;
padding: 1em;
border-radius: 0.3em;
}
#controls > div { margin-bottom: 0.6em; }
label { display: inline-block; width: 90px; }
select, input[type=range], input[type=number] { width: 150px; }
button { margin-left: 10px; }
#info { max-width: 600px; margin: 1em auto; font-size: 0.85rem; color: #999; }
</style>
</head>
<body>
<h1>HTML Chiptune Tracker</h1>
<div id="tracker"></div>
<div id="controls">
<div>
<label for="bpm">BPM</label>
<input type="number" id="bpm" min="20" max="300" value="120" />
</div>
<div>
<label for="pattern">Pattern</label>
<select id="pattern"></select>
<button id="prevPattern"><</button>
<button id="nextPattern">></button>
<button id="addPattern">Add</button>
</div>
<div>
<label for="instrument">Instrument</label>
<select id="instrument"></select>
</div>
<div>
<label for="osc">Oscillator</label>
<select id="osc">
<option value="square">Square</option>
<option value="sawtooth">Sawtooth</option>
<option value="sine">Sine</option>
<option value="triangle">Triangle</option>
<option value="custom">Custom (triangle+square mix)</option>
</select>
</div>
<div>
<label for="vol">Volume</label>
<input type="range" id="vol" min="0" max="1" step="0.01" value="0.8" />
</div>
<div>
<label for="detune">Detune (cents)</label>
<input type="range" id="detune" min="-100" max="100" step="1" value="0" />
</div>
<div>
<label for="attack">Attack (s)</label>
<input type="range" id="attack" min="0" max="1" step="0.01" value="0.01" />
</div>
<div>
<label for="decay">Decay (s)</label>
<input type="range" id="decay" min="0" max="1" step="0.01" value="0.1" />
</div>
<div>
<label for="sustain">Sustain</label>
<input type="range" id="sustain" min="0" max="1" step="0.01" value="0.7" />
</div>
<div>
<label for="release">Release (s)</label>
<input type="range" id="release" min="0" max="2" step="0.01" value="0.2" />
</div>
<div>
<label for="filterFreq">Filter Freq (Hz)</label>
<input type="range" id="filterFreq" min="0" max="10000" step="1" value="8000" />
</div>
<div>
<label for="noise">Noise</label>
<input type="checkbox" id="noise" />
</div>
<button id="addInstrument">Add Instrument</button>
</div>
<div id="info">
<p><b>Controls:</b> Click cells to add notes (C4 = 60). Space to play/pause. Arrows to navigate patterns and instruments.</p>
<p>Song data is saved in the URL for sharing.</p>
</div>
<script>
(() => {
// Constants
const NOTES = [
'C-', 'C#', 'D-', 'D#', 'E-', 'F-', 'F#', 'G-',
'G#', 'A-', 'A#', 'B-'
];
const NUM_PATTERNS = 8; // max number of patterns
const ROWS_PER_PATTERN = 16;
const MAX_INSTRUMENTS = 4;
// Utils: MIDI note number to note string like "C-4"
function noteToStr(noteNum) {
if (noteNum === null) return '...';
let octave = Math.floor(noteNum / 12) - 1;
let note = NOTES[noteNum % 12];
return note + octave;
}
// Parse note string to midi number or null
// Examples: C-4=60, D#3=51, ... '---' or '...' = null
// Not used here for input, but could be extended
// Convert array to base64 for URL hash
function encodeSong(data) {
return btoa(unescape(encodeURIComponent(JSON.stringify(data))));
}
function decodeSong(str) {
try {
return JSON.parse(decodeURIComponent(escape(atob(str))));
} catch {
return null;
}
}
// Song state
let song = {
bpm: 120,
patterns: [],
instruments: [],
currentPattern: 0,
currentInstrument: 0
};
// Initialize empty patterns
function initEmptyPattern() {
// 16 rows x 4 channels (one per instrument max here; could expand)
let pat = [];
for(let r=0; r<ROWS_PER_PATTERN; r++) {
let row = [];
for(let ch=0; ch<MAX_INSTRUMENTS; ch++) {
row.push(null); // null means no note
}
pat.push(row);
}
return pat;
}
function initEmptyInstrument(name = 'Inst ' + (song.instruments.length+1)) {
return {
name,
osc: 'square',
volume: 0.8,
detune: 0,
adsr: { attack: 0.01, decay: 0.1, sustain: 0.7, release: 0.2 },
filterFreq: 8000,
noise: false
};
}
// DOM elements
const tracker = document.getElementById('tracker');
const bpmInput = document.getElementById('bpm');
const patternSelect = document.getElementById('pattern');
const prevPatternBtn = document.getElementById('prevPattern');
const nextPatternBtn = document.getElementById('nextPattern');
const addPatternBtn = document.getElementById('addPattern');
const instrumentSelect = document.getElementById('instrument');
const oscSelect = document.getElementById('osc');
const volSlider = document.getElementById('vol');
const detuneSlider = document.getElementById('detune');
const attackSlider = document.getElementById('attack');
const decaySlider = document.getElementById('decay');
const sustainSlider = document.getElementById('sustain');
const releaseSlider = document.getElementById('release');
const filterFreqSlider = document.getElementById('filterFreq');
const noiseCheckbox = document.getElementById('noise');
const addInstrumentBtn = document.getElementById('addInstrument');
// Audio context
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioCtx = new AudioContext();
// Pattern editor
// Build header: "Row" + Inst0 Inst1 Inst2 Inst3
function buildTrackerGrid() {
tracker.innerHTML = '';
// Header row
let headerCells = ['Row'];
for (let i = 0; i < song.instruments.length; i++) {
headerCells.push('Inst ' + (i+1));
}
// Fill empty cols if less than MAX_INSTRUMENTS
for (let i = song.instruments.length; i < MAX_INSTRUMENTS; i++) {
headerCells.push('');
}
headerCells.forEach(h => {
let div = document.createElement('div');
div.classList.add('header');
div.textContent = h;
tracker.appendChild(div);
});
// Rows
for (let r = 0; r < ROWS_PER_PATTERN; r++) {
// Row label cell
let rowLabel = document.createElement('div');
rowLabel.classList.add('header');
rowLabel.textContent = r.toString().padStart(2, '0');
tracker.appendChild(rowLabel);
for (let ch = 0; ch < MAX_INSTRUMENTS; ch++) {
let cell = document.createElement('div');
cell.classList.add('cell');
// Fill cell with note if exists
let note = song.patterns[song.currentPattern][r][ch];
if (note !== null) {
cell.textContent = noteToStr(note);
cell.classList.add('note');
} else {
cell.textContent = '...';
cell.classList.add('empty');
}
// Disable cells for unused instrument columns
if (ch >= song.instruments.length) {
cell.style.background = '#111';
cell.style.cursor = 'default';
cell.textContent = '';
cell.classList.remove('note', 'empty');
} else {
// Interactive
cell.dataset.row = r;
cell.dataset.inst = ch;
cell.addEventListener('click', onCellClick);
}
tracker.appendChild(cell);
}
}
}
// On cell click - input notes
// Cycle notes on click: null -> C4 -> D4 -> E4 -> F4 -> G4 -> A4 -> B4 -> null
const C4 = 60;
const playableNotes = [C4, C4+2, C4+4, C4+5, C4+7, C4+9, C4+11];
function onCellClick(e) {
const r = +e.target.dataset.row;
const inst = +e.target.dataset.inst;
let currentNote = song.patterns[song.currentPattern][r][inst];
let idx = playableNotes.indexOf(currentNote);
idx++; // next note
if (idx >= playableNotes.length) idx = -1; // cycle off
let newNote = idx === -1 ? null : playableNotes[idx];
song.patterns[song.currentPattern][r][inst] = newNote;
updateTrackerCell(e.target, newNote);
saveToUrl();
}
function updateTrackerCell(cell, note) {
if (note === null) {
cell.textContent = '...';
cell.classList.remove('note');
cell.classList.add('empty');
} else {
cell.textContent = noteToStr(note);
cell.classList.add('note');
cell.classList.remove('empty');
}
}
// Load controls from selected instrument
function loadInstrumentSettings() {
let inst = song.instruments[song.currentInstrument];
if (!inst) return;
oscSelect.value = inst.osc;
volSlider.value = inst.volume;
detuneSlider.value = inst.detune;
attackSlider.value = inst.adsr.attack;
decaySlider.value = inst.adsr.decay;
sustainSlider.value = inst.adsr.sustain;
releaseSlider.value = inst.adsr.release;
filterFreqSlider.value = inst.filterFreq;
noiseCheckbox.checked = inst.noise;
}
// Save controls to current instrument
function saveInstrumentSettings() {
let inst = song.instruments[song.currentInstrument];
if (!inst) return;
inst.osc = oscSelect.value;
inst.volume = parseFloat(volSlider.value);
inst.detune = parseFloat(detuneSlider.value);
inst.adsr.attack = parseFloat(attackSlider.value);
inst.adsr.decay = parseFloat(decaySlider.value);
inst.adsr.sustain = parseFloat(sustainSlider.value);
inst.adsr.release = parseFloat(releaseSlider.value);
inst.filterFreq = parseFloat(filterFreqSlider.value);
inst.noise = noiseCheckbox.checked;
saveToUrl();
}
// Initialize select options
function updatePatternSelector() {
patternSelect.innerHTML = '';
for (let i = 0; i < song.patterns.length; i++) {
let opt = document.createElement('option');
opt.value = i;
opt.textContent = 'Pattern ' + i;
patternSelect.appendChild(opt);
}
patternSelect.value = song.currentPattern;
}
function updateInstrumentSelector() {
instrumentSelect.innerHTML = '';
song.instruments.forEach((inst, idx) => {
let opt = document.createElement('option');
opt.value = idx;
opt.textContent = inst.name || ('Inst ' + (idx + 1));
instrumentSelect.appendChild(opt);
});
instrumentSelect.value = song.currentInstrument;
}
// Handlers
bpmInput.addEventListener('change', () => {
let val = parseInt(bpmInput.value);
if (!isNaN(val) && val>=20 && val<=300) {
song.bpm = val;
saveToUrl();
}
});
patternSelect.addEventListener('change', () => {
song.currentPattern = parseInt(patternSelect.value);
buildTrackerGrid();
});
prevPatternBtn.addEventListener('click', () => {
song.currentPattern = (song.currentPattern - 1 + song.patterns.length) % song.patterns.length;
updatePatternSelector();
buildTrackerGrid();
});
nextPatternBtn.addEventListener('click', () => {
song.currentPattern = (song.currentPattern + 1) % song.patterns.length;
updatePatternSelector();
buildTrackerGrid();
});
addPatternBtn.addEventListener('click', () => {
if(song.patterns.length >= NUM_PATTERNS) return alert('Max patterns reached');
song.patterns.push(initEmptyPattern());
song.currentPattern = song.patterns.length-1;
updatePatternSelector();
buildTrackerGrid();
saveToUrl();
});
instrumentSelect.addEventListener('change', () => {
saveInstrumentSettings();
song.currentInstrument = parseInt(instrumentSelect.value);
loadInstrumentSettings();
buildTrackerGrid();
});
oscSelect.addEventListener('change', () => { saveInstrumentSettings(); });
volSlider.addEventListener('input', () => { saveInstrumentSettings(); });
detuneSlider.addEventListener('input', () => { saveInstrumentSettings(); });
attackSlider.addEventListener('input', () => { saveInstrumentSettings(); });
decaySlider.addEventListener('input', () => { saveInstrumentSettings(); });
sustainSlider.addEventListener('input', () => { saveInstrumentSettings(); });
releaseSlider.addEventListener('input', () => { saveInstrumentSettings(); });
filterFreqSlider.addEventListener('input', () => { saveInstrumentSettings(); });
noiseCheckbox.addEventListener('change', () => { saveInstrumentSettings(); });
addInstrumentBtn.addEventListener('click', () => {
if(song.instruments.length >= MAX_INSTRUMENTS) return alert('Max instruments reached');
song.instruments.push(initEmptyInstrument());
// Add new instrument column also enables notes for it
// Also add column for pattern notes (nulls)
for(let p=0; p<song.patterns.length; p++) {
for(let r=0; r<ROWS_PER_PATTERN; r++) {
song.patterns[p][r].push(null);
}
}
song.currentInstrument = song.instruments.length -1;
updateInstrumentSelector();
loadInstrumentSettings();
buildTrackerGrid();
saveToUrl();
});
// Playback engine
let isPlaying = false;
let currentRow = 0;
let lookahead = 25.0; // ms
let scheduleAheadTime = 0.1; // sec
let nextNoteTime = 0.0;
let timerID;
function nextNote() {
let secondsPerBeat = 60.0 / song.bpm;
nextNoteTime += 0.25 * secondsPerBeat; // 16th notes: 1/4 of beat
currentRow++;
if(currentRow >= ROWS_PER_PATTERN) {
currentRow = 0;
}
}
function scheduleNote(time, row) {
// For each instrument (channel)
let pattern = song.patterns[song.currentPattern];
for(let ch=0; ch < song.instruments.length; ch++) {
let note = pattern[row][ch];
if(note !== null) {
playNote(note, time, song.instruments[ch]);
}
}
}
function scheduler() {
while(nextNoteTime < audioCtx.currentTime + scheduleAheadTime ) {
scheduleNote(nextNoteTime, currentRow);
nextNote();
}
timerID = setTimeout(scheduler, lookahead);
}
// Custom oscillator - mix of triangle + square
class CustomOscillatorNode extends AudioWorkletNode {
// Would require registering AudioWorklet processor - omitted for brevity
}
// Play a note at a given time, with instrument settings
function playNote(midiNote, startTime, inst) {
if(audioCtx.state === 'suspended') audioCtx.resume();
// Carrier osc1
let osc1 = audioCtx.createOscillator();
osc1.type = inst.osc === 'custom' ? 'triangle' : inst.osc;
osc1.frequency.value = 440 * Math.pow(2, (midiNote - 69)/12);
osc1.detune.value = inst.detune;
// Carrier osc2 for custom osc
let osc2 = null;
if(inst.osc === 'custom') {
osc2 = audioCtx.createOscillator();
osc2.type = 'square';
osc2.frequency.value = 440 * Math.pow(2, (midiNote - 69)/12);
osc2.detune.value = inst.detune;
}
// Noise
let noiseNode = null;
if(inst.noise) {
let bufferSize = audioCtx.sampleRate * 0.1;
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) * 0.2;
noiseNode = audioCtx.createBufferSource();
noiseNode.buffer = buffer;
noiseNode.loop = true;
}
// Gain node for volume/adsr
let gainNode = audioCtx.createGain();
gainNode.gain.setValueAtTime(0, startTime);
gainNode.gain.linearRampToValueAtTime(inst.volume, startTime + inst.adsr.attack);
gainNode.gain.linearRampToValueAtTime(inst.volume * inst.adsr.sustain, startTime + inst.adsr.attack + inst.adsr.decay);
// Release scheduled on stop - scheduled outside for now: short notes
gainNode.gain.setTargetAtTime(0, startTime + 0.25, inst.adsr.release);
// Filter
let filter = audioCtx.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.setValueAtTime(inst.filterFreq, startTime);
// Connect
osc1.connect(gainNode);
if(osc2) osc2.connect(gainNode);
if(noiseNode) noiseNode.connect(gainNode);
gainNode.connect(filter);
filter.connect(audioCtx.destination);
osc1.start(startTime);
if(osc2) osc2.start(startTime);
if(noiseNode) noiseNode.start(startTime);
osc1.stop(startTime + 0.3);
if(osc2) osc2.stop(startTime + 0.3);
if(noiseNode) noiseNode.stop(startTime + 0.3);
}
// Controls shortcuts
window.addEventListener('keydown', e => {
if(e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT') return; // ignore input typing
if(e.code === 'Space') {
e.preventDefault();
togglePlayback();
} else if(e.code === 'ArrowRight') {
// Next instrument
song.currentInstrument = (song.currentInstrument +1) % song.instruments.length;
updateInstrumentSelector();
loadInstrumentSettings();
buildTrackerGrid();
} else if(e.code === 'ArrowLeft') {
// Prev instrument
song.currentInstrument = (song.currentInstrument -1 + song.instruments.length) % song.instruments.length;
updateInstrumentSelector();
loadInstrumentSettings();
buildTrackerGrid();
} else if(e.code === 'ArrowDown') {
song.currentPattern = (song.currentPattern +1) % song.patterns.length;
updatePatternSelector();
buildTrackerGrid();
} else if(e.code === 'ArrowUp') {
song.currentPattern = (song.currentPattern -1 + song.patterns.length) % song.patterns.length;
updatePatternSelector();
buildTrackerGrid();
}
});
// Playback control
function togglePlayback() {
if(isPlaying) {
stopPlayback();
} else {
startPlayback();
}
}
function startPlayback() {
if(audioCtx.state === 'suspended') audioCtx.resume();
isPlaying = true;
currentRow = 0;
nextNoteTime = audioCtx.currentTime + 0.05;
scheduler();
}
function stopPlayback() {
isPlaying = false;
clearTimeout(timerID);
}
// Save and load song from URL hash
function saveToUrl() {
let data = {
bpm: song.bpm,
patterns: song.patterns,
instruments: song.instruments
};
let encoded = encodeSong(data);
location.hash = encoded;
}
function loadFromUrl() {
if(location.hash.length < 2) return false;
let data = decodeSong(location.hash.substr(1));
if(!data) return false;
if(data.bpm && data.patterns && data.instruments) {
song.bpm = data.bpm;
song.patterns = data.patterns;
song.instruments = data.instruments;
song.currentPattern = 0;
song.currentInstrument = 0;
return true;
}
return false;
}
// Init song data
function init() {
let loaded = loadFromUrl();
if(!loaded) {
// First load: 1 pattern, 1 instrument
song.patterns.push(initEmptyPattern());
song.instruments.push(initEmptyInstrument());
}
bpmInput.value = song.bpm;
updatePatternSelector();
updateInstrumentSelector();
loadInstrumentSettings();
buildTrackerGrid();
}
init();
})();
</script>
</body>
</html>
Explanation
- The tracker grid shows rows and one column per instrument (max 4).
- Click cells to cycle through a preset scale from C4 up in a simple major-ish scale.
- You can add patterns and instruments.
- Each instrument has its synth settings: oscillator type, volume, detune, ADSR, filter frequency, and noise toggle.
- Playback plays through the current pattern in a loop with 16 rows per pattern.
- The song state is saved and restored from the URL hash, so you can share the link to share your song.
- Spacebar toggles playback. Arrow keys navigate instruments and patterns.
- The "Custom" oscillator combines triangle and square wave oscillators together to simulate a custom waveform.
- No demo audio included, only synthesized sounds from the Web Audio API.
This is a starter template you can extend further to include more complex features like:
- Real note input by keyboard
- Multiple channels per pattern, advanced pattern sequencing
- More advanced waveforms or custom wavetable oscillators
- Export to WAV/MP3
- UI improvements
But I think this matches your requested features and is a basic full tracker system in a single HTML file for quick testing and sharing.
If you want me to add or adjust any feature, please let me know!