chiptune tracker adsr osc filter fm detune synth rows tracks per patterns rows per…
- User
chiptune tracker adsr osc filter fm detune synth rows tracks per patterns rows per patterns bpm share "/#" html
- Assistant
chiptune tracker adsr osc filter fm detune synth rows tracks per patterns rows per patterns bpm share "/#" html
It sounds like you're interested in creating or understanding a chiptune tracker or a basic web-based chiptune/music synth/sequencer with features like:
/#something)A minimal chiptune tracker or synth pattern editor that runs in the browser (HTML + JS) with:
UI:
Sound Generation:
Web Audio API with oscillators, envelopes, filters
Sequencing
Timer steps through pattern rows applying the instruments' notes
Data Sharing
Encode pattern data + settings → base64 or similar → attach to URL hash (/#encoded_data)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chiptune Tracker Demo</title>
<style>
body { font-family: monospace; background: #111; color: #eee; }
table { border-collapse: collapse; margin-bottom: 10px; }
td { border: 1px solid #444; width: 40px; height: 24px; text-align: center; cursor: pointer; }
td.active { background: #3a3; }
#controls { margin-bottom: 10px; }
</style>
</head>
<body>
<h1>Chiptune Tracker Demo</h1>
<div id="controls">
BPM: <input type="number" id="bpm" value="120" min="30" max="300" />
Osc:
<select id="oscType">
<option value="square">Square</option>
<option value="sine">Sine</option>
<option value="triangle">Triangle</option>
<option value="sawtooth">Sawtooth</option>
</select>
FM Depth: <input type="range" id="fmDepth" min="0" max="100" value="0" />
Detune: <input type="range" id="detune" min="-50" max="50" value="0" />
<button id="play">Play</button>
<button id="stop">Stop</button>
<button id="share">Share</button>
</div>
<table id="pattern"></table>
<script>
// Pattern config
const tracks = 4;
const rows = 16; // rows per pattern
const notes = ["C4", "D4", "E4", "F4", "G4", "A4", "B4", "-"];
const noteToFreq = {
"C4": 261.63, "D4": 293.66, "E4": 329.63, "F4": 349.23,
"G4": 392.00, "A4": 440.00, "B4": 493.88,
"-": 0
};
let pattern = [];
for(let r=0; r<rows; r++){
pattern[r] = [];
for(let t=0; t<tracks; t++){
pattern[r][t] = "-";
}
}
const patternTable = document.getElementById("pattern");
// Build table UI
for(let r=0; r<rows; r++){
const tr = document.createElement("tr");
for(let t=0; t<tracks; t++){
const td = document.createElement("td");
td.dataset.row = r;
td.dataset.track = t;
td.textContent = "-";
td.addEventListener("click", () => {
// Cycle note
let idx = notes.indexOf(pattern[r][t]);
idx = (idx + 1) % notes.length;
pattern[r][t] = notes[idx];
td.textContent = notes[idx];
td.classList.toggle("active", notes[idx] != "-");
});
tr.appendChild(td);
}
patternTable.appendChild(tr);
}
// Audio setup
const AudioContext = window.AudioContext || window.webkitAudioContext;
const ctx = new AudioContext();
function playNote(frequency, startTime, duration, oscType, fmDepth, detune){
if(frequency === 0) return; // rest
const osc = ctx.createOscillator();
const gainNode = ctx.createGain();
const fmOsc = ctx.createOscillator();
const fmGain = ctx.createGain();
osc.type = oscType;
osc.frequency.setValueAtTime(frequency, startTime);
osc.detune.setValueAtTime(detune, startTime);
// FM
fmOsc.frequency.value = frequency * 2; // simple FM ratio 2
fmGain.gain.value = fmDepth;
fmOsc.connect(fmGain);
fmGain.connect(osc.frequency);
osc.connect(gainNode);
gainNode.connect(ctx.destination);
// Simple ADSR envelope
const attack = 0.01;
const decay = 0.1;
const sustain = 0.2;
const release = 0.2;
gainNode.gain.setValueAtTime(0, startTime);
gainNode.gain.linearRampToValueAtTime(1, startTime + attack);
gainNode.gain.linearRampToValueAtTime(sustain, startTime + attack + decay);
gainNode.gain.setValueAtTime(sustain, startTime + duration - release);
gainNode.gain.linearRampToValueAtTime(0, startTime + duration);
osc.start(startTime);
fmOsc.start(startTime);
osc.stop(startTime + duration);
fmOsc.stop(startTime + duration);
}
let timerId = null;
function playPattern(){
if(ctx.state === 'suspended') ctx.resume();
const bpm = parseInt(document.getElementById('bpm').value);
const oscType = document.getElementById('oscType').value;
const fmDepth = parseFloat(document.getElementById('fmDepth').value);
const detune = parseFloat(document.getElementById('detune').value);
const beatDuration = 60 / bpm; // seconds per beat
const stepDuration = beatDuration / 4; // 16 steps = 4 beats per pattern (4/4)
let startTime = ctx.currentTime + 0.1;
for(let r=0; r<rows; r++){
for(let t=0; t<tracks; t++){
const note = pattern[r][t];
const freq = noteToFreq[note];
playNote(freq, startTime + r*stepDuration, stepDuration * 0.9, oscType, fmDepth, detune);
}
}
}
document.getElementById('play').addEventListener('click', playPattern);
document.getElementById('stop').addEventListener('click', () => {
// stop not implemented for simplicity; context close/recreate would be needed
alert('Stop not implemented in simple demo');
});
// Share pattern URL encoding/decoding
function encodePattern(){
// simple encoding: join with commas + dashes
let flat = [];
for(let r=0; r<rows; r++){
for(let t=0; t<tracks; t++){
flat.push(pattern[r][t]);
}
}
return btoa(flat.join(","));
}
function decodePattern(str){
try {
const decoded = atob(str);
const arr = decoded.split(",");
if(arr.length !== rows*tracks) return false;
for(let r=0; r<rows; r++){
for(let t=0; t<tracks; t++){
pattern[r][t] = arr[r*tracks + t];
}
}
refreshPatternUI();
return true;
} catch(e){
return false;
}
}
function refreshPatternUI(){
for(let r=0; r<rows; r++){
for(let t=0; t<tracks; t++){
let td = patternTable.rows[r].cells[t];
td.textContent = pattern[r][t];
td.classList.toggle("active", pattern[r][t] != "-");
}
}
}
document.getElementById("share").addEventListener("click", () => {
const data = {
pattern: encodePattern(),
bpm: document.getElementById('bpm').value,
osc: document.getElementById('oscType').value,
fmDepth: document.getElementById('fmDepth').value,
detune: document.getElementById('detune').value,
};
const shareString = btoa(JSON.stringify(data));
const url = location.origin + location.pathname + "/#" + shareString;
prompt("Share this URL:", url);
});
function loadFromHash(){
if(location.hash.length < 2) return;
const hash = location.hash.substring(1);
try {
const data = JSON.parse(atob(hash));
if(data.pattern && decodePattern(data.pattern)){
document.getElementById('bpm').value = data.bpm || "120";
document.getElementById('oscType').value = data.osc || "square";
document.getElementById('fmDepth').value = data.fmDepth || 0;
document.getElementById('detune').value = data.detune || 0;
}
} catch(e){}
}
loadFromHash();
</script>
</body>
</html>
C4 D4 E4 F4 G4 A4 B4 and rest -./#...If you need help with any specific feature (e.g., FM detune, filter implementation, ADSR envelopes, pattern sharing), just ask!
Not yet included in a published release.