Got it! You're asking for a chiptune tracker implemented with HTML/CSS/JS that includes these features:
- Track playback with BPM control
- Support for song, chord, size, patterns, rows per pattern
- Synth per instrument with custom waveform/oscillator
- Volume, detune, ADSR envelope, filter, noise per instrument
- Ability to share songs (e.g. via URL hash or export)
- Keyboard shortcuts for common operations (duplicate, delete, copy, paste pattern)
- Loop playback
- No external demo or third-party libraries, fully self-contained
Below is a simplified chiptune tracker example implementing these features. It’s a single-page app with:
- Pattern editor grid for notes
- Play/pause with BPM control
- ADSR/envelope/filter per instrument
- Custom waveform selection
- Noise channel toggle
- Simple pattern copy/duplicate/delete via shortcuts
- Share songs via URL hash in JSON encoded form
- Loop playback through given patterns
This can be extended/customized but covers your requested features in a minimal way.
Minimal Chiptune Tracker Example
<!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: monospace, monospace;
background: #111;
color: #eee;
margin: 0;
padding: 0;
user-select: none;
}
header {
padding: 10px 20px;
background: #222;
display: flex;
align-items: center;
gap: 10px;
}
input[type=number], select {
background: #222;
border: 1px solid #555;
color: #eee;
width: 60px;
padding: 2px 4px;
}
button {
background: #333;
border: 1px solid #555;
color: #eee;
cursor: pointer;
padding: 4px 8px;
font-size: 1rem;
}
button:disabled {
opacity: 0.4;
cursor: default;
}
main {
display: flex;
height: calc(100vh - 50px);
overflow: hidden;
}
#patternContainer {
flex: 1;
overflow: auto;
background: #101010;
border-right: 1px solid #444;
}
table {
border-collapse: collapse;
width: 100%;
user-select: none;
}
th, td {
border: 1px solid #333;
text-align: center;
padding: 4px 2px;
font-size: 0.8rem;
min-width: 26px;
color: #aaa;
}
th {
background: #222;
}
td.note {
cursor: pointer;
color: #eee;
}
td.note.active {
background: #444;
color: #0f0;
}
td.note.playing {
background: #0a0;
color: #fff;
}
#instrumentPanel {
width: 280px;
background: #222;
padding: 10px;
box-sizing: border-box;
}
label {
display: block;
margin: 8px 0 4px;
}
input[type=range] {
width: 100%;
}
#shortcuts {
background: #111;
padding: 6px 10px;
font-size:0.85rem;
color:#555;
}
#shareLink {
width: 100%;
box-sizing: border-box;
font-family: monospace;
background: #111;
color: #eee;
border: none;
padding: 6px 4px;
margin-top: 10px;
}
small {
color: #666;
}
</style>
</head>
<body>
<header>
<button id=playBtn>▶ Play</button>
<button id=stopBtn disabled>■ Stop</button>
<label for=bpmInput>BPM:</label>
<input id=bpmInput type=number min=30 max=300 value=120 />
<label for=loopToggle>Loop:</label>
<input id=loopToggle type=checkbox checked />
<button id=copyPatBtn title="Copy current pattern">Copy Pattern</button>
<button id=pastePatBtn title="Paste pattern">Paste Pattern</button>
<button id=dupPatBtn title="Duplicate pattern">Duplicate Pattern</button>
<button id=delPatBtn title="Delete pattern">Delete Pattern</button>
</header>
<main>
<div id=patternContainer>
<table id=patternTable></table>
</div>
<div id=instrumentPanel>
<h3>Instrument 1 Settings</h3>
<label>Waveform:
<select id=waveform>
<option value=sine>sine</option>
<option value=square selected>square</option>
<option value=triangle>triangle</option>
<option value=sawtooth>sawtooth</option>
</select>
</label>
<label>Volume: <input id=volume type=range min=0 max=1 step=0.01 value=0.2></label>
<label>Detune (cents): <input id=detune type=number min=-1200 max=1200 value=0></label>
<label>Attack (s): <input id=attack type=number min=0 max=2 step=0.01 value=0.01></label>
<label>Decay (s): <input id=decay type=number min=0 max=2 step=0.01 value=0.1></label>
<label>Sustain (0-1): <input id=sustain type=number min=0 max=1 step=0.01 value=0.6></label>
<label>Release (s): <input id=release type=number min=0 max=2 step=0.01 value=0.2></label>
<label>Filter Frequency (Hz): <input id=filterFreq type=number min=20 max=5000 step=1 value=1200></label>
<label>Filter Q: <input id=filterQ type=number min=0 max=20 step=0.1 value=5></label>
<label><input id=noiseToggle type=checkbox> Enable Noise</label>
<h4>Shortcuts:</h4>
<div id=shortcuts>
<b>Pattern:</b> Copy: Ctrl+C, Paste: Ctrl+V, Duplicate: Ctrl+D, Delete: Del<br/>
<b>Playback:</b> Space: Play/Pause<br/>
</div>
<textarea id=shareLink readonly></textarea>
</div>
</main>
<script>
(() => {
const AudioCtx = window.AudioContext || window.webkitAudioContext;
const ctx = new AudioCtx();
let playing = false;
let timerID = 0;
// Constants
const ROWS_PER_PATTERN = 16;
const PATTERN_COUNT = 4;
const NOTES = ['C-', 'C#', 'D-', 'D#', 'E-', 'F-', 'F#', 'G-', 'G#', 'A-', 'A#', 'B-'];
const OCTAVES = [2,3,4,5];
// Map from note name (e.g. C#4) to frequency
function noteToFreq(noteStr) {
if (!noteStr || noteStr === '-') return 0;
// e.g. "C#4"
let note = noteStr.substring(0,noteStr.length-1);
let octave = parseInt(noteStr.slice(-1));
let n = NOTES.indexOf(note);
if (n < 0 || isNaN(octave)) return 0;
let keyNum = n + (octave + 1) * 12; // Note number relative to A0=21 on piano, but formula works if accurate freq below
return 440 * Math.pow(2, (keyNum - 57) / 12);
}
// Data Model
let song = {
bpm: 120,
patterns: [], // each pattern: rows: [{note, chord, instrument}, ...]
sequence: [0,1,2,3],
currentPattern: 0,
rowsPerPattern: ROWS_PER_PATTERN,
};
// Each pattern has ROWS_PER_PATTERN rows
function createEmptyPattern() {
const p = [];
for(let i=0; i<ROWS_PER_PATTERN; i++){
p.push({
note: '-',
chord: '-', // placeholder for possible future; ignored now
instrument: 0 // currently one instrument only
});
}
return p;
}
for(let i=0; i<PATTERN_COUNT; i++) {
song.patterns.push(createEmptyPattern());
}
// Instrument Settings
let instrument = {
waveform: 'square',
volume: 0.2,
detune: 0,
attack: 0.01,
decay: 0.1,
sustain: 0.6,
release: 0.2,
filterFreq: 1200,
filterQ: 5,
noise: false
}
// UI Elements
const playBtn = document.getElementById('playBtn');
const stopBtn = document.getElementById('stopBtn');
const bpmInput = document.getElementById('bpmInput');
const loopToggle = document.getElementById('loopToggle');
const patternTable = document.getElementById('patternTable');
const waveformInput = document.getElementById('waveform');
const volumeInput = document.getElementById('volume');
const detuneInput = document.getElementById('detune');
const attackInput = document.getElementById('attack');
const decayInput = document.getElementById('decay');
const sustainInput = document.getElementById('sustain');
const releaseInput = document.getElementById('release');
const filterFreqInput = document.getElementById('filterFreq');
const filterQInput = document.getElementById('filterQ');
const noiseToggleInput = document.getElementById('noiseToggle');
// Shortcut pattern buttons
const copyPatBtn = document.getElementById('copyPatBtn');
const pastePatBtn = document.getElementById('pastePatBtn');
const dupPatBtn = document.getElementById('dupPatBtn');
const delPatBtn = document.getElementById('delPatBtn');
const shareLink = document.getElementById('shareLink');
let clipboardPattern = null;
// Build pattern table headers (columns): row # and note entry
// For simplicity show only note column for now
function buildPatternTable() {
patternTable.innerHTML = '';
const thead = document.createElement('thead');
const headRow = document.createElement('tr');
const hdRowNum = document.createElement('th');
hdRowNum.textContent = 'Row';
headRow.appendChild(hdRowNum);
const hdNote = document.createElement('th');
hdNote.textContent = 'Note';
headRow.appendChild(hdNote);
thead.appendChild(headRow);
patternTable.appendChild(thead);
const tbody = document.createElement('tbody');
for(let r=0; r < ROWS_PER_PATTERN; r++) {
const tr = document.createElement('tr');
const tdRowNum = document.createElement('td');
tdRowNum.textContent = r.toString(16).toUpperCase().padStart(2,'0');
tr.appendChild(tdRowNum);
const tdNote = document.createElement('td');
tdNote.classList.add('note');
tdNote.dataset.row = r;
// Show current note in pattern
const note = song.patterns[song.currentPattern][r].note;
tdNote.textContent = note;
if(note !== '-') tdNote.classList.add('active');
tr.appendChild(tdNote);
tbody.appendChild(tr);
}
patternTable.appendChild(tbody);
}
function updatePatternTableUI() {
const rows = patternTable.querySelectorAll('tbody tr');
rows.forEach((tr) => {
const r = parseInt(tr.children[0].textContent, 16);
const tdNote = tr.children[1];
const note = song.patterns[song.currentPattern][r].note;
tdNote.textContent = note;
tdNote.classList.toggle('active', note !== '-');
tdNote.classList.remove('playing');
});
}
// Change note at row in current pattern
function setNoteAt(row, note) {
if(row < 0 || row >= ROWS_PER_PATTERN) return;
song.patterns[song.currentPattern][row].note = note;
updatePatternTableUI();
}
// Select note by cycling through NOTES+octaves + '-'
// For simplicity, notes displayed as NOTE+OCT (like C#4), user clicks to cycle
// We'll implement click on note cell cycles to next note for demo
function cycleNoteAt(row) {
if(row<0||row>=ROWS_PER_PATTERN)return;
const current = song.patterns[song.currentPattern][row].note;
let allNotes = [];
for (const oct of OCTAVES) {
for (const nt of NOTES) allNotes.push(nt + oct);
}
allNotes.push('-');
let idx = allNotes.indexOf(current);
idx = (idx + 1) % allNotes.length;
song.patterns[song.currentPattern][row].note = allNotes[idx];
updatePatternTableUI();
}
// Event: Click note to cycle note
patternTable.addEventListener('click', e=>{
if(e.target.classList.contains('note')){
const row = +e.target.dataset.row;
cycleNoteAt(row);
}
});
// Playback management
let currentPlayRow = 0;
let currentPlayPatternIdx = 0;
function playRow(patternIdx,row) {
if(patternIdx >= song.sequence.length) {
if(loopToggle.checked) {
currentPlayPatternIdx = 0;
currentPlayRow = 0;
} else {
stopPlayback();
return;
}
}
const patNum = song.sequence[patternIdx];
const pattern = song.patterns[patNum];
if(!pattern) return;
// clear previous playing highlight
const oldPlaying = patternTable.querySelector('td.playing');
if(oldPlaying) oldPlaying.classList.remove('playing');
// Highlight current playing row if current pattern shown
if(patNum === song.currentPattern){
const rows = patternTable.querySelectorAll('tbody tr');
if(row < rows.length) {
rows[row].children[1].classList.add('playing');
}
}
const rowData = pattern[row];
playNote(rowData.note);
currentPlayRow++;
if(currentPlayRow >= ROWS_PER_PATTERN) {
currentPlayRow = 0;
currentPlayPatternIdx++;
}
if(playing){
const intervalMs = (60000 / song.bpm) / 4; // 16th note steps
timerID = setTimeout(() => playRow(currentPlayPatternIdx, currentPlayRow), intervalMs);
}
}
// Synth playback
function playNote(noteStr) {
if(noteStr === '-' || noteStr === '') return;
if(instrument.noise) {
// play noise burst
const noiseBuffer = ctx.createBuffer(1, ctx.sampleRate * 0.1, ctx.sampleRate);
const output = noiseBuffer.getChannelData(0);
for(let i=0;i<output.length;i++){
output[i] = Math.random()*2-1;
}
const noiseSource = ctx.createBufferSource();
noiseSource.buffer = noiseBuffer;
// Gain envelope + filter
const gainNode = ctx.createGain();
const filterNode = ctx.createBiquadFilter();
filterNode.type='lowpass';
filterNode.frequency.value = instrument.filterFreq;
filterNode.Q.value = instrument.filterQ;
noiseSource.connect(filterNode).connect(gainNode).connect(ctx.destination);
const now = ctx.currentTime;
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(instrument.volume, now + instrument.attack);
gainNode.gain.linearRampToValueAtTime(instrument.volume * instrument.sustain, now + instrument.attack + instrument.decay);
gainNode.gain.setTargetAtTime(0, now + instrument.attack + instrument.decay + 0.05, instrument.release);
noiseSource.start(now);
noiseSource.stop(now + instrument.attack + instrument.decay + instrument.release + 0.1);
} else {
// Pure tone using oscillator
const osc = ctx.createOscillator();
osc.type = instrument.waveform;
osc.frequency.value = noteToFreq(noteStr);
osc.detune.value = instrument.detune;
const gainNode = ctx.createGain();
const filterNode = ctx.createBiquadFilter();
filterNode.type='lowpass';
filterNode.frequency.value = instrument.filterFreq;
filterNode.Q.value = instrument.filterQ;
osc.connect(filterNode).connect(gainNode).connect(ctx.destination);
const now = ctx.currentTime;
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(instrument.volume, now + instrument.attack);
gainNode.gain.linearRampToValueAtTime(instrument.volume * instrument.sustain, now + instrument.attack + instrument.decay);
gainNode.gain.setTargetAtTime(0, now + instrument.attack + instrument.decay + instrument.release, instrument.release);
osc.start(now);
osc.stop(now + instrument.attack + instrument.decay + instrument.release + 0.1);
}
}
function startPlayback(){
if(!playing){
playing = true;
currentPlayRow = 0;
currentPlayPatternIdx = 0;
playBtn.textContent = '⏸ Pause';
stopBtn.disabled = false;
bpmInput.disabled = true;
loopToggle.disabled = true;
playRow(currentPlayPatternIdx, currentPlayRow);
}
}
function pausePlayback(){
if(playing){
playing = false;
playBtn.textContent = '▶ Play';
bpmInput.disabled = false;
loopToggle.disabled = false;
clearTimeout(timerID);
const oldPlaying = patternTable.querySelector('td.playing');
if(oldPlaying) oldPlaying.classList.remove('playing');
}
}
function stopPlayback(){
if(playing){
playing = false;
playBtn.textContent = '▶ Play';
stopBtn.disabled = true;
bpmInput.disabled = false;
loopToggle.disabled = false;
clearTimeout(timerID);
const oldPlaying = patternTable.querySelector('td.playing');
if(oldPlaying) oldPlaying.classList.remove('playing');
}
}
// Playback button handlers
playBtn.addEventListener('click', () => {
// resume audio context on first user interaction if suspended
if(ctx.state === 'suspended'){
ctx.resume().then(() => {
if(playing) pausePlayback();
else startPlayback();
});
} else {
if(playing) pausePlayback();
else startPlayback();
}
});
stopBtn.addEventListener('click', () => {
stopPlayback();
});
// Update BPM
bpmInput.addEventListener('change', e => {
let n = parseInt(e.target.value);
if(isNaN(n) || n < 30) n=30;
if(n > 300) n=300;
song.bpm = n;
bpmInput.value = n;
});
// Update instrument on controls input
function updateInstrumentFromUI(){
instrument.waveform = waveformInput.value;
instrument.volume = +volumeInput.value;
instrument.detune = +detuneInput.value;
instrument.attack = +attackInput.value;
instrument.decay = +decayInput.value;
instrument.sustain = +sustainInput.value;
instrument.release = +releaseInput.value;
instrument.filterFreq = +filterFreqInput.value;
instrument.filterQ = +filterQInput.value;
instrument.noise = noiseToggleInput.checked;
}
waveformInput.addEventListener('change', updateInstrumentFromUI);
volumeInput.addEventListener('input', updateInstrumentFromUI);
detuneInput.addEventListener('change', updateInstrumentFromUI);
attackInput.addEventListener('change', updateInstrumentFromUI);
decayInput.addEventListener('change', updateInstrumentFromUI);
sustainInput.addEventListener('change', updateInstrumentFromUI);
releaseInput.addEventListener('change', updateInstrumentFromUI);
filterFreqInput.addEventListener('change', updateInstrumentFromUI);
filterQInput.addEventListener('change', updateInstrumentFromUI);
noiseToggleInput.addEventListener('change', updateInstrumentFromUI);
updateInstrumentFromUI();
// Pattern management: copy / paste / duplicate / delete current pattern
function copyPattern(){
clipboardPattern = JSON.parse(JSON.stringify(song.patterns[song.currentPattern]));
alert('Pattern copied!');
}
function pastePattern(){
if(clipboardPattern){
song.patterns[song.currentPattern] = JSON.parse(JSON.stringify(clipboardPattern));
updatePatternTableUI();
alert('Pattern pasted!');
} else alert('No pattern copied');
}
function duplicatePattern(){
if(song.patterns.length >= 16) {
alert('Max 16 patterns allowed');
return;
}
// insert duplicate after current one
song.patterns.splice(song.currentPattern+1,0, JSON.parse(JSON.stringify(song.patterns[song.currentPattern])));
song.sequence.splice(song.currentPattern+1,0, song.currentPattern+1);
alert('Pattern duplicated');
}
function deletePattern(){
if(song.patterns.length <=1) {
alert('Cannot delete last pattern');
return;
}
song.patterns.splice(song.currentPattern,1);
song.sequence.splice(song.currentPattern,1);
if(song.currentPattern >= song.patterns.length) song.currentPattern = song.patterns.length -1;
updatePatternTableUI();
alert('Pattern deleted');
}
copyPatBtn.addEventListener('click', copyPattern);
pastePatBtn.addEventListener('click', pastePattern);
dupPatBtn.addEventListener('click', duplicatePattern);
delPatBtn.addEventListener('click', deletePattern);
// Keyboard shortcuts
document.addEventListener('keydown', e=>{
if(e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable){
return; // ignore inside inputs
}
// Ctrl+C - Copy Pattern
if(e.ctrlKey && e.key.toLowerCase() === 'c'){
e.preventDefault();
copyPattern();
}
// Ctrl+V - Paste Pattern
else if(e.ctrlKey && e.key.toLowerCase() === 'v'){
e.preventDefault();
pastePattern();
}
// Ctrl+D - Duplicate Pattern
else if(e.ctrlKey && e.key.toLowerCase() === 'd'){
e.preventDefault();
duplicatePattern();
}
// Del - Delete Pattern
else if(e.key === 'Delete'){
e.preventDefault();
deletePattern();
}
else if(e.key === ' '){
e.preventDefault();
if(playing) pausePlayback(); else startPlayback();
}
});
// Song sharing: export/import song data as JSON base64 in URL hash
function exportSong() {
const data = {
bpm: song.bpm,
patterns: song.patterns,
sequence: song.sequence,
instrument: instrument
};
const jsonStr = JSON.stringify(data);
try {
return btoa(encodeURIComponent(jsonStr));
} catch(e) {
return '';
}
}
function importSong(b64) {
try {
let jsonStr = decodeURIComponent(atob(b64));
let data = JSON.parse(jsonStr);
if(data.bpm && data.patterns && data.sequence){
song.bpm = data.bpm;
bpmInput.value = data.bpm;
song.patterns = data.patterns;
song.sequence = data.sequence;
if(data.instrument){
Object.assign(instrument, data.instrument);
waveformInput.value = instrument.waveform;
volumeInput.value = instrument.volume;
detuneInput.value = instrument.detune;
attackInput.value = instrument.attack;
decayInput.value = instrument.decay;
sustainInput.value = instrument.sustain;
releaseInput.value = instrument.release;
filterFreqInput.value = instrument.filterFreq;
filterQInput.value = instrument.filterQ;
noiseToggleInput.checked = instrument.noise;
updateInstrumentFromUI();
}
updatePatternTableUI();
}
} catch(e) {
console.warn('Invalid song data');
}
}
// On page load, try to load from URL
function loadFromHash() {
if(location.hash.length > 2) {
const b64 = location.hash.slice(2);
importSong(b64);
}
}
// Update share text area with URL
function updateShareLink(){
const b64 = exportSong();
if(b64) {
const url = location.origin + location.pathname + '/#' + b64;
shareLink.value = url;
} else shareLink.value = '';
}
shareLink.addEventListener('click', () => {
shareLink.select();
});
// Update share every 2 sec while editing (to keep updated)
setInterval(updateShareLink, 2000);
// Initial build
buildPatternTable();
updatePatternTableUI();
loadFromHash();
// Allow changing current pattern by clicking row # (TODO: add UI for pattern selector)
// For now just allow switching patterns by clicking row number multiple times
patternTable.querySelectorAll('tbody tr td:first-child').forEach(td=>{
td.style.cursor = 'pointer';
td.title = 'Click to switch pattern';
td.addEventListener('click', e=>{
song.currentPattern = (song.currentPattern + 1) % song.patterns.length;
buildPatternTable();
});
});
})();
</script>
</body>
</html>
How to Use
-
Click note cells to cycle through notes C2..B5 or empty "-"
-
Press Play to hear the sequence (4 patterns).
-
Use BPM input to change speed.
-
Loop toggle for looping playback.
-
Adjust synth parameters on the right side (waveform, volume, ADSR, etc)
-
Enable noise oscillator toggle to play noise instead of tone.
-
Use shortcuts:
- Ctrl+C: Copy pattern
- Ctrl+V: Paste pattern
- Ctrl+D: Duplicate pattern
- Delete: Delete pattern
- Space: Play/pause
-
Click row numbers to cycle current pattern viewed.
-
The share link textarea updates with a URL that encodes the current song — copy/paste that URL to share.
-
Paste a shared URL on page load to import the song.
Notes / Limitations
- This example is minimal and lacks advanced features like chords or multiple instruments.
- The sequence is fixed to 4 patterns initially.
- The UI is simple for demonstration.
- The pitch detection and oscillator can be expanded for more synthesis features.
- Only one instrument is supported; adding more instruments you'd extend the song model and UI.
Feel free to build on this or request additional features!