It sounds like you want to create a simple web-based rhythm game editor with the following features:
- Load an MP3 file via URL
- Set BPM (beats per minute)
- Show bars & beats (a grid)
- Allow marking combo notes on the grid
- Support deleting notes
- Sharing the current editor state via URL hash (
#/...)
- Keyboard shortcuts for ease of editing
Below is a minimal but functional example using HTML/CSS/JS that demonstrates these features. It uses the hash portion of the URL to encode/load the editor state (mp3 URL, BPM, bars count, and combo note positions).
Features implemented in this example:
- Input for MP3 URL and BPM
- Setting number of bars and beats per bar (default 4 beats)
- A grid representing bars x beats, click cells to toggle "combo note"
- Display combo notes in grid cells
- Keyboard shortcuts on grid:
Delete to clear selected note
- Arrows to move selection
- Space to toggle combo on selected cell
- State is serialized into a compact JSON string and encoded in the URL hash so you can share/edit state by copying URL
- Loads MP3 as an
<audio> element to play (with simple play/pause button)
How share works
The URL hash encodes a compressed JSON with all parameters:
{
"mp3": "https://....mp3",
"bpm": 120,
"bars": 4,
"notes": [{bar:1, beat:2}, ...]
}
The editor loads that on page load and update hash on any state change.
Code
<!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: Arial, sans-serif; background:#222; color:#eee; margin:0; padding:1rem; }
label { display:block; margin:0.5rem 0 0.2rem; }
input[type=text], input[type=number] { width: 100%; max-width: 400px; padding: 0.3rem; font-size: 1rem; }
#controls { max-width: 420px; margin-bottom: 1rem; }
#grid {
display: grid;
gap: 2px;
background:#444;
max-width: 600px;
user-select:none;
}
.cell {
width: 40px; height: 40px;
background:#333;
border-radius:4px;
display:flex;
justify-content: center;
align-items: center;
cursor: pointer;
font-weight: bold;
font-size: 14px;
color:#ccc;
transition: background 0.2s;
}
.cell.combo {
background: #4caf50;
color: #000;
}
.cell.selected {
outline: 2px solid #ff9800;
outline-offset: -2px;
}
#audio-controls {
margin-top: 1rem;
display: flex;
align-items: center;
gap: 1rem;
}
button {
background:#ff9800;
border:none;
color:black;
padding:0.5rem 1rem;
font-weight:bold;
cursor:pointer;
border-radius:4px;
}
button:disabled {
background:#888;
cursor:not-allowed;
}
small { color: #aaa; }
</style>
</head>
<body>
<h1>Rhythm Game Editor</h1>
<div id="controls">
<label for="mp3-url">MP3 URL</label>
<input type="text" id="mp3-url" placeholder="https://example.com/song.mp3" list="exampleUrls" />
<datalist id="exampleUrls">
<option value="https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3"></option>
</datalist>
<label for="bpm">BPM</label>
<input type="number" id="bpm" min="20" max="300" value="120" />
<label for="bars">Bars</label>
<input type="number" id="bars" min="1" max="32" value="4" />
<small>Click grid cells to toggle combo notes. Keyboard shortcuts: ↑↓←→ to move, SPACE to toggle note, DEL to delete.</small>
</div>
<div id="grid" tabindex="0" aria-label="Rhythm grid" role="grid"></div>
<div id="audio-controls">
<button id="play-pause" disabled>Play</button>
<audio id="audio" crossorigin="anonymous"></audio>
<span id="current-status"></span>
</div>
<script>
(() => {
const mp3Input = document.getElementById("mp3-url");
const bpmInput = document.getElementById("bpm");
const barsInput = document.getElementById("bars");
const gridEl = document.getElementById("grid");
const audio = document.getElementById("audio");
const playPauseBtn = document.getElementById("play-pause");
const statusSpan = document.getElementById("current-status");
let state = {
mp3: '',
bpm: 120,
bars: 4,
beatsPerBar: 4,
notes: [], // {bar: int, beat: int}
};
// Selection coords in grid
let selected = {bar: 1, beat: 1};
// Helper: serialize state as JSON, encode to URI component & base64
function serializeState() {
try {
const json = JSON.stringify(state);
return btoa(encodeURIComponent(json));
} catch(e) {
return "";
}
}
// Decode from hash string back to state object
function deserializeState(str) {
try {
const json = decodeURIComponent(atob(str));
return JSON.parse(json);
} catch(e) {
return null;
}
}
// Save state to URL hash
function updateHash() {
const s = serializeState();
if (s) {
location.hash = "#/" + s;
}
}
// Load state from URL hash (if exists)
function loadFromHash() {
if (location.hash.startsWith("#/")) {
const s = location.hash.slice(2);
const st = deserializeState(s);
if (st && st.mp3 !== undefined && st.bpm !== undefined && st.bars !== undefined && st.notes !== undefined) {
state = Object.assign({}, state, st);
return true;
}
}
return false;
}
function clampSelection() {
if (selected.bar < 1) selected.bar = 1;
if (selected.bar > state.bars) selected.bar = state.bars;
if (selected.beat < 1) selected.beat = 1;
if (selected.beat > state.beatsPerBar) selected.beat = state.beatsPerBar;
}
// Whether a note exists at bar/beat
function noteExists(bar, beat) {
return state.notes.some(n => n.bar === bar && n.beat === beat);
}
// Add note
function addNote(bar, beat) {
if (!noteExists(bar, beat)) {
state.notes.push({bar, beat});
sortNotes();
}
}
// Remove note
function removeNote(bar, beat) {
state.notes = state.notes.filter(n => !(n.bar === bar && n.beat === beat));
}
// Sort notes by bar then beat (for nice ordering)
function sortNotes() {
state.notes.sort((a, b) => (a.bar - b.bar) || (a.beat - b.beat));
}
// Render grid cells
function renderGrid() {
gridEl.innerHTML = '';
const totalCells = state.bars * state.beatsPerBar;
gridEl.style.gridTemplateColumns = `repeat(${state.beatsPerBar}, 40px)`;
gridEl.setAttribute("aria-rowcount", state.bars);
gridEl.setAttribute("aria-colcount", state.beatsPerBar);
for(let bar = 1; bar <= state.bars; bar++) {
for(let beat = 1; beat <= state.beatsPerBar; beat++) {
const cell = document.createElement("div");
cell.className = "cell";
cell.dataset.bar = bar;
cell.dataset.beat = beat;
cell.setAttribute("role", "gridcell");
cell.setAttribute("aria-label", `Bar ${bar}, Beat ${beat}`);
if (noteExists(bar, beat)) {
cell.classList.add("combo");
cell.textContent = "★";
} else {
cell.textContent = "";
}
if (selected.bar === bar && selected.beat === beat) {
cell.classList.add("selected");
cell.setAttribute("aria-selected", "true");
} else {
cell.setAttribute("aria-selected", "false");
}
cell.addEventListener("click", () => {
toggleCombo(bar, beat);
selected.bar = bar;
selected.beat = beat;
renderGrid();
updateHash();
});
gridEl.appendChild(cell);
}
}
}
function toggleCombo(bar, beat) {
if (noteExists(bar, beat)) {
removeNote(bar, beat);
} else {
addNote(bar, beat);
}
}
// Load audio from URL and enable controls
function loadAudio() {
if (state.mp3.trim()) {
audio.src = state.mp3.trim();
audio.load();
playPauseBtn.disabled = false;
statusSpan.textContent = "";
} else {
audio.src = "";
playPauseBtn.disabled = true;
statusSpan.textContent = "No MP3 URL";
}
}
// Update status display
function updateStatus() {
if (audio.paused) {
statusSpan.textContent = "Paused";
} else {
statusSpan.textContent = `Playing ${audio.currentTime.toFixed(1)}s`;
}
}
// Hook inputs
mp3Input.addEventListener("change", () => {
state.mp3 = mp3Input.value.trim();
loadAudio();
updateHash();
});
bpmInput.addEventListener("change", () => {
let val = parseInt(bpmInput.value);
if (isNaN(val) || val < 20) val = 20;
if (val > 300) val = 300;
bpmInput.value = val;
state.bpm = val;
updateHash();
});
barsInput.addEventListener("change", () => {
let val = parseInt(barsInput.value);
if (isNaN(val) || val < 1) val = 1;
if (val > 32) val = 32;
barsInput.value = val;
state.bars = val;
// Remove notes out of range when bars decrease
state.notes = state.notes.filter(n => n.bar <= val);
// Clamp selection
if(selected.bar > val) selected.bar = val;
renderGrid();
updateHash();
});
playPauseBtn.addEventListener("click", () => {
if (audio.paused) audio.play();
else audio.pause();
});
audio.addEventListener("play", updateStatus);
audio.addEventListener("pause", updateStatus);
audio.addEventListener("timeupdate", updateStatus);
audio.addEventListener("ended", () => {
playPauseBtn.textContent = "Play";
updateStatus();
});
audio.addEventListener("play", () => playPauseBtn.textContent = "Pause");
audio.addEventListener("pause", () => playPauseBtn.textContent = "Play");
// Keyboard navigation for grid
gridEl.addEventListener("keydown", e => {
const {bar, beat} = selected;
let handled = false;
switch(e.key) {
case "ArrowUp":
selected.bar = bar > 1 ? bar - 1 : bar;
handled = true;
break;
case "ArrowDown":
selected.bar = bar < state.bars ? bar + 1 : bar;
handled = true;
break;
case "ArrowLeft":
selected.beat = beat > 1 ? beat - 1 : beat;
handled = true;
break;
case "ArrowRight":
selected.beat = beat < state.beatsPerBar ? beat + 1 : beat;
handled = true;
break;
case " ":
case "Spacebar": // for older browsers
toggleCombo(selected.bar, selected.beat);
updateHash();
handled = true;
break;
case "Delete":
case "Backspace":
removeNote(selected.bar, selected.beat);
updateHash();
handled = true;
break;
}
if (handled) {
clampSelection();
renderGrid();
e.preventDefault();
}
});
// Initialize inputs and grid from state
function init() {
if (!loadFromHash()) {
// Defaults if no hash
state = {
mp3: "",
bpm: 120,
bars: 4,
beatsPerBar: 4,
notes: [],
};
}
mp3Input.value = state.mp3;
bpmInput.value = state.bpm;
barsInput.value = state.bars;
clampSelection();
loadAudio();
renderGrid();
}
// Update URL hash when user interacts with grid or inputs already handled on change
// Initial load
init();
// Save state when page is unloaded (optional)
window.addEventListener("beforeunload", () => {
updateHash();
});
// Focus grid by default for keyboard shortcuts
gridEl.focus();
})();
</script>
</body>
</html>
Usage:
- Enter a direct MP3 URL (must allow CORS, e.g. some file hosting or public URLs).
- Set BPM and bars count.
- Click grid cells or use keyboard to toggle combo notes.
- The URL hash will update automatically — copy/paste URL will reload your edits.
- Use space to toggle note at selected cell, arrow keys to move selection, delete to remove notes.
- Press Play to listen to audio.
This is a base foundation you can extend:
- Add timing overlay with milliseconds based on BPM
- Add different note types/colors
- Export chart data
- Playback sync with notes lighting up
- Save to localStorage
But hopefully this meets your original requirements as a neat shareable rhythm game editor! Let me know if you want help adding more features or refactoring.