It looks like you’re asking for an HTML chiptune tracker with features like:
- BPM (tempo control)
- Patterns with multiple rows per pattern
- Multiple instruments, each using a synth with a customizable oscillator
- Controls for volume, detune, ADSR (Attack, Decay, Sustain, Release), filter, and noise for each instrument
- Ability to share songs (e.g., via a URL / hash share)
- Keyboard shortcuts for editing/navigating
- Looping support
- No demo sounds or example songs loaded by default
To help you, here’s a minimal, fully client-side HTML/JS chiptune tracker skeleton that includes all these features or a structure where you can build on:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Chiptune Tracker</title>
<style>
body { font-family: monospace; background: #222; color: #eee; margin:0; padding:0; }
#tracker { display: flex; flex-direction: row; gap: 10px; padding: 10px; }
#patterns, #instrsettings { background: #333; padding: 10px; border-radius: 5px; }
#patterns { flex-grow: 1; overflow-x: auto; }
table { border-collapse: collapse; }
td, th { border: 1px solid #555; padding: 4px 6px; text-align: center; min-width: 30px; user-select:none; cursor: pointer; }
td.active { background: #077; }
#controls { background: #222; padding: 10px; border-top: 1px solid #555; display: flex; gap: 20px; }
input[type=range] { width: 100px; }
button { background:#055; color:#eee; border:none; padding:5px 10px; cursor:pointer; border-radius: 3px; }
button:hover { background:#077; }
</style>
</head>
<body>
<h1>Simple HTML Chiptune Tracker</h1>
<div id="tracker">
<div id="patterns">
<h2>Patterns</h2>
<div id="pattern-container"></div>
<button id="addPattern">Add Pattern</button>
<button id="playBtn">Play</button>
<button id="stopBtn" disabled>Stop</button>
</div>
<div id="instrsettings">
<h2>Instruments</h2>
<select id="instrumentSelect"></select><br /><br />
<label>Oscillator:
<select id="oscType">
<option value="square">Square</option>
<option value="sawtooth">Sawtooth</option>
<option value="triangle">Triangle</option>
<option value="sine">Sine</option>
</select>
</label><br /><br />
<label>Volume: <input type="range" id="volume" min="0" max="1" step="0.01" value="0.5"></label><br />
<label>Detune (cents): <input type="range" id="detune" min="-100" max="100" step="1" value="0"></label><br />
<label>Attack (s): <input type="range" id="attack" min="0" max="1" step="0.01" value="0.01"></label><br />
<label>Decay (s): <input type="range" id="decay" min="0" max="1" step="0.01" value="0.1"></label><br />
<label>Sustain (0-1): <input type="range" id="sustain" min="0" max="1" step="0.01" value="0.8"></label><br />
<label>Release (s): <input type="range" id="release" min="0" max="1" step="0.01" value="0.1"></label><br />
<label>Filter Cutoff (Hz): <input type="range" id="filterCutoff" min="100" max="10000" step="1" value="5000"></label><br />
<label>Noise Volume: <input type="range" id="noiseVol" min="0" max="1" step="0.01" value="0"></label><br />
<button id="addInstrument">Add Instrument</button>
</div>
</div>
<div id="controls">
<label>BPM: <input type="number" id="bpm" value="120" min="30" max="300" style="width:60px"></label>
<button id="shareBtn">Share Song</button>
</div>
<script>
/*
Simple chiptune tracker with:
- multiple patterns (each pattern is 16 rows)
- multiple instruments with synth parameters
- oscillator types
- ADSR and filter (basic)
- noise volume
- BPM control
- share via URL hash (serialization)
- keyboard shortcuts for navigation and editing notes
- looping playback
*/
const AudioContext = window.AudioContext || window.webkitAudioContext;
const ctx = new AudioContext();
let state = {
bpm: 120,
rowsPerPattern: 16,
patterns: [], // array of pattern objects {rows: [{notes per instrument}]}
instruments: [], // array of instrument parameter objects
currentPatternIndex: 0,
currentRow: 0,
playing: false,
loop: true,
};
const NOTES = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];
const NOTE_TO_FREQ = (note, octave) => {
// Calculate freq for note name + octave
let semitones = NOTES.indexOf(note);
if (semitones < 0) return 0;
let n = semitones + (octave - 4) * 12;
return 440 * Math.pow(2, n / 12);
};
/* --- Initialize --- */
function createEmptyPattern() {
// 16 rows, 4 channels = instruments for now
let pattern = {
rows: []
};
for(let i=0; i<state.rowsPerPattern; i++){
// Each row: array of notes/instrument sound params
let row = [];
for(let ch=0; ch<state.instruments.length; ch++){
row.push(null); // no note initially
}
pattern.rows.push(row);
}
return pattern;
}
function createDefaultInstrument(name='Inst') {
return {
name,
oscType:'square',
volume:0.5,
detune:0,
adsr: {attack: 0.01, decay: 0.1, sustain: 0.8, release:0.1},
filterCutoff: 5000,
noiseVol: 0,
};
}
/* --- Patterns UI --- */
const patternContainer = document.getElementById('pattern-container');
const instrumentSelect = document.getElementById('instrumentSelect');
const oscTypeInput = document.getElementById('oscType');
const volumeInput = 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 noiseVolInput = document.getElementById('noiseVol');
const addInstrumentBtn = document.getElementById('addInstrument');
const addPatternBtn = document.getElementById('addPattern');
const bpmInput = document.getElementById('bpm');
const playBtn = document.getElementById('playBtn');
const stopBtn = document.getElementById('stopBtn');
const shareBtn = document.getElementById('shareBtn');
/* --- Song Data & Playback --- */
function saveStateToHash() {
// Serialize state (patterns + instruments + bpm) into URL hash as compressed base64 JSON
const data = {
bpm: state.bpm,
patterns: state.patterns,
instruments: state.instruments,
};
const json = JSON.stringify(data);
const b64 = btoa(unescape(encodeURIComponent(json)));
location.hash = '#song=' + b64;
}
function loadStateFromHash() {
if(location.hash.startsWith('#song=')){
try {
const b64 = location.hash.slice(6);
const json = decodeURIComponent(escape(atob(b64)));
const data = JSON.parse(json);
state.bpm = data.bpm || 120;
state.patterns = data.patterns || [];
state.instruments = data.instruments || [];
bpmInput.value = state.bpm;
if(state.patterns.length === 0 && state.instruments.length === 0){
initDefaultSong();
}
renderAll();
} catch(e){
console.warn('Failed to load song from URL hash', e);
initDefaultSong();
}
} else {
initDefaultSong();
}
}
function initDefaultSong(){
state.instruments = [createDefaultInstrument('Inst 1')];
state.patterns = [createEmptyPattern()];
renderAll();
saveStateToHash();
}
/* --- UI Rendering --- */
function renderPatterns() {
patternContainer.innerHTML = '';
state.patterns.forEach((pattern, pIndex) => {
const table = document.createElement('table');
const headerRow = document.createElement('tr');
let th = document.createElement('th');
th.textContent = "Row";
headerRow.appendChild(th);
for(let i=0; i<state.instruments.length; i++) {
th = document.createElement('th');
th.textContent = "Inst " + (i+1);
headerRow.appendChild(th);
}
table.appendChild(headerRow);
pattern.rows.forEach((row,nr) => {
let tr = document.createElement('tr');
let rowNumCell = document.createElement('td');
rowNumCell.textContent = nr + 1;
tr.appendChild(rowNumCell);
for(let ch=0; ch<state.instruments.length; ch++){
let td = document.createElement('td');
let note = pattern.rows[nr][ch];
td.textContent = note ? formatNote(note) : '-';
td.dataset.patternIndex = pIndex;
td.dataset.row = nr;
td.dataset.channel = ch;
td.addEventListener('click', onNoteCellClick);
if(pIndex === state.currentPatternIndex && nr === state.currentRow) td.classList.add('active');
tr.appendChild(td);
}
table.appendChild(tr);
});
patternContainer.appendChild(table);
});
}
function formatNote(note) {
if(!note) return '-';
if(note.type === 'noise') return 'Noise';
return note.note + note.octave;
}
function renderInstruments() {
instrumentSelect.innerHTML = '';
state.instruments.forEach((inst,i)=>{
let opt = document.createElement('option');
opt.value = i;
opt.textContent = inst.name || 'Inst ' + (i+1);
instrumentSelect.appendChild(opt);
});
instrumentSelect.selectedIndex = state.currentInstrumentIndex || 0;
loadInstrumentToUI(state.currentInstrumentIndex || 0);
}
function loadInstrumentToUI(index){
if(index == null || !state.instruments[index]) return;
let inst = state.instruments[index];
oscTypeInput.value = inst.oscType;
volumeInput.value = inst.volume;
detuneInput.value = inst.detune;
attackInput.value = inst.adsr.attack;
decayInput.value = inst.adsr.decay;
sustainInput.value = inst.adsr.sustain;
releaseInput.value = inst.adsr.release;
filterCutoffInput.value = inst.filterCutoff;
noiseVolInput.value = inst.noiseVol;
}
/* --- Events --- */
function onNoteCellClick(e){
let td = e.currentTarget;
let pIndex = +td.dataset.patternIndex;
let row = +td.dataset.row;
let ch = +td.dataset.channel;
let pattern = state.patterns[pIndex];
let note = pattern.rows[row][ch];
// Toggle note between null and C4 (for demo)
if(note){
pattern.rows[row][ch] = null;
} else {
pattern.rows[row][ch] = {note:'C', octave:4, type:'note'};
}
renderPatterns();
saveStateToHash();
}
addInstrumentBtn.onclick = () => {
const name = prompt("Name of new instrument", "Inst " + (state.instruments.length + 1));
if(!name) return;
state.instruments.push(createDefaultInstrument(name));
state.patterns.forEach(p=>{
p.rows.forEach(row=>{
row.push(null);
});
});
renderInstruments();
renderPatterns();
saveStateToHash();
};
addPatternBtn.onclick = () => {
state.patterns.push(createEmptyPattern());
renderPatterns();
saveStateToHash();
};
instrumentSelect.onchange = () => {
state.currentInstrumentIndex = +instrumentSelect.value;
loadInstrumentToUI(state.currentInstrumentIndex);
};
[oscTypeInput, volumeInput, detuneInput, attackInput, decayInput, sustainInput, releaseInput, filterCutoffInput, noiseVolInput].forEach(input=>{
input.oninput = () => {
if(state.currentInstrumentIndex == null) return;
const inst = state.instruments[state.currentInstrumentIndex];
inst.oscType = oscTypeInput.value;
inst.volume = +volumeInput.value;
inst.detune = +detuneInput.value;
inst.adsr.attack = +attackInput.value;
inst.adsr.decay = +decayInput.value;
inst.adsr.sustain = +sustainInput.value;
inst.adsr.release = +releaseInput.value;
inst.filterCutoff = +filterCutoffInput.value;
inst.noiseVol = +noiseVolInput.value;
saveStateToHash();
};
});
bpmInput.onchange = () => {
state.bpm = +bpmInput.value;
saveStateToHash();
};
/* --- Playback --- */
let timerId = null;
let currentPlayRow = 0;
function playRow(row) {
stopAllSounds(); // stop previous
state.patterns[state.currentPatternIndex].rows[row].forEach((note, ch) => {
if(!note) return;
playNote(note, ch);
});
}
function playNote(note, ch){
if(!state.instruments[ch]) return;
let inst = state.instruments[ch];
let now = ctx.currentTime;
// Oscillator
let osc = ctx.createOscillator();
osc.type = inst.oscType;
let freq;
if(note.type === 'noise'){
freq = null;
} else {
freq = NOTE_TO_FREQ(note.note, note.octave);
}
if(freq){
osc.frequency.setValueAtTime(freq, now);
osc.detune.setValueAtTime(inst.detune, now);
}
// Gain envelope (ADSR)
let gainNode = ctx.createGain();
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(inst.volume, now + inst.adsr.attack);
gainNode.gain.linearRampToValueAtTime(inst.volume * inst.adsr.sustain, now + inst.adsr.attack + inst.adsr.decay);
gainNode.gain.setTargetAtTime(0, now + inst.adsr.attack + inst.adsr.decay + 0.1, inst.adsr.release);
// Filter
let filter = ctx.createBiquadFilter();
filter.frequency.setValueAtTime(inst.filterCutoff, now);
// Noise oscillator if noiseVol > 0 and note is noise
let noiseGain = null;
if(inst.noiseVol > 0 && note.type === 'noise'){
let noiseBuffer = ctx.createBuffer(1, ctx.sampleRate * 1, ctx.sampleRate);
let data = noiseBuffer.getChannelData(0);
for(let i=0; i<data.length; i++) data[i] = Math.random()*2 - 1;
let noiseSource = ctx.createBufferSource();
noiseSource.buffer = noiseBuffer;
noiseGain = ctx.createGain();
noiseGain.gain.setValueAtTime(inst.noiseVol, now);
noiseSource.connect(noiseGain).connect(filter);
noiseSource.start(now);
noiseSource.stop(now + 0.2);
// Save to stop later
playingNoiseSources.push(noiseSource);
}
osc.connect(gainNode).connect(filter).connect(ctx.destination);
osc.start(now);
osc.stop(now + 0.5);
playingOscillators.push(osc);
}
function stopAllSounds(){
playingOscillators.forEach(o=>{
try{
o.stop();
}catch(e){}
});
playingOscillators = [];
playingNoiseSources.forEach(n=>{
try{
n.stop();
}catch(e){}
});
playingNoiseSources = [];
}
let playingOscillators = [];
let playingNoiseSources = [];
function playLoop(){
if(!state.playing) return;
playRow(currentPlayRow);
currentPlayRow++;
if(currentPlayRow >= state.rowsPerPattern){
currentPlayRow = 0;
}
timerId = setTimeout(playLoop, (60000 / state.bpm) / 4); // 4 rows per beat (16th notes) - adjust if you want
}
playBtn.onclick = async () => {
if(ctx.state === 'suspended') await ctx.resume();
state.playing = true;
playBtn.disabled = true;
stopBtn.disabled = false;
currentPlayRow = 0;
playLoop();
};
stopBtn.onclick = () => {
state.playing = false;
playBtn.disabled = false;
stopBtn.disabled = true;
clearTimeout(timerId);
stopAllSounds();
};
shareBtn.onclick = () => {
saveStateToHash();
alert('Song share URL copied to address bar');
};
/* --- Keyboard navigation and editing --- */
document.body.addEventListener('keydown', e=>{
if(state.playing) return; // disable while playing
switch(e.key) {
case 'ArrowDown':
state.currentRow = (state.currentRow + 1) % state.rowsPerPattern;
e.preventDefault();
break;
case 'ArrowUp':
state.currentRow = (state.currentRow - 1 + state.rowsPerPattern) % state.rowsPerPattern;
e.preventDefault();
break;
case 'ArrowRight':
state.currentInstrumentIndex = (state.currentInstrumentIndex + 1) % state.instruments.length;
loadInstrumentToUI(state.currentInstrumentIndex);
instrumentSelect.selectedIndex = state.currentInstrumentIndex;
e.preventDefault();
break;
case 'ArrowLeft':
state.currentInstrumentIndex = (state.currentInstrumentIndex -1 + state.instruments.length) % state.instruments.length;
loadInstrumentToUI(state.currentInstrumentIndex);
instrumentSelect.selectedIndex = state.currentInstrumentIndex;
e.preventDefault();
break;
case 'c': // clear note under cursor
let p = state.patterns[state.currentPatternIndex];
if(p && p.rows[state.currentRow]){
p.rows[state.currentRow][state.currentInstrumentIndex] = null;
}
e.preventDefault();
break;
case 'n': // insert C4 note
let p2 = state.patterns[state.currentPatternIndex];
if(p2 && p2.rows[state.currentRow]){
p2.rows[state.currentRow][state.currentInstrumentIndex] = {note:'C', octave:4, type:'note'};
}
e.preventDefault();
break;
case 'm': // insert noise note
let p3 = state.patterns[state.currentPatternIndex];
if(p3 && p3.rows[state.currentRow]){
p3.rows[state.currentRow][state.currentInstrumentIndex] = {type:'noise'};
}
e.preventDefault();
break;
}
renderPatterns();
saveStateToHash();
});
/* --- Initialization --- */
loadStateFromHash();
renderInstruments();
renderPatterns();
</script>
</body>
</html>
How to use:
- Click a cell in the pattern to insert/delete a note (it will toggle C4 note).
- Use keyboard arrows Up/Down to move cursor row, Left/Right to switch instruments.
- Press
n to insert a C4 note at current row/instrument.
- Press
c to clear note.
- Press
m to insert noise.
- Adjust synth parameters on the right for the selected instrument.
- Add instruments or patterns using the buttons.
Play and Stop to hear the current pattern in a loop.
- Change BPM with the input below.
- Share song by clicking "Share Song" which serializes the whole state into the URL hash.
- Reloading page with the generated URL restores the song and instruments.
What’s included?
- Basic WebAudio synth with ADSR envelope for each instrument.
- Oscillator type selection per instrument.
- Volume, detune, filter cutoff, noise level per instrument.
- Multiple instruments and patterns.
- 16 rows per pattern as default.
- Share via URL hash (base64 encoded JSON).
- Keyboard shortcuts for quick editing.
- Looping playback at BPM specified.
If you'd like me to help extend this (like adding effects, pattern chaining, saving/loading files, more notes/octaves, etc.) just ask!