You're asking for a rhythm game editor implemented in HTML/CSS/JS with the following features:
- Load a song via URL (MP3)
- Set the BPM
- Edit notes on a grid (showing bars and beats)
- Play song with notes rhythmically (like a rhythm game)
- Combo count (score)
- Shortcuts to control editor (delete note, play, etc)
- Share the created chart via URL (e.g., encoding notes in URL hash)
- Visual bars count shown
- Ability to add/delete notes
Here's a minimal but fairly complete rhythm game editor prototype in HTML/CSS/JS implementing these features.
<!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;
background: #222;
color: #eee;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
height: 100vh;
}
header {
padding: 10px;
background: #111;
display: flex;
align-items: center;
gap: 10px;
}
input[type="text"], input[type="number"] {
background: #333;
border: none;
outline: none;
color: #eee;
padding: 5px 8px;
border-radius: 3px;
width: 200px;
}
button {
background: #555;
border: none;
padding: 6px 12px;
border-radius: 3px;
color: white;
cursor: pointer;
user-select: none;
}
button:hover {
background: #777;
}
#editor {
flex-grow: 1;
background: #111;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 40px;
gap: 1px;
user-select: none;
position: relative;
overflow-x: auto;
padding: 10px;
}
.cell {
background: #222;
border: 1px solid #333;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
transition: background-color 0.15s;
}
.cell.note {
background: #e03e3e;
}
.bar-label {
grid-column: span 4;
background: #444;
color: #aaa;
text-align: center;
font-size: 12px;
padding-top: 4px;
user-select: none;
}
#status {
background: #111;
padding: 8px;
font-size: 14px;
}
#share-url {
width: 100%;
box-sizing: border-box;
background: #222;
border: none;
color: #eee;
padding: 5px;
margin-top: 5px;
user-select: all;
}
#combo {
font-weight: bold;
font-size: 18px;
}
</style>
</head>
<body>
<header>
<label>MP3 URL: <input type="text" id="mp3url" placeholder="https://.../song.mp3" spellcheck="false" autocorrect="off" autocapitalize="off"></label>
<label>BPM: <input type="number" id="bpm" min="20" max="300" value="120"></label>
<button id="loadSongBtn">Load & New</button>
<button id="playBtn">Play</button>
<button id="clearBtn">Clear Notes</button>
<button id="shareBtn">Share Chart</button>
</header>
<div id="editor"></div>
<div id="status">Status: Idle. <span id="combo"></span></div>
<input id="share-url" readonly style="display:none">
<audio id="audio" crossorigin="anonymous"></audio>
<script>
(() => {
// Config
const lanes = 4;
const beatsPerBar = 4;
const barsCountDefault = 16;
const cellsPerBar = beatsPerBar; // 1 cell per beat
const beatDuration_default = 0.5; // 120bpm seconds per beat (computed dynamically)
// State
let barsCount = barsCountDefault;
let bpm = 120;
let notes = {}; // key: "bar-beat-lane" -> true (note present)
// bar index from 0, beat in bar from 0..3, lane from 0..3
let isPlaying = false;
let audioContext = null;
let audioSource = null;
let startTime = 0;
let animationFrameId = 0;
const editor = document.getElementById('editor');
const mp3urlInput = document.getElementById('mp3url');
const bpmInput = document.getElementById('bpm');
const loadSongBtn = document.getElementById('loadSongBtn');
const playBtn = document.getElementById('playBtn');
const clearBtn = document.getElementById('clearBtn');
const shareBtn = document.getElementById('shareBtn');
const shareUrlInput = document.getElementById('share-url');
const statusEl = document.getElementById('status');
const comboEl = document.getElementById('combo');
const audioEl = document.getElementById('audio');
// --- NOTES DATA HELPERS ---
function noteKey(bar, beat, lane) {
return `${bar}-${beat}-${lane}`;
}
// --- EDITOR UI ---
function buildGrid() {
editor.innerHTML = '';
// Set grid width: lanes
editor.style.gridTemplateColumns = `repeat(${lanes}, 1fr)`;
// For each bar, show label row + 4 beat rows
for(let bar=0; bar<barsCount; bar++) {
// bar label spans lanes width
const label = document.createElement('div');
label.className = 'bar-label';
label.textContent = `Bar ${bar+1}`;
editor.appendChild(label);
for(let beat=0; beat<beatsPerBar; beat++) {
for(let lane=0; lane<lanes; lane++) {
const cell = document.createElement('div');
cell.className = 'cell';
const key = noteKey(bar, beat, lane);
if(notes[key]) cell.classList.add('note');
cell.dataset.bar = bar;
cell.dataset.beat = beat;
cell.dataset.lane = lane;
cell.addEventListener('click', (e) => {
toggleNote(bar, beat, lane);
renderGrid();
});
editor.appendChild(cell);
}
}
}
}
function renderGrid() {
for(const cell of editor.querySelectorAll('.cell')) {
const bar = +cell.dataset.bar;
const beat = +cell.dataset.beat;
const lane = +cell.dataset.lane;
const key = noteKey(bar, beat, lane);
if(notes[key]) cell.classList.add('note');
else cell.classList.remove('note');
}
}
function toggleNote(bar, beat, lane) {
const key = noteKey(bar, beat, lane);
if(notes[key]) delete notes[key];
else notes[key] = true;
}
function clearNotes() {
notes = {};
renderGrid();
}
// --- PLAYBACK & SYNCHRONIZATION ---
let combo = 0;
function setStatus(text) {
statusEl.textContent = 'Status: ' + text + (combo ? ' Combo: ' + combo : '');
}
function playSong() {
if(!mp3urlInput.value.trim()) {
alert("Please enter an MP3 URL.");
return;
}
if(isPlaying) {
stopSong();
return;
}
bpm = Math.max(20, Math.min(300, +bpmInput.value)) || 120;
playBtn.textContent = "Stop";
isPlaying = true;
combo = 0;
setStatus('Playing...');
comboEl.textContent = "";
// Setup audio
audioEl.src = mp3urlInput.value.trim();
audioEl.currentTime = 0;
audioEl.play();
startTime = performance.now();
// Start game loop
requestAnimationFrame(playLoop);
}
function stopSong() {
isPlaying = false;
playBtn.textContent = "Play";
audioEl.pause();
setStatus("Stopped.");
}
let playedNotesOnBeat = new Set();
function playLoop() {
if(!isPlaying) return;
const currentTimeAudio = audioEl.currentTime; // seconds
const secondsPerBeat = 60 / bpm;
const totalBeats = barsCount * beatsPerBar;
// Calculate current beat (floating)
const beatPos = currentTimeAudio / secondsPerBeat;
// Figure out which notes should trigger this frame, only once each
// We consider notes on beats floor(beatPos) and maybe some tolerance.
// Using small tolerance here
playedNotesOnBeat = playedNotesOnBeat || new Set();
const currentBeatIndex = Math.floor(beatPos);
// Detect note hits at currentBeatIndex
for(let lane=0; lane<lanes; lane++) {
// find note at this beat and lane
const bar = Math.floor(currentBeatIndex / beatsPerBar);
const beat = currentBeatIndex % beatsPerBar;
if(bar < 0 || bar >= barsCount) continue;
const key = noteKey(bar, beat, lane);
if(notes[key] && !playedNotesOnBeat.has(key)) {
// simulate hit (increase combo)
combo++;
playedNotesOnBeat.add(key);
comboEl.textContent = "Combo: " + combo;
// visual feedback for hit
highlightCell(bar, beat, lane);
}
}
if(currentBeatIndex >= totalBeats) {
stopSong();
return;
}
// Visual cursor on current beat
renderGrid(); // Clear any previous highlights
highlightBeatBar(beatPos);
animationFrameId = requestAnimationFrame(playLoop);
}
function highlightCell(bar, beat, lane) {
const cells = editor.querySelectorAll('.cell');
for(let cell of cells) {
if(+cell.dataset.bar === bar && +cell.dataset.beat === beat && +cell.dataset.lane === lane) {
cell.style.backgroundColor = '#ff6666';
setTimeout(() => {
cell.style.backgroundColor = '';
}, 200);
break;
}
}
}
function highlightBeatBar(beatPos) {
// highlight the cells corresponding to floating beatPos
// floor and fractional part used for some effect
const cells = editor.querySelectorAll('.cell');
const bar = Math.floor(beatPos / beatsPerBar);
const beat = Math.floor(beatPos % beatsPerBar);
for(let cell of cells) {
const cBar = +cell.dataset.bar;
const cBeat = +cell.dataset.beat;
if(cBar === bar && cBeat === beat) {
cell.style.borderColor = '#66f';
} else {
cell.style.borderColor = '#333';
}
}
}
// --- SHORTCUTS ---
window.addEventListener('keydown', (e) => {
if(e.target.tagName === 'INPUT') return;
// Del & Backspace delete note on hovered cell
if(e.key === "Delete" || e.key === "Backspace") {
if(hoveredCell) {
const b = +hoveredCell.dataset.bar;
const bt = +hoveredCell.dataset.beat;
const l = +hoveredCell.dataset.lane;
const key = noteKey(b, bt, l);
if(notes[key]) {
delete notes[key];
renderGrid();
e.preventDefault();
}
}
}
// Space - play/stop
else if(e.key === " ") {
e.preventDefault();
playBtn.click();
}
// C - clear notes
else if(e.key.toLowerCase() === 'c') {
clearBtn.click();
}
});
// Track hovered cell to operate keyboard shortcuts
let hoveredCell = null;
editor.addEventListener('mousemove', (e) => {
if(e.target.classList.contains('cell')) {
hoveredCell = e.target;
} else {
hoveredCell = null;
}
});
editor.addEventListener('mouseleave', (e) => {
hoveredCell = null;
});
// --- SHARE CHART IN URL HASH ---
// Chart in format: "bpm|bars|notes" where notes = "b-b-l,b-b-l,..."
function encodeChartToHash() {
const notesParts = [];
for(let key in notes) {
if(notes[key]) {
// key like "bar-beat-lane"
notesParts.push(key);
}
}
const notesStr = notesParts.join(',');
const bpmVal = bpmInput.value;
const hash = `bpm=${bpmVal}&bars=${barsCount}¬es=${notesStr}&mp3=${encodeURIComponent(mp3urlInput.value.trim())}`;
location.hash = hash;
}
function decodeHash() {
const h = location.hash.slice(1);
const params = new URLSearchParams(h);
const bpmV = params.get('bpm');
const bars = params.get('bars');
const notesStr = params.get('notes');
const mp3 = params.get('mp3') ? decodeURIComponent(params.get('mp3')) : '';
if(bpmV) bpmInput.value = bpmV;
if(bars) barsCount = Math.min(32, Math.max(1, +bars));
if(mp3) mp3urlInput.value = mp3;
notes = {};
if(notesStr) {
const noteKeys = notesStr.split(',');
for(let k of noteKeys) {
if(k.match(/^\d+-\d+-\d+$/)) {
notes[k] = true;
}
}
}
buildGrid();
renderGrid();
}
// --- BUTTONS ---
loadSongBtn.addEventListener('click', () => {
barsCount = barsCountDefault;
notes = {};
buildGrid();
renderGrid();
combo = 0;
comboEl.textContent = '';
setStatus("Loaded new song, ready to edit!");
});
playBtn.addEventListener('click', () => {
playSong();
});
clearBtn.addEventListener('click', () => {
if(confirm("Clear all notes?")) {
clearNotes();
combo = 0;
comboEl.textContent = '';
setStatus("All notes cleared.");
}
});
shareBtn.addEventListener('click', () => {
encodeChartToHash();
shareUrlInput.style.display = 'block';
shareUrlInput.value = location.href;
shareUrlInput.select();
try {
document.execCommand('copy');
setStatus("Share URL copied to clipboard.");
} catch {
setStatus("Share URL ready - copy manually.");
}
});
// --- INIT ---
decodeHash();
// Initial grid build if none decoded
if(!notes || Object.keys(notes).length === 0) {
buildGrid();
}
})();
</script>
</body>
</html>
How to use this:
- Paste your MP3 file URL (ensure CORS enabled or use a public accessible mp3) in the input.
- Set the BPM of the song.
- Press "Load & New" to reset.
- Click the grid cells to add/delete notes.
- Press "Play" to start the song and play notes.
- Notes will highlight on hit, and combo count increases.
- Keyboard shortcuts:
- Space: toggle play/stop
- Delete/Backspace: delete note on hovered cell
- C: clear all notes (with confirmation)
- Press "Share Chart" to create a URL encoding the current chart, copied to clipboard and shown in the input field below.
- Reloading the page with that URL hash will load your chart.
Notes:
- This example is quite basic and uses simple 1-note per beat resolution. You can extend to smaller note subdivisions (e.g. 8th notes) by changing
beatsPerBar or adding more cells per beat.
- The player highlights notes and lets you visually edit them.
- No advanced audio synchronization with WebAudio API, relies on the native
<audio> timing.
- The grid is 4 lanes x 4 beats per bar x N bars.
- Sharing is encoded in URL hash for easy sharing.
If you'd like me to add features such as drag selection, note velocities, custom subdivisions, or WebAudio scheduling, just ask!