Certainly! You want an HTML-based chiptune tracker that supports:
- BPM control
- Patterns with rows per pattern
- Multiple instruments with synth per instrument
- Custom oscillator types (e.g., square, triangle, sawtooth, noise)
- Volume, detune, ADSR envelope, filter and noise controls per instrument
- Ability to share song data (e.g., encoded in URL or text)
- Keyboard or UI shortcuts
- Pattern loop control
- URL hash (
/#) based song sharing
- No demo/demo audio auto-play
I’ll provide a basic but functional chiptune tracker scaffold written fully in plain HTML/JS using Web Audio API, focused on the requested features.
Chiptune Tracker HTML/JS example
<!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:#111; color:#eee; margin:0; padding:10px; }
table { border-collapse: collapse; }
td, th { padding: 2px 4px; border: 1px solid #444; text-align:center; min-width:22px; }
.cell { cursor: pointer; }
.active { background:#2a2; }
#instruments { margin-top:10px; }
input[type=range] { width:80px;}
</style>
</head>
<body>
<h1>HTML Chiptune Tracker</h1>
<label>BPM: <input id="bpm" type="number" min="30" max="300" value="120"></label>
<label>Rows per Pattern: <input id="rowsPerPattern" type="number" min="8" max="64" value="16"></label>
<div id="patternContainer"></div>
<div id="controls">
<button id="playBtn">Play</button>
<button id="stopBtn">Stop</button>
<button id="prevPattern">Prev Pattern</button>
<button id="nextPattern">Next Pattern</button>
<label><input type="checkbox" id="loopToggle" checked> Loop Pattern</label>
</div>
<h2>Instruments</h2>
<div id="instruments"></div>
<button id="addInstrument">Add Instrument</button>
<h2>Sharing</h2>
<button id="copyLink">Copy Song Link</button>
<p>Paste link/hash in URL to load song</p>
<script>
(() => {
const context = new (window.AudioContext || window.webkitAudioContext)();
// --- Tracker Data Structures ---
const maxPatterns = 4; // 4 patterns total for demo
let rowsPerPattern = +document.getElementById('rowsPerPattern').value;
// Each pattern is array of rows
// Each row is array of channels (1 channel for simplicity)
// Each cell: {note:number(0-24 = 2 oct range), instr:number, volume:number (0-1)}
const noteNames = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];
// Map note index (0..24) => freq
// base octave 4, C4=261.63Hz
function noteToFreq(noteIndex) {
if(noteIndex == null) return 0;
return 261.63 * Math.pow(2,(noteIndex-12)/12);
}
// Tracker State
let patterns = [];
for(let p=0;p<maxPatterns;p++) {
const pattern = [];
for(let r=0;r<rowsPerPattern;r++) {
// 1 channel = single note/instr/volume per row
pattern.push({note:null, instr:0, volume:1});
}
patterns.push(pattern);
}
let currentPattern = 0;
let currentRow = 0;
let isPlaying = false;
let playbackTimer = null;
// --- Instruments ---
// Each instrument: {
// oscType: "square", "triangle", "sawtooth", "custom" (custom - noise),
// volume: 1.0,
// detune: 0 (cents),
// adsr: {attack, decay, sustain, release}, all in s,
// filter: {type, freq, Q},
// noise: boolean (true = noise enabled)
// }
const instruments = [
{oscType: 'square', volume:1, detune:0,
adsr: {attack:0.01, decay:0.1, sustain:0.7, release:0.2},
filter: {type:'lowpass', freq:1000, Q:1},
noise:false,
}
];
// --- DOM Helpers ---
const patternContainer = document.getElementById('patternContainer');
const instrumentsDiv = document.getElementById('instruments');
const bpmInput = document.getElementById('bpm');
const rowsPerPatternInput = document.getElementById('rowsPerPattern');
const playBtn = document.getElementById('playBtn');
const stopBtn = document.getElementById('stopBtn');
const prevPatternBtn = document.getElementById('prevPattern');
const nextPatternBtn = document.getElementById('nextPattern');
const loopToggle = document.getElementById('loopToggle');
const addInstrumentBtn = document.getElementById('addInstrument');
const copyLinkBtn = document.getElementById('copyLink');
// --- Build Pattern Table ---
function buildPatternTable() {
patternContainer.innerHTML = '';
const tbl = document.createElement('table');
const header = document.createElement('thead');
const headerRow = document.createElement('tr');
headerRow.appendChild(document.createElement('th')); // row numbers col title
// One channel for demo
headerRow.appendChild(document.createElement('th')).textContent='Ch1';
header.appendChild(headerRow);
tbl.appendChild(header);
const tbody = document.createElement('tbody');
for(let r=0;r<rowsPerPattern;r++) {
const tr = document.createElement('tr');
const rowNumTd = document.createElement('td');
rowNumTd.textContent = r;
tr.appendChild(rowNumTd);
const cell = document.createElement('td');
cell.classList.add('cell');
updateCellText(cell, r);
cell.dataset.row = r;
cell.addEventListener('click', () => {
editCell(r);
});
tr.appendChild(cell);
tbody.appendChild(tr);
}
tbl.appendChild(tbody);
patternContainer.appendChild(tbl);
}
// Update cell text (note+instrument info)
function updateCellText(cell, row) {
const c = patterns[currentPattern][row];
if(c.note == null) {
cell.textContent = '---';
} else {
let noteName = '?';
if(c.note != null) {
const n = c.note % 12;
const octave = 4 + Math.floor(c.note/12);
noteName = noteNames[n] + octave;
}
cell.textContent = `${noteName} I${c.instr+1} V${Math.round(c.volume*9)}`;
}
}
// Edit cell by prompt (for demo)
function editCell(row) {
let c = patterns[currentPattern][row];
const noteStr = prompt(`Enter note (e.g. C4, D#3 or blank to clear):`, c.note != null ? noteNumberToName(c.note) : '');
if(noteStr === null) return; // cancel
let noteNum = parseNote(noteStr);
if(noteStr.trim()==='') noteNum=null;
let instrNum = c.instr;
// Select instrument
let instrStr = prompt(`Enter instrument number (1-${instruments.length}):`, instrNum+1);
if(instrStr === null) return;
let instr = parseInt(instrStr) -1;
if(isNaN(instr) || instr<0 || instr >= instruments.length) instr = 0;
let volStr = prompt('Enter volume 0-9:', Math.round(c.volume*9));
if(volStr === null) return;
let vol = parseInt(volStr);
if(isNaN(vol) || vol<0) vol=0;
if(vol>9) vol=9;
c.note = noteNum;
c.instr = instr;
c.volume = vol/9;
// Update UI
rebuildPatternUI();
}
// Parse note string like C4,D#3 => number 0..24 (2 octaves)
function parseNote(str) {
str = (str||'').trim().toUpperCase();
if(!str) return null;
const regex = /^([A-G])(#?)(\d)?$/;
let m = str.match(regex);
if(!m) return null;
let noteBase = m[1];
let sharp = m[2];
let octave = parseInt(m[3]);
if(isNaN(octave)) octave = 4; // default
let baseNoteIndex = noteNames.indexOf(noteBase);
if(sharp) baseNoteIndex++;
let noteNum = (octave -4)*12 + baseNoteIndex;
if(noteNum<0) noteNum=0;
if(noteNum>24) noteNum=24;
return noteNum;
}
function noteNumberToName(num) {
if(num == null) return '';
let n = num%12;
let octave = 4 + Math.floor(num/12);
return noteNames[n]+octave;
}
// Rebuild pattern UI cells with updated data
function rebuildPatternUI() {
const tbody = patternContainer.querySelector('tbody');
for(let r=0;r<rowsPerPattern;r++) {
const cell = tbody.rows[r].cells[1];
updateCellText(cell, r);
}
}
// --- Instruments UI ---
function buildInstrumentsUI() {
instrumentsDiv.innerHTML = '';
instruments.forEach((instr,i) => {
const div = document.createElement('div');
div.style.border = '1px solid #666';
div.style.padding = '5px';
div.style.marginBottom = '5px';
div.innerHTML = `
<strong>Instrument ${i+1}</strong> <button data-index="${i}" class="delInstr" title="Delete">x</button><br>
Oscillator:
<select data-index="${i}" class="oscType">
<option ${instr.oscType==='square'?'selected':''}>square</option>
<option ${instr.oscType==='triangle'?'selected':''}>triangle</option>
<option ${instr.oscType==='sawtooth'?'selected':''}>sawtooth</option>
<option ${instr.oscType==='custom'?'selected':''}>custom (noise)</option>
</select><br>
Volume: <input type="range" min="0" max="1" step="0.01" value="${instr.volume}" data-index="${i}" class="volume"><br>
Detune (cents): <input type="range" min="-100" max="100" step="1" value="${instr.detune}" data-index="${i}" class="detune"><br>
<details>
<summary>ADSR Envelope (sec)</summary>
Attack: <input type="number" min="0" max="2" step="0.01" value="${instr.adsr.attack}" data-index="${i}" class="attack"><br>
Decay: <input type="number" min="0" max="2" step="0.01" value="${instr.adsr.decay}" data-index="${i}" class="decay"><br>
Sustain: <input type="number" min="0" max="1" step="0.01" value="${instr.adsr.sustain}" data-index="${i}" class="sustain"><br>
Release: <input type="number" min="0" max="2" step="0.01" value="${instr.adsr.release}" data-index="${i}" class="release"><br>
</details>
<details>
<summary>Filter</summary>
Type:
<select data-index="${i}" class="filterType">
<option ${instr.filter.type==='lowpass'?'selected':''}>lowpass</option>
<option ${instr.filter.type==='highpass'?'selected':''}>highpass</option>
<option ${instr.filter.type==='bandpass'?'selected':''}>bandpass</option>
<option ${instr.filter.type==='allpass'?'selected':''}>allpass</option>
<option ${instr.filter.type==='notch'?'selected':''}>notch</option>
</select><br>
Freq: <input type="range" min="100" max="10000" step="10" value="${instr.filter.freq}" data-index="${i}" class="filterFreq"><br>
Q: <input type="range" min="0.1" max="20" step="0.1" value="${instr.filter.Q}" data-index="${i}" class="filterQ"><br>
</details>
Noise: <input type="checkbox" data-index="${i}" class="noise"${instr.noise?' checked':''}>
`;
instrumentsDiv.appendChild(div);
});
// Edit handlers
instrumentsDiv.querySelectorAll('select.oscType').forEach(el=>{
el.onchange = e => {
const idx = +e.target.dataset.index;
instruments[idx].oscType = e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.volume').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].volume = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.detune').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].detune = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.attack').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].adsr.attack = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.decay').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].adsr.decay = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.sustain').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].adsr.sustain = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.release').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].adsr.release = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('select.filterType').forEach(el=>{
el.onchange = e => {
const idx = +e.target.dataset.index;
instruments[idx].filter.type = e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.filterFreq').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].filter.freq = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.filterQ').forEach(el=>{
el.oninput = e => {
const idx = +e.target.dataset.index;
instruments[idx].filter.Q = +e.target.value;
}
});
instrumentsDiv.querySelectorAll('input.noise').forEach(el=>{
el.onchange = e => {
const idx = +e.target.dataset.index;
instruments[idx].noise = e.target.checked;
}
});
instrumentsDiv.querySelectorAll('button.delInstr').forEach(btn => {
btn.onclick = e => {
const idx = +btn.dataset.index;
if(instruments.length <=1) {
alert('At least 1 instrument required');
return;
}
instruments.splice(idx,1);
// Fix patterns using deleted instrument
for(let p=0;p<patterns.length;p++) {
for(let r=0;r<patterns[p].length;r++) {
if(patterns[p][r].instr >= instruments.length) {
patterns[p][r].instr = 0;
} else if(patterns[p][r].instr > idx) {
patterns[p][r].instr--;
}
}
}
buildInstrumentsUI();
rebuildPatternUI();
}
});
}
// --- Playback ---
let currentOscillator = null;
let currentGainNode = null;
let currentFilter = null;
let noiseSource = null;
function playNote(note, instrument, volume, duration) {
if(note == null || volume<=0) return;
const instr = instruments[instrument];
if(!instr) return;
let freq = noteToFreq(note);
freq *= Math.pow(2, instr.detune/1200);
const now = context.currentTime;
if(instr.noise || instr.oscType==='custom') {
// noise synth
noiseSource = context.createBufferSource();
const bufferSize = context.sampleRate * duration;
const buffer = context.createBuffer(1, bufferSize, context.sampleRate);
const data = buffer.getChannelData(0);
for(let i=0;i<bufferSize;i++) {
data[i] = (Math.random()*2-1)*0.3;
}
noiseSource.buffer = buffer;
noiseSource.loop = false;
currentGainNode = context.createGain();
applyADSR(currentGainNode.gain, now, instr.adsr, duration);
currentFilter = context.createBiquadFilter();
currentFilter.type = instr.filter.type;
currentFilter.frequency.value = instr.filter.freq;
currentFilter.Q.value = instr.filter.Q;
noiseSource.connect(currentGainNode);
currentGainNode.connect(currentFilter);
currentFilter.connect(context.destination);
noiseSource.start(now);
noiseSource.stop(now+duration);
noiseSource.onended = ()=> {
noiseSource.disconnect();
currentGainNode.disconnect();
currentFilter.disconnect();
};
return;
}
// Normal oscillator synth
currentOscillator = context.createOscillator();
currentOscillator.type = instr.oscType;
currentOscillator.frequency.setValueAtTime(freq, now);
currentOscillator.detune.setValueAtTime(instr.detune, now);
currentGainNode = context.createGain();
currentGainNode.gain.setValueAtTime(0, now);
applyADSR(currentGainNode.gain, now, instr.adsr, duration);
currentFilter = context.createBiquadFilter();
currentFilter.type = instr.filter.type;
currentFilter.frequency.setValueAtTime(instr.filter.freq, now);
currentFilter.Q.setValueAtTime(instr.filter.Q, now);
currentOscillator.connect(currentGainNode);
currentGainNode.connect(currentFilter);
currentFilter.connect(context.destination);
currentOscillator.start(now);
currentOscillator.stop(now + duration);
// Cleanup
currentOscillator.onended = () => {
currentOscillator.disconnect();
currentGainNode.disconnect();
currentFilter.disconnect();
};
}
// ADSR envelope helper
function applyADSR(gainParam, startTime, adsr, duration) {
const aEnd = startTime + adsr.attack;
const dEnd = aEnd + adsr.decay;
const releaseStart = startTime + duration;
gainParam.cancelScheduledValues(startTime);
gainParam.setValueAtTime(0, startTime);
gainParam.linearRampToValueAtTime(1, aEnd);
gainParam.linearRampToValueAtTime(adsr.sustain, dEnd);
gainParam.setValueAtTime(adsr.sustain, releaseStart);
gainParam.linearRampToValueAtTime(0, releaseStart + adsr.release);
}
// Playback Loop
function playPattern() {
if(isPlaying) return;
isPlaying = true;
const bpm = +bpmInput.value;
rowsPerPattern = +rowsPerPatternInput.value;
const interval = (60 / bpm) / 4; // 4 steps per beat, common for trackers
currentRow = 0;
function step() {
if(!isPlaying) return;
if(currentRow >= rowsPerPattern) {
if(loopToggle.checked) {
currentRow=0;
} else {
stopPlayback();
return;
}
}
// Play note at currentRow
const cell = patterns[currentPattern][currentRow];
if(cell.note != null) {
playNote(cell.note, cell.instr, cell.volume * instruments[cell.instr].volume, interval * 0.9);
}
highlightRow(currentRow);
currentRow++;
playbackTimer = setTimeout(step, interval*1000);
}
step();
}
function stopPlayback() {
isPlaying = false;
clearTimeout(playbackTimer);
playbackTimer = null;
unhighlightRows();
}
// Row highlight for playback
function highlightRow(row) {
const tbody = patternContainer.querySelector('tbody');
for(let r=0;r<rowsPerPattern;r++) {
if(r === row) {
tbody.rows[r].classList.add('active');
} else {
tbody.rows[r].classList.remove('active');
}
}
}
function unhighlightRows() {
const tbody = patternContainer.querySelector('tbody');
for(let r=0;r<rowsPerPattern;r++) {
tbody.rows[r].classList.remove('active');
}
}
// --- Pattern selection ---
function selectPattern(num) {
if(num < 0) num = 0;
if(num >= maxPatterns) num = maxPatterns-1;
currentPattern = num;
rebuildPatternUI();
}
// --- Sharing song data as JSON hash ---
function exportSong() {
const data = {
bpm: +bpmInput.value,
rowsPerPattern: +rowsPerPatternInput.value,
patterns: patterns,
instruments: instruments
};
return encodeURIComponent(JSON.stringify(data));
}
function importSong(encoded) {
try {
const str = decodeURIComponent(encoded);
const data = JSON.parse(str);
if(data.bpm) bpmInput.value = data.bpm;
if(data.rowsPerPattern) {
rowsPerPatternInput.value = data.rowsPerPattern;
rowsPerPattern = data.rowsPerPattern;
}
if(data.patterns) {
for(let p=0;p<maxPatterns;p++) {
if(data.patterns[p]) {
patterns[p] = data.patterns[p].map(c => ({note: c.note, instr: c.instr, volume: c.volume}));
}
}
}
if(data.instruments) {
instruments.length = 0;
for(let ins of data.instruments) {
instruments.push(ins);
}
}
buildInstrumentsUI();
buildPatternTable();
rebuildPatternUI();
} catch(e) {
alert('Error loading song data');
}
}
// --- Keyboard shortcuts ---
window.addEventListener('keydown', e => {
if(e.target.tagName==='INPUT' || e.target.tagName==='TEXTAREA') return; // ignore typing
switch(e.key) {
case ' ': // space = play/pause
e.preventDefault();
if(isPlaying) stopPlayback(); else playPattern();
break;
case 'ArrowLeft':
selectPattern(currentPattern-1);
break;
case 'ArrowRight':
selectPattern(currentPattern+1);
break;
case 'l':
case 'L': // toggle loop
loopToggle.checked = !loopToggle.checked;
break;
}
});
// --- Event Listeners ---
playBtn.onclick = () => {
playPattern();
};
stopBtn.onclick = () => {
stopPlayback();
};
prevPatternBtn.onclick = () => {
selectPattern(currentPattern-1);
};
nextPatternBtn.onclick = () => {
selectPattern(currentPattern+1);
};
rowsPerPatternInput.onchange = () => {
const newRows = +rowsPerPatternInput.value;
if(newRows != rowsPerPattern) {
rowsPerPattern = newRows;
// resize patterns
for(let p=0;p<patterns.length;p++) {
let pat = patterns[p];
if(pat.length > newRows) {
patterns[p] = pat.slice(0,newRows);
} else if(pat.length < newRows) {
for(let i=pat.length;i<newRows;i++) {
pat.push({note:null, instr:0, volume:1});
}
}
}
buildPatternTable();
rebuildPatternUI();
}
};
addInstrumentBtn.onclick = () => {
instruments.push({
oscType: 'square',
volume:1, detune:0,
adsr: {attack:0.01, decay:0.1, sustain:0.7, release:0.2},
filter: {type:'lowpass', freq:1000, Q:1},
noise:false
});
buildInstrumentsUI();
};
copyLinkBtn.onclick = () => {
const url = window.location.origin + window.location.pathname + '#'+exportSong();
navigator.clipboard.writeText(url).then(()=>{
alert('Song link copied to clipboard!');
}).catch(()=>{
alert('Failed to copy to clipboard.');
});
};
// Load song from URL hash on load
window.addEventListener('load', () => {
if(location.hash.length > 1) {
importSong(location.hash.slice(1));
}
buildPatternTable();
buildInstrumentsUI();
rebuildPatternUI();
});
})();
</script>
</body>
</html>
Features in this example:
- 4 patterns, editable rows per pattern (8-64 rows)
- One channel pattern grid (expandable)
- Per row: note (musical note names), instrument number, volume 0-9
- Play/stop buttons, navigate patterns
- Loop toggle for playback
- Instrument editor (osc type, volume, detune, ADSR, filter, noise toggle)
- Playback uses Web Audio API oscillator/noise with ADSR and biquad filter
- Edit pattern cells by clicking (prompts for note/instrument/volume)
- Keyboard shortcuts: space=play toggle, left/right arrow=change pattern, L=toggle loop
- Song export/import as JSON in URL hash with copy link button
- No demo playback/autoplay, user triggers play manually
- Pure vanilla HTML/JS, no dependencies
How to Use:
- Click cells to enter notes. Refer to format like C4, D#3, etc.
- Use instrument editor to tweak synth parameters.
- Adjust BPM and rows per pattern to your liking.
- Play patterns and listen to chiptune synth play notes.
- Share song by clicking "Copy Song Link" and sharing the URL (hash encoded). Paste URL to reload song.
This is a minimal but extendable chiptune tracker foundation meeting your criteria. You can expand it with multi-channel patterns, better UI, pattern sequencing, and more instruments.
If you want me to help extend or build features in specific detail just ask!