Creating a basic rhythm game editor with features like loading an audio URL, playing notes, recording bars, counting rhythm, supporting shortcuts for delete and share, and using modern web technologies can be quite involved but definitely doable.
Below is a simplified example of such an editor in HTML, CSS, and JS. It includes:
Loading and playing an audio file via URL.
A timeline editor with bars and beats.
Recording notes (click to add).
Keyboard shortcuts for deleting notes and sharing the chart via URL hash.
Displaying current bar count and rhythm.
Simple play/pause controls.
You can extend this with more features and polish as needed.
Rhythm Game Editor (Simplified)
html Copy 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;
margin: 0; padding: 0; background: #111; color: #eee;
display: flex; flex-direction: column; align-items: center;
}
#audioUrl {
width: 80%;
margin: 10px 0;
padding: 8px;
font-size: 16px;
}
#controls {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
#playBtn, #pauseBtn, #recordBtn {
padding: 6px 12px;
font-size: 16px;
cursor: pointer;
background: #222;
border: 1px solid #666;
color: #eee;
border-radius: 4px;
}
#timeline {
position: relative;
width: 90%;
height: 120px;
background: #222;
margin-bottom: 20px;
border: 1px solid #555;
user-select: none;
}
.bar {
position: absolute;
top: 0; bottom: 0;
border-left: 1px solid #555;
}
.beat {
position: absolute;
top: 0; bottom: 0;
border-left: 1px solid #777;
}
.note {
position: absolute;
top: 40px;
width: 12px;
height: 40px;
background: #4caf50;
border-radius: 3px;
cursor: pointer;
transition: background 0.3s;
}
.note.selected {
background: #f44336;
}
#info {
margin-bottom: 10px;
}
#shareLink {
width: 90%;
padding: 6px;
font-family: monospace;
font-size: 12px;
}
</style>
</head>
<body>
<h1>Rhythm Game Editor</h1>
<input type="text" id="audioUrl" placeholder="Enter audio file URL and press Enter" />
<div id="controls">
<button id="playBtn">Play ▶</button>
<button id="pauseBtn" disabled>Pause ❚❚</button>
<button id="recordBtn">Record Notes</button>
</div>
<div id="info">Bars: <span id="barsCount">4</span> | Beats per bar: <span id="beatsPerBar">4</span></div>
<div id="timeline"></div>
<textarea id="shareLink" readonly placeholder="Share link will appear here..."></textarea>
<audio id="audio" crossorigin="anonymous"></audio>
<script>
(() => {
const audioUrlInput = document.getElementById('audioUrl');
const audio = document.getElementById('audio');
const playBtn = document.getElementById('playBtn');
const pauseBtn = document.getElementById('pauseBtn');
const recordBtn = document.getElementById('recordBtn');
const timeline = document.getElementById('timeline');
const barsCountElem = document.getElementById('barsCount');
const beatsPerBarElem = document.getElementById('beatsPerBar');
const shareLink = document.getElementById('shareLink');
// Configuration
let bars = 4;
let beatsPerBar = 4;
let bpm = 120;
let isRecording = false;
let notes = []; // Array of objects { time, bar, beat, id }
// Timeline dimensions
const timelineWidthPx = timeline.clientWidth;
function secondsPerBeat() {
return 60 / bpm;
}
function totalBeats() {
return bars * beatsPerBar;
}
function timelineDraw() {
timeline.innerHTML = '';
// Draw bars
for(let b = 0; b <= bars; b++){
const barDiv = document.createElement('div');
barDiv.classList.add('bar');
const leftPercent = (b / bars) * 100;
barDiv.style.left = `${leftPercent}%`;
timeline.appendChild(barDiv);
}
// Draw beats
for(let i = 0; i < totalBeats(); i++){
if(i % beatsPerBar === 0) continue; // skip bar lines
const beatDiv = document.createElement('div');
beatDiv.classList.add('beat');
const leftPercent = (i / totalBeats()) * 100;
beatDiv.style.left = `${leftPercent}%`;
timeline.appendChild(beatDiv);
}
// Draw notes
notes.forEach(n => {
const noteDiv = document.createElement('div');
noteDiv.classList.add('note');
noteDiv.style.left = `${(n.time / audio.duration) * 100}%`;
noteDiv.title = `Bar ${n.bar + 1}, Beat ${n.beat + 1}`;
noteDiv.dataset.id = n.id;
timeline.appendChild(noteDiv);
noteDiv.addEventListener('click', e => {
e.stopPropagation();
toggleNoteSelection(noteDiv, n.id);
});
});
}
// Selection
let selectedNoteId = null;
function toggleNoteSelection(noteDiv, id) {
if(selectedNoteId === id){
noteDiv.classList.remove('selected');
selectedNoteId = null;
} else {
// Deselect old
const oldNote = timeline.querySelector('.note.selected');
if(oldNote) oldNote.classList.remove('selected');
selectedNoteId = id;
noteDiv.classList.add('selected');
}
}
// Load audio from URL
audioUrlInput.addEventListener('keypress', e => {
if(e.key === 'Enter'){
loadAudioUrl(audioUrlInput.value.trim());
}
});
function loadAudioUrl(url){
audio.src = url;
audio.load();
audio.addEventListener('loadedmetadata', () => {
// Reset notes
notes = [];
selectedNoteId = null;
isRecording = false;
recordBtn.textContent = 'Record Notes';
pauseBtn.disabled = true;
playBtn.disabled = false;
timelineDraw();
updateShareLink();
}, { once: true });
}
// Play controls
playBtn.addEventListener('click', () => {
if(!audio.src) return;
audio.play();
playBtn.disabled = true;
pauseBtn.disabled = false;
});
pauseBtn.addEventListener('click', () => {
audio.pause();
pauseBtn.disabled = true;
playBtn.disabled = false;
});
audio.addEventListener('ended', () => {
pauseBtn.disabled = true;
playBtn.disabled = false;
});
// Clicking on timeline to add notes when recording
timeline.addEventListener('click', e => {
if(!isRecording || !audio.duration) return;
const rect = timeline.getBoundingClientRect();
const clickX = e.clientX - rect.left;
const clickRatio = clickX / rect.width;
const time = clickRatio * audio.duration;
// Convert time to bar and beat
const beatsElapsed = time / secondsPerBeat();
const bar = Math.floor(beatsElapsed / beatsPerBar);
const beat = Math.floor(beatsElapsed % beatsPerBar);
// Assign unique ID
const id = Date.now() + Math.random();
notes.push({ time, bar, beat, id });
timelineDraw();
updateShareLink();
});
// Record toggle
recordBtn.addEventListener('click', () => {
if(!audio.duration){
alert('Load an audio first.');
return;
}
isRecording = !isRecording;
recordBtn.textContent = isRecording ? 'Stop Recording' : 'Record Notes';
});
// Keyboard Shortcuts
window.addEventListener('keydown', e => {
if(e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
// Delete selected note
if(e.key === 'Delete' && selectedNoteId !== null){
notes = notes.filter(n => n.id !== selectedNoteId);
selectedNoteId = null;
timelineDraw();
updateShareLink();
}
// Share shortcut: Ctrl+S or Cmd+S
if((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's'){
e.preventDefault();
shareChart();
}
});
// Sharing
function shareChart(){
const data = {
audioUrl: audio.src,
bpm,
bars,
beatsPerBar,
notes
};
const json = JSON.stringify(data);
const encoded = encodeURIComponent(btoa(json));
location.hash = encoded;
shareLink.value = location.href;
alert('Chart shared in URL hash! Copy the link below.');
}
function loadFromHash(){
if(!location.hash) return;
try {
const encoded = location.hash.substring(1);
const json = atob(decodeURIComponent(encoded));
const data = JSON.parse(json);
if(data.audioUrl){
audio.src = data.audioUrl;
audio.load();
bpm = data.bpm || 120;
bars = data.bars || 4;
beatsPerBar = data.beatsPerBar || 4;
notes = data.notes || [];
barsCountElem.textContent = bars;
beatsPerBarElem.textContent = beatsPerBar;
audio.addEventListener('loadedmetadata', () => {
timelineDraw();
updateShareLink();
}, { once: true});
audioUrlInput.value = data.audioUrl;
}
}
catch(err){
console.log('Failed to load chart from hash', err);
}
}
function updateShareLink(){
if(!audio.src) {
shareLink.value = '';
return;
}
const data = {
audioUrl: audio.src,
bpm,
bars,
beatsPerBar,
notes
};
const json = JSON.stringify(data);
const encoded = encodeURIComponent(btoa(json));
shareLink.value = location.origin + location.pathname + '#/' + encoded;
}
// Initial setup
barsCountElem.textContent = bars;
beatsPerBarElem.textContent = beatsPerBar;
loadFromHash();
})();
</script>
</body>
</html>
How it works:
Paste an audio URL (must support CORS or be same origin) and hit Enter.
Audio is loaded and timeline appears with bars and beats markers.
Click "Record Notes" to enable note input mode.
Click anywhere on the timeline to add a note at that position.
Notes appear as green bars on timeline.
Click on a note to select it (turns red).
Hit Delete to delete selected note.
Use Play/Pause buttons to control audio playback.
Press Ctrl+S or Cmd+S to generate a shareable link with current chart serialized in URL hash.
Opening the page with that URL hash loads the chart again.
Notes for further improvement
Quantize note input to nearest beat.
Add BPM / bars / beatsPerBar edit controls.
Add note types or lanes.
Add scroll/zoom and snapping on timeline.
Better UI for note selection and editing.
Export/import charts in JSON or custom format.
Add support for keyboard/midi input recording.
Let me know if you want me to expand or focus on any specific aspect!