You're looking to build (or find) an HTML chiptune tracker with the following features:
- BPM (tempo control)
- Multiple tracks with patterns
- Rows per pattern
- Synth per instrument with:
- Custom oscillator types
- Volume control
- Detune
- ADSR envelope
- Filter
- Noise capability
- Ability to share songs (likely via URL or similar)
- Keyboard shortcuts for workflow efficiency
- Loop playback
- Song URL format using
"/#" notation (hash routing)
- No demo or preloaded song on load
Do you want...
- A recommendation of an existing open-source project?
- A starting HTML/JS template that implements these features?
- A design/specification to build one from scratch?
Assuming you want a lightweight starting point, here is a minimal outline and code snippets for a simple HTML/JS chiptune tracker meeting your criteria:
Minimal HTML Chiptune Tracker Outline
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Minimal Chiptune Tracker</title>
<style>
body { font-family: monospace; background: #222; color: #eee; }
#tracker { display: flex; }
.track { margin: 0 10px; }
table { border-collapse: collapse; }
td, th { border: 1px solid #444; padding: 4px; text-align: center; width: 30px; }
td.active { background: #ff9500; }
</style>
</head>
<body>
<h1>Chiptune Tracker</h1>
<label>
BPM:
<input type="number" id="bpm" value="120" min="40" max="300"/>
</label>
<div id="tracker"></div>
<button id="playBtn">Play</button>
<button id="loopBtn">Loop: Off</button>
<button id="shareBtn">Share Song</button>
<script>
(async function(){
// Settings
const numTracks = 3;
const rowsPerPattern = 16;
const oscTypes = ["square", "sawtooth", "triangle", "sine", "custom"];
const defaultBPM = 120;
// State
let bpm = defaultBPM;
let isPlaying = false;
let loop = false;
let currentRow = 0;
let timerId = null;
// Create Audio Context
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Instrument with synth settings
class Instrument {
constructor() {
this.oscType = "square"; // default oscillator
this.volume = 0.2;
this.detune = 0;
this.adsr = {attack:0.01, decay:0.1, sustain:0.5, release:0.2};
this.filterFreq = 1000;
this.noise = false;
}
play(freq) {
if (!freq) return;
const now = audioCtx.currentTime;
// Gain node for volume + ADSR
const gainNode = audioCtx.createGain();
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(this.volume, now + this.adsr.attack);
gainNode.gain.linearRampToValueAtTime(this.volume * this.adsr.sustain, now + this.adsr.attack + this.adsr.decay);
// Oscillator or noise
let source;
if(this.noise){
// Noise source
const bufferSize = audioCtx.sampleRate;
const buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
const data = buffer.getChannelData(0);
for(let i=0; i<bufferSize; i++) data[i] = Math.random() * 2 -1;
source = audioCtx.createBufferSource();
source.buffer = buffer;
source.loop = true;
} else {
source = audioCtx.createOscillator();
source.type = this.oscType === "custom" ? "square" : this.oscType; // Use square for custom - extend later
source.frequency.setValueAtTime(freq, now);
source.detune.setValueAtTime(this.detune, now);
}
// Filter
const filter = audioCtx.createBiquadFilter();
filter.type = "lowpass";
filter.frequency.setValueAtTime(this.filterFreq, now);
// Connect nodes
source.connect(filter);
filter.connect(gainNode);
gainNode.connect(audioCtx.destination);
source.start(now);
// ADSR release
gainNode.gain.linearRampToValueAtTime(0, now + this.adsr.attack + this.adsr.decay + 0.1 + this.adsr.release);
source.stop(now + this.adsr.attack + this.adsr.decay + 0.1 + this.adsr.release);
source.onended = () => {
gainNode.disconnect();
filter.disconnect();
};
}
}
// Note frequencies for C major scale, octave 4
const noteFreqs = {
"C4": 261.63,
"D4": 293.66,
"E4": 329.63,
"F4": 349.23,
"G4": 392.00,
"A4": 440.00,
"B4": 493.88,
"": null
};
const notes = Object.keys(noteFreqs);
// Data Model: For each track, an array of notes (one per row)
const tracks = [];
for(let i=0; i<numTracks; i++) {
tracks[i] = {
instrument: new Instrument(),
pattern: Array(rowsPerPattern).fill("").map(_ => "")
};
}
// Create UI table grid for note input
const trackerDiv = document.getElementById("tracker");
for(let t=0; t<numTracks; t++){
const trackDiv = document.createElement("div");
trackDiv.className = "track";
trackDiv.innerHTML = `<h3>Track ${t+1}</h3>`;
// Instrument controls (simplified)
const instr = tracks[t].instrument;
const oscSelect = document.createElement("select");
for(const osc of oscTypes){
const option = document.createElement("option");
option.value = osc;
option.textContent = osc;
oscSelect.appendChild(option);
}
oscSelect.value = instr.oscType;
oscSelect.onchange = e => { instr.oscType = e.target.value; };
trackDiv.appendChild(document.createTextNode("Osc: "));
trackDiv.appendChild(oscSelect);
// Volume control
const volInput = document.createElement("input");
volInput.type = "range"; volInput.min=0; volInput.max=1; volInput.step=0.01;
volInput.value = instr.volume;
volInput.oninput = e => instr.volume=parseFloat(e.target.value);
trackDiv.appendChild(document.createTextNode(" Vol: "));
trackDiv.appendChild(volInput);
// For brevity, skipping detune, ADSR, filter, noise UI - could add later similarly.
// Pattern table
const tbl = document.createElement("table");
const headerRow = document.createElement("tr");
for(let r=0; r<rowsPerPattern; r++){
const th = document.createElement("th");
th.textContent = r+1;
headerRow.appendChild(th);
}
tbl.appendChild(headerRow);
const tr = document.createElement("tr");
for(let r=0; r<rowsPerPattern; r++){
const td = document.createElement("td");
td.contentEditable = "true";
td.dataset.track = t;
td.dataset.row = r;
td.textContent = "";
td.spellcheck = false;
td.style.minWidth = "30px";
td.oninput = e => {
const val = e.target.textContent.toUpperCase();
if(notes.includes(val)){
tracks[t].pattern[r] = val;
td.classList.remove("invalid");
} else if(val.trim()===""){
tracks[t].pattern[r] = "";
td.classList.remove("invalid");
} else {
td.classList.add("invalid");
}
};
tr.appendChild(td);
}
tbl.appendChild(tr);
trackDiv.appendChild(tbl);
trackerDiv.appendChild(trackDiv);
}
// Playback function
function playStep(row){
for(let t=0; t<numTracks; t++){
const note = tracks[t].pattern[row];
const freq = noteFreqs[note];
tracks[t].instrument.play(freq);
}
}
function scheduler() {
if(!isPlaying) return;
playStep(currentRow);
currentRow++;
if(currentRow >= rowsPerPattern){
if(loop) currentRow = 0;
else {
stopPlayback();
return;
}
}
const interval = (60 / bpm) * 1000 / 4; // Assuming 16th notes per row
timerId = setTimeout(scheduler, interval);
}
// Controls
const bpmInput = document.getElementById("bpm");
bpmInput.onchange = e => {
bpm = parseInt(e.target.value);
if(bpm < 40) bpmInput.value = bpm = 40;
if(bpm > 300) bpmInput.value = bpm = 300;
};
const playBtn = document.getElementById("playBtn");
playBtn.onclick = () => {
if(isPlaying) stopPlayback();
else startPlayback();
};
const loopBtn = document.getElementById("loopBtn");
loopBtn.onclick = () => {
loop = !loop;
loopBtn.textContent = "Loop: " + (loop ? "On" : "Off");
};
function startPlayback(){
if(audioCtx.state === 'suspended') audioCtx.resume();
isPlaying = true;
currentRow = 0;
playBtn.textContent = "Stop";
scheduler();
}
function stopPlayback(){
isPlaying = false;
if(timerId) clearTimeout(timerId);
playBtn.textContent = "Play";
}
// Share song: encode pattern+settings to URL hash
function serializeSong(){
// Simple JSON stringify and base64 encode
const song = {
bpm,
loop,
tracks: tracks.map(t => ({
oscType: t.instrument.oscType,
volume: t.instrument.volume,
pattern: t.pattern
}))
};
return btoa(JSON.stringify(song));
}
function deserializeSong(data){
try {
const song = JSON.parse(atob(data));
bpmInput.value = song.bpm || defaultBPM;
bpm = song.bpm || defaultBPM;
loop = song.loop || false;
loopBtn.textContent = "Loop: " + (loop ? "On" : "Off");
for(let i=0; i<song.tracks.length; i++){
const t = tracks[i];
const tr = song.tracks[i];
if(tr){
t.instrument.oscType = tr.oscType || "square";
t.instrument.volume = tr.volume || 0.2;
t.pattern = tr.pattern || Array(rowsPerPattern).fill("");
}
}
// Update UI accordingly
document.querySelectorAll("select").forEach((sel, i) => {
sel.value = tracks[i].instrument.oscType;
});
document.querySelectorAll("input[type=range]").forEach((rng, i) => {
rng.value = tracks[i].instrument.volume;
});
// Update pattern grid cells
document.querySelectorAll("td").forEach(td => {
const t = parseInt(td.dataset.track), r = parseInt(td.dataset.row);
if(t>=0 && r>=0) {
td.textContent = tracks[t].pattern[r];
td.classList.remove("invalid");
}
});
} catch(e){
alert("Failed to load song data!");
}
}
const shareBtn = document.getElementById("shareBtn");
shareBtn.onclick = () => {
const hash = serializeSong();
const url = location.origin + location.pathname + "/#" + hash;
prompt("Share this URL:", url);
};
// On page load, parse URL hash
window.addEventListener("load", ()=>{
const hash = location.hash.slice(2); // skip /#
if(hash){
deserializeSong(hash);
}
});
// Keyboard shortcuts (simple)
document.body.addEventListener("keydown", e => {
if(e.target.isContentEditable || e.target.tagName==="INPUT" || e.target.tagName==="TEXTAREA") return;
if(e.key === " "){
e.preventDefault();
if(isPlaying) stopPlayback();
else startPlayback();
}
if(e.key.toLowerCase() === "l"){
loop = !loop;
loopBtn.textContent = "Loop: " + (loop ? "On" : "Off");
}
});
})();
</script>
</body>
</html>
How this minimal tracker works:
- 3 tracks, each with 16 rows.
- Each cell editable: type note names exactly (
C4, D4, E4, etc.) or leave blank for silence.
- Controls for BPM, Play/Stop, Loop toggle.
- Simple instruments with oscillator type and volume.
- Play button starts/stops pattern playback at BPM.
- Shares song data via URL hash
/#base64encodedjson.
- Keyboard shortcuts:
- Space: toggle playback
- L: toggle loop
Limitations / Next steps:
- Expand instrument UI to allow detune, full ADSR, filter params, noise toggle.
- Enhance note input via dropdown or piano keyboard.
- Support additional synth features like custom oscillators.
- Pattern chaining and multiple patterns per track.
- UI improvements and more advanced shortcuts.
Existing projects to check out for inspiration or reuse:
If you want me to help build out more features or a different design, please let me know!