import React, { useState, useEffect, useMemo } from 'react'; import { Play, Pause, RotateCcw, Music, Zap, Waves } from 'lucide-react'; interface Note { name: string; frequency: number; phase: number; quantumState: string; } interface HarmonicSeries { fundamental: number; harmonics: number[]; ratios: string[]; } const QuantumHarmonyExplorer: React.FC = () => { const [isPlaying, setIsPlaying] = useState(false); const [selectedNote, setSelectedNote] = useState(null); const [time, setTime] = useState(0); const [showQuantumView, setShowQuantumView] = useState(false); // Musical notes and their quantum phase mappings const notes: Note[] = useMemo(() => [ { name: 'C4', frequency: 261.63, phase: 0, quantumState: '|0⟩' }, { name: 'D4', frequency: 293.66, phase: Math.PI/4, quantumState: '(|0⟩+|1⟩)/√2' }, { name: 'E4', frequency: 329.63, phase: Math.PI/2, quantumState: '|1⟩' }, { name: 'F4', frequency: 349.23, phase: 3*Math.PI/4, quantumState: '(|0⟩-|1⟩)/√2' }, { name: 'G4', frequency: 392.00, phase: Math.PI, quantumState: '|0⟩' }, { name: 'A4', frequency: 440.00, phase: 5*Math.PI/4, quantumState: '(|0⟩+i|1⟩)/√2' }, { name: 'B4', frequency: 493.88, phase: 3*Math.PI/2, quantumState: '|1⟩' }, { name: 'C5', frequency: 523.25, phase: 2*Math.PI, quantumState: '|0⟩' }, ], []); // Calculate harmonic series for fundamental frequency const harmonicSeries: HarmonicSeries = useMemo(() => { if (!selectedNote) return { fundamental: 0, harmonics: [], ratios: [] }; const fundamental = selectedNote.frequency; const harmonics = Array.from({ length: 8 }, (_, i) => fundamental * (i + 1)); const ratios = harmonics.map((h, i) => `${i + 1}:1`); return { fundamental, harmonics, ratios }; }, [selectedNote]); // Animation loop useEffect(() => { let animationFrame: number; if (isPlaying) { const animate = () => { setTime(prev => prev + 0.016); // ~60fps animationFrame = requestAnimationFrame(animate); }; animationFrame = requestAnimationFrame(animate); } return () => { if (animationFrame) cancelAnimationFrame(animationFrame); }; }, [isPlaying]); const calculateWaveAmplitude = (frequency: number, t: number, phase: number = 0): number => { return Math.sin(2 * Math.PI * frequency * t / 100 + phase) * 0.3; }; const getConsonanceColor = (ratio: number): string => { // Color based on harmonic consonance ratios if (ratio === 1) return 'rgb(59, 130, 246)'; // Perfect unison - blue if (Math.abs(ratio - 2) < 0.1) return 'rgb(16, 185, 129)'; // Octave - green if (Math.abs(ratio - 1.5) < 0.1) return 'rgb(245, 158, 11)'; // Perfect fifth - amber if (Math.abs(ratio - 4/3) < 0.1) return 'rgb(168, 85, 247)'; // Perfect fourth - purple if (Math.abs(ratio - 5/4) < 0.1) return 'rgb(236, 72, 153)'; // Major third - pink return 'rgb(156, 163, 175)'; // Other intervals - gray }; const renderWaveform = (note: Note, index: number) => { const points = Array.from({ length: 200 }, (_, i) => { const x = i * 2; const y = 100 + calculateWaveAmplitude(note.frequency, time + i, note.phase) * 80; return `${x},${y}`; }).join(' '); return ( {note.name} - {note.frequency.toFixed(1)}Hz {showQuantumView && ( φ = {note.phase.toFixed(2)} | {note.quantumState} )} ); }; const renderHarmonicSpectrum = () => { if (!selectedNote) return null; return (

Harmonic Series Analysis

{harmonicSeries.harmonics.slice(0, 8).map((freq, i) => (
{i + 1}
{freq.toFixed(0)}Hz
{harmonicSeries.ratios[i]}
))}

Quantum Phase Relationship: Each harmonic corresponds to a different quantum phase state.

Consonance Theory: Simple ratios (2:1, 3:2, 4:3) create more consonant harmonies and more stable quantum interference patterns.

); }; return (

Quantum-Musical Harmony Explorer

Explore the fascinating mathematical connections between musical harmony and quantum mechanics. While not a practical quantum computer, this demonstrates real relationships between wave physics, harmonic ratios, and quantum phase states.

{/* Controls */}
{/* Note Selection */}
{notes.map((note) => ( ))}
{/* Waveform Display */}

Wave Interference Patterns

{notes.slice(0, 4).map((note, index) => renderWaveform(note, index))}

Scientific Connection:

Musical waves and quantum wave functions both follow wave equations. The phase relationships in harmony (consonance/dissonance) mirror constructive/destructive interference in quantum systems. However, actual quantum computers require precise control at the atomic level, not just wave mathematics.

{/* Harmonic Analysis */} {selectedNote && renderHarmonicSpectrum()} {/* Educational Information */}

Real Science vs Speculation

✅ Real Connections

  • • Wave equations govern both sound and quantum mechanics
  • • Phase relationships are fundamental to both domains
  • • Harmonic ratios relate to frequency relationships
  • • Interference patterns follow similar mathematics
  • • Fourier transforms are used in both music and quantum computing

⚠️ Current Limitations

  • • Quantum computers require atomic-scale precision
  • • Decoherence is caused by environmental interactions, not musical dissonance
  • • Current systems need extreme cooling for isolation
  • • Musical harmony alone cannot create quantum entanglement
  • • Scaling quantum systems remains an engineering challenge
); }; export default QuantumHarmonyExplorer;