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

html chiptune tracker bpm patterns rows per pattern synth per instrument custom osc…

  1. User

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

  2. Assistant

    It sounds like you want an HTML-based chiptune tracker with the following features:

    • BPM control
    • Patterns and rows per pattern
    • Multiple instruments, each with its own synth / custom oscillator
    • Volume, detune, ADSR envelope, and filter per instrument
    • Noise channel support
    • Ability to share songs (probably export/import)
    • Keyboard shortcuts for actions like duplicate, delete, loop
    • Avoid URLs like "/#" in sharing (clean URLs or encoded data maybe)
    • No demo (so a tool without demo audio auto-playing or demo song preset)

    I can help you with a minimal example or a starting point using Web Audio API and HTML/JS, or point you towards existing open-source projects. Let me proceed with an outline and a small prototype script.


    Minimal Chiptune Tracker Concept in HTML/JS

    To build a chiptune tracker with the described features requires a lot of code, so here’s a basic skeleton:

    • Song structure:
      • BPM: adjustable
      • Patterns: array of pattern objects
      • Each pattern: 64 rows (configurable)
      • Each row: notes for each instrument
    • Instruments:
      • Synth using basic waveforms or custom oscillators
      • Controls: Volume, Detune, ADSR envelope, Filter, Noise toggle
    • Playback engine:
      • Advances row by row based on BPM timing
      • Plays notes with assigned instrument settings
    • UI:
      • Grid like tracker pattern editor
      • Instrument editor panel
      • Controls for play, pause, loop, BPM
    • Share:
      • Serialize song data into a string (JSON or compressed)
      • Encode string in URL hash or export text
      • Avoid “/#” URLs or unwanted URL fragments by using base64 or user export text

    Example: Basic HTML Setup for this

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title>Minimal Chiptune Tracker</title>
    <style>
      body { font-family: monospace; background: #111; color: #eee; }
      #tracker { display: grid; grid-template-columns: repeat(4, 60px); gap: 4px; margin: 10px; }
      .cell { background:#222; padding:4px; text-align: center; cursor: pointer; user-select:none;}
      .cell.active { background:#48f; color: #fff; }
      #controls { margin: 10px; }
      button { margin-right: 5px; }
    </style>
    </head>
    <body>
    
    <h1>Minimal Chiptune Tracker</h1>
    <div id="controls">
      BPM: <input type="number" id="bpm" value="120" min="30" max="300" style="width:50px" />
      <button id="playBtn">Play</button>
      <button id="stopBtn">Stop</button>
      <button id="loopBtn">Loop: Off</button>
    </div>
    
    <div id="tracker"></div>
    
    <script>
    (() => {
      const bpmInput = document.getElementById('bpm');
      const playBtn = document.getElementById('playBtn');
      const stopBtn = document.getElementById('stopBtn');
      const loopBtn = document.getElementById('loopBtn');
      const tracker = document.getElementById('tracker');
    
      const rowsPerPattern = 16;
      const instruments = [
        { waveform: 'square', volume: 0.5, detune: 0, adsr: [0.1,0.1,0.7,0.1], filterFreq: 8000, noise: false },
        { waveform: 'triangle', volume: 0.3, detune: 0, adsr: [0.01,0.2,0.5,0.2], filterFreq: 1200, noise: false }
      ];
      
      // Simple note names and corresponding freq for octave 4
      const notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
      const baseFreqs = {
        '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
      };
    
      // Song: 1 pattern, 2 instruments, rowsPerPattern rows
      // Store notes as frequencies or null
      const pattern = [];
      for(let r=0; r < rowsPerPattern; r++) {
        let row = [];
        for(let i=0; i<instruments.length; i++) {
          row.push(null); // null = no note
        }
        pattern.push(row);
      }
    
      let currentRow = 0;
      let playing = false;
      let loop = false;
      let audioCtx;
      let timerId;
    
      // Create UI grid for pattern
      function buildGrid() {
        tracker.innerHTML = '';
        tracker.style.gridTemplateColumns = `repeat(${instruments.length}, 60px)`;
    
        for(let r=0; r < rowsPerPattern; r++) {
          for(let i=0; i < instruments.length; i++) {
            const cell = document.createElement('div');
            cell.className = 'cell';
            cell.dataset.row = r;
            cell.dataset.instrument = i;
            cell.textContent = '-';
            cell.addEventListener('click', () => {
              editNote(r, i, cell);
            });
            tracker.appendChild(cell);
          }
        }
        renderPattern();
      }
    
      // Cycle note on click: null -> C4 -> D4 -> E4 ... -> null
      function editNote(r, i, cell) {
        const currentFreq = pattern[r][i];
        let idx = -1;
        if(currentFreq !== null) {
          idx = notes.findIndex(n=>baseFreqs[n+'4']===currentFreq);
        }
        idx++;
        if(idx >= notes.length) idx = -1;
        pattern[r][i] = idx === -1 ? null : baseFreqs[notes[idx]+'4'];
        renderPattern();
      }
    
      function renderPattern() {
        for(let r=0; r < rowsPerPattern; r++) {
          for(let i=0; i < instruments.length; i++) {
            const cell = tracker.children[r*instruments.length + i];
            const freq = pattern[r][i];
            if(freq === null) {
              cell.textContent = '-';
              cell.classList.remove('active');
            } else {
              // find note name
              let noteName = Object.entries(baseFreqs).find(([n, f]) => f===freq);
              cell.textContent = noteName ? noteName[0].slice(0,-1) : '?';
              cell.classList.remove('active');
            }
    
            // Highlight current row
            if(r === currentRow && playing) {
              cell.classList.add('active');
            } else {
              cell.classList.remove('active');
            }
          }
        }
      }
    
      // Play note for instrument
      function playNote(freq, instrument) {
        if(!audioCtx) return;
        const osc = audioCtx.createOscillator();
        const gainNode = audioCtx.createGain();
        const filter = audioCtx.createBiquadFilter();
    
        osc.type = instrument.waveform;
        osc.frequency.setValueAtTime(freq, audioCtx.currentTime);
        osc.detune.setValueAtTime(instrument.detune, audioCtx.currentTime);
    
        filter.type = 'lowpass';
        filter.frequency.setValueAtTime(instrument.filterFreq, audioCtx.currentTime);
    
        gainNode.gain.setValueAtTime(0, audioCtx.currentTime);
    
        // ADSR envelope simple implementation
        const [a, d, s, r] = instrument.adsr;
        const now = audioCtx.currentTime;
        gainNode.gain.cancelScheduledValues(now);
        gainNode.gain.setValueAtTime(0, now);
        gainNode.gain.linearRampToValueAtTime(instrument.volume, now + a);
        gainNode.gain.linearRampToValueAtTime(instrument.volume * s, now + a + d);
    
        osc.connect(filter);
        filter.connect(gainNode);
        gainNode.connect(audioCtx.destination);
    
        osc.start(now);
    
        // Release after 0.5s
        gainNode.gain.setTargetAtTime(0, now + 0.5, r);
    
        osc.stop(now + 1);
    
        osc.onended = () => {
          osc.disconnect();
          filter.disconnect();
          gainNode.disconnect();
        }
      }
    
      function advanceRow() {
        currentRow++;
        if(currentRow >= rowsPerPattern) {
          if(loop) currentRow = 0;
          else {
            stopPlayback();
            return;
          }
        }
    
        // Play notes at currentRow
        for(let i=0; i<instruments.length; i++) {
          let freq = pattern[currentRow][i];
          if(freq !== null) {
            playNote(freq, instruments[i]);
          }
        }
    
        renderPattern();
      }
    
      function startPlayback() {
        if(playing) return;
        audioCtx = new AudioContext();
        currentRow = -1;
        playing = true;
        advanceRow();
    
        const intervalMs = 60000 / bpmInput.value / 4; // 16th notes?
    
        timerId = setInterval(advanceRow, intervalMs);
        loopBtn.textContent = 'Loop: ' + (loop ? 'On' : 'Off');
      }
    
      function stopPlayback() {
        playing = false;
        if(timerId) clearInterval(timerId);
        timerId = null;
        if(audioCtx) audioCtx.close();
        audioCtx = null;
        currentRow = -1;
        renderPattern();
      }
    
      bpmInput.addEventListener('change', () => {
        if(playing) {
          stopPlayback();
          startPlayback();
        }
      });
    
      playBtn.addEventListener('click', startPlayback);
      stopBtn.addEventListener('click', stopPlayback);
      loopBtn.addEventListener('click', () => {
        loop = !loop;
        loopBtn.textContent = 'Loop: ' + (loop ? 'On' : 'Off');
      });
    
      buildGrid();
      renderPattern();
    
    })();
    </script>
    
    </body>
    </html>
    

    Explanation:

    • This creates a very simple 2-instrument tracker, 16 rows, each cell is clickable to cycle notes.
    • Playback controlled by BPM, plays notes with oscillator.
    • Basic ADSR is applied.
    • No noise channel yet, but it can be added.
    • Loop toggle implemented.
    • No sharing or URL encoding in this demo; that can be added by serializing pattern + instruments + bpm.
    • Keyboard shortcuts are not implemented here for brevity but can be added.

    To add next:

    • Noise instrument: create a noise instrument that uses AudioBufferSourceNode with random noise buffer.
    • More instruments: add UI to edit synth settings (waveform, volume, detune, ADSR, filter).
    • Pattern management: multiple patterns, arrange in order.
    • Sharing: export/import JSON pattern and instrument data.
    • Keyboard shortcuts: use keyboard event listeners.
    • No URLs with "/#": use base64 or localStorage for saving.

    Summary

    This is a minimal starting point in plain HTML/JS for a chiptune tracker with some requested features.

    If you want a more complete open-source project that already does this:

    • FamiTracker (native Windows app)
    • BeepBox - browser chiptune editor with patterns, custom instruments, noise etc (but it uses /# in URL for sharing)
    • jsfx - not full tracker but synth engine

    I can help you build more features or polish this further if you want. Would you like me to continue with adding noise, pattern management, and sharing?

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