gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
chiptune sequencer adsr synth pattern share "/#" html
- User
chiptune sequencer adsr synth pattern share "/#" html
- Assistant
chiptune sequencer adsr synth pattern share "/#" html
It looks like you want to create or share a chiptune sequencer with ADSR synth patterns in HTML, possibly including a way to share patterns via a URL (using "/#" fragment identifiers). Here’s a basic example of how you can create a simple chiptune ADSR synth sequencer in HTML/JavaScript, with pattern sharing using the URL hash.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chiptune ADSR Sequencer</title>
<style>
body {
font-family: monospace;
background: #111;
color: #eee;
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
padding: 1rem;
}
.sequencer {
display: flex;
gap: 0.25rem;
}
.step {
width: 30px;
height: 30px;
background: #333;
border: 1px solid #555;
cursor: pointer;
}
.step.active {
background: #0f0;
}
label {
display: block;
margin-top: 0.5rem;
}
.adsr-controls {
display: flex;
gap: 1rem;
justify-content: center;
}
input[type=range] {
width: 100px;
}
button {
padding: 0.5rem 1rem;
background: #222;
border: 1px solid #555;
color: #eee;
cursor: pointer;
margin-top: 1rem;
}
</style>
</head>
<body>
<h1>Chiptune ADSR Synth Sequencer</h1>
<div class="sequencer" id="sequencer">
<!-- Steps will be generated here -->
</div>
<div class="adsr-controls">
<label>Attack <input type="range" min="0" max="1" step="0.01" id="attack" value="0.05"></label>
<label>Decay <input type="range" min="0" max="1" step="0.01" id="decay" value="0.1"></label>
<label>Sustain <input type="range" min="0" max="1" step="0.01" id="sustain" value="0.5"></label>
<label>Release <input type="range" min="0" max="1" step="0.01" id="release" value="0.2"></label>
</div>
<button id="play">Play / Stop</button>
<p>Share Pattern URL: <a href="#" id="shareUrl" target="_blank"></a></p>
<script>
const stepsCount = 8;
let pattern = new Array(stepsCount).fill(0); // 0 = off, 1 = on
let isPlaying = false;
let currentStep = 0;
let intervalId = null;
// ADSR parameters
let adsr = {
attack: 0.05,
decay: 0.1,
sustain: 0.5,
release: 0.2,
};
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Create step buttons
const sequencer = document.getElementById('sequencer');
for (let i = 0; i < stepsCount; i++) {
const stepElem = document.createElement('div');
stepElem.classList.add('step');
stepElem.dataset.index = i;
stepElem.addEventListener('click', () => {
pattern[i] = pattern[i] ? 0 : 1;
updateSequencerUI();
updateShareUrl();
})
sequencer.appendChild(stepElem);
}
// Update UI based on pattern
function updateSequencerUI() {
for (let i = 0; i < stepsCount; i++) {
const stepElem = sequencer.children[i];
if (pattern[i]) stepElem.classList.add('active');
else stepElem.classList.remove('active');
}
}
// ADSR controls
const controls = ['attack', 'decay', 'sustain', 'release'];
controls.forEach(control => {
const elem = document.getElementById(control);
elem.addEventListener('input', e => {
adsr[control] = parseFloat(e.target.value);
updateShareUrl();
})
})
// Simple square wave beep with ADSR envelope
function playNote(duration = 0.3, frequency = 440) {
let now = audioCtx.currentTime;
const osc = audioCtx.createOscillator();
osc.type = 'square';
osc.frequency.value = frequency;
const gainNode = audioCtx.createGain();
osc.connect(gainNode).connect(audioCtx.destination);
// ADSR envelope
gainNode.gain.cancelScheduledValues(now);
gainNode.gain.setValueAtTime(0, now);
gainNode.gain.linearRampToValueAtTime(1, now + adsr.attack);
gainNode.gain.linearRampToValueAtTime(adsr.sustain, now + adsr.attack + adsr.decay);
gainNode.gain.setValueAtTime(adsr.sustain, now + duration);
gainNode.gain.linearRampToValueAtTime(0, now + duration + adsr.release);
osc.start(now);
osc.stop(now + duration + adsr.release + 0.05);
}
// Play sequencer
const playButton = document.getElementById('play');
playButton.addEventListener('click', () => {
if (!isPlaying) startSequencer();
else stopSequencer();
});
function startSequencer() {
if (audioCtx.state === 'suspended') {
audioCtx.resume();
}
isPlaying = true;
playButton.textContent = 'Stop';
currentStep = 0;
intervalId = setInterval(() => {
stepTick();
}, 400); // 150 BPM = 400ms per step approx
}
function stopSequencer() {
isPlaying = false;
playButton.textContent = 'Play / Stop';
clearInterval(intervalId);
clearActiveStepUI();
}
function stepTick() {
clearActiveStepUI();
if (pattern[currentStep]) {
playNote(0.3, 440 + currentStep * 50); // frequency steps for fun
}
sequencer.children[currentStep].classList.add('playing');
currentStep = (currentStep + 1) % stepsCount;
}
function clearActiveStepUI() {
for(let i=0; i<stepsCount; i++) {
sequencer.children[i].classList.remove('playing');
}
}
// URL encoding / decoding
// Pattern & ADSR encoded as base64 JSON in the hash (simple)
function updateShareUrl() {
const data = {
pattern,
adsr,
};
const jsonString = JSON.stringify(data);
const encoded = btoa(jsonString);
const shareUrlElem = document.getElementById('shareUrl');
const url = `${window.location.origin}${window.location.pathname}#${encoded}`;
shareUrlElem.href = url;
shareUrlElem.textContent = url;
}
function loadFromHash() {
if(location.hash.length > 1) {
try {
const encoded = location.hash.slice(1);
const jsonString = atob(encoded);
const data = JSON.parse(jsonString);
if (data.pattern && Array.isArray(data.pattern) && data.pattern.length === stepsCount) {
pattern = data.pattern;
updateSequencerUI();
}
if(data.adsr) {
adsr = {...adsr, ...data.adsr};
controls.forEach(control => {
const elem = document.getElementById(control);
if (adsr[control] !== undefined) {
elem.value = adsr[control];
}
})
}
} catch (e) {
console.warn('Failed to load pattern from URL');
}
}
updateShareUrl();
}
loadFromHash();
</script>
</body>
</html>
yourpage.html#/eyJwYXR0ZXJuIjpb...If you want a more advanced tracker-style interface, or more steps, or waveform options, you can expand on this base.
Let me know if you'd like help adding other features!
Not yet included in a published release.