It sounds like you want to create (or use) an HTML-based chiptune tracker with features such as:
- BPM (Beats Per Minute) control
- Rows per track and rows per pattern
- Multiple patterns and tracks
- Synth per instrument with custom oscillator options
- Volume, detune, ADSR envelope, filter, and noise controls
- Ability to share songs (likely via URL hash
/#)
- Keyboard shortcuts
- Loop playback
- No demo data included by default
What you might be asking for:
- A simple HTML/JS chiptune tracker with these features
- A minimal example implementation
- An existing open source tracker that fits
Here's a brief explanation and a minimal prototype example to get started:
Explanation of features
- BPM: controls speed of song playback.
- Rows per track: number of steps in a pattern (vertical rows).
- Patterns: sequences of rows played in order.
- Instruments: define sound synthesis parameters.
- Synth per instrument: each instrument uses an oscillator type (sine, square, saw, triangle).
- Volume, detune, ADSR, filter, noise: sound shaping controls.
- Song sharing: encode your song as JSON/string in URL hash to share.
- Keyboard shortcuts: e.g., space to play/pause, arrows to navigate.
- Loop: continuously repeat playback.
Minimal demo HTML tracker skeleton (no demo song, no external libs)
Here is a minimal starting point that you can extend. It plays a simple beep sound and supports basic step sequencing with keyboard shortcuts and sharable song data in URL hash.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Minimal HTML Chiptune Tracker</title>
<style>
body { font-family: monospace; background: #111; color: #eee; }
#controls { margin-bottom: 1em; }
#pattern { font-size: 14px; white-space: pre; background: #222; padding: 1em; }
button, input { margin-right: 0.5em; }
input[type=number] { width: 50px; }
</style>
</head>
<body>
<h1>Minimal Chiptune Tracker</h1>
<div id="controls">
BPM: <input type="number" id="bpm" value="120" min="30" max="300" step="1" />
Rows per Pattern: <input type="number" id="rows" value="16" min="4" max="64" step="1" />
<button id="playPause">Play</button>
<label><input type="checkbox" id="loop" checked /> Loop</label>
<button id="share">Share Song URL</button>
</div>
<div id="pattern"></div>
<script>
// Basic data structures
class Instrument {
constructor({osc='square', volume=0.5, detune=0, adsr={attack:0.01, decay:0.1, sustain:0.5, release:0.2}, filterFrequency=0, noise=0} = {}) {
this.osc = osc;
this.volume = volume;
this.detune = detune;
this.adsr = adsr;
this.filterFrequency = filterFrequency;
this.noise = noise;
}
}
class Pattern {
constructor(rows) {
this.rows = rows;
this.notes = new Array(rows).fill(null); // Could store notes like {note: 60, instrument:0}
}
}
// Note to frequency (A4=440Hz)
function noteToFreq(note) {
return 440 * Math.pow(2, (note - 69) / 12);
}
// Simple Sine/Square/Saw/Triangle oscillator creation with Web Audio API
class Synth {
constructor(audioCtx, instrument) {
this.ctx = audioCtx;
this.inst = instrument;
}
playNote(note, durationSeconds) {
if(note === null) return;
const freq = noteToFreq(note);
const now = this.ctx.currentTime;
const osc = this.ctx.createOscillator();
osc.type = this.inst.osc;
osc.frequency.value = freq;
osc.detune.value = this.inst.detune;
const gainNode = this.ctx.createGain();
// ADSR envelope
const {attack, decay, sustain, release} = this.inst.adsr;
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(this.inst.volume, now + attack);
gainNode.gain.linearRampToValueAtTime(this.inst.volume*sustain, now + attack + decay);
gainNode.gain.setValueAtTime(this.inst.volume*sustain, now + durationSeconds - release);
gainNode.gain.linearRampToValueAtTime(0, now + durationSeconds);
osc.connect(gainNode);
gainNode.connect(this.ctx.destination);
osc.start(now);
osc.stop(now + durationSeconds);
}
}
// Globals and state
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const bpmInput = document.getElementById('bpm');
const rowsInput = document.getElementById('rows');
const patternDiv = document.getElementById('pattern');
const playPauseBtn = document.getElementById('playPause');
const loopCheckbox = document.getElementById('loop');
const shareBtn = document.getElementById('share');
let bpm = parseInt(bpmInput.value);
let rowsPerPattern = parseInt(rowsInput.value);
let pattern = new Pattern(rowsPerPattern);
let tick = 0;
let playing = false;
let timerId = null;
let instrument = new Instrument({osc:'square', volume:0.2});
let synth = new Synth(audioCtx, instrument);
// Demo sequence (all null, so quiet start)
// Let's add a C4 note at row 0 for testing:
pattern.notes[0] = {note: 60, instrument: 0};
pattern.notes[4] = {note: 64, instrument: 0};
pattern.notes[8] = {note: 67, instrument: 0};
pattern.notes[12] = {note: 72, instrument: 0};
function drawPattern() {
let output = '';
for(let i=0; i<pattern.rows; i++) {
if(i === tick) {
output += '▶ '; // Current playhead
} else {
output += ' ';
}
const note = pattern.notes[i];
if(note && note.note !== null) {
output += noteToName(note.note) + '\n';
} else {
output += '--\n';
}
}
patternDiv.textContent = output;
}
function noteToName(note) {
const names = ['C', 'C#','D','D#','E','F','F#','G','G#','A','A#','B'];
const octave = Math.floor(note / 12) - 1;
const name = names[note % 12];
return name + octave;
}
function playStep() {
let currentNote = pattern.notes[tick];
if(currentNote) {
synth.playNote(currentNote.note, (60/bpm)/4);
}
drawPattern();
tick++;
if(tick >= pattern.rows) {
if(loopCheckbox.checked) {
tick = 0;
} else {
stop();
}
}
}
function start() {
if(audioCtx.state === 'suspended') {
audioCtx.resume();
}
if(playing) return;
playing = true;
playPauseBtn.textContent = "Pause";
const intervalMs = (60000 / bpm) / 4; // 4 ticks per beat (rows)
tick = 0;
timerId = setInterval(playStep, intervalMs);
}
function stop() {
playing = false;
playPauseBtn.textContent = "Play";
if(timerId) {
clearInterval(timerId);
timerId = null;
}
tick = 0;
drawPattern();
}
// Event listeners
playPauseBtn.onclick = () => {
if(playing) {
stop();
} else {
start();
}
};
bpmInput.onchange = () => {
bpm = parseInt(bpmInput.value);
if(playing) {
stop();
start();
}
};
rowsInput.onchange = () => {
rowsPerPattern = parseInt(rowsInput.value);
pattern = new Pattern(rowsPerPattern);
tick = 0;
drawPattern();
};
shareBtn.onclick = () => {
// Encode pattern data as JSON and put in URL hash
const songData = {
bpm,
rowsPerPattern,
notes: pattern.notes,
instrument,
};
const str = encodeURIComponent(JSON.stringify(songData));
navigator.clipboard.writeText(location.origin + location.pathname + "/#" + str)
.then(()=>alert("Song URL copied to clipboard!"));
};
// Load from URL
function loadFromHash() {
if(location.hash.length > 1) {
try {
const data = JSON.parse(decodeURIComponent(location.hash.substring(1)));
bpm = data.bpm || bpm;
rowsPerPattern = data.rowsPerPattern || rowsPerPattern;
pattern = new Pattern(rowsPerPattern);
pattern.notes = data.notes || pattern.notes;
if(data.instrument) {
Object.assign(instrument, data.instrument);
}
bpmInput.value = bpm;
rowsInput.value = rowsPerPattern;
drawPattern();
} catch (e) {
console.warn("Invalid song data in URL");
}
}
}
loadFromHash();
drawPattern();
</script>
</body>
</html>
How to use:
- Change BPM and rows per pattern
- See a simple pattern display with notes C4, E4, G4, C5 every 4 steps
- Press Play to hear sequence, press Pause to stop
- Use checkbox to toggle loop
- Click Share Song URL to copy a sharable link with pattern/instrument encoded in URL hash
- Paste URL to reload that song
What you can add next:
- Editing notes via UI or keyboard input
- Multiple instruments, multiple tracks, pattern chaining
- More oscillator types or custom waveforms
- Volume/detune/ADSR/filter UI per instrument
- Noise channel synthesis
- Keyboard shortcut support for nav/playback/edit
Existing Projects You Might Like:
If you want, I can help you extend the above minimal prototype or provide guidance on how to implement full multi-pattern multi-track editing with synth controls!