You want a rhythm game editor implemented in HTML/CSS/JS with features including:
- Load audio from a URL
- Play the audio
- Display notes on a timeline/beat bars
- Record notes (probably by key presses)
- Show bars counting beats/measures
- Rhythm shortcuts (e.g., snap to grid, note input via keyboard)
- Delete notes
- Share the created sequence (probably via URL hash
"#/" or something similar)
Here's a minimal but functional example. It includes:
- An audio input by URL
- Audio playback controls
- Timeline showing bars and beat grid
- Recording notes via keyboard key (e.g., space bar)
- Displaying notes on the timeline aligned with beat bars
- Deleting notes by clicking them
- Sharing via a URL hash containing JSON-encoded note data and the audio URL
<!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: 10px;
background: #222;
color: #eee;
}
#container {
max-width: 900px;
margin: auto;
}
label {
display: block;
margin-top: 10px;
}
input[type="text"] {
width: 80%;
font-size: 1em;
padding: 6px;
}
button {
font-size: 1em;
margin-left: 10px;
padding: 6px 12px;
cursor: pointer;
}
#timeline {
margin-top: 20px;
position: relative;
height: 120px;
background: #111;
border: 2px solid #555;
user-select: none;
overflow-x: auto;
white-space: nowrap;
}
.bar {
display: inline-block;
width: 200px;
height: 100%;
border-left: 1px solid #555;
box-sizing: border-box;
position: relative;
}
.bar-label {
position: absolute;
top: 2px;
left: 4px;
font-size: 12px;
color: #555;
}
.beat-line {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
background: #444;
opacity: 0.4;
}
.note {
position: absolute;
bottom: 5px;
width: 14px;
height: 14px;
background: #0f0;
border-radius: 50%;
cursor: pointer;
border: 1px solid #0a0;
user-select: none;
}
.note:hover {
background: #afa;
border-color: #7f7;
}
#status {
margin-top: 10px;
font-size: 14px;
height: 18px;
}
#shortcuts {
margin-top: 10px;
font-size: 14px;
color: #aaa;
}
</style>
</head>
<body>
<div id="container">
<h1>Rhythm Game Editor</h1>
<label>
Audio URL:
<input type="text" id="audio-url" placeholder="Enter audio URL here" />
<button id="load-audio">Load</button>
</label>
<audio id="audio" controls crossorigin="anonymous"></audio>
<div id="timeline"></div>
<div id="status">Load audio and play. Press SPACE to record notes in time with music.</div>
<div id="shortcuts">
<b>Shortcuts:</b> SPACE = add note, DELETE key = delete selected note, ← / → = move selected note, S = save/share<br/>
Click on notes to select and delete. Scroll timeline horizontally with mouse wheel or scrollbar.
</div>
<button id="share-btn" style="margin-top:10px;">Share Link (Generate URL)</button>
<input type="text" id="share-link" readonly style="width:100%; margin-top:5px; font-size:0.9em;"/>
</div>
<script>
(() => {
const audio = document.getElementById('audio');
const audioUrlInput = document.getElementById('audio-url');
const loadAudioBtn = document.getElementById('load-audio');
const timeline = document.getElementById('timeline');
const status = document.getElementById('status');
const shareBtn = document.getElementById('share-btn');
const shareLinkInput = document.getElementById('share-link');
// Config
const bpm = 120;
const beatsPerBar = 4;
const barsCount = 16; // total bars in timeline
const pixelsPerBeat = 50; // spacing for beats on timeline in px
// State
let notes = []; // {time: seconds}
let selectedNoteIndex = null;
let startTime = 0; // audio starting offset (usually 0)
let isAudioLoaded = false;
// Helpers
function secondsToPosition(time) {
// convert seconds to pixel position on timeline
// beats = time * bpm / 60
const beats = time * bpm / 60;
return beats * pixelsPerBeat;
}
function positionToSeconds(pos) {
const beats = pos / pixelsPerBeat;
return beats * 60 / bpm;
}
function roundToNearestBeat(time) {
const beatDuration = 60 / bpm;
return Math.round(time / beatDuration) * beatDuration;
}
function clearTimeline() {
timeline.innerHTML = '';
}
function renderTimeline() {
clearTimeline();
// Draw bars
for(let bar=0; bar<barsCount; bar++) {
const barEl = document.createElement('div');
barEl.className = 'bar';
barEl.style.display = 'inline-block';
barEl.style.position = 'relative';
barEl.style.width = (beatsPerBar * pixelsPerBeat) + 'px';
barEl.style.height = '100%';
barEl.style.borderLeft = (bar === 0 ? '2px solid #999' : '1px solid #555');
barEl.style.boxSizing = 'border-box';
// Bar number label
const label = document.createElement('div');
label.className = 'bar-label';
label.textContent = bar + 1;
barEl.appendChild(label);
// Draw beat lines inside bar
for(let beat=0; beat<beatsPerBar; beat++) {
if(beat === 0) continue; // left edge is bar border
const beatLine = document.createElement('div');
beatLine.className = 'beat-line';
beatLine.style.left = (beat * pixelsPerBeat - 1) + 'px';
barEl.appendChild(beatLine);
}
timeline.appendChild(barEl);
}
// Draw notes
notes.forEach((note, i) => {
const pos = secondsToPosition(note.time);
if(pos > barsCount * beatsPerBar * pixelsPerBeat) return; // out of view
const noteEl = document.createElement('div');
noteEl.className = 'note';
noteEl.style.left = pos - 7 + 'px'; // center on pos (7px radius)
noteEl.title = 'Note at ' + note.time.toFixed(2) + 's';
if(i === selectedNoteIndex) {
noteEl.style.background = '#ff0';
noteEl.style.borderColor = '#cc0';
}
noteEl.addEventListener('click', e => {
e.stopPropagation();
selectNote(i);
});
timeline.appendChild(noteEl);
});
}
function selectNote(index) {
selectedNoteIndex = index;
status.textContent = `Selected note at ${notes[index].time.toFixed(2)}s. Use ←/→ to move, DELETE to delete.`;
renderTimeline();
}
function deselectNote() {
selectedNoteIndex = null;
status.textContent = 'No note selected. Press SPACE to add note.';
renderTimeline();
}
function addNoteAtCurrentTime() {
if(!isAudioLoaded) {
status.textContent = 'Load audio first.';
return;
}
const t = roundToNearestBeat(audio.currentTime);
// don't duplicate notes at same spot
if(notes.find(n => Math.abs(n.time - t) < 0.01)) {
status.textContent = "Note already exists at " + t.toFixed(2) + "s";
return;
}
notes.push({time: t});
notes.sort((a,b) => a.time - b.time);
status.textContent = `Added note at ${t.toFixed(2)}s`;
renderTimeline();
}
function deleteSelectedNote() {
if(selectedNoteIndex === null) {
status.textContent = 'No note selected to delete.';
return;
}
const removed = notes.splice(selectedNoteIndex, 1);
status.textContent = `Deleted note at ${removed[0].time.toFixed(2)}s`;
selectedNoteIndex = null;
renderTimeline();
}
function moveSelectedNote(amountBeats) {
if(selectedNoteIndex === null) return;
const note = notes[selectedNoteIndex];
let newTime = note.time + amountBeats * 60 / bpm;
if(newTime < 0) newTime = 0;
const rounded = roundToNearestBeat(newTime);
// Avoid duplicates
if(notes.find((n,i) => i !== selectedNoteIndex && Math.abs(n.time - rounded) < 0.01)) {
status.textContent = 'Cannot move, note exists at that position.';
return;
}
note.time = rounded;
notes.sort((a,b) => a.time - b.time);
selectedNoteIndex = notes.findIndex(n => n.time === rounded); // update selection index
status.textContent = `Moved note to ${rounded.toFixed(2)}s`;
renderTimeline();
}
// Load audio URL entered by user
loadAudioBtn.addEventListener('click', () => {
const url = audioUrlInput.value.trim();
if(!url) {
status.textContent = 'Enter a valid audio URL.';
return;
}
audio.src = url;
audio.load();
status.textContent = 'Loading audio...';
audio.oncanplaythrough = () => {
isAudioLoaded = true;
status.textContent = 'Audio loaded. Play and press SPACE to add notes.';
renderTimeline();
};
audio.onerror = () => {
isAudioLoaded = false;
status.textContent = 'Error loading audio. Check URL/CORS.';
};
deselectNote();
notes = [];
});
// Keyboard shortcuts
window.addEventListener('keydown', e => {
if(document.activeElement === audioUrlInput) return; // ignore if typing URL
// SPACE to add note at current audio time
if(e.code === 'Space') {
e.preventDefault();
addNoteAtCurrentTime();
return;
}
// Delete a note
if(e.key === 'Delete' || e.key === 'Backspace') {
if(selectedNoteIndex !== null) {
e.preventDefault();
deleteSelectedNote();
}
return;
}
// Left arrow - move note left (one beat)
if(e.key === 'ArrowLeft') {
if(selectedNoteIndex !== null) {
e.preventDefault();
moveSelectedNote(-1);
}
return;
}
// Right arrow - move note right
if(e.key === 'ArrowRight') {
if(selectedNoteIndex !== null) {
e.preventDefault();
moveSelectedNote(1);
}
return;
}
// S to share (generate URL)
if(e.key.toLowerCase() === 's') {
e.preventDefault();
shareBtn.click();
return;
}
});
// Clicking on timeline deselect note
timeline.addEventListener('click', () => {
deselectNote();
});
// Share link generation
shareBtn.addEventListener('click', () => {
if(!isAudioLoaded) {
status.textContent = 'Load audio first before sharing.';
return;
}
// Prepare share data
const data = {
audioUrl: audio.src,
notes,
bpm,
barsCount,
beatsPerBar
};
const json = encodeURIComponent(JSON.stringify(data));
const url = location.origin + location.pathname + '#/' + json;
shareLinkInput.value = url;
shareLinkInput.select();
status.textContent = 'Share link generated! Copy and share.';
});
// Try to load from URL hash on page load
function loadFromHash() {
if(location.hash.startsWith('#/')) {
try {
const jsonStr = decodeURIComponent(location.hash.slice(2));
const data = JSON.parse(jsonStr);
if(data.audioUrl) {
audio.src = data.audioUrl;
audio.load();
audioUrlInput.value = data.audioUrl;
notes = data.notes || [];
// Optional: bpm, barsCount etc from data?
status.textContent = 'Loaded from URL hash. Play audio and edit.';
isAudioLoaded = false;
audio.oncanplaythrough = () => {
isAudioLoaded = true;
status.textContent = 'Audio loaded. Play and press SPACE to add notes.';
renderTimeline();
};
deselectNote();
renderTimeline();
}
} catch(e) {
status.textContent = 'Error loading data from URL hash.';
}
}
}
// Initial run
loadFromHash();
// Render empty timeline
renderTimeline();
})();
</script>
</body>
</html>
How to Use
- Enter any CORS-enabled audio file URL in the Audio URL input and press Load.
- When audio is loaded, press play.
- Press SPACE to add a note at the nearest beat to the current audio time.
- Notes appear as green circles on the timeline.
- Click a note to select it (highlighted yellow).
- Use left/right arrow keys to move selected note by one beat.
- Press DELETE or BACKSPACE key to delete the selected note.
- Click on empty timeline space to deselect notes.
- Press 'S' or use Share Link button to generate a sharing URL that encodes audio URL + notes.
- Copy the generated URL or share it; opening the page with that hash will load the rhythm chart and audio automatically.
Notes
- The timeline shows 16 bars of 4 beats each at 120bpm by default.
- Notes snap to the nearest beat.
- This is a simple editor and can be extended with:
- Multiple keys/instruments
- Different BPM changes
- Visual feedback synchronized with audio
- Save/Load from files
- Drag and drop notes
- More complex sharing/exporting
Let me know if you want me to add features or polish the UI further!