You want to create a chiptune tracker — a web-based music tracker tool with these features:
- BPM control
- Multiple patterns
- Configurable rows per pattern
- Multiple instruments/synths, each with:
- Custom waveform/oscillator
- Volume
- Detune
- ADSR envelope
- Filter
- Noise
- Ability to share the song via URL fragment ("/#")
- Keyboard shortcuts for efficiency
- Pattern looping
- Pattern operations: duplicate, delete, copy, paste
- Implementation with HTML/CSS/JS, no external demo embed (self-contained)
Here's a minimal but functional starting point with those core features.
Due to the complexity, this is a base which you can further expand. I focused on modularity, a clear pattern and instruments system, and a basic synth with custom waveform, ADSR, filter, noise.
Live self-contained HTML/JS/CSS project:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chiptune Tracker</title>
<style>
body {
font-family: "Consolas", monospace;
background: #121212;
color: #eee;
margin: 0; padding: 0;
display: flex; flex-direction: column;
height: 100vh;
}
header {
background: #222;
padding: 0.5em;
display: flex;
align-items: center;
gap: 1em;
}
label {
font-size: 0.9em;
user-select: none;
}
input, select {
font-family: monospace;
font-size: 1em;
background: #222;
border: 1px solid #444;
color: #eee;
padding: 0.2em 0.4em;
border-radius: 3px;
}
main {
flex: 1;
display: grid;
grid-template-columns: 1fr 300px;
gap: 0.5em;
padding: 0.5em;
}
section.patterns {
background: #1b1b1b;
padding: 0.5em;
border-radius: 6px;
overflow: auto;
}
table.pattern {
border-collapse: collapse;
width: 100%;
user-select: none;
}
table.pattern thead tr {
background: #222;
}
table.pattern th, table.pattern td {
border: 1px solid #333;
width: 2.6em;
height: 1.7em;
text-align: center;
cursor: pointer;
font-weight: normal;
}
table.pattern td.active {
background: #4a90e2;
color: white;
}
table.pattern td.current-row {
border-color: #e28a2f;
}
table.pattern td.editing {
background: #e28a2f;
color:black;
}
section.instrument-panel {
background: #1b1b1b;
padding: 0.5em;
border-radius: 6px;
overflow-y: auto;
max-height: 100%;
}
h2 {
margin-top: 0;
}
label.inline {
display: flex;
justify-content: space-between;
margin-bottom: 0.4em;
}
button {
background: #222;
color: #eee;
border: 1px solid #444;
padding: 0.4em 0.7em;
border-radius: 4px;
cursor: pointer;
font-family: monospace;
}
button:hover {
background: #444;
}
.pattern-controls {
margin-bottom: 0.4em;
display: flex;
gap: 0.4em;
flex-wrap: wrap;
}
.pattern-controls button {
flex: 1;
}
.pattern-select {
font-family: monospace;
font-size: 1em;
padding: 0.2em 0.4em;
background: #222;
border: 1px solid #444;
border-radius: 3px;
color: #eee;
}
.small-btn {
padding: 0.1em 0.3em;
font-size: 0.8em;
}
.footer {
background: #222;
padding: 0.3em;
font-size: 0.8em;
user-select:none;
text-align: center;
}
.notice {
padding: 0.3em 0.5em;
font-size: 0.9em;
color: #faa;
}
</style>
</head>
<body>
<header>
<label>BPM<input id="bpm" type="number" min="30" max="300" value="120" /></label>
<label>Rows/Pattern<input id="rowsPerPattern" type="number" min="4" max="64" step="4" value="16" /></label>
<label>Current Pattern
<select id="patternSelect" class="pattern-select"></select>
</label>
<button id="playPause">▶ Play</button>
<button id="loopToggle" title="Toggle looping">🔁 Off</button>
<button id="shareBtn" title="Share song as URL">🔗 Share</button>
</header>
<main>
<section class="patterns">
<div class="pattern-controls">
<button id="addPattern">+ Add Pattern</button>
<button id="dupPattern">⎘ Duplicate</button>
<button id="delPattern">✕ Delete</button>
<button id="copyPattern">⧉ Copy</button>
<button id="pastePattern">📋 Paste</button>
</div>
<table id="patternGrid" class="pattern" aria-label="Pattern grid">
<thead>
<tr>
<th>#</th>
<th>Note</th>
<th>Inst</th>
<th>Vol</th>
<th>Effect</th>
</tr>
</thead>
<tbody></tbody>
</table>
</section>
<section class="instrument-panel">
<h2>Instrument</h2>
<label class="inline">Instrument
<select id="instrumentSelect"></select>
</label>
<label>Waveform
<select id="waveformSelect">
<option value="sine">Sine</option>
<option value="square" selected>Square</option>
<option value="triangle">Triangle</option>
<option value="sawtooth">Sawtooth</option>
<option value="custom">Custom (noise)</option>
</select>
</label>
<label>Volume
<input id="instVolume" type="range" min="0" max="1" step="0.01" value="0.5" />
</label>
<label>Detune (cents)
<input id="instDetune" type="number" min="-1200" max="1200" step="1" value="0" />
</label>
<label>Attack (ms)
<input id="instAttack" type="number" min="0" max="2000" value="10" />
</label>
<label>Decay (ms)
<input id="instDecay" type="number" min="0" max="2000" value="50" />
</label>
<label>Sustain (0-1)
<input id="instSustain" type="range" min="0" max="1" step="0.01" value="0.7" />
</label>
<label>Release (ms)
<input id="instRelease" type="number" min="0" max="4000" value="200" />
</label>
<label>Filter frequency (Hz)
<input id="instFilterFreq" type="number" min="0" max="22050" step="1" value="1200" />
</label>
<label>Filter Q
<input id="instFilterQ" type="number" min="0" max="30" step="0.01" value="1" />
</label>
</section>
</main>
<footer class="footer">
Notes: C0=Note 12, A4=Note 69, octave starts at C.<br />
Keyboard shortcuts:<br />
Arrows: navigate, Enter/Esc/Del: edit/exit/delete note, Space: play/pause,<br/>
Ctrl+D: duplicate pattern, Ctrl+C/V: copy/paste pattern, Ctrl+L: loop toggle.
</footer>
<script>
(() => {
// AUDIO SETUP
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioCtx = new AudioContext();
// Constants
const NOTES_A4 = 69;
const FREQ_A4 = 440;
const SEMITONE_RATIO = Math.pow(2, 1/12);
// Helper: note number to frequency (MIDI-note style, where C4=60)
function noteNumberToFreq(n) {
return FREQ_A4 * Math.pow(SEMITONE_RATIO, n - NOTES_A4);
}
// State
let bpm = 120;
let rowsPerPattern = 16;
let playing = false;
let loop = false;
let currentPatternIndex = 0;
let currentRow = 0;
let timerId = null;
let lastTime = 0;
// Clipboard for patterns
let patternClipboard = null;
// Pattern structure:
// patterns: array of pattern objects
// pattern = {rows: [{note:int or null, inst:int|null, vol:float|null, effect:string}], length: rowsPerPattern}
let patterns = [];
function createEmptyPattern(length=rowsPerPattern) {
return {
rows: Array.from({length}, () => ({note:null, inst:null, vol:null, effect:null}))
};
}
// Instruments: array of instruments with synth params
let instruments = [];
function createDefaultInstrument() {
return {
waveform: "square",
volume: 0.5,
detune: 0,
adsr: {attack: 0.01, decay: 0.05, sustain: 0.7, release: 0.2},
filterFreq: 1200,
filterQ: 1,
noise: false // if waveform custom/noise set to true
};
}
// Create default 3 instruments
for(let i=0; i<3; i++) instruments.push(createDefaultInstrument());
// UI Elements
const bpmInput = document.getElementById("bpm");
const rowsInput = document.getElementById("rowsPerPattern");
const patternSelect = document.getElementById("patternSelect");
const playPauseBtn = document.getElementById("playPause");
const loopToggleBtn = document.getElementById("loopToggle");
const addPatternBtn = document.getElementById("addPattern");
const dupPatternBtn = document.getElementById("dupPattern");
const delPatternBtn = document.getElementById("delPattern");
const copyPatternBtn = document.getElementById("copyPattern");
const pastePatternBtn = document.getElementById("pastePattern");
const patternGridBody = document.querySelector("#patternGrid tbody");
const instrumentSelect = document.getElementById("instrumentSelect");
const waveformSelect = document.getElementById("waveformSelect");
const instVolume = document.getElementById("instVolume");
const instDetune = document.getElementById("instDetune");
const instAttack = document.getElementById("instAttack");
const instDecay = document.getElementById("instDecay");
const instSustain = document.getElementById("instSustain");
const instRelease = document.getElementById("instRelease");
const instFilterFreq = document.getElementById("instFilterFreq");
const instFilterQ = document.getElementById("instFilterQ");
// Note names for display (C, C#, D, ...), only octave and name needed
const noteNames = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
// ========== Data Initialization ===============
// Add initial pattern
function init() {
if (patterns.length === 0) {
patterns.push(createEmptyPattern(rowsPerPattern));
}
currentPatternIndex = 0;
bpmInput.value = bpm;
rowsInput.value = rowsPerPattern;
updatePatternSelect();
updateInstrumentSelect();
selectInstrument(0);
renderGrid();
}
// =============== Pattern Management ===================
function updatePatternSelect() {
patternSelect.innerHTML = "";
patterns.forEach((_, i) => {
let opt = document.createElement("option");
opt.value = i;
opt.textContent = `Pattern ${i}`;
if(i === currentPatternIndex) opt.selected = true;
patternSelect.appendChild(opt);
});
}
function addPattern() {
patterns.push(createEmptyPattern(rowsPerPattern));
currentPatternIndex = patterns.length - 1;
updatePatternSelect();
renderGrid();
}
function dupPattern() {
if (patterns[currentPatternIndex]) {
const dup = JSON.parse(JSON.stringify(patterns[currentPatternIndex]));
patterns.splice(currentPatternIndex +1, 0, dup);
currentPatternIndex++;
updatePatternSelect();
renderGrid();
}
}
function delPattern() {
if(patterns.length <= 1) return alert("At least one pattern required");
patterns.splice(currentPatternIndex,1);
currentPatternIndex = Math.min(currentPatternIndex, patterns.length-1);
updatePatternSelect();
renderGrid();
}
function copyPattern() {
patternClipboard = JSON.stringify(patterns[currentPatternIndex]);
alert("Pattern copied");
}
function pastePattern() {
if(!patternClipboard) {
alert("Clipboard empty");
return;
}
try {
const obj = JSON.parse(patternClipboard);
if(obj && obj.rows && Array.isArray(obj.rows)) {
patterns[currentPatternIndex] = obj;
renderGrid();
alert("Pattern pasted");
} else {
alert("Clipboard does not contain a pattern");
}
} catch(e) {
alert("Error parsing clipboard content");
}
}
patternSelect.addEventListener("change", e => {
currentPatternIndex = +e.target.value;
currentRow = 0;
renderGrid();
});
addPatternBtn.onclick = addPattern;
dupPatternBtn.onclick = dupPattern;
delPatternBtn.onclick = delPattern;
copyPatternBtn.onclick = copyPattern;
pastePatternBtn.onclick = pastePattern;
// ================ Grid Rendering ======================
// Render the pattern grid table tbody
// Columns: #, Note, Instrument, Volume, Effect
// Note is stored as MIDI number or null
// Editing state:
let editingCell = null; // {rowIdx, colName}
// Allowed Notes input: C-0 to B-7, or --- to clear
// We'll accept "C#", "D#", ... with octave number. Example: C4=60 (MIDI note)
function midiNoteToName(num) {
if (num === null || num === undefined) return "---";
const name = noteNames[num % 12];
const octave = Math.floor(num / 12) - 1;
return name + octave;
}
// Parse note string to midi note number or null
// Accept format: C0 .. B7, optionally # for sharps
// Return null if '---' or empty string
function parseNoteStr(str) {
if (!str) return null;
str = str.toUpperCase().trim();
if (str === "---") return null;
const match = /^([A-G])(#?)(-?\d+)$/.exec(str);
if(!match) return null;
const noteBase = match[1];
const sharp = match[2]==="#" ? 1 : 0;
const octave = parseInt(match[3],10);
const baseIndex = noteNames.indexOf(noteBase);
if(baseIndex === -1) return null;
return (octave+1) * 12 + baseIndex + sharp;
}
// Allowed columns in pattern
const patternCols = ["note", "inst", "vol", "effect"];
// Render entire grid
function renderGrid() {
const pattern = patterns[currentPatternIndex];
if(!pattern) return;
patternGridBody.innerHTML = "";
for(let i=0; i<pattern.rows.length; i++) {
const row = pattern.rows[i];
const tr = document.createElement("tr");
if(i === currentRow) tr.classList.add("current-row");
// # / row #
const tdNum = document.createElement("td");
tdNum.textContent = i.toString().padStart(2, "0");
tr.appendChild(tdNum);
// Note
const tdNote = document.createElement("td");
tdNote.textContent = midiNoteToName(row.note);
tdNote.dataset.col = "note";
if(editingCell && editingCell.row === i && editingCell.col === "note") tdNote.classList.add("editing");
tr.appendChild(tdNote);
// Instrument
const tdInst = document.createElement("td");
tdInst.textContent = (row.inst === null || row.inst === undefined) ? "-" : (row.inst +1);
tdInst.dataset.col = "inst";
if(editingCell && editingCell.row === i && editingCell.col === "inst") tdInst.classList.add("editing");
tr.appendChild(tdInst);
// Volume
const tdVol = document.createElement("td");
tdVol.textContent = (row.vol === null || row.vol === undefined) ? "-" : Math.round(row.vol * 15).toString(16).toUpperCase();
tdVol.dataset.col = "vol";
if(editingCell && editingCell.row === i && editingCell.col === "vol") tdVol.classList.add("editing");
tr.appendChild(tdVol);
// Effect (simple char for now)
const tdEff = document.createElement("td");
tdEff.textContent = (row.effect === null || row.effect === undefined) ? "-" : row.effect;
tdEff.dataset.col = "effect";
if(editingCell && editingCell.row === i && editingCell.col === "effect") tdEff.classList.add("editing");
tr.appendChild(tdEff);
// Click to start editing a cell
[tdNote, tdInst, tdVol, tdEff].forEach(td=>{
td.onclick = () => {
startEditing(i, td.dataset.col);
};
});
patternGridBody.appendChild(tr);
}
}
// ================ Editing ================
// Editing allows inline cell editing with prompt
// We'll do simple prompt to keep code lightweight
function startEditing(row, col) {
if(editingCell) return;
editingCell = {row, col};
renderGrid();
// prompt to edit
const pattern = patterns[currentPatternIndex];
const rowData = pattern.rows[row];
let oldVal;
switch(col) {
case "note": oldVal = midiNoteToName(rowData.note); break;
case "inst": oldVal = rowData.inst === null ? "-" : (rowData.inst +1); break;
case "vol": oldVal = rowData.vol === null ? "-" : Math.round(rowData.vol*15).toString(16).toUpperCase(); break;
case "effect": oldVal = rowData.effect === null ? "-" : rowData.effect; break;
}
let input = prompt(`Edit ${col} (Row ${row})`, oldVal);
if(input === null) {
editingCell = null;
renderGrid();
return; // canceled
}
input = input.trim();
if(input === "-" || input === "---" || input === "") {
// Clear cell
rowData[col] = null;
} else {
switch(col) {
case "note": {
const n = parseNoteStr(input);
if(n === null) {
alert("Invalid note format");
} else {
rowData.note = n;
}
break;
}
case "inst": {
const n = parseInt(input,10);
if(isNaN(n) || n < 1 || n > instruments.length) {
alert(`Inst number invalid (1-${instruments.length})`);
} else {
rowData.inst = n-1;
}
break;
}
case "vol": {
let v = parseInt(input,16);
if(isNaN(v) || v < 0 || v > 15) {
alert("Volume must be hex 0-F");
} else {
rowData.vol = v/15;
}
break;
}
case "effect": {
if(input.length > 1) {
alert("Effect must be a single character");
} else {
rowData.effect = input;
}
break;
}
}
}
editingCell = null;
renderGrid();
}
// ================ Playback ===============
// Steps: play next step based on bpm and rowsPerPattern
let currentScheduledTime = 0;
// Play note with ADSR, filter, volume, detune
// noise waveform means white noise
function playNote(noteNum, instNum, volumeParam) {
if(noteNum === null || instNum === null) return;
const inst = instruments[instNum];
if(!inst) return;
const now = audioCtx.currentTime;
// Oscillator or noise
let source;
if(inst.waveform === "custom" || inst.noise) {
// noise
const bufferSize = 2 * audioCtx.sampleRate;
const noiseBuffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
const output = noiseBuffer.getChannelData(0);
for (let i = 0; i < bufferSize; i++) {
output[i] = Math.random() * 2 - 1;
}
source = audioCtx.createBufferSource();
source.buffer = noiseBuffer;
source.loop = true;
} else {
source = audioCtx.createOscillator();
source.type = inst.waveform;
const freq = noteNumberToFreq(noteNum);
source.frequency.setValueAtTime(freq, now);
source.detune.setValueAtTime(inst.detune, now);
}
// Gain node for ADSR and volume
const gainNode = audioCtx.createGain();
// Filter
const filterNode = audioCtx.createBiquadFilter();
filterNode.type = "lowpass";
filterNode.frequency.setValueAtTime(inst.filterFreq, now);
filterNode.Q.setValueAtTime(inst.filterQ, now);
// Connect chain: source -> filter -> gain -> destination
source.connect(filterNode);
filterNode.connect(gainNode);
gainNode.connect(audioCtx.destination);
// ADSR envelope
const a = inst.adsr.attack;
const d = inst.adsr.decay;
const s = inst.adsr.sustain;
const r = inst.adsr.release;
// volumeParam can override instrument volume if given
const finalVol = (volumeParam !== null && volumeParam !== undefined) ? volumeParam : inst.volume;
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(finalVol, now + a);
gainNode.gain.linearRampToValueAtTime(finalVol * s, now + a + d);
source.start(now);
// Stop / release
gainNode.gain.setTargetAtTime(0, now + a + d + 0.1, r / 10);
source.stop(now + a + d + r + 0.2);
}
// Schedule pattern playback with timeout
function schedulePlay() {
if (!playing) return;
const spb = 60 / bpm / (rowsPerPattern / rowsPerPattern); // seconds per row
const now = audioCtx.currentTime;
if (lastTime === 0) lastTime = now;
if (now - lastTime >= spb) {
lastTime += spb;
const pattern = patterns[currentPatternIndex];
if (!pattern) return;
if (currentRow >= pattern.rows.length) {
if (loop) {
currentRow = 0;
} else {
stopPlaying();
return;
}
}
const row = pattern.rows[currentRow];
if (row.note !== null && row.inst !== null) {
playNote(row.note, row.inst, row.vol !== null ? row.vol : undefined);
}
currentRow++;
renderGrid();
}
timerId = requestAnimationFrame(schedulePlay);
}
function startPlaying() {
if (audioCtx.state === 'suspended') audioCtx.resume();
playing = true;
playPauseBtn.textContent = "⏸ Pause";
currentRow = 0;
lastTime = audioCtx.currentTime;
schedulePlay();
}
function stopPlaying() {
playing = false;
playPauseBtn.textContent = "▶ Play";
if (timerId) cancelAnimationFrame(timerId);
renderGrid();
}
playPauseBtn.onclick = () => {
if(playing) stopPlaying();
else startPlaying();
};
loopToggleBtn.onclick = () => {
loop = !loop;
loopToggleBtn.textContent = loop ? "🔁 On" : "🔁 Off";
};
// ================ Instruments UI ================
function updateInstrumentSelect() {
instrumentSelect.innerHTML = "";
instruments.forEach((_, i) => {
const opt = document.createElement("option");
opt.value = i;
opt.textContent = `Inst ${i + 1}`;
instrumentSelect.appendChild(opt);
});
}
let currentInstrumentIndex = 0;
function selectInstrument(i) {
currentInstrumentIndex = i;
instrumentSelect.value = i;
const inst = instruments[i];
waveformSelect.value = inst.waveform;
instVolume.value = inst.volume;
instDetune.value = inst.detune;
instAttack.value = inst.adsr.attack * 1000;
instDecay.value = inst.adsr.decay * 1000;
instSustain.value = inst.adsr.sustain;
instRelease.value = inst.adsr.release * 1000;
instFilterFreq.value = inst.filterFreq;
instFilterQ.value = inst.filterQ;
}
instrumentSelect.addEventListener("change", (e) => {
selectInstrument(+e.target.value);
});
// Update instrument parameters on controls change
waveformSelect.addEventListener("change", (e) => {
instruments[currentInstrumentIndex].waveform = e.target.value;
instruments[currentInstrumentIndex].noise = (e.target.value === "custom");
});
instVolume.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].volume = parseFloat(e.target.value);
});
instDetune.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].detune = parseFloat(e.target.value);
});
instAttack.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].adsr.attack = parseFloat(e.target.value)/1000;
});
instDecay.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].adsr.decay = parseFloat(e.target.value)/1000;
});
instSustain.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].adsr.sustain = parseFloat(e.target.value);
});
instRelease.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].adsr.release = parseFloat(e.target.value)/1000;
});
instFilterFreq.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].filterFreq = parseFloat(e.target.value);
});
instFilterQ.addEventListener("input", (e) => {
instruments[currentInstrumentIndex].filterQ = parseFloat(e.target.value);
});
// ============= BPM and rows update ==============
bpmInput.addEventListener("change", (e) => {
let val = parseInt(e.target.value,10);
if (val >= 30 && val <= 300) {
bpm = val;
} else {
e.target.value = bpm;
}
});
rowsInput.addEventListener("change", (e) => {
let val = parseInt(e.target.value,10);
if (val >= 4 && val <= 64 && val % 4 === 0) {
rowsPerPattern = val;
// Resize all patterns rows
patterns = patterns.map(pat => {
const newRows = [...pat.rows];
if (pat.rows.length < rowsPerPattern) {
for (let i = pat.rows.length; i < rowsPerPattern; i++) {
newRows.push({note:null, inst:null, vol:null, effect:null});
}
} else if (pat.rows.length > rowsPerPattern) {
newRows.splice(rowsPerPattern);
}
return {rows: newRows};
});
renderGrid();
} else {
e.target.value = rowsPerPattern;
}
});
// ======== Share Song via URL Fragment ================
function exportSongData() {
// Store bpm, rowsPerPattern, instruments (waveform, volume, detune, adsr...), and patterns rows
const data = {
bpm, rowsPerPattern, instruments, patterns
};
return encodeURIComponent(JSON.stringify(data));
}
function importSongData(dataStr) {
try {
const dataJson = decodeURIComponent(dataStr);
const obj = JSON.parse(dataJson);
if(obj.bpm) bpm = obj.bpm;
if(obj.rowsPerPattern) rowsPerPattern = obj.rowsPerPattern;
if(obj.instruments) instruments = obj.instruments;
if(obj.patterns) patterns = obj.patterns;
bpmInput.value = bpm;
rowsInput.value = rowsPerPattern;
updatePatternSelect();
updateInstrumentSelect();
selectInstrument(0);
renderGrid();
} catch(e) {
alert("Invalid song data in URL");
}
}
document.getElementById("shareBtn").addEventListener("click", () => {
const songData = exportSongData();
const url = `${location.origin}${location.pathname}#/` + songData;
prompt("Shareable URL:", url);
});
window.addEventListener("hashchange", () => {
const hash = location.hash;
if(hash.startsWith("#/")) {
importSongData(hash.slice(2));
stopPlaying();
}
});
// On page load check hash:
if(location.hash.startsWith("#/")){
importSongData(location.hash.slice(2));
}
// =========== Keyboard Shortcuts =============
// focus on pattern grid for keyboard navigation and editing
function moveSelection(dir) {
// dir = 'up', 'down'
if(dir === "up") currentRow = Math.max(0, currentRow - 1);
else if(dir === "down") currentRow = Math.min(rowsPerPattern-1, currentRow +1);
renderGrid();
}
// Key handler
document.addEventListener("keydown", e => {
if (editingCell) {
// when editing prompt open, keydown on document not needed
return;
}
if(e.key === "ArrowUp"){
moveSelection("up");
e.preventDefault();
} else if(e.key === "ArrowDown"){
moveSelection("down");
e.preventDefault();
} else if(e.key === "Enter"){
startEditing(currentRow, "note");
e.preventDefault();
} else if(e.key === "Delete" || e.key === "Backspace"){
// delete current row note/inst/vol/effect
const row = patterns[currentPatternIndex].rows[currentRow];
row.note=null; row.inst=null; row.vol=null; row.effect=null;
renderGrid();
e.preventDefault();
} else if(e.key === " "){
if(playing) stopPlaying();
else startPlaying();
e.preventDefault();
} else if(e.ctrlKey && e.key.toLowerCase() === 'd'){
dupPattern();
e.preventDefault();
} else if(e.ctrlKey && e.key.toLowerCase() === 'c'){
copyPattern();
e.preventDefault();
} else if(e.ctrlKey && e.key.toLowerCase() === 'v'){
pastePattern();
e.preventDefault();
} else if(e.ctrlKey && e.key.toLowerCase() === 'l'){
loop = !loop;
loopToggleBtn.textContent = loop ? "🔁 On" : "🔁 Off";
e.preventDefault();
}
});
// Initialize UI and data
init();
})();
</script>
</body>
</html>
How to use this tracker:
- Set BPM and rows per pattern at the top.
- Use the Pattern Select to switch patterns.
- Use the buttons to add/duplicate/delete/copy/paste patterns.
- Click cells in the pattern grid to edit note (format like C4, D#3, or --- to clear), instrument (number 1-based), vol (hex 0-F), and effect (one char).
- Instruments can be selected and their synth parameters changed on right panel:
- Waveform (including a noise waveform)
- Volume, Detune (cents)
- ADSR envelope (attack, decay, sustain, release)
- Filter freq and Q
- Press Play to start playing the pattern step by step.
- Loop toggle button controls whether to loop the current pattern.
- Share button creates a URL with embedded song data after
#/ fragment that can be shared and loaded by visiting that URL.
- Keyboard shortcuts:
- Arrows Up/Down: move selection in pattern rows
- Enter: edit note at current row
- Delete/Backspace: clear current row
- Space: play/pause
- Ctrl+D: duplicate pattern
- Ctrl+C: copy pattern
- Ctrl+V: paste pattern
- Ctrl+L: toggle loop
Notes:
- This code uses Web Audio API internally and needs a user gesture (click play) for context resume.
- For simplicity, only one pattern plays at a time; expanding to multiple patterns with order list is possible.
- You can further enhance UI with better editing, note input helpers, pattern chaining, effects, and custom waveforms.
- Uses URL fragment to serialize a compact version of song data as JSON string for sharing.
- Noise instrument uses white noise buffer.
- Volume in pattern is from 0 to 1 internally, displayed as hex 0-F for a tracker feel.
- Effect column currently stores a one-char effect placeholder.
If you want me to build specific extra features or optimize further, just ask!