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

html chiptune tracker bpm piano rows per tracks patterns rows per pattern custom osc…

  1. User

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

  2. Assistant

    It looks like you're asking for an HTML chiptune music tracker with features such as:

    • BPM control
    • Piano keyboard input
    • Rows per track and rows per pattern settings
    • Custom oscillators
    • Volume, detune, ADSR, filter, and noise control
    • Ability to share, use shortcuts, and loop playback
    • Uses hash/URL for sharing state ("/#")
    • No demo audio or preloaded demo patterns

    I can help by providing a minimal working example of a basic chiptune tracker in HTML/JS that includes these features or at least is structured for you to extend with these capabilities.

    Due to complexity, a full advanced tracker in a single snippet is a huge project. However, I'll provide a base to start with, focusing on the main requested points:

    • A grid pattern interface
    • Piano keyboard input
    • BPM control
    • Simple custom oscillator
    • Volume + detune controls
    • Basic ADSR envelope
    • Noise playback
    • Shareable URL state (using location.hash)
    • Loop control
    • Keyboard shortcuts

    Basic HTML Chiptune Tracker Prototype

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>HTML Chiptune Tracker</title>
    <style>
      body { font-family: monospace; background:#111; color:#ccc; margin:0; }
      #tracker { display: grid; grid-template-columns: 60px repeat(var(--cols), 1fr); }
      .row-label, .cell { border: 1px solid #444; padding: 4px; text-align: center; user-select:none; }
      .row-label { background:#222; }
      .cell { cursor:pointer; }
      .cell.active { background:#0cf; color:#000; }
      #piano { margin-top: 10px; }
      button, input { margin: 4px; }
    </style>
    </head>
    <body>
    
    <h1>HTML Chiptune Tracker</h1>
    
    <div>
      BPM: <input type="number" id="bpm" value="120" min="30" max="300" step="1" style="width:60px;" />
      Rows per pattern: <input type="number" id="rowsPerPattern" value="16" min="4" max="64" style="width:60px;" />
      Patterns: <input type="number" id="numPatterns" value="1" min="1" max="16" style="width:60px;" />
      Tracks: <input type="number" id="numTracks" value="4" min="1" max="8" style="width:60px;" />
      <button id="btnNew">New</button>
      <button id="btnPlay">Play</button>
      <button id="btnStop">Stop</button>
      <button id="btnShare">Share (copy URL)</button>
      Loop: <input type="checkbox" id="loop" checked />
    </div>
    
    <div id="tracker-container" style="margin-top:10px; overflow-x:auto;">
      <div id="tracker" style="--cols:4"></div>
    </div>
    
    <div id="piano"></div>
    
    <h3>Oscillator</h3>
    Waveform:
    <select id="oscWave">
      <option>square</option>
      <option>sine</option>
      <option>triangle</option>
      <option>sawtooth</option>
      <option>noise</option>
    </select>
    
    Detune: <input type="range" id="detune" min="-1200" max="1200" value="0" />
    Volume: <input type="range" id="volume" min="0" max="1" step="0.01" value="0.3" />
    
    <h3>ADSR Envelope (ms)</h3>
    Attack: <input type="number" id="attack" value="10" min="0" max="1000" />
    Decay: <input type="number" id="decay" value="100" min="0" max="1000" />
    Sustain: <input type="range" id="sustain" min="0" max="1" step="0.01" value="0.7" />
    Release: <input type="number" id="release" value="200" min="0" max="1000" />
    
    <script>
    (() => {
      // Constants
      const NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
      const BASE_OCTAVE = 4;
    
      // Initialize state
      let bpm = 120;
      let rowsPerPattern = 16;
      let numPatterns = 1;
      let numTracks = 4;
      let currentPattern = 0;
      let playing = false;
      let loop = true;
      let timerId = null;
      let currentRow = 0;
    
      // Data structure: patterns[pattern][row][track] = {note, octave}
      let patterns = [];
    
      // Audio context
      const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
    
      // Elements
      const trackerEl = document.getElementById("tracker");
      const bpmEl = document.getElementById("bpm");
      const rowsPerPatternEl = document.getElementById("rowsPerPattern");
      const numPatternsEl = document.getElementById("numPatterns");
      const numTracksEl = document.getElementById("numTracks");
      const btnNew = document.getElementById("btnNew");
      const btnPlay = document.getElementById("btnPlay");
      const btnStop = document.getElementById("btnStop");
      const btnShare = document.getElementById("btnShare");
      const loopEl = document.getElementById("loop");
    
      // Oscillator controls:
      const oscWaveEl = document.getElementById("oscWave");
      const detuneEl = document.getElementById("detune");
      const volumeEl = document.getElementById("volume");
      const attackEl = document.getElementById("attack");
      const decayEl = document.getElementById("decay");
      const sustainEl = document.getElementById("sustain");
      const releaseEl = document.getElementById("release");
    
      // Piano container
      const pianoEl = document.getElementById("piano");
    
      // Build piano keyboard (one octave, to start)
      function buildPiano(baseOctave=4) {
        pianoEl.innerHTML = "";
        for(let i=0; i<12; i++) {
          const note = NOTES[i];
          let keyEl = document.createElement("div");
          keyEl.textContent = note;
          keyEl.className = "piano-key";
          keyEl.style.display = "inline-block";
          keyEl.style.width = "40px";
          keyEl.style.height = "120px";
          keyEl.style.border = "1px solid #444";
          keyEl.style.margin = "1px";
          keyEl.style.background = note.includes("#") ? "#222" : "#eee";
          keyEl.style.color = note.includes("#") ? "#ccc" : "#000";
          keyEl.style.userSelect = "none";
          keyEl.style.textAlign = "center";
          keyEl.style.lineHeight = "120px";
          keyEl.style.cursor = "pointer";
          keyEl.dataset.note = note;
          keyEl.dataset.octave = baseOctave;
          keyEl.addEventListener("click", () => {
            insertNote(note, baseOctave);
          });
          pianoEl.appendChild(keyEl);
        }
      }
    
      function freqFromNote(note, octave) {
        // A4 = 440 Hz
        // Calculate semitones away from A4
        const semitonesMap = { 'C': -9, 'C#': -8, 'D': -7, 'D#': -6, 'E': -5, 'F': -4, 'F#': -3, 'G': -2, 'G#': -1, 'A': 0, 'A#': 1, 'B': 2 };
        let semitones = semitonesMap[note] + (octave - 4) * 12;
        return 440 * Math.pow(2, semitones / 12);
      }
    
      // Initialize pattern data structure
      function initPatterns() {
        patterns = [];
        for(let p=0; p<numPatterns; p++) {
          let pattern = [];
          for(let r=0; r<rowsPerPattern; r++) {
            let row = [];
            for(let t=0; t<numTracks; t++) {
              row.push(null); // no note
            }
            pattern.push(row);
          }
          patterns.push(pattern);
        }
      }
    
      // Render tracker grid
      function renderTracker() {
        trackerEl.style.setProperty("--cols", numTracks);
        trackerEl.innerHTML = "";
    
        // Column headers (empty cell + track #)
        trackerEl.appendChild(document.createElement("div")); // empty top-left cell
        for(let t=0; t<numTracks; t++) {
          let header = document.createElement("div");
          header.textContent = "Tr " + (t+1);
          header.className = "row-label";
          trackerEl.appendChild(header);
        }
    
        // Rows and cells
        for(let r=0; r<rowsPerPattern; r++) {
          let rowLabel = document.createElement("div");
          rowLabel.textContent = r.toString().padStart(2, '0');
          rowLabel.className = "row-label";
          trackerEl.appendChild(rowLabel);
    
          for(let t=0; t<numTracks; t++) {
            let cell = document.createElement("div");
            cell.className = "cell";
            cell.dataset.row = r;
            cell.dataset.track = t;
    
            // Fill note if exists
            let noteObj = patterns[currentPattern][r][t];
            if(noteObj) {
              cell.textContent = noteToString(noteObj);
              cell.classList.add("active");
            } else {
              cell.textContent = "-";
            }
    
            cell.addEventListener("click", () => {
              // Cycle the note: null -> C4 -> D4 ... , for demo, toggle note
              // but better allow editing with piano input
              // For simplicity, on click remove note
              if(patterns[currentPattern][r][t]) {
                patterns[currentPattern][r][t] = null;
              } else {
                // Insert C4 by default
                patterns[currentPattern][r][t] = {note:"C", octave:4};
              }
              renderTracker();
            });
            trackerEl.appendChild(cell);
          }
        }
      }
      
      function noteToString(noteObj) {
        return noteObj.note + noteObj.octave;
      }
    
      // Insert note at currentRow and first track (for simplicity)
      function insertNote(note, octave) {
        if(currentRow >= rowsPerPattern) currentRow = 0;
        patterns[currentPattern][currentRow][0] = {note, octave};
        renderTracker();
      }
    
      // Play note
      function playNote(noteObj) {
        if(!noteObj) return;
        const frequency = freqFromNote(noteObj.note, noteObj.octave);
        const wave = oscWaveEl.value;
        const detuneCents = parseInt(detuneEl.value);
        const volumeLevel = parseFloat(volumeEl.value);
    
        const attack = parseInt(attackEl.value) / 1000;
        const decay = parseInt(decayEl.value) / 1000;
        const sustain = parseFloat(sustainEl.value);
        const release = parseInt(releaseEl.value) / 1000;
    
        if(wave === "noise") {
          // Noise playback
          const bufferSize = audioCtx.sampleRate * 0.1;
          const buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
          const data = buffer.getChannelData(0);
          for(let i=0; i<bufferSize; i++) {
            data[i] = Math.random() * 2 - 1;
          }
          const noiseSource = audioCtx.createBufferSource();
          noiseSource.buffer = buffer;
    
          const gainNode = audioCtx.createGain();
    
          noiseSource.connect(gainNode);
          gainNode.connect(audioCtx.destination);
    
          gainNode.gain.setValueAtTime(0, audioCtx.currentTime);
          gainNode.gain.linearRampToValueAtTime(volumeLevel, audioCtx.currentTime + attack);
          gainNode.gain.linearRampToValueAtTime(volumeLevel * sustain, audioCtx.currentTime + attack + decay);
          gainNode.gain.setTargetAtTime(0, audioCtx.currentTime + attack + decay + 0.05, release);
    
          noiseSource.start();
          noiseSource.stop(audioCtx.currentTime + attack + decay + release + 0.1);
          return;
        }
    
        // For other waveforms
        const osc = audioCtx.createOscillator();
        const gainNode = audioCtx.createGain();
    
        osc.type = wave;
        osc.frequency.value = frequency;
        osc.detune.value = detuneCents;
    
        osc.connect(gainNode);
        gainNode.connect(audioCtx.destination);
    
        // ADSR Envelope
        let now = audioCtx.currentTime;
        gainNode.gain.setValueAtTime(0, now);
        gainNode.gain.linearRampToValueAtTime(volumeLevel, now + attack);
        gainNode.gain.linearRampToValueAtTime(volumeLevel * sustain, now + attack + decay);
        osc.start(now);
    
        gainNode.gain.setTargetAtTime(0, now + attack + decay + 0.1, release);
        osc.stop(now + attack + decay + release + 0.2);
      }
    
      // Playback control
      function play() {
        if(playing) return;
        playing = true;
        currentRow = 0;
        step();
      }
    
      function stop() {
        playing = false;
        if(timerId) clearTimeout(timerId);
      }
    
      function step() {
        if(!playing) return;
    
        // Highlight row in tracker
        highlightRow(currentRow);
    
        // Play notes in that row
        let row = patterns[currentPattern][currentRow];
        row.forEach(noteObj => {
          if(noteObj) playNote(noteObj);
        });
    
        currentRow++;
        if(currentRow >= rowsPerPattern) {
          if(loop) {
            currentRow = 0;
          } else {
            stop();
            return;
          }
        }
    
        const rowDuration = (60 / bpm) / 4; // assuming 4 rows per beat (16 rows per 4 beats)
        timerId = setTimeout(step, rowDuration * 1000);
      }
    
      function highlightRow(rowIndex) {
        // Remove highlight from all rows
        Array.from(trackerEl.children).forEach(child => {
          child.classList.remove("highlight");
        });
        // Each row has (numTracks+1) cells, skipping header row and col, calculate offset
        // First row is header row (numTracks+1 cells)
        // Then rows start at index (numTracks+1)
        const offset = (numTracks + 1);
        const startIndex = offset + rowIndex * (numTracks + 1);
        for(let i=0; i<=numTracks; i++) {
          const cell = trackerEl.children[startIndex + i];
          if(cell) cell.classList.add("highlight");
        }
      }
    
      // Save state to URL hash
      function saveToHash() {
        const state = {
          bpm,
          rowsPerPattern,
          numPatterns,
          numTracks,
          patterns,
          oscWave: oscWaveEl.value,
          detune: detuneEl.value,
          volume: volumeEl.value,
          attack: attackEl.value,
          decay: decayEl.value,
          sustain: sustainEl.value,
          release: releaseEl.value,
          loop
        };
        const json = JSON.stringify(state);
        const encoded = btoa(unescape(encodeURIComponent(json)));
        location.hash = encoded;
      }
      // Load state from URL hash
      function loadFromHash() {
        if(location.hash.length > 1){
          try {
            const encoded = location.hash.substring(1);
            const json = decodeURIComponent(escape(atob(encoded)));
            const state = JSON.parse(json);
            bpm = state.bpm;
            rowsPerPattern = state.rowsPerPattern;
            numPatterns = state.numPatterns;
            numTracks = state.numTracks;
            patterns = state.patterns || patterns;
    
            // Update UI and inputs
            bpmEl.value = bpm;
            rowsPerPatternEl.value = rowsPerPattern;
            numPatternsEl.value = numPatterns;
            numTracksEl.value = numTracks;
            oscWaveEl.value = state.oscWave || "square";
            detuneEl.value = state.detune || 0;
            volumeEl.value = state.volume || 0.3;
            attackEl.value = state.attack || 10;
            decayEl.value = state.decay || 100;
            sustainEl.value = state.sustain || 0.7;
            releaseEl.value = state.release || 200;
            loopEl.checked = state.loop !== false;
    
            renderTracker();
          } catch(e) {console.warn("Could not load state from URL", e);}
        } else {
          initPatterns();
          renderTracker();
        }
      }
    
      // New pattern handler
      function newPattern() {
        bpm = parseInt(bpmEl.value);
        rowsPerPattern = parseInt(rowsPerPatternEl.value);
        numPatterns = parseInt(numPatternsEl.value);
        numTracks = parseInt(numTracksEl.value);
        loop = loopEl.checked;
    
        initPatterns();
        renderTracker();
      }
    
      // Keyboard shortcuts
      document.body.addEventListener("keydown", (e) => {
        if(e.target.tagName === "INPUT") return; // skip if typing in input
    
        // Space for play / stop
        if(e.code === "Space"){
          e.preventDefault();
          if(playing) stop();
          else play();
        }
        // N for new pattern
        if(e.key.toLowerCase() === "n") {
          e.preventDefault();
          newPattern();
        }
      });
    
      // Init
      buildPiano(BASE_OCTAVE);
      loadFromHash();
    
      // Event listeners
      btnNew.addEventListener("click", () => {
        newPattern();
      });
      btnPlay.addEventListener("click", () => {
        play();
      });
      btnStop.addEventListener("click", () => {
        stop();
      });
      btnShare.addEventListener("click", () => {
        saveToHash();
        navigator.clipboard.writeText(location.href)
          .then(() => alert("URL copied to clipboard"))
          .catch(() => alert("Failed to copy URL"));
      });
      bpmEl.addEventListener("change", () => bpm = parseInt(bpmEl.value));
      rowsPerPatternEl.addEventListener("change", () => rowsPerPattern = parseInt(rowsPerPatternEl.value));
      numPatternsEl.addEventListener("change", () => numPatterns = parseInt(numPatternsEl.value));
      numTracksEl.addEventListener("change", () => numTracks = parseInt(numTracksEl.value));
      loopEl.addEventListener("change", () => loop = loopEl.checked);
    
    })();
    </script>
    
    </body>
    </html>
    

    How to Use

    • Adjust BPM, Rows per Pattern, Number of Patterns, Tracks, then click "New" to create a new empty tracker.
    • Click on a cell to add/remove a note (default to C4).
    • Use the piano keys to insert C, C#, D... notes at the current row and track 0.
    • Play / Stop Playback with buttons or Spacebar.
    • Loop playback enabled by default, toggleable.
    • Adjust oscillator waveform, detune, volume, and ADSR envelope.
    • Noise waveform plays white noise instead of pitched oscillator.
    • Share button copies a base64 JSON-encoded URL hash that stores the entire pattern + settings.
    • Load that URL anywhere to restore state.
    • Keyboard shortcuts: Space = play/pause, N = New pattern.

    Features Not Implemented / To Extend

    • Editing notes for all tracks with piano keys.
    • Selecting which track to edit.
    • Multiple octaves piano.
    • Better UI/UX and mobile-friendly design.
    • More detailed pattern management.
    • GUI filter controls.
    • Import/export patterns as files.
    • Waveform visualizations or advanced oscillator customization.

    If you want me to extend or focus on any particular feature next, just ask!

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