gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js rhythm game editor load url mp3 bpm share "#/"
- User
html css js rhythm game editor load url mp3 bpm share "#/"
- Assistant
html css js rhythm game editor load url mp3 bpm share "#/"
Creating a simple rhythm game editor that:
#/ syntax)is definitely doable with HTML, CSS, and JS.
Below is a minimal basic implementation. This can be improved in many ways but shows core functionality.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rhythm Game Editor</title>
<style>
body {
font-family: sans-serif;
margin: 1rem;
background: #f0f0f0;
}
input, button {
font-size: 1rem;
margin: 0.25rem 0.5rem 0.25rem 0;
padding: 0.25rem 0.5rem;
}
#timeline {
margin-top: 1rem;
background: white;
position: relative;
height: 80px;
width: 90vw;
max-width: 1000px;
border: 1px solid #ccc;
overflow-x: scroll;
white-space: nowrap;
font-family: monospace;
}
.beat {
display: inline-block;
width: 40px;
height: 80px;
border-left: 1px solid #ddd;
box-sizing: border-box;
position: relative;
vertical-align: top;
cursor: pointer;
}
.beat-number {
font-size: 0.7rem;
color: #999;
position: absolute;
top: 0;
left: 2px;
}
.note {
width: 20px;
height: 20px;
border-radius: 50%;
background: #e44;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
pointer-events: none;
box-shadow: 0 0 6px 2px #f77;
}
#playerControls {
margin-top: 1rem;
}
#shareLink {
width: 100%;
font-size: 0.9rem;
margin-top: 0.5rem;
}
</style>
</head>
<body>
<h1>Rhythm Game Editor</h1>
<label>MP3 URL: <input type="text" id="mp3url" size="50" placeholder="Enter mp3 URL here" /></label><br />
<label>BPM: <input type="number" id="bpm" min="30" max="300" value="120" /></label>
<button id="loadBtn">Load Song</button>
<div id="playerControls" style="display:none;">
<button id="playBtn">Play</button>
<button id="pauseBtn">Pause</button>
<button id="stopBtn">Stop</button>
<span id="timeDisplay">00:00 / 00:00</span>
</div>
<div id="timeline"></div>
<textarea id="shareLink" rows="3" placeholder="Share URL will appear here"></textarea>
<script>
(() => {
const inputUrl = document.getElementById('mp3url');
const inputBpm = document.getElementById('bpm');
const loadBtn = document.getElementById('loadBtn');
const timeline = document.getElementById('timeline');
const shareLink = document.getElementById('shareLink');
const playerControls = document.getElementById('playerControls');
const playBtn = document.getElementById('playBtn');
const pauseBtn = document.getElementById('pauseBtn');
const stopBtn = document.getElementById('stopBtn');
const timeDisplay = document.getElementById('timeDisplay');
let audio = new Audio();
let notes = []; // array of beat indexes with notes
let bpm = 120;
let duration = 0;
let beatsCount = 0;
// --- Helpers ---
function padZero(n) {
return n < 10 ? '0' + n : n;
}
function formatTime(secs) {
const m = Math.floor(secs / 60);
const s = Math.floor(secs % 60);
return padZero(m) + ':' + padZero(s);
}
// --- Render timeline with beats and placed notes ---
function renderTimeline() {
timeline.innerHTML = '';
for(let b=0;b<beatsCount;b++) {
const beatDiv = document.createElement('div');
beatDiv.className = 'beat';
beatDiv.dataset.beat = b;
const numSpan = document.createElement('span');
numSpan.className = 'beat-number';
numSpan.textContent = (b+1);
beatDiv.appendChild(numSpan);
if(notes.includes(b)) {
const noteEl = document.createElement('div');
noteEl.className = 'note';
beatDiv.appendChild(noteEl);
}
beatDiv.addEventListener('click', () => {
toggleNote(b);
});
timeline.appendChild(beatDiv);
}
}
// --- Toggle note presence at beat index ---
function toggleNote(beatIdx) {
const i = notes.indexOf(beatIdx);
if(i >= 0) {
notes.splice(i, 1);
} else {
notes.push(beatIdx);
notes.sort((a,b)=>a-b);
}
renderTimeline();
updateShareLink();
}
// --- When user clicks Load Song button ---
loadBtn.addEventListener('click', () => {
if(!inputUrl.value) {
alert('Please enter an MP3 URL.');
return;
}
bpm = Number(inputBpm.value);
if(isNaN(bpm) || bpm<30 || bpm>300) {
alert('BPM must be between 30 and 300.');
return;
}
loadAudio(inputUrl.value);
});
// --- Load audio and setup duration and beats ---
function loadAudio(url) {
audio.pause();
audio = new Audio();
audio.crossOrigin = "anonymous"; // for some public accessible files
audio.src = url;
audio.addEventListener('canplaythrough', () => {
duration = audio.duration;
beatsCount = Math.floor(duration / (60 / bpm));
notes = []; // reset notes when loading new song
renderTimeline();
updateShareLink();
playerControls.style.display = 'inline-block';
updateTimeDisplay();
});
audio.addEventListener('timeupdate', updateTimeDisplay);
audio.addEventListener('ended', () => {
audio.currentTime = 0;
updateTimeDisplay();
});
}
// --- Update time display ---
function updateTimeDisplay() {
timeDisplay.textContent = `${formatTime(audio.currentTime)} / ${formatTime(duration)}`;
}
// --- Player controls ---
playBtn.addEventListener('click', () => {
audio.play();
});
pauseBtn.addEventListener('click', () => {
audio.pause();
});
stopBtn.addEventListener('click', () => {
audio.pause();
audio.currentTime = 0;
updateTimeDisplay();
});
// --- Encode data into hash ---
function updateShareLink() {
// Data to encode: mp3url, bpm, notes[]
// We'll put notes as comma separated beat numbers
const data = {
url: inputUrl.value,
bpm,
notes: notes.join(','),
};
// Encode data as JSON, then URI encode for URL safety
const json = JSON.stringify(data);
const encoded = encodeURIComponent(json);
// Set hash
window.location.hash = '#/' + encoded;
shareLink.value = window.location.href;
}
// --- Parse hash and load state ---
function parseHash() {
if(window.location.hash.startsWith('#/')) {
try {
const encoded = window.location.hash.slice(2);
const json = decodeURIComponent(encoded);
const data = JSON.parse(json);
if(data.url) inputUrl.value = data.url;
if(data.bpm) inputBpm.value = data.bpm;
if(Array.isArray(data.notes)) {
notes = data.notes;
} else if(typeof data.notes === 'string' && data.notes.length) {
notes = data.notes.split(',').map(Number).filter(n => !isNaN(n));
} else {
notes = [];
}
bpm = Number(data.bpm) || 120;
loadAudio(data.url);
} catch(e) {
console.error('Failed to parse URL hash', e);
}
}
}
// On load parse hash if exists
window.addEventListener('load', () => {
parseHash();
});
// Also update link when bpm or url changes
inputBpm.addEventListener('change', () => {
bpm = Number(inputBpm.value);
if(!isNaN(bpm) && audio.src) {
beatsCount = Math.floor(duration / (60 / bpm));
renderTimeline();
updateShareLink();
}
});
inputUrl.addEventListener('change', () => {
// Do nothing here, wait for Load button
});
})();
</script>
</body>
</html>
If you'd like, I can help extend this editor with more features like lanes, fine timing, note types, or recording notes live.
Not yet included in a published release.