It sounds like you want to create a simple rhythm game editor with the following features:
I can help you build a minimal but functional version of this using HTML, CSS, and JS.
html
<!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: 20px; background: #222; color: #eee; }
label { display: block; margin-bottom: 5px; }
input[type="text"] { width: 80%; padding: 5px; }
button { margin: 5px 0 20px; padding: 10px 20px; font-size: 16px; }
#timeline { position: relative; width: 100%; height: 80px; background: #444; border-radius: 8px; overflow-x: auto; white-space: nowrap; }
.bar { display: inline-block; width: 160px; height: 100%; border-left: 1px solid #666; position: relative; box-sizing: border-box; }
.bar:first-child { border-left: none; }
.bar-label { position: absolute; top: 2px; left: 2px; font-size: 10px; color: #999; }
.note { position: absolute; width: 10px; height: 20px; background: #0f0; border-radius: 4px; top: 30px; }
#shareLink { word-break: break-all; background: #333; padding: 10px; margin-top: 20px; border-radius: 4px; user-select: all; }
#info { margin-top: 20px; font-size: 14px; color: #ccc;}
</style>
</head>
<body>
<h1>Rhythm Game Editor</h1>
<label for="audioURL">Audio URL:</label>
<input type="text" id="audioURL" placeholder="Enter audio URL and press Enter" />
<button id="loadAudio">Load Audio</button>
<div>
<button id="playPause" disabled>Play</button>
<button id="stop" disabled>Stop</button>
</div>
<div id="timeline"></div>
<div id="info">
<p>Controls:</p>
<ul>
<li><strong>Space</strong> - add note at current time</li>
<li><strong>Delete</strong> - remove last note</li>
<li>Click timeline to add note at clicked position</li>
</ul>
</div>
<h3>Share Link:</h3>
<div id="shareLink"></div>
<script>
(() => {
const audioURLInput = document.getElementById('audioURL');
const loadAudioButton = document.getElementById('loadAudio');
const playPauseButton = document.getElementById('playPause');
const stopButton = document.getElementById('stop');
const timeline = document.getElementById('timeline');
const shareLink = document.getElementById('shareLink');
let audio = new Audio();
let isPlaying = false;
const bpm = 120; // fixed BPM for simplicity
const beatsPerBar = 4;
let barsCount = 16; // starting number of bars, adjustable
// notes array: each note is {bar: number, beat: number} zero-based
let notes = [];
// Duration in seconds, will be set after audio loads
let audioDuration = 0;
function calculateBarsCount() {
if (audioDuration === 0) return barsCount;
// total beats = duration * (BPM/60)
const totalBeats = audioDuration * (bpm / 60);
return Math.ceil(totalBeats / beatsPerBar);
}
function renderTimeline() {
timeline.innerHTML = '';
barsCount = calculateBarsCount();
timeline.style.width = (barsCount * 160) + 'px';
for (let bar = 0; bar < barsCount; bar++) {
const barDiv = document.createElement('div');
barDiv.className = 'bar';
barDiv.dataset.bar = bar;
barDiv.style.position = 'relative';
const label = document.createElement('div');
label.className = 'bar-label';
label.textContent = `Bar ${bar + 1}`;
barDiv.appendChild(label);
timeline.appendChild(barDiv);
}
renderNotes();
}
function renderNotes() {
// Clear all notes first
document.querySelectorAll('.note').forEach(n => n.remove());
notes.forEach(({ bar, beat }) => {
if (bar < 0 || bar >= barsCount) return;
const barDiv = timeline.querySelector(`.bar[data-bar="${bar}"]`);
if (!barDiv) return;
const noteDiv = document.createElement('div');
noteDiv.className = 'note';
// position note according to beat
// beat from 0 to beatsPerBar-1
const beatWidth = 160 / beatsPerBar;
noteDiv.style.left = (beat * beatWidth + (beatWidth - 10)/2) + 'px';
noteDiv.title = `Bar ${bar + 1} Beat ${beat + 1}`;
barDiv.appendChild(noteDiv);
});
}
function timeToBarBeat(time) {
// Convert audio time (seconds) to bar and beat indexes
const beatsPassed = time * (bpm / 60);
const bar = Math.floor(beatsPassed / beatsPerBar);
const beat = Math.floor(beatsPassed % beatsPerBar);
return { bar, beat };
}
function barBeatToTime(bar, beat) {
const totalBeats = bar * beatsPerBar + beat;
return totalBeats * (60 / bpm);
}
function addNoteAtTime(time) {
const { bar, beat } = timeToBarBeat(time);
if (bar >= barsCount) {
barsCount = bar + 1;
renderTimeline();
}
// Prevent duplicate notes at same bar and beat
if (!notes.some(n => n.bar === bar && n.beat === beat)) {
notes.push({ bar, beat });
notes.sort((a,b) => a.bar - b.bar || a.beat - b.beat);
renderNotes();
updateShareLink();
}
}
function removeLastNote() {
if (notes.length > 0) {
notes.pop();
renderNotes();
updateShareLink();
}
}
// Loading audio from URL entered by user
loadAudioButton.addEventListener('click', () => {
const url = audioURLInput.value.trim();
if (!url) return alert('Enter a valid audio URL');
audio.pause();
audio.src = url;
audio.load();
audio.oncanplay = () => {
audioDuration = audio.duration;
barsCount = calculateBarsCount();
renderTimeline();
playPauseButton.disabled = false;
stopButton.disabled = false;
isPlaying = false;
playPauseButton.textContent = 'Play';
notes = [];
renderNotes();
updateShareLink();
};
audio.onerror = () => {
alert('Failed to load audio. Check the URL or CORS policy.');
};
});
playPauseButton.addEventListener('click', () => {
if (isPlaying) {
audio.pause();
isPlaying = false;
playPauseButton.textContent = 'Play';
} else {
audio.play();
isPlaying = true;
playPauseButton.textContent = 'Pause';
}
});
stopButton.addEventListener('click', () => {
audio.pause();
audio.currentTime = 0;
isPlaying = false;
playPauseButton.textContent = 'Play';
});
// Add note on space key during playback or pause
window.addEventListener('keydown', (e) => {
if(e.target.tagName === 'INPUT') return; // ignore inputs
if (e.code === 'Space') {
e.preventDefault();
addNoteAtTime(audio.currentTime);
} else if (e.code === 'Delete') {
e.preventDefault();
removeLastNote();
}
});
// Clicking timeline adds note at clicked position
timeline.addEventListener('click', e => {
// Find the bar clicked
let barDiv = e.target.closest('.bar');
if (!barDiv) return;
const bar = Number(barDiv.dataset.bar);
const rect = barDiv.getBoundingClientRect();
// Calculate beat from click X inside bar
const relativeX = e.clientX - rect.left;
const beatWidth = rect.width / beatsPerBar;
const beat = Math.floor(relativeX / beatWidth);
addNoteAtTime(barBeatToTime(bar, beat));
});
// Share the notes data encoded in URL hash
function updateShareLink() {
// Data to save: { bpm, barsCount, notes }
const data = { bpm, barsCount, notes };
const json = JSON.stringify(data);
const base64 = btoa(json);
const url = `${location.origin}${location.pathname}#/` + base64;
shareLink.textContent = url;
}
// Load from URL hash if present
function loadFromHash() {
const hash = location.hash;
if (hash.startsWith('#/')) {
const base64 = hash.slice(2);
try {
const json = atob(base64);
const data = JSON.parse(json);
if (data.bpm === bpm && data.notes) {
notes = data.notes;
barsCount = data.barsCount || 16;
renderTimeline();
renderNotes();
updateShareLink();
}
} catch (e) {
console.warn('Invalid rhythm data in URL hash');
}
}
}
window.addEventListener('hashchange', loadFromHash);
loadFromHash();
})();
</script>
</body>
</html>