Certainly! Below is a minimal, self-contained HTML + JavaScript snippet implementing a basic chiptune-style tracker with the features you requested:
- Tracker layout: tracks, patterns, rows
- Per instrument: oscillator, ADSR envelope, filter, FM, detune
- Basic playback engine using Web Audio API
- BPM control
- Copy/Paste of pattern data through a custom text format with a
/ and # separator for lines and columns
- No external libraries or demo links — fully inline code
How this tracker works:
- The tracker has 1 pattern by default, with 4 tracks and 16 rows.
- Each track has an instrument with these parameters adjustable: oscillator type, ADSR, filter cutoff, FM amount, detune.
- You can edit note entries as numbers (MIDI note number).
0 means no note.
- Playback steps through rows at selected BPM and plays notes with the corresponding instrument parameters.
- You can Copy the entire pattern data as raw text, which is
/ separated rows and # separated tracks in each row.
- You can Paste a valid string to load pattern data.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Minimal Chiptune Tracker</title>
<style>
body {
background: #111;
color: #eee;
font-family: monospace, monospace;
user-select: none;
display: flex;
flex-direction: column;
align-items: center;
margin: 0; padding: 0;
}
h1 {
margin: 0.5em 0 0.2em;
}
#tracker {
background: #222;
padding: 10px;
margin: 10px;
border-radius: 6px;
display: inline-block;
}
table {
border-collapse: collapse;
table-layout: fixed;
width: 100%;
}
td, th {
border: 1px solid #444;
text-align: center;
font-variant-numeric: tabular-nums;
}
td.note {
width: 3em;
cursor: pointer;
}
td.note.editing {
background: #444;
}
input, select {
background: #222;
border: 1px solid #555;
color: #eee;
font-family: monospace;
font-size: 0.9em;
width: 6em;
margin: 0 0.2em 0.4em 0.2em;
}
label {
user-select: none;
font-size: 0.9em;
margin: 0 0.1em 0 0.5em;
}
#controls {
margin: 1em 0;
}
button {
margin: 0 0.3em;
background: #333;
border: 1px solid #555;
color: #eee;
font-family: monospace;
font-size: 1em;
padding: 0.3em 0.7em;
cursor: pointer;
}
button:hover {
background: #555;
}
#copyArea {
margin-top: 1em;
width: 100%;
height: 5em;
font-family: monospace;
background: #111;
border: 1px solid #444;
color: #eee;
padding: 5px;
resize: vertical;
}
.instrument-settings {
background: #333;
color: #eee;
border-radius: 4px;
padding: 5px;
margin: 4px 0;
}
.instrument-settings > * {
margin-right: 0.4em;
}
</style>
</head>
<body>
<h1>Minimal Chiptune Tracker</h1>
<div id="controls">
<label>BPM:
<input type="number" id="bpm" min="30" max="300" value="150" />
</label>
<button id="playBtn">Play</button>
<button id="stopBtn" disabled>Stop</button>
<button id="copyBtn">Copy Pattern</button>
<button id="pasteBtn">Paste Pattern</button>
</div>
<div id="instruments"></div>
<div id="tracker"></div>
<textarea id="copyArea" placeholder="Copy/paste pattern data here"></textarea>
<script>
(() => {
// Constants
const ROWS_PER_PATTERN = 16;
const TRACKS_PER_PATTERN = 4;
const NOTES_RANGE = [0, 127];
// Default instrument params
function defaultInstrument() {
return {
oscType: "square", // square, sawtooth, triangle, sine
adsr: {attack: 0.01, decay: 0.1, sustain:0.3, release:0.2},
filterCutoff: 1500,
fmAmount: 150,
detune: 0,
};
}
// State storage
let patternData = []; // [row][track] = note number 0=empty
for(let r=0; r<ROWS_PER_PATTERN; r++) {
patternData.push(new Array(TRACKS_PER_PATTERN).fill(0));
}
let instruments = [];
for(let t=0; t<TRACKS_PER_PATTERN; t++) {
instruments.push(defaultInstrument());
}
let isPlaying = false;
let currentRow = 0;
let timerId = null;
// DOM refs
const trackerDiv = document.getElementById("tracker");
const instrumentsDiv = document.getElementById("instruments");
const bpmInput = document.getElementById("bpm");
const playBtn = document.getElementById("playBtn");
const stopBtn = document.getElementById("stopBtn");
const copyBtn = document.getElementById("copyBtn");
const pasteBtn = document.getElementById("pasteBtn");
const copyArea = document.getElementById("copyArea");
// Audio Context Setup
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Convert MIDI note number to frequency
function mtof(m) {
return 440 * Math.pow(2, (m - 69) / 12);
}
// Play a note with given instrument settings
function playNote(midiNote, instrument, time) {
if(midiNote === 0) return; // no note
const freq = mtof(midiNote);
// Create oscillator
const osc = audioCtx.createOscillator();
osc.type = instrument.oscType;
osc.frequency.setValueAtTime(freq, time);
// Detune cent offset
osc.detune.setValueAtTime(instrument.detune, time);
// FM - create an oscillator as modulator
let fmOsc = null;
let fmGain = null;
if(instrument.fmAmount > 0) {
fmOsc = audioCtx.createOscillator();
fmOsc.type = (instrument.oscType === "square") ? "triangle" : "square";
fmOsc.frequency.setValueAtTime(freq * 2, time);
fmGain = audioCtx.createGain();
fmGain.gain.setValueAtTime(instrument.fmAmount, time);
fmOsc.connect(fmGain);
fmGain.connect(osc.frequency);
fmOsc.start(time);
fmOsc.stop(time + 1);
}
// Envelope
const gainNode = audioCtx.createGain();
gainNode.gain.setValueAtTime(0, time);
gainNode.gain.linearRampToValueAtTime(1, time + instrument.adsr.attack);
gainNode.gain.linearRampToValueAtTime(instrument.adsr.sustain, time + instrument.adsr.attack + instrument.adsr.decay);
// Filter
const filter = audioCtx.createBiquadFilter();
filter.type = "lowpass";
filter.frequency.setValueAtTime(instrument.filterCutoff, time);
// Chain nodes: osc -> filter -> gain -> destination
osc.connect(filter);
filter.connect(gainNode);
gainNode.connect(audioCtx.destination);
osc.start(time);
// Stop after 1s
// Release envelope
gainNode.gain.setTargetAtTime(0, time + 0.2, instrument.adsr.release);
osc.stop(time + 1);
// Cleanup fmOsc on stop
if(fmOsc) {
fmOsc.stop(time + 1);
fmOsc.disconnect();
fmGain.disconnect();
}
}
// Render tracker grid table
function renderTracker() {
let html = "<table><thead><tr><th>#</th>";
for(let t=0; t<TRACKS_PER_PATTERN; t++) {
html += `<th>Trk${t+1}</th>`;
}
html += "</tr></thead><tbody>";
for(let r=0; r<ROWS_PER_PATTERN; r++) {
html += `<tr><td>${r.toString().padStart(2,'0')}</td>`;
for(let t=0; t<TRACKS_PER_PATTERN; t++) {
const note = patternData[r][t];
html += `<td class="note" data-row="${r}" data-track="${t}">${note || ""}</td>`;
}
html += "</tr>";
}
html += "</tbody></table>";
trackerDiv.innerHTML = html;
}
// Render instrument controls
function renderInstruments() {
let html = "";
for(let t=0; t<TRACKS_PER_PATTERN; t++) {
const inst = instruments[t];
html += `<div class="instrument-settings" data-track="${t}">
<strong>Instrument ${t+1}</strong>
<label>OSC:
<select data-prop="oscType" data-track="${t}">
<option${inst.oscType==="square"?" selected":""}>square</option>
<option${inst.oscType==="sawtooth"?" selected":""}>sawtooth</option>
<option${inst.oscType==="triangle"?" selected":""}>triangle</option>
<option${inst.oscType==="sine"?" selected":""}>sine</option>
</select>
</label>
<label>Atk:
<input type="number" step="0.01" min="0" max="2" value="${inst.adsr.attack}" data-prop="adsr.attack" data-track="${t}" />
</label>
<label>Dec:
<input type="number" step="0.01" min="0" max="2" value="${inst.adsr.decay}" data-prop="adsr.decay" data-track="${t}" />
</label>
<label>Sus:
<input type="number" step="0.01" min="0" max="1" value="${inst.adsr.sustain}" data-prop="adsr.sustain" data-track="${t}" />
</label>
<label>Rel:
<input type="number" step="0.01" min="0" max="2" value="${inst.adsr.release}" data-prop="adsr.release" data-track="${t}" />
</label>
<label>Flt cutoff:
<input type="number" min="200" max="8000" step="10" value="${inst.filterCutoff}" data-prop="filterCutoff" data-track="${t}" />
</label>
<label>FM amt:
<input type="number" min="0" max="1000" step="1" value="${inst.fmAmount}" data-prop="fmAmount" data-track="${t}" />
</label>
<label>Detune (cents):
<input type="number" min="-100" max="100" step="1" value="${inst.detune}" data-prop="detune" data-track="${t}" />
</label>
</div>`;
}
instrumentsDiv.innerHTML = html;
}
// Update instrument parameter from input change
function updateInstrument(track, prop, value) {
const inst = instruments[track];
if(prop.includes(".")) {
const parts = prop.split(".");
if(parts.length === 2 && inst[parts[0]]) {
inst[parts[0]][parts[1]] = Number(value);
}
} else {
if(typeof inst[prop] === "number") {
inst[prop] = Number(value);
} else {
inst[prop] = value;
}
}
}
// Handle editing a note cell
function editCell(td) {
if(td.querySelector("input")) return;
const r = Number(td.dataset.row);
const t = Number(td.dataset.track);
const oldVal = patternData[r][t] || "";
td.classList.add("editing");
td.innerHTML = `<input type="number" min="0" max="127" style="width:3em" value="${oldVal}" />`;
const input = td.querySelector("input");
input.focus();
input.select();
function commit() {
let v = parseInt(input.value);
if(isNaN(v) || v < 0 || v > 127) v = 0;
patternData[r][t] = v;
td.classList.remove("editing");
td.textContent = v>0 ? v : "";
}
input.addEventListener("blur", commit);
input.addEventListener("keydown", e => {
if(e.key === "Enter" || e.key === "Tab") {
e.preventDefault();
commit();
// move focus + edit next cell
let nextT = t + 1;
let nextR = r;
if(nextT >= TRACKS_PER_PATTERN) {
nextT = 0;
nextR++;
if(nextR >= ROWS_PER_PATTERN) nextR=0;
}
const nextCell = trackerDiv.querySelector(`td.note[data-row="${nextR}"][data-track="${nextT}"]`);
if(nextCell) editCell(nextCell);
}
if(e.key === "Escape") {
td.classList.remove("editing");
td.textContent = oldVal > 0 ? oldVal : "";
}
});
}
// Playback loop
function schedulePlayback() {
const bpm = Number(bpmInput.value);
const rowDuration = 60 / bpm / 4; // tracker speed = quarter notes split into 4 steps
if(!isPlaying) return;
// Play notes in current row
const now = audioCtx.currentTime;
for(let t = 0; t < TRACKS_PER_PATTERN; t++) {
const note = patternData[currentRow][t];
playNote(note, instruments[t], now);
}
// Highlight current row in tracker:
highlightRow(currentRow);
currentRow = (currentRow + 1) % ROWS_PER_PATTERN;
timerId = setTimeout(schedulePlayback, rowDuration * 1000);
}
// Highlight current row visually
function highlightRow(row) {
const trs = trackerDiv.querySelectorAll("tbody tr");
trs.forEach((tr,i) => {
if(i === row) tr.style.background = "#444";
else tr.style.background = "transparent";
});
}
// Copy pattern data to textarea with "/#" separators
function serializePattern() {
// rows separated by /
// tracks separated by #
// example: "60#0#64#0/0#62#0#65/..."
return patternData.map(row => row.join("#")).join("/");
}
// Deserialize pattern data string
function deserializePattern(str) {
try {
const rows = str.trim().split("/");
if(rows.length !== ROWS_PER_PATTERN) throw "Incorrect row count";
const newPattern = [];
for(let r=0; r<ROWS_PER_PATTERN; r++) {
const tracks = rows[r].split("#");
if(tracks.length !== TRACKS_PER_PATTERN) throw "Incorrect track count";
const rowNotes = tracks.map(x => {
const n = Number(x);
if(isNaN(n) || n < 0 || n > 127) throw "Invalid note: "+x;
return n;
});
newPattern.push(rowNotes);
}
patternData = newPattern;
renderTracker();
} catch(e) {
alert("Invalid pattern data: "+e);
}
}
// Event listeners
trackerDiv.addEventListener("click", e => {
if(e.target.classList.contains("note")) {
editCell(e.target);
}
});
instrumentsDiv.addEventListener("change", e => {
const el = e.target;
if(el.dataset.track === undefined || el.dataset.prop === undefined) return;
const t = Number(el.dataset.track);
const p = el.dataset.prop;
updateInstrument(t,p,el.value);
});
playBtn.addEventListener("click", () => {
if(audioCtx.state === "suspended") audioCtx.resume();
if(isPlaying) return;
isPlaying = true;
currentRow = 0;
schedulePlayback();
playBtn.disabled = true;
stopBtn.disabled = false;
});
stopBtn.addEventListener("click", () => {
isPlaying = false;
clearTimeout(timerId);
playBtn.disabled = false;
stopBtn.disabled = true;
highlightRow(-1);
});
copyBtn.addEventListener("click", () => {
const data = serializePattern();
copyArea.value = data;
copyArea.select();
document.execCommand("copy");
alert("Pattern copied to clipboard.");
});
pasteBtn.addEventListener("click", () => {
const data = copyArea.value.trim();
deserializePattern(data);
});
// Initialize display
renderInstruments();
renderTracker();
})();
</script>
</body>
</html>
Usage:
- Click a note cell to edit it with MIDI note numbers (
60=Middle C). 0 means no note.
- Adjust instruments parameters below (oscillator, ADSR, filter cutoff, FM amount, detune).
- Set BPM and click Play to hear the pattern loop, Stop to stop.
- Click Copy Pattern to copy the pattern data as text (
/ separates rows, # separates tracks).
- Modify pattern data or paste a copied pattern and click Paste Pattern to load it.
This is a minimal chiptune-style tracker interface without external dependencies, easily extensible.
If you want me to enhance or tailor it further, just ask!