If none available exactly fits, next is option 2.
html Copy 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 { font-family: monospace; background: #111; color: #eee; }
.tracker { display: flex; }
.pattern { margin-right: 20px; }
input, select { background: #222; color: #eee; border: 1px solid #555; padding: 4px; margin-bottom: 8px; width: 100%; }
label { font-size: 14px; }
</style>
</head>
<body>
<h1>Minimal Chiptune Tracker</h1>
<div>
<label>BPM: <input type="number" id="bpm" min="30" max="300" value="120" /></label>
</div>
<div class="tracker">
<div class="pattern">
<h3>Pattern 0</h3>
<textarea id="pattern0" rows="16" cols="8" spellcheck="false">
// Format: note instrument volume detune
// Example: C4 0 15 0
C4 0 15 0
D4 0 15 0
E4 0 15 0
F4 0 15 0
G4 0 15 0
A4 0 15 0
B4 0 15 0
C5 0 15 0
-- 0 0 0
-- 0 0 0
-- 0 0 0
-- 0 0 0
-- 0 0 0
-- 0 0 0
-- 0 0 0
-- 0 0 0
</textarea>
</div>
<div class="instrument">
<h3>Instrument 0</h3>
<label>Oscillator:
<select id="osc0">
<option value="sine">sine</option>
<option value="square" selected>square</option>
<option value="triangle">triangle</option>
<option value="sawtooth">sawtooth</option>
</select>
</label><br />
<label>Volume: <input id="vol0" type="range" min="0" max="1" step="0.01" value="0.25"></label><br />
<label>Detune (cents): <input id="detune0" type="number" min="-100" max="100" value="0"></label><br />
<label>ADSR (ms)</label><br />
<label>Attack: <input id="attack0" type="number" min="0" max="1000" value="10"></label><br />
<label>Decay: <input id="decay0" type="number" min="0" max="1000" value="100"></label><br />
<label>Sustain: <input id="sustain0" type="range" min="0" max="1" step="0.01" value="0.7"></label><br />
<label>Release: <input id="release0" type="number" min="0" max="1000" value="200"></label><br />
<label>Filter Cutoff (Hz): <input id="filter0" type="number" min="50" max="10000" value="1000"></label><br />
<label>Noise (on/off): <input id="noise0" type="checkbox"></label>
</div>
</div>
<div>
<button id="playBtn">Play</button>
<button id="stopBtn">Stop</button>
<button id="shareBtn">Share</button>
</div>
<div>
<textarea id="shareData" rows="4" cols="80" placeholder="Paste shared song data here"></textarea>
</div>
<script>
// Audio context and basic synth setup
const AudioContext = window.AudioContext || window.webkitAudioContext;
let audioCtx;
let isPlaying = false;
let currentNoteTimeouts = [];
// Note frequencies for 12 tone equal temperament tuning
const noteFreqs = {
'C4': 261.63, 'C#4':277.18, 'D4':293.66, 'D#4':311.13, 'E4':329.63,
'F4':349.23, 'F#4':369.99, 'G4':392.00, 'G#4':415.30, 'A4':440.00,
'A#4':466.16, 'B4':493.88,
'C5':523.25
};
function playNote(freq, instrument, duration) {
if (!audioCtx) audioCtx = new AudioContext();
const osc = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
const filter = audioCtx.createBiquadFilter();
const noiseOsc = audioCtx.createBufferSource();
const noiseGain = audioCtx.createGain();
// Oscillator params
osc.type = instrument.osc;
osc.frequency.setValueAtTime(freq * Math.pow(2, instrument.detune/1200), audioCtx.currentTime);
osc.detune.value = instrument.detune || 0;
// ADSR envelope
const now = audioCtx.currentTime;
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(instrument.volume * instrument.sustain, now + instrument.attack/1000);
gainNode.gain.linearRampToValueAtTime(instrument.volume * instrument.sustain, now + (instrument.attack + instrument.decay)/1000);
gainNode.gain.setTargetAtTime(0, now + (instrument.attack + instrument.decay + duration - instrument.release)/1000, instrument.release/1000);
// Filter
filter.type = 'lowpass';
filter.frequency.setValueAtTime(instrument.filterCutoff, now);
// Noise (optional)
if (instrument.noise) {
// Create noise buffer
let bufferSize = audioCtx.sampleRate * duration/1000;
let buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
let data = buffer.getChannelData(0);
for(let i=0; i<data.length; i++) data[i] = (Math.random() * 2 - 1) * 0.2;
noiseOsc.buffer = buffer;
noiseOsc.loop = true;
noiseGain.gain.setValueAtTime(0.1, now);
noiseOsc.connect(noiseGain).connect(filter);
noiseOsc.start(now);
noiseOsc.stop(now + duration/1000);
}
osc.connect(gainNode).connect(filter).connect(audioCtx.destination);
osc.start(now);
osc.stop(now + duration/1000);
// Cleanup on stop
osc.onended = () => {
gainNode.disconnect();
filter.disconnect();
osc.disconnect();
if (instrument.noise) {
noiseGain.disconnect();
noiseOsc.disconnect();
}
}
}
// Parse pattern text area lines into note events
function parsePattern(text) {
let lines = text.trim().split('\n');
let events = [];
lines.forEach((line,i) => {
line = line.trim();
if (!line || line.startsWith('//')) return;
let parts = line.split(' ');
if (parts.length < 4) return;
let note = parts[0];
let instr = parseInt(parts[1]);
let vol = parseInt(parts[2]);
let detune = parseInt(parts[3]);
events.push({note, instr, vol, detune});
});
return events;
}
// Build instruments object from inputs
function getInstrumentSettings() {
let inst = {
osc: document.getElementById('osc0').value,
volume: parseFloat(document.getElementById('vol0').value),
detune: parseInt(document.getElementById('detune0').value),
attack: parseInt(document.getElementById('attack0').value),
decay: parseInt(document.getElementById('decay0').value),
sustain: parseFloat(document.getElementById('sustain0').value),
release: parseInt(document.getElementById('release0').value),
filterCutoff: parseInt(document.getElementById('filter0').value),
noise: document.getElementById('noise0').checked
};
return [inst]; // only 1 instr here, can extend for more
}
// Play pattern sequentially obeying BPM
function playPattern(pattern, instruments, bpm) {
if (isPlaying) return;
isPlaying = true;
let events = parsePattern(pattern);
const beatDuration = 60 / bpm; // in seconds
const rowDuration = beatDuration / 4; // assuming 4 rows per beat
events.forEach((event, i) => {
let time = i * rowDuration * 1000;
if(event.note === '--') return;
let freq = noteFreqs[event.note] || 440;
let instr = instruments[event.instr] || instruments[0];
let vol = instr.volume * (event.vol/15);
let detune = event.detune + (instr.detune || 0);
let timeout = setTimeout(() => {
playNote(freq, {...instr, volume: vol, detune: detune}, rowDuration * 1000);
}, time);
currentNoteTimeouts.push(timeout);
});
// Stop playing after pattern duration
let stopTimeout = setTimeout(() => { isPlaying = false; }, events.length * rowDuration * 1000);
currentNoteTimeouts.push(stopTimeout);
}
function stopPlaying() {
currentNoteTimeouts.forEach(t => clearTimeout(t));
currentNoteTimeouts = [];
isPlaying = false;
}
// Share song data as JSON string
function getShareData() {
let patternText = document.getElementById('pattern0').value;
let instruments = getInstrumentSettings();
let bpm = parseInt(document.getElementById('bpm').value);
return JSON.stringify({bpm, patternText, instruments});
}
function loadShareData(data) {
try {
let song = JSON.parse(data);
document.getElementById('pattern0').value = song.patternText || '';
document.getElementById('bpm').value = song.bpm || 120;
if(song.instruments && song.instruments[0]) {
let ins = song.instruments[0];
document.getElementById('osc0').value = ins.osc || 'square';
document.getElementById('vol0').value = ins.volume || 0.25;
document.getElementById('detune0').value = ins.detune || 0;
document.getElementById('attack0').value = ins.attack || 10;
document.getElementById('decay0').value = ins.decay || 100;
document.getElementById('sustain0').value = ins.sustain || 0.7;
document.getElementById('release0').value = ins.release || 200;
document.getElementById('filter0').value = ins.filterCutoff || 1000;
document.getElementById('noise0').checked = ins.noise || false;
}
} catch(e) {
alert('Invalid share data');
}
}
// Event listeners
document.getElementById('playBtn').onclick = () => {
let bpm = parseInt(document.getElementById('bpm').value);
let patternText = document.getElementById('pattern0').value;
let instruments = getInstrumentSettings();
playPattern(patternText, instruments, bpm);
};
document.getElementById('stopBtn').onclick = () => {
stopPlaying();
};
document.getElementById('shareBtn').onclick = () => {
let data = getShareData();
document.getElementById('shareData').value = data;
navigator.clipboard?.writeText(data).then(() => {
alert('Song data copied to clipboard!');
});
};
document.getElementById('shareData').addEventListener('paste', (e) => {
let text = (e.clipboardData || window.clipboardData).getData('text');
loadShareData(text);
});
// Keyboard shortcuts: Space to play/pause
document.addEventListener('keydown', e => {
if(e.code === 'Space') {
e.preventDefault();
if(isPlaying) {
stopPlaying();
} else {
document.getElementById('playBtn').click();
}
}
});
</script>
</body>
</html>
Just open this HTML file and try it. Let me know if you want it more advanced!