Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

html chiptune tracker bpm rows per tracks patterns rows per pattern synth per instrument…

  1. User

    html chiptune tracker bpm rows per tracks patterns rows per pattern synth per instrument custom osc volume detune adsr filter noise share song shortcuts loop "/#" no demo

  2. Assistant

    It looks like you're looking to create or find an HTML-based chiptune tracker with features such as:

    • BPM control
    • Rows per track
    • Patterns and rows per pattern
    • Multiple instruments with synth options, custom oscillators
    • Volume, detune, ADSR envelopes, filters, noise control
    • Ability to share songs (e.g., via URLs)
    • Shortcuts for control and looping
    • No demo/sample data

    I'll help you with a minimal but extensible example of a chiptune tracker built in HTML + JS with the above features. This will be a starting point that you can easily extend, focusing on core functionality: a simple step sequencer with patterns, instruments, synth control, and sharing via URL.


    Minimal HTML/JS Chiptune Tracker Example

    <!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: #222; color: #eee; margin:0; padding:1em;}
      #tracker { display: flex; }
      .pattern, .instrument {
        border: 1px solid #555; margin: 0 1em 1em 0; padding: 0.5em;
        background: #111; min-width: 300px;
      }
      table { border-collapse: collapse; }
      td, th { border: 1px solid #444; padding: 0.3em 0.5em; text-align: center;}
      td.note { cursor: pointer; }
      td.note.active { background: #4a4; }
      td.note.playing { background: #afa; }
      .controls { margin-bottom: 1em; }
      button { margin-right: 0.5em; }
      label { margin-right: 1em; }
      input[type=range] { vertical-align: middle; }
    </style>
    </head>
    <body>
    
    <h1>Minimal Chiptune Tracker</h1>
    
    <div class="controls">
      <label>BPM: <input id="bpm" type="number" min="30" max="300" value="120"></label>
      <label>Rows Per Pattern: <input id="rowsPerPattern" type="number" min="4" max="64" value="16"></label>
      <button id="playPause">Play</button>
      <button id="clear">Clear Pattern</button>
      <button id="share">Share Pattern</button>
      <input type="text" id="shareUrl" readonly style="width: 60%;" />
    </div>
    
    <div id="tracker">
      <div class="pattern">
        <h3>Pattern</h3>
        <table id="patternTable"></table>
      </div>
      <div class="instrument">
        <h3>Instrument</h3>
        <label>Waveform:
          <select id="waveform">
            <option value="square">Square</option>
            <option value="sawtooth">Sawtooth</option>
            <option value="triangle">Triangle</option>
            <option value="sine">Sine</option>
          </select>
        </label><br><br>
        <label>Volume: <input id="volume" type="range" min="0" max="1" step="0.01" value="0.5"></label><br>
        <label>Detune: <input id="detune" type="range" min="-1200" max="1200" step="1" value="0"></label><br>
        <label>Attack (ms): <input id="attack" type="number" min="0" max="5000" step="10" value="10"></label><br>
        <label>Decay (ms): <input id="decay" type="number" min="0" max="5000" step="10" value="100"></label><br>
        <label>Sustain (0-1): <input id="sustain" type="number" min="0" max="1" step="0.01" value="0.8"></label><br>
        <label>Release (ms): <input id="release" type="number" min="0" max="5000" step="10" value="200"></label><br>
        <label>Filter Frequency (Hz):
          <input id="filterFreq" type="number" min="20" max="20000" value="20000" />
        </label><br>
        <label>Noise: <input id="noise" type="range" min="0" max="1" step="0.01" value="0"></label><br>
      </div>
    </div>
    
    <script>
    (() => {
      const noteNames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
    
      // Basic notes for one octave plus octave number (4)
      // We'll allow notes from C3 (MIDI 48) to B5 (MIDI 83)
      // MIDI note to freq: 440 * 2^((note-69)/12)
      const minNote = 48, maxNote = 83;
      const notes = [];
      for (let n = minNote; n <= maxNote; n++) {
        let octave = Math.floor(n / 12) - 1;
        let name = noteNames[n % 12] + octave;
        notes.push({ midi: n, name });
      }
      // Add "Rest"
      notes.unshift({midi: null, name: '-'});
    
      const rowsPerPatternInput = document.getElementById('rowsPerPattern');
      const bpmInput = document.getElementById('bpm');
      const patternTable = document.getElementById('patternTable');
      const playPauseBtn = document.getElementById('playPause');
      const clearBtn = document.getElementById('clear');
      const shareBtn = document.getElementById('share');
      const shareUrlInput = document.getElementById('shareUrl');
    
      // Instrument controls
      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 noiseInput = document.getElementById('noise');
    
      let rowsPerPattern = +rowsPerPatternInput.value;
      let bpm = +bpmInput.value;
      let playing = false;
      let currentRow = 0;
      let timerId;
    
      // Pattern data: Array of rows, each row is a midi note or null for rest
      // Since this is one instrument and one track, just one column.
      let pattern = new Array(rowsPerPattern).fill(null);
    
      // Web Audio setup
      const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
    
      function createOscillator(freq, wave, detune) {
        const osc = audioCtx.createOscillator();
        osc.type = wave;
        osc.frequency.setValueAtTime(freq, audioCtx.currentTime);
        osc.detune.setValueAtTime(detune, audioCtx.currentTime);
        return osc;
      }
    
      function createNoiseBuffer() {
        const bufferSize = audioCtx.sampleRate * 1; // 1 sec
        const buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
        const output = buffer.getChannelData(0);
        for (let i = 0; i < bufferSize; i++) {
          output[i] = Math.random() * 2 - 1;
        }
        return buffer;
      }
    
      // Play one note at the given row index
      function playNote(noteMidi) {
        if (noteMidi === null) return; // rest
    
        const now = audioCtx.currentTime;
        const freq = 440 * Math.pow(2, (noteMidi - 69) / 12);
    
        // Oscillator
        const osc = createOscillator(freq, waveformInput.value, +detuneInput.value);
        // Gain for ADSR envelope
        const gainNode = audioCtx.createGain();
        // Filter
        const filter = audioCtx.createBiquadFilter();
        filter.type = "lowpass";
        filter.frequency.setValueAtTime(+filterFreqInput.value, now);
    
        // Noise
        let noiseNode;
        if (+noiseInput.value > 0) {
          const noiseBuffer = createNoiseBuffer();
          noiseNode = audioCtx.createBufferSource();
          noiseNode.buffer = noiseBuffer;
          noiseNode.loop = true;
    
          const noiseGain = audioCtx.createGain();
          noiseGain.gain.setValueAtTime(+noiseInput.value, now + 0.05);
    
          noiseNode.connect(noiseGain).connect(filter);
          noiseNode.start(now);
        }
    
        osc.connect(gainNode).connect(filter).connect(audioCtx.destination);
    
        // ADSR envelope timings
        const attack = +attackInput.value / 1000;
        const decay = +decayInput.value / 1000;
        const sustain = +sustainInput.value;
        const release = +releaseInput.value / 1000;
    
        gainNode.gain.setValueAtTime(0, now);
        gainNode.gain.linearRampToValueAtTime(+volumeInput.value, now + attack);
        gainNode.gain.linearRampToValueAtTime(sustain * +volumeInput.value, now + attack + decay);
    
        // Note length = row duration
        const rowDuration = 60 / bpm / 4; // Let's say 4 rows per beat
    
        // Release phase
        gainNode.gain.setTargetAtTime(0, now + rowDuration, release / 5);
    
        osc.start(now);
        osc.stop(now + rowDuration + release + 0.1);
        osc.onended = () => gainNode.disconnect();
    
        if (noiseNode) {
          noiseNode.stop(now + rowDuration + release + 0.1);
          noiseNode.onended = () => {/* cleanup? */};
        }
      }
    
      // Render pattern table
      function renderPattern() {
        // Clear existing
        patternTable.innerHTML = "";
        let trHeader = document.createElement("tr");
        let thRow = document.createElement("th");
        thRow.textContent = "#";
        let thNote = document.createElement("th");
        thNote.textContent = "Note";
        trHeader.appendChild(thRow);
        trHeader.appendChild(thNote);
        patternTable.appendChild(trHeader);
    
        for (let i = 0; i < rowsPerPattern; i++) {
          let tr = document.createElement("tr");
          let tdRow = document.createElement("td");
          tdRow.textContent = i + 1;
          let tdNote = document.createElement("td");
          tdNote.className = "note";
          let noteMidi = pattern[i];
          // Show note name or rest
          let noteName = noteMidi === null ? "-" : notes.find(n=>n.midi === noteMidi)?.name || "?";
          tdNote.textContent = noteName;
          if (i === currentRow) tdNote.classList.add('playing');
          if (noteMidi !== null) tdNote.classList.add('active');
          tdNote.addEventListener("click", () => {
            cycleNote(i);
          });
          tr.appendChild(tdRow);
          tr.appendChild(tdNote);
          patternTable.appendChild(tr);
        }
      }
    
      // Cycle note on row i through notes list (skip silence first)
      function cycleNote(i) {
        let currentIndex = notes.findIndex(n => n.midi === pattern[i]);
        if (currentIndex === -1) currentIndex = 0; // rest
        currentIndex++;
        if (currentIndex >= notes.length) currentIndex = 0;
        // Set note midi or null
        pattern[i] = notes[currentIndex].midi;
        renderPattern();
      }
    
      // Playback loop
      function playLoop() {
        if (!playing) return;
        playNote(pattern[currentRow]);
        currentRow++;
        if (currentRow >= rowsPerPattern) currentRow = 0;
        renderPattern();
        // Row duration in ms (assuming 4 rows per beat)
        const rowDurationMs = (60 / bpm) / 4 * 1000;
        timerId = setTimeout(playLoop, rowDurationMs);
      }
    
      // Controls event listeners
      playPauseBtn.onclick = () => {
        if (playing) {
          playing = false;
          playPauseBtn.textContent = "Play";
          clearTimeout(timerId);
          currentRow = 0;
          renderPattern();
        } else {
          // Resume audio context if suspended
          if (audioCtx.state === "suspended") {
            audioCtx.resume();
          }
          playing = true;
          playPauseBtn.textContent = "Pause";
          playLoop();
        }
      };
    
      clearBtn.onclick = () => {
        pattern.fill(null);
        currentRow = 0;
        renderPattern();
      };
    
      // Update rows per pattern changes
      rowsPerPatternInput.onchange = () => {
        const newRows = +rowsPerPatternInput.value;
        if (newRows < 4 || newRows > 64) return;
        rowsPerPattern = newRows;
        // Resize pattern array preserving existing data
        const newPattern = new Array(rowsPerPattern).fill(null);
        for(let i=0; i < Math.min(pattern.length, rowsPerPattern); i++) {
          newPattern[i] = pattern[i];
        }
        pattern = newPattern;
        currentRow = 0;
        renderPattern();
      };
    
      bpmInput.onchange = () => {
        let val = +bpmInput.value;
        if (val < 30) val = 30;
        if (val > 300) val =300;
        bpm = val;
        // If playing, restart loop with new bpm
        if (playing) {
          clearTimeout(timerId);
          currentRow = 0;
          playLoop();
        }
      };
    
      // Share pattern by encoding pattern and settings in URL hash
      function encodePattern() {
        // pattern array to string, - = rest, else encoded note midi as base36
        let patternStr = pattern.map(n => n === null ? '-' : n.toString(36)).join('');
        // encode synth params similarly as key=value lists
        const params = {
          bpm,
          rows: rowsPerPattern,
          waveform: waveformInput.value,
          volume: volumeInput.value,
          detune: detuneInput.value,
          attack: attackInput.value,
          decay: decayInput.value,
          sustain: sustainInput.value,
          release: releaseInput.value,
          filterFreq: filterFreqInput.value,
          noise: noiseInput.value,
          p: patternStr
        };
        // serialize
        let parts = [];
        for (const [k,v] of Object.entries(params)) {
          parts.push(k + '=' + encodeURIComponent(v));
        }
        return parts.join('&');
      }
      function decodePattern(str) {
        const params = {};
        for (const part of str.split('&')) {
          let [k,v] = part.split('=');
          params[k] = decodeURIComponent(v);
        }
        bpmInput.value = params.bpm || 120;
        rowsPerPatternInput.value = params.rows || 16;
        waveformInput.value = params.waveform || 'square';
        volumeInput.value = params.volume || 0.5;
        detuneInput.value = params.detune || 0;
        attackInput.value = params.attack || 10;
        decayInput.value = params.decay || 100;
        sustainInput.value = params.sustain || 0.8;
        releaseInput.value = params.release || 200;
        filterFreqInput.value = params.filterFreq || 20000;
        noiseInput.value = params.noise || 0;
    
        bpm = +bpmInput.value;
        rowsPerPattern = +rowsPerPatternInput.value;
    
        // Decode pattern string back into array
        let arr = new Array(rowsPerPattern).fill(null);
        if (params.p) {
          for (let i = 0; i < Math.min(params.p.length, rowsPerPattern); i++) {
            let c = params.p[i];
            if (c === '-') {
              arr[i] = null;
            } else {
              arr[i] = parseInt(c, 36);
            }
          }
        }
        pattern = arr;
      }
    
      shareBtn.onclick = () => {
        const encoded = encodePattern();
        const url = window.location.origin + window.location.pathname + "#/" + encoded;
        shareUrlInput.value = url;
        shareUrlInput.select();
        try {
          navigator.clipboard.writeText(url);
        } catch (e) {
          // ignore
        }
      };
    
      // On page load, check URL for pattern sharing
      function loadFromURL() {
        const hash = window.location.hash;
        if (hash.startsWith("#/")) {
          decodePattern(hash.slice(2));
          renderPattern();
        }
      }
    
      // Loop toggle via space bar
      window.addEventListener('keydown', e => {
        if (e.code === "Space") {
          e.preventDefault();
          playPauseBtn.click();
        }
      });
    
      // Initial render
      renderPattern();
      loadFromURL();
    })();
    </script>
    
    </body>
    </html>
    

    How It Works

    • It's a 1-track, 1-instrument chiptune step sequencer.
    • You select notes for each row in the pattern by clicking the note cell — each click cycles through notes and rest.
    • You can control BPM and pattern length (rows per pattern).
    • Instrument parameters let you change waveform, volume, detune, ADSR envelope, filter frequency, and noise amount.
    • Plays back in a loop with correct timing.
    • Press Spacebar to play/pause.
    • Share a song by clicking "Share Pattern" — generates a shareable URL encoding your pattern and parameters.
    • Paste that URL back to load the pattern.

    You can extend from here:

    • Add multiple instruments and tracks.
    • Add pattern chaining/sequencing.
    • Better UI with piano roll or keyboard input.
    • More sound controls (custom oscillators, FM synth, effects).
    • Save/Load locally in IndexedDB or localStorage.
    • Export as WAV or download audio.

    Let me know if you want me to expand or add any specific advanced features!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.