Clef Karaoke Player - Midi

.player background: #0f0f1a; border-radius: 20px; padding: 20px; box-shadow: inset 0 1px 3px rgba(255,255,255,0.1), 0 10px 20px rgba(0,0,0,0.5);

initEventListeners() document.getElementById('midiFileInput').addEventListener('change', (e) => this.loadMIDI(e)); document.getElementById('playBtn').addEventListener('click', () => this.play()); document.getElementById('pauseBtn').addEventListener('click', () => this.pause()); document.getElementById('stopBtn').addEventListener('click', () => this.stop());

detectClef() if (!this.notes.length) return; // Calculate average pitch const avgPitch = this.notes.reduce((sum, n) => sum + n.pitch, 0) / this.notes.length; // MIDI note 60 = middle C // Treble clef typically for notes > 60, Bass clef for notes < 60 if (avgPitch > 62) this.clef = 'treble'; else if (avgPitch < 58) this.clef = 'bass'; else // Mixed - check range const highNotes = this.notes.filter(n => n.pitch > 64).length; const lowNotes = this.notes.filter(n => n.pitch < 56).length; this.clef = highNotes > lowNotes ? 'treble' : 'bass'; document.getElementById('clefIndicator').innerHTML = `Clef: $this.clef === 'treble' ? '𝄞 Treble' : '𝄢 Bass'`; midi clef karaoke player

.info color: white; text-align: center; margin-top: 15px; font-size: 14px;

button background: #e94560; color: white; border: none; padding: 12px 24px; font-size: 16px; border-radius: 50px; cursor: pointer; transition: all 0.3s ease; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.2); (performance

.controls display: flex; gap: 15px; margin-bottom: 20px; flex-wrap: wrap; justify-content: center;

drawStaff() this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); const staffTop = 50; const staffBottom = 250; const lineSpacing = 25; // Draw 5 staff lines this.ctx.beginPath(); this.ctx.strokeStyle = '#333'; this.ctx.lineWidth = 1.5; for (let i = 0; i < 5; i++) const y = staffTop + (i * lineSpacing); this.ctx.moveTo(50, y); this.ctx.lineTo(this.canvas.width - 50, y); this.ctx.stroke(); // Draw clef this.ctx.font = 'bold 60px "Segoe UI", "Arial"'; this.ctx.fillStyle = '#e94560'; if (this.clef === 'treble') this.ctx.fillText('𝄞', 20, staffTop + 100); else this.ctx.fillText('𝄢', 20, staffTop + 100); // Draw notes based on current scroll offset const currentTime = this.isPlaying ? (performance.now() - this.startTime) / 1000 : this.currentPauseTime; const visibleTimeRange = 4; // seconds visible const pixelsPerSecond = (this.canvas.width - 100) / visibleTimeRange; this.notes.forEach(note => const noteTime = note.startTime; const x = 80 + (noteTime - currentTime) * pixelsPerSecond; if (x > 30 && x < this.canvas.width - 30) const midiPitch = note.pitch; const staffPosition = this.midiToStaffY(midiPitch); if (staffPosition !== null) this.drawNote(x, staffPosition, note.duration * pixelsPerSecond); ); // Draw current time marker this.ctx.beginPath(); this.ctx.strokeStyle = '#ff0000'; this.ctx.lineWidth = 2; this.ctx.moveTo(80, 20); this.ctx.lineTo(80, this.canvas.height - 20); this.ctx.stroke(); if (this.isPlaying) this.animationId = requestAnimationFrame(() => this.drawStaff()); const visibleTimeRange = 4

.lyrics background: rgba(0,0,0,0.7); color: #ffd700; padding: 15px; border-radius: 15px; text-align: center; font-size: 20px; font-weight: bold; margin-top: 15px; font-family: monospace;

.staff-container background: #fff9e8; border-radius: 15px; padding: 20px; margin-bottom: 20px; overflow-x: auto; position: relative; box-shadow: inset 0 0 10px rgba(0,0,0,0.1);

pause() if (this.isPlaying) this.isPlaying = false; this.currentPauseTime = (performance.now() - this.startTime) / 1000; MIDI.stopAllNotes();

button:active transform: translateY(0);