1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[73024],{1628:(e,t,r)=>{"use strict";r.d(t,{B:()=>o,J:()=>i});var l=r(95155),n=r(12115),a=r(46482);let s=(0,n.createContext)(null),o=e=>{let{children:t}=e,[r,o]=(0,n.useState)(!1);return(0,n.useEffect)(()=>(a.o.initialize(),a.o.loadVolumeSettings(),()=>{a.o.cleanup()}),[]),(0,l.jsx)(s.Provider,{value:{playCorrect:()=>a.o.playCorrect(),playWrong:()=>a.o.playWrong(),playBadge:()=>a.o.playBadge(),playComplete:()=>a.o.playComplete(),setUIVolume:e=>a.o.setUIVolume(e),setMusicVolume:e=>a.o.setMusicVolume(e),setExerciseVolume:e=>a.o.setMusicVolume(e),setUserVolume:e=>a.o.setMusicVolume(e),getUIVolume:()=>a.o.getUIVolume(),getMusicVolume:()=>a.o.getMusicVolume(),getExerciseVolume:()=>a.o.getMusicVolume(),getUserVolume:()=>a.o.getMusicVolume(),isVolumeControlOpen:r,setVolumeControlOpen:o},children:t})},i=()=>{let e=(0,n.useContext)(s);if(!e)throw Error("useSoundEffects must be used within a SoundEffectsProvider");return e}},68368:(e,t,r)=>{"use strict";r.d(t,{g:()=>n});var l=r(12115);function n(e){let{bpm:t,beatsPerMeasure:r=4,enabled:n,onBeat:a,backbeatOnly:s=!1}=e,[o,i]=(0,l.useState)(!1),[c,u]=(0,l.useState)(0),d=(0,l.useRef)(null),h=(0,l.useRef)(0),f=(0,l.useRef)(null),p=(0,l.useRef)(0);(0,l.useEffect)(()=>(d.current=new(window.AudioContext||window.webkitAudioContext),()=>{d.current&&d.current.close()}),[]);let m=(0,l.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!d.current)return;let r=d.current,l=r.createOscillator(),n=r.createGain();l.connect(n),n.connect(r.destination),l.frequency.value=t?1200:800,l.type="sine",n.gain.setValueAtTime(0,e),n.gain.linearRampToValueAtTime(t?.3:.15,e+.005),n.gain.exponentialRampToValueAtTime(.001,e+.08),l.start(e),l.stop(e+.1)},[]),x=(0,l.useCallback)(()=>{if(!d.current||!o)return;let e=d.current.currentTime;for(;h.current<e+.1;){let l=h.current,n=p.current,o=(n-1)%r+1,i=2===o||4===o,c=1===o;(!s||i)&&m(l,c&&!s),a&&setTimeout(()=>{a(n),u(n)},Math.max(0,(l-e-.02)*1e3));let d=60/t;h.current+=d,p.current+=1}},[t,r,o,m,a,s]),g=(0,l.useCallback)(()=>{d.current&&!o&&("suspended"===d.current.state&&d.current.resume(),p.current=1,h.current=d.current.currentTime,i(!0))},[o]),b=(0,l.useCallback)(()=>{i(!1),f.current&&(clearInterval(f.current),f.current=null),p.current=1,u(0)},[]);return(0,l.useEffect)(()=>(o&&n?(x(),f.current=window.setInterval(x,25)):f.current&&(clearInterval(f.current),f.current=null),()=>{f.current&&clearInterval(f.current)}),[o,n,x]),(0,l.useEffect)(()=>{!n&&o&&b()},[n,o,b]),{isPlaying:o,start:g,stop:b,currentBeat:c}}},51569:(e,t,r)=>{"use strict";r.d(t,{B:()=>n});var l=r(12115);let n=e=>{let{onSpacebar:t,disabled:r=!1}=e,n=(0,l.useCallback)(e=>{r||"Space"!==e.code||(e.preventDefault(),t())},[t,r]);(0,l.useEffect)(()=>(window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)),[n])}},3115:(e,t,r)=>{"use strict";r.d(t,{Z:()=>n});var l=r(12115);let n=e=>{let[t,r]=(0,l.useState)(null),[n,a]=(0,l.useState)([]),[s,o]=(0,l.useState)(null),[i,c]=(0,l.useState)(null),u=(0,l.useCallback)(t=>{let r=t.data,l=r[0],n=r[1],a=r[2];e&&((240&l)==144&&a>0?e(n,!0):((240&l)==128||(240&l)==144&&0===a)&&e(n,!1))},[e]);return(0,l.useEffect)(()=>{if(!navigator.requestMIDIAccess){c("WebMIDI is not supported in this browser");return}let e=!0;return navigator.requestMIDIAccess().then(t=>{if(!e)return;r(t);let l=Array.from(t.inputs.values());a(l),l.length>0&&o(l[0]),t.onstatechange=()=>{let e=Array.from(t.inputs.values());a(e),o(t=>t&&e.find(e=>e.id===t.id)?t:e.length>0?e[0]:null)}}).catch(t=>{e&&c("Failed to access MIDI devices: ".concat(t.message))}),()=>{e=!1,t&&(t.onstatechange=null)}},[]),(0,l.useEffect)(()=>(n.forEach(e=>{e.onmidimessage=null}),s&&(s.onmidimessage=u),()=>{s&&(s.onmidimessage=null)}),[s,u]),{midiInputs:n,selectedInput:s,setSelectedInput:o,error:i}}},79469:(e,t,r)=>{"use strict";r.d(t,{u:()=>a});var l=r(95155),n=r(21567);function a(e){let{className:t,...r}=e;return(0,l.jsx)("kbd",{"data-slot":"kbd",className:(0,n.cn)("bg-muted text-muted-foreground pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm px-1 font-sans text-xs font-medium","[&_svg:not([class*='size-'])]:size-3","[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10",t),...r})}},73024:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>ek});var l=r(95155),n=r(12115),a=r(25683),s=r(2178),o=r(43226),i=r(79469),c=r(11536),u=r(89227),d=r(46482),h=r(81798);class f{normalizeNote(e){var t;let r=null!==(t=h.L7.midi(e))&&void 0!==t?t:/\d/.test(e)?null:h.L7.midi("".concat(e,"4"));if(null===r)return e;if(e.includes("##")||e.includes("bb")||e.includes("x")){let t=h.L7.fromMidi(r);return null!=t?t:e}return e}playNote(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],l=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=this.normalizeNote(e),a=t*(l?d.o.getUserVolume():d.o.getExerciseVolume());r&&(a=Math.min(a,.3));let s=u.JD.playNoteWithId?u.JD.playNoteWithId(n,a):null;if(s&&s.howl&&"number"==typeof s.id){let e=s.noteKey||n,t=this.activeNoteIds.get(e)||[];t.push({howl:s.howl,id:s.id}),this.activeNoteIds.set(e,t)}else u.JD.playNote(n,a)}fadeOutNote(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3,r=this.normalizeNote(e),l=this.activeNoteIds.get(r);if(!l||0===l.length)return;let n=this.fadeIntervals.get(r);
1n&&(clearTimeout(n),this.fadeIntervals.delete(r));let a=Math.max(t,100),s=[...l];try{s.forEach(e=>{let{howl:t,id:r}=e;if("function"==typeof t.fade){var l,n;let e=null!==(n=null===(l=t.volume)||void 0===l?void 0:l.call(t,r))&&void 0!==n?n:.3;e>.01&&t.fade(e,0,a,r)}})}finally{let e=setTimeout(()=>{s.forEach(e=>{let{howl:t,id:r}=e;try{var l,n;(null!==(n=null===(l=t.volume)||void 0===l?void 0:l.call(t,r))&&void 0!==n?n:0)<.01&&t.stop(r)}catch(e){}}),this.activeNoteIds.delete(r),this.fadeIntervals.delete(r)},a+50);this.fadeIntervals.set(r,e)}}stopAllSounds(){this.fadeIntervals.forEach(e=>clearInterval(e)),this.fadeIntervals.clear(),this.activeNoteIds.forEach(e=>{e.forEach(e=>{let{howl:t,id:r}=e;try{t.stop(r)}catch(e){}})}),this.activeNoteIds.clear(),u.JD.stopAllSounds()}stopNote(e){let t=this.normalizeNote(e),r=this.fadeIntervals.get(t);r&&(clearInterval(r),this.fadeIntervals.delete(t));let l=this.activeNoteIds.get(t);l&&(l.forEach(e=>{let{howl:t,id:r}=e;try{t.stop(r)}catch(e){}}),this.activeNoteIds.delete(t))}cleanup(){this.stopAllSounds()}playNoteSequence(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:500,l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=l*(n?d.o.getUserVolume():d.o.getExerciseVolume()),s=e.map(e=>this.normalizeNote(e));if(t)s.forEach(e=>this.playNote(e,a));else{let e=t=>{t>=s.length||(this.playNote(s[t],a),setTimeout(()=>e(t+1),r))};e(0)}}async waitForLoad(){return u.JD.waitForLoad()}constructor(){this.activeNoteIds=new Map,this.fadeIntervals=new Map}}let p=new f;var m=r(68368);let x={C:0,"C#":1,D:2,"D#":3,E:4,F:5,"F#":6,G:7,"G#":8,A:9,"A#":10,B:11},g=Object.fromEntries(Object.entries(x).map(e=>{let[t,r]=e;return[r,t]})),b=e=>{let t=Math.floor(e/12)-1,r=g[e%12]||"";return"".concat(r).concat(t)},v=["A","S","D","F","G","H","J","K","L"],y={1:"W",3:"E",6:"T",8:"Y",10:"U"},w=e=>{let{firstNote:t="C2",lastNote:r="B5",onPlayNote:a,disabled:s=!1,showKeyboardShortcuts:o=!1,keyboardOctave:c=4}=e,[u,d]=(0,n.useState)(new Set),h=e=>{let t=e.match(/^([A-G]#?)(\d)$/);if(!t)throw Error("Invalid note format: ".concat(e));return{noteName:t[1],octave:parseInt(t[2])}},f=h(t),p=h(r),m=(f.octave+1)*12+x[f.noteName],g=(p.octave+1)*12+x[p.noteName],w=e=>{!s&&a&&(d(t=>new Set(t).add(e)),a(e),setTimeout(()=>{d(t=>{let r=new Set(t);return r.delete(e),r})},200))},N=e=>[1,3,6,8,10].includes(e%12),j=e=>({1:.7,3:1.7,6:3.75,8:4.75,10:5.75})[e%12]||0,k=[];for(let e=f.octave;e<=p.octave;e++)k.push(e);let C=[],E=[];for(let e=m;e<=g;e++)N(e)?E.push(e):C.push(e);return(0,l.jsx)("div",{className:"relative w-full h-44",role:"group","aria-label":"Piano keyboard",children:(0,l.jsxs)("div",{className:"relative w-full h-full flex rounded-lg overflow-hidden",children:[C.map((e,t)=>{let r=Math.floor(e/12)-1,n=e%12,a=u.has(e);return(0,l.jsxs)("button",{onMouseDown:()=>w(e),disabled:s,"aria-label":b(e),"aria-pressed":a,className:"\n relative flex-1 mx-[0.5px] rounded-b-lg\n transition-all duration-150 ease-out\n border-r border-l border-b-2\n bg-gradient-to-b from-white via-gray-50 to-gray-100 dark:from-slate-50 dark:via-slate-100 dark:to-slate-200\n border-gray-200 dark:border-slate-300\n shadow-[0_2px_0_rgba(0,0,0,0.08)]\n ".concat(s?"cursor-not-allowed opacity-90":a?"brightness-90 shadow-[inset_0_2px_4px_rgba(0,0,0,0.2)] translate-y-[1px]":"hover:brightness-95 active:brightness-90 active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.2)] active:translate-y-[1px]","\n "),style:{minWidth:0},children:[0===n&&(0,l.jsx)("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2",children:(0,l.jsxs)("span",{className:"text-[10px] font-mono text-slate-400 dark:text-slate-500 font-bold",children:["C",r]})}),o&&r===c&&(()=>{let e=[0,2,4,5,7,9,11].indexOf(n),t=r===c+1&&(0===n||2===n),a=0===n?7:2===n?8:-1,s=t?a:e,o=s>=0&&s<v.length?v[s]:null;return o?(0,l.jsx)("div",{className:"absolute bottom-[32px] left-1/2 -translate-x-1/2",children:(0,l.jsx)(i.u,{className:"h-4 text-[9px] min-w-4 px-1 bg-slate-200/80 dark:bg-slate-300/80 text-slate-600 dar
1k:text-slate-700",children:o})}):null})(),o&&r===c+1&&(()=>{let e=[0,2,4,5,7,9,11].indexOf(n);return 0===e?(0,l.jsx)("div",{className:"absolute bottom-[32px] left-1/2 -translate-x-1/2",children:(0,l.jsx)(i.u,{className:"h-4 text-[9px] min-w-4 px-1 bg-slate-200/80 dark:bg-slate-300/80 text-slate-600 dark:text-slate-700",children:"K"})}):1===e?(0,l.jsx)("div",{className:"absolute bottom-[32px] left-1/2 -translate-x-1/2",children:(0,l.jsx)(i.u,{className:"h-4 text-[9px] min-w-4 px-1 bg-slate-200/80 dark:bg-slate-300/80 text-slate-600 dark:text-slate-700",children:"L"})}):null})()]},e)}),(0,l.jsx)("div",{className:"absolute inset-0 flex pointer-events-none px-[0.5px]",children:E.map(e=>{let t=u.has(e),r=Math.floor(e/12)-f.octave-1,n=j(e),a=100/C.length;return(0,l.jsx)("button",{onMouseDown:()=>w(e),disabled:s,"aria-label":b(e),"aria-pressed":t,className:"\n absolute top-0 h-[65%] rounded-b-lg\n pointer-events-auto transition-all duration-150\n border border-b-2\n bg-gradient-to-b from-slate-700 via-slate-800 to-black dark:from-slate-800 dark:via-slate-900 dark:to-black\n border-black\n shadow-[0_2px_0_rgba(0,0,0,0.5),0_3px_6px_rgba(0,0,0,0.3)]\n ".concat(s?"cursor-not-allowed opacity-90":t?"brightness-125 shadow-[inset_0_2px_6px_rgba(0,0,0,0.7)]":"hover:brightness-110 active:brightness-125 active:shadow-[inset_0_2px_6px_rgba(0,0,0,0.7)]","\n "),style:{left:"".concat((7*r+n)*a,"%"),width:"".concat(.65*a,"%"),zIndex:10},children:o&&(()=>{let t=Math.floor(e/12)-1,r=e%12;return t===c&&y[r]?(0,l.jsx)("div",{className:"absolute bottom-[5px] left-1/2 -translate-x-1/2",children:(0,l.jsx)(i.u,{className:"h-4 text-[9px] bg-slate-600/80 text-slate-200",children:y[r]})}):null})()},e)})})]})})};var N=r(3115),j=r(51569),k=r(12096);let C={hasCompletedSessions:e=>t=>t.totalSessions>=e,hasStreak:e=>t=>t.currentStreak>=e,hasAccuracy:(e,t)=>r=>r.exerciseAccuracy[e]>=t,hasMasteredConcepts:(e,t)=>r=>{var l,n,a,s,o,i;return({intervals:r.masteredConcepts.intervals.length,chords:r.masteredConcepts.chords.length,scales:r.masteredConcepts.scales.length,"jazz-voicings":r.masteredConcepts.voicings.length,"harmonic-quest":(null===(l=r.masteredConcepts.harmonicQuest)||void 0===l?void 0:l.length)||0,guido:(null===(n=r.masteredConcepts.guido)||void 0===n?void 0:n.length)||0,functioneer:(null===(a=r.masteredConcepts.tonalProgressions)||void 0===a?void 0:a.length)||0,slashmaster:(null===(s=r.masteredConcepts.slashmaster)||void 0===s?void 0:s.length)||0,"hybrid-lab":(null===(o=r.masteredConcepts.hybridLab)||void 0===o?void 0:o.length)||0,polychordist:(null===(i=r.masteredConcepts.polychordist)||void 0===i?void 0:i.length)||0})[e]>=t}},E={sessionProgress:e=>t=>Math.min(t.totalSessions/e*100,100),streakProgress:e=>t=>Math.min(t.currentStreak/e*100,100),accuracyProgress:(e,t)=>r=>Math.min(r.exerciseAccuracy[e]/t*100,100)},S=[{id:"first-steps",category:"milestone",title:"First Steps",description:"Complete your first practice session",criteria:C.hasCompletedSessions(1),reward:{type:"badge",value:"beginner"}},{id:"practice-enthusiast",category:"milestone",title:"Practice Enthusiast",description:"Complete 10 practice sessions",criteria:C.hasCompletedSessions(10),reward:{type:"badge",value:"enthusiast"},progress:E.sessionProgress(10)},{id:"dedication",category:"consistency",title:"Dedication",description:"Maintain a 5-day practice streak",criteria:C.hasStreak(5),reward:{type:"feature",value:"custom-exercises"},progress:E.streakProgress(5)},{id:"interval-novice",category:"mastery",title:"Interval Novice",description:"Achieve 80% accuracy in interval recognition",criteria:C.hasAccuracy("intervals",.8),reward:{type:"badge",value:"interval-novice"},progress:E.accuracyProgress("intervals",.8)},{id:"interval-master",category:"mastery",title:"Interval Master",description:"Master all basic intervals",criteria:C.hasMasteredConcepts("intervals",8),reward:{type:"customization",value:"interval-sounds"}},{id:"chord-novice",category:"mastery",title:"Chord Novice",description:"Achieve 80% accuracy in chord recognition",criteria:C.hasAccuracy("chords",.8),reward:{type:"badge",value:"chord-novice"},progress:E.accuracyProgress("chords",.8)},{id:"chord-master",category:"mastery",title:"Chord Master",description:"Master all basic chord types",criteria:C.hasMasteredConcepts("chords",10),reward:{type:"customization",value:"chord-voicings"}},{id:"scale-novice",category:"mastery",title:"Scale Novice",description:"Achieve 80% accuracy in scale recognition",criteria:C.hasAccuracy("scales",.8),reward:{type:"badge",value:"scale-novice"},progress:E.accuracyProgress("scales",.8)},{id:"scale-master",category:"mastery",title:"Scale Master",description:"Master all basic scales",criteria:C.hasMasteredConcepts("scales",7),reward:{type:"customization",value:"scale-patterns"}},{id:"voicing-novice",category:"mastery",title:"Voicing Novice",description:"Achieve 80% accuracy in jazz voicing recognition",criteria:C.hasAccuracy("jazz-voicings",.8),reward:{type:"badge",value:"voicing-novice"},progress:E.accuracyProgress("jazz-voicings",.8)},{id:"voicing-master",category:"mastery",title:"Voicing Master",description:"Master all basic voicing types",criteria:C.hasMasteredConcepts("jazz-voicings",5),reward:{type:"customization",value:"advanced-voicings"}},{id:"explorer",category:"exploration",title:"Musical Explorer",description:"Try all exercise types",criteria:e=>Object.values(e.exerciseAccuracy).every(e=>e>0),reward:{type:"feature",value:"custom-sequences"}}],T=(e,t)=>
1{let r=S.find(t=>t.id===e);return!!r&&r.criteria(t)},A=[{id:"welcome",title:"Welcome to Practice Mode",description:"This is your space for focused skill development without pressure. Let's look at how to find the right drill.",target:".text-4xl.font-bold",position:"bottom"},{id:"exercise-types",title:"Choose Your Exercise",description:"Select from different exercise types: intervals, chords, scales, jazz voicings, or harmonic quest. Pick what you want to sharpen today.",target:".exercise-type-selector",position:"bottom"},{id:"exercise-cards",title:"Exercise Progress",description:"Each card outlines what you'll practise along with plan availability. Hover or tap for details, then jump straight into the drill.",target:".exercise-type-selector .app-card",position:"right"},{id:"locked-exercises",title:"Unlock More Content",description:"Pro-only exercises are marked with a lock. Upgrade any time to open advanced drills and keep your momentum going.",target:".exercise-type-selector .app-card.opacity-60",position:"top"}],M={intervals:[{id:"interval-input",title:"Interval Recognition",description:"Listen to the interval played and select your answer. You can replay the sound using the repeat button.",target:".interval-input",position:"bottom"}],chords:[{id:"chord-input",title:"Chord Recognition",description:"Identify the chord type being played. Pay attention to the quality and extensions.",target:".chord-input",position:"bottom"},{id:"chord-inversions",title:"Chord Inversions",description:"Practice with different chord inversions to improve your recognition of chord voicings.",target:".inversion-toggle",position:"right"}],scales:[{id:"scale-input",title:"Scale Recognition",description:"Listen to the scale and identify its type. Focus on the characteristic intervals of each scale.",target:".scale-input",position:"bottom"}],"jazz-voicings":[{id:"voicing-input",title:"Jazz Voicing Recognition",description:"Identify different jazz voicing types. Listen for the characteristic sound of each voicing style.",target:".voicing-input",position:"bottom"}],"harmonic-quest":[{id:"harmonic-quest-intro",title:"Harmonic Quest",description:"Practice harmonic recognition with step-by-step exercises. Follow the sequence and identify the correct notes.",target:".harmonic-quest-container",position:"bottom"},{id:"harmonic-quest-steps",title:"Step Navigation",description:"Navigate through steps using the controls. You can play the current step, move to the next or previous step, or play the entire sequence.",target:".harmonic-quest-controls",position:"top"},{id:"harmonic-quest-notation",title:"Sheet Music Notation",description:"The sheet music displays the current step. Try to identify the notes shown and play them on the keyboard or MIDI device.",target:".harmonic-quest-notation",position:"bottom"}]};function I(e){return M[e]||[]}function V(){let{state:e,dispatch:t}=(0,k.vU)(),{practice:r}=e,l=(0,n.useRef)(null),a=(0,n.useCallback)(e=>{t({type:"UPDATE_PRACTICE_STATS",payload:e})},[t]),s=(0,n.useCallback)(e=>{if(l.current){let{startTime:e,questionCount:t,totalAccuracy:n,exerciseType:s}=l.current,o=(Date.now()-e)/1e3;t>0&&a({focusMinutes:r.stats.focusMinutes+o/60})}let t={startTime:Date.now(),questionCount:0,totalAccuracy:0,exerciseType:e,correctCount:0,wrongCount:0};return l.current=t,a({lastUpdateTimestamp:Date.now()}),t},[r.stats,a]),o=(0,n.useCallback)(()=>{if(!l.current)return;let{startTime:e,questionCount:t,totalAccuracy:n,exerciseType:s}=l.current,o=(Date.now()-e)/1e3,i=new Date,c=r.stats.lastPracticeDate,u=!c||new Date(c).toDateString()!==i.toDateString(),d=r.stats.currentStreak;u&&(d=c&&i.getTime()-new Date(c).getTime()<1728e5?d+1:1);let h=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.3;return e*(1-r)+t*r}(r.stats.exerciseAccuracy[s]||0,t>0?n/t:0);a({totalSessions:t>0?r.stats.totalSessions+1:r.stats.totalSessions,currentStreak:d,maxStreak:Math.max(d,r.stats.maxStreak),lastPracticeDate:i,focusMinutes:r.stats.focusMinutes+o/60,exerciseAccuracy:{...r.stats.exerciseAccuracy,[s]:h}}),l.current=null},[r.stats,a]),i=(0,n.useCallback)(e=>{if(l.current||s("intervals"),!l.current)return;let t=l.current.correctCount,r=l.current.wrongCount,n=1===e?t+1:t,o=0===e?r+1:r,i={...l.current,questionCount:l.current.questionCount+1,totalAccuracy:l.current.totalAccuracy+e,correctCount:n,wrongCount:o};return l.current=i,a({lastUpdateTimestamp:Date.now()}),{correct:n,wrong:o,total:n+o,accuracy:n+o>0?Math.round(n/(n+o)*100):0}},[s,a]),c=(0,n.useCallback)(()=>
1{S.forEach(e=>{!r.stats.unlockedAchievements.includes(e.id)&&T(e.id,r.stats)&&(t({type:"UNLOCK_ACHIEVEMENT",payload:e.id}),t({type:"START_ANIMATION",payload:{type:"achievement",duration:5e3,intensity:"celebratory"}}))})},[r.stats,t]),u=(0,n.useCallback)(()=>S.map(e=>({...e,unlocked:r.stats.unlockedAchievements.includes(e.id)})),[r.stats.unlockedAchievements]),d=(0,n.useCallback)(e=>{let l=(e?[...A,...I(e)]:A).find(e=>!r.tutorial.completed.includes(e.id)&&function(e){if("undefined"==typeof document)return!1;let t=document.querySelector(e.target);if(!t)return!1;let r=t.getBoundingClientRect();return r.width>0&&r.height>0}(e));l&&t({type:"SET_CURRENT_TUTORIAL_STEP",payload:l.id})},[r.tutorial.completed,t]),h=(0,n.useCallback)(()=>[...A,...Object.values(I).flat()].find(e=>e.id===r.tutorial.current)||null,[r.tutorial.current]),f=(0,n.useCallback)(e=>{t({type:"COMPLETE_TUTORIAL_STEP",payload:e})},[t]),p=(0,n.useCallback)(()=>{t({type:"SKIP_TUTORIAL"})},[t]);return(0,n.useEffect)(()=>{c()},[r.stats,c]),{stats:r.stats,updateStats:a,startSession:s,endSession:o,recordAttempt:i,currentSession:l,achievements:u(),checkAchievements:c,currentAnimation:r.currentAnimation,clearAnimation:()=>t({type:"CLEAR_ANIMATION"}),tutorial:r.tutorial,startTutorial:d,getCurrentTutorialStep:h,completeTutorialStep:f,skipTutorial:p,dispatch:t}}var q=r(75556),P=r(2496),D=r(32528);let F={C:0,D:2,E:4,F:5,G:7,A:9,B:11};function R(e){var t,r,l,n,a,s,o,i;let c=e.querySelector("pitch");if(!c)return -1;let u=null!==(a=null===(r=c.querySelector("step"))||void 0===r?void 0:null===(t=r.textContent)||void 0===t?void 0:t.trim())&&void 0!==a?a:"C",d=parseInt(null!==(s=null===(l=c.querySelector("alter"))||void 0===l?void 0:l.textContent)&&void 0!==s?s:"0",10)||0;return((parseInt(null!==(o=null===(n=c.querySelector("octave"))||void 0===n?void 0:n.textContent)&&void 0!==o?o:"4",10)||4)+1)*12+(null!==(i=F[u])&&void 0!==i?i:0)+d}function B(e,t){for(let n of Array.from(e.children)){var r,l;if(n.tagName===t)return null!==(l=null===(r=n.textContent)||void 0===r?void 0:r.trim())&&void 0!==l?l:null}return null}function L(e,t){return Array.from(e.children).some(e=>e.tagName===t)}let O=[[6,"whole",1],[4,"whole",0],[3,"half",1],[2,"half",0],[1.5,"quarter",1],[1,"quarter",0],[.75,"eighth",1],[.5,"eighth",0],[.375,"16th",1],[.25,"16th",0],[.125,"32nd",0]],_={6:[0,4,7,9],m6:[0,3,7,9],maj7:[0,4,7,11],7:[0,4,7,10],"7b5":[0,4,6,10],dim7:[0,3,6,9],m7:[0,3,7,10],m7b5:[0,3,6,10],maj:[0,4,7],min:[0,3,7],dim:[0,3,6],aug:[0,4,8]},G=["dim7","6","m6","maj7","7","7b5","m7","m7b5","maj","min","dim","aug"],z={6:"6",m6:"m6",maj7:"maj7",7:"7","7b5":"7b5",dim7:"dim7",m7:"m7",m7b5:"m7b5",maj:"",min:"m",dim:"dim",aug:"aug"},H={C:0,D:2,E:4,F:5,G:7,A:9,B:11},U=/^([A-G])(#{1,2}|b{1,2}|x)?(-?\d)$/;function W(e){let t=e.trim().match(U);if(!t)return null;let[,r,l="",n]=t,a=0;for(let e of l)"#"===e?a+=1:"b"===e?a-=1:"x"===e&&(a+=2);let s=parseInt(n,10),o=((H[r]+a)%12+12)%12,i=(s+1)*12+H[r]+a;return{letter:r,alter:a,octave:s,midi:i,pc:o}}function K(e,t,r){let l=new Set(_[r].map(e=>(t+e)%12));for(let t of e)if(!l.has(t))return!1;return!0}var Q=r(46724),X=r(11555),$=r(49711),Y=r(58803),Z=r.n(Y),J=r(58604);let ee="59,130,246",et="rgb(".concat(ee,")"),er="transform 380ms cubic-bezier(0.2, 0.8, 0.2, 1), left 380ms cubic-bezier(0.2, 0.8, 0.2, 1)",el=(0,n.forwardRef)(function(e,t){let{xmlInput:r,currentStepIndex:a=0,followPlayhead:s=!1,showPlayhead:o=!1,width:i=800,height:c=300,onOSMDReady:u}=e,d=(0,n.useRef)(null),h=(0,n.useRef)(null),f=(0,n.useRef)(null),p=(0,n.useRef)(null),m=(0,n.useRef)(null),x=(0,n.useRef)([]),g=(0,n.useRef)(null),b=(0,n.useRef)(new Map),[v,y]=(0,n.useState)(!0),[w,N]=(0,n.useState)(null),[j,k]=(0,n.useState)(c),[C,E]=(0,n.useState)(c),[S,T]=(0,n.use
1State)(i),A=(0,n.useRef)(i),[M,I]=(0,n.useState)(0),V=(0,n.useRef)(0),[q,P]=(0,n.useState)({x:28,y:22}),D=(0,n.useRef)({x:28,y:22}),F=(0,n.useCallback)(()=>{var e;let t=(null===(e=d.current)||void 0===e?void 0:e.clientWidth)||i;return A.current=t,T(t),t},[i]),R=(0,n.useCallback)(e=>{let t=h.current,r=e.graphic;if(!t||!r||!r.MeasureList)return[];let l=t.getBoundingClientRect(),n=[];for(let e of r.MeasureList){let t=null==e?void 0:e[0];if(null==t?void 0:t.staffEntries)for(let e of t.staffEntries){var a,s,o,i;let t=null==e?void 0:null===(o=e.graphicalVoiceEntries)||void 0===o?void 0:null===(s=o[0])||void 0===s?void 0:null===(a=s.notes)||void 0===a?void 0:a[0],r=null==t?void 0:null===(i=t.getSVGGElement)||void 0===i?void 0:i.call(t);if(!r)continue;let c=r.getBoundingClientRect();n.push(c.left-l.left+c.width/2)}}return n},[]),B=(0,n.useCallback)(()=>(D.current.x+V.current+A.current)/2,[]),L=(0,n.useCallback)((e,t)=>{let r=h.current;if(!r)return;let l=D.current.x,n=Math.min(V.current>0?V.current-12:0,Math.round(B()-l-e));r.style.transition=t?er:"none",r.style.transform="translateX(".concat(n,"px)");let a=p.current;a&&(a.style.transition=t?er:"none",a.style.left="".concat(Math.round(e+n+l),"px"))},[B]),O=(0,n.useCallback)((e,t)=>{let r=x.current;if(0===r.length)return;let l=Math.max(0,Math.min(r.length-1,e));L(r[l],t)},[L]),_=(0,n.useCallback)(e=>{let t=h.current,r=f.current,l=null==t?void 0:t.querySelector("svg");if(!t||!r||!l)return 0;let n=l.getBoundingClientRect(),a=Math.max(0,e-18),s=l.cloneNode(!0),o=(e,t,r)=>{var l,s;let i=e.getBoundingClientRect(),c=i.left-n.left,u=i.right-n.left;if((i.width>0||i.height>0)&&a>=24&&u<=a&&c>=-24){e.style.opacity="0";return}let d=null!==(s=null===(l=e.parentElement)||void 0===l?void 0:l.getBoundingClientRect().width)&&void 0!==s?s:0;if(!("path"===e.tagName.toLowerCase()&&i.height<=2&&i.width>40&&i.width>=.85*d)){if(r<12&&e.children.length>0){let l=Array.from(e.children),n=Array.from(t.children);l.forEach((e,t)=>{n[t]&&o(e,n[t],r+1)});return}t.remove()}};return Array.from(l.children).forEach((e,t)=>{let r=s.children[t];r&&o(e,r,0)}),r.innerHTML="",r.appendChild(s),a>=24?Math.round(a):0},[]);(0,n.useImperativeHandle)(t,()=>({flashNotes(e,t,r){let l=m.current;if(!l||0===t.length)return;let n=new Set(t);for(let t of function(e,t){let r=e.graphic;if(!(null==r?void 0:r.MeasureList)||t<0)return[];let l=0;for(let e of r.MeasureList){let r=null==e?void 0:e[0];if(!(null==r?void 0:r.staffEntries))continue;let s=r.staffEntries.length;if(t<l+s){let r=t-l,s=[];for(let t of e){var n,a;let e=null==t?void 0:null===(n=t.staffEntries)||void 0===n?void 0:n[r];if(null==e?void 0:e.graphicalVoiceEntries)for(let t of e.graphicalVoiceEntries)for(let e of null!==(a=null==t?void 0:t.notes)&&void 0!==a?a:[])(null==e?void 0:e.sourceNote)&&!e.sourceNote.isRest()&&s.push(e)}return s}l+=s}return[]}(l,e)){var a,s,o;let e=function(e){var t,r,l;let n=null!==(l=null==e?void 0:null===(t=e.sourceNote)||void 0===t?void 0:t.Pitch)&&void 0!==l?l:null==e?void 0:null===(r=e.sourceNote)||void 0===r?void 0:r.pitch;return n&&"function"==typeof n.getHalfTone?n.getHalfTone()+12:null}(t);if(null===e||!n.has(e))continue;let l=null===(a=t.getSVGGElement)||void 0===a?void 0:a.call(t);if(!l)continue;let i=Array.isArray(t.vfnote)?t.vfnote[1]:void 0,c=Array.from(l.querySelectorAll(".vf-notehead")),u=void 0!==i&&c[i]?c[i]:l,d=Array.from(u.querySelectorAll("path, ellipse, circle"));for(let e of d)e.dataset.hqInkFill||(e.dataset.hqInkFill=null!==(s=e.getAttribute("fill"))&&void 0!==s?s:"",e.dataset.hqInkStroke=null!==(o=e.getAttribute("stroke"))&&void 0!==o?o:""),e.setAttribute("fill",et),e.setAttribute("stroke",et),e.style.transition="fill 120ms ease-out, stroke 120ms ease-out";let h=b.current.get(u);h&&clearTimeout(h),b.current.set(u,setTimeout(()=>{for(let e of d){let t=e.dataset.hqInkFill,r=e.dataset.hqInkStroke;t?e.setAttribute("fill",t):e.removeAttribute("fill"),r?e.setAttribute("stroke",r):e.removeAttribute("stroke")}b.current.delete(u)},Math.max(120,r)))}}}),[]),(0,n.useEffect)(()=>{if(!h.current||!r)return;let e=!1;return(async()=>{let t=h.current;if(t)try{var l,n,s;
1y(!0),N(null),b.current.forEach(e=>clearTimeout(e)),b.current.clear(),t.innerHTML="",t.style.transition="none",t.style.transform="translateX(0px)";let o=new J.OpenSheetMusicDisplay(t,{autoResize:!1,drawTitle:!1,drawSubtitle:!1,drawComposer:!1,drawCredits:!1,drawPartNames:!1,drawMeasureNumbers:!1,drawTimeSignatures:!0,followCursor:!1,renderSingleHorizontalStaffline:!0,defaultColorMusic:"#1f2433",pageBackgroundColor:"transparent",drawingParameters:"compacttight"});if(m.current=o,await o.load(r),e||m.current!==o)return;try{null===(n=o.Sheet)||void 0===n||null===(l=n.Instruments)||void 0===l||l.forEach(e=>{let t=!1;e.Voices.forEach(e=>{var r;null===(r=e.VoiceEntries)||void 0===r||r.forEach(e=>{var r;null===(r=e.Notes)||void 0===r||r.forEach(e=>{e.isRest()||(t=!0)})})}),t||(e.Visible=!1)})}catch(e){}let i=o.EngravingRules;i&&(i.PageLeftMargin=1,i.PageRightMargin=1,i.PageTopMargin=1.5,i.PageBottomMargin=1,i.SystemLeftMargin=0,i.SystemRightMargin=0,i.MinimumDistanceBetweenSystems=0);try{o.render()}catch(e){}if(e)return;let c=F(),d=R(o);if(d.length>1){let t=d.slice(1).map((e,t)=>e-d[t]).filter(e=>e>0),r=t.reduce((e,t)=>e+t,0)/t.length,l=Math.max(.9,Math.min(1.6,(c-56)/5.2/r));if(Math.abs(l-1)>.05){o.zoom=l;try{o.render()}catch(e){}if(e)return}}x.current=R(o);let h=_(null!==(s=x.current[0])&&void 0!==s?s:0);V.current=h,I(h);let f=t.querySelector("svg");if(f){let e=parseFloat(f.getAttribute("height")||"0")||f.getBoundingClientRect().height,t=(f.getAttribute("viewBox")||"").split(/\s+/).map(Number),r=4===t.length&&t[3]>0?e/t[3]:1,l=0,n=0,a=e;try{let e=f.getBBox();l=e.y*r,n=e.x*r,a=e.height*r}catch(e){}let s={x:Math.round(28-Math.min(0,n)),y:Math.round(22-Math.min(0,l))};D.current=s,P(s);let o=Math.max(e,l+a);E(Math.round(o)),k(Math.max(200,Math.min(520,Math.round(o+s.y+22))))}O(a,!1),null==u||u(o),y(!1)}catch(t){e||(N("Failed to load music notation. Please try again."),y(!1))}})(),()=>{e=!0}},[r,i,R,O,F,_]),(0,n.useEffect)(()=>{s||O(a,!0)},[a,s,O]),(0,n.useEffect)(()=>{if(!s){null!==g.current&&cancelAnimationFrame(g.current),g.current=null;return}let e=()=>{var t;let r=null===(t=h.current)||void 0===t?void 0:t.querySelector(".smooth-playhead"),l=r?parseFloat(r.style.left||""):NaN;Number.isNaN(l)||L(l,!1),g.current=requestAnimationFrame(e)};return g.current=requestAnimationFrame(e),()=>{null!==g.current&&cancelAnimationFrame(g.current),g.current=null}},[s,L]);let G=Math.max(56,Math.round((S-q.x-M)/5.2*.5)),z=M+4,H="linear-gradient(to right, transparent ".concat(z,"px, rgba(0,0,0,0.6) ").concat(z+50,"px, black ").concat(z+110,"px, black calc(100% - ").concat(188,"px), rgba(0,0,0,0.55) calc(100% - ").concat(98,"px), transparent calc(100% - ").concat(Math.round(14),"px))"),U={position:"absolute",top:"".concat(q.y,"px"),left:"".concat(q.x,"px"),right:0,height:"".concat(C,"px")};return(0,l.jsxs)("div",{style:{maxWidth:"".concat(i,"px"),margin:"0 auto"},className:"jsx-1450118d80370c8f harmonic-quest-osmd relative w-full",children:[v&&(0,l.jsx)("div",{className:"jsx-1450118d80370c8f absolute inset-0 z-20 flex items-center justify-center",children:(0,l.jsxs)("div",{className:"jsx-1450118d80370c8f inline-flex items-center gap-3 px-5 py-2.5 bg-card rounded-lg border border-border shadow",children:[(0,l.jsx)("div",{className:"jsx-1450118d80370c8f w-4 h-4 border-2 border-action border-t-transparent rounded-full animate-spin"}),(0,l.jsx)("span",{className:"jsx-1450118d80370c8f text-sm text-muted-foreground",children:"Loading notationâ¦"})]})}),w&&(0,l.jsx)("div",{className:"jsx-1450118d80370c8f text-center py-8",children:(0,l.jsx)("div",{className:"jsx-1450118d80370c8f px-6 py-3 bg-red-500/10 border border-red-500/50 rounded-lg text-red-400",children:w})}),(0,l.jsxs)("div",{ref:d,"data-playhead":o?"on":"off",style:{width:"100%",height:"".concat(j,"px"),background:"radial-gradient(120% 140% at 50% 0%, #fffdf8 0%, ".concat("#f6f1e7"," 55%, #ece5d6 100%)"),boxShadow:"inset 0 1px 0 rgba(255,255,255,0.7), inset 0 -18px 30px -24px rgba(60,40,10,0.35), 0 18px 40px -24px rgba(0,0,0,0.6)"},className:"jsx-1450118d80370c8f hq-paper relative overflow-hidden rounded-2xl",children:[(0,l.jsx)("div",{ref:f,"aria-hidden":"true",style:U,className:"jsx-1450118d80370c8f hq-backdrop pointer-events-none z-[4]"}
1),(0,l.jsx)("div",{ref:p,"aria-hidden":"true",style:{top:"".concat(Math.max(6,q.y-10),"px"),bottom:"".concat(12,"px"),width:"".concat(G,"px"),transform:"translateX(-50%)",borderRadius:"14px",background:"linear-gradient(to bottom, rgba(".concat(ee,",0.30) 0%, rgba(").concat(ee,",0.16) 50%, rgba(").concat(ee,",0.30) 100%)"),boxShadow:"inset 0 0 0 1.5px rgba(".concat(ee,",0.45), 0 0 24px rgba(").concat(ee,",0.18)")},className:"jsx-1450118d80370c8f pointer-events-none absolute z-[5]",children:(0,l.jsx)("div",{style:{width:"60%",background:"rgba(".concat(ee,",0.85)")},className:"jsx-1450118d80370c8f absolute left-1/2 -translate-x-1/2 bottom-0 h-1 rounded-full"})}),(0,l.jsx)("div",{style:{...U,WebkitMaskImage:H,maskImage:H},className:"jsx-1450118d80370c8f z-[6]",children:(0,l.jsx)("div",{ref:h,id:"osmd-container","data-xml-length":r.length,style:{width:"max-content",minWidth:"100%",height:"100%"},className:"jsx-1450118d80370c8f hq-tape absolute top-0 left-0 will-change-transform"})})]}),(0,l.jsx)(Z(),{id:"1450118d80370c8f",children:'.opensheetmusicdisplay-cursor{opacity:0!important}
1.hq-tape svg,.hq-backdrop svg{display:block;overflow:visible}.hq-paper[data-playhead="off"] .smooth-playhead{opacity:0!important}'})]})});var en=r(19966);let ea=e=>{let t=e.match(/^([A-Ga-g])([#b]{0,2}|x)?(-?\d+)$/);if(!t)return null;let[,r,l="",n]=t,a=parseInt(n,10),s={C:0,D:2,E:4,F:5,G:7,A:9,B:11,c:0,d:2,e:4,f:5,g:7,a:9,b:11}[r];return void 0===s?null:("#"===l?(s+=1)>=12&&(s-=12,a+=1):"##"===l||"x"===l?(s+=2)>=12&&(s-=12,a+=1):"b"===l?(s-=1)<0&&(s+=12,a-=1):"bb"===l&&(s-=2)<0&&(s+=12,a-=1),(a+1)*12+s)},es=e=>{let{osmdInstance:t,isPlaying:r,currentStepIndex:l,steps:a,tempo:s,getAudioTime:o,latencyOffset:i}=e,c=(0,n.useRef)(null),u=(0,n.useRef)(null),d=(0,n.useRef)(null),h=(0,n.useRef)([]),f=(0,n.useRef)(0),p=(0,n.useCallback)(()=>{if(!t||!t.graphic)return[];let e=[],r=t.graphic.MeasureList;if(!r)return[];console.log("\uD83C\uDFA8 [VisualEngine] Extracting positions - steps.length:",a.length,"measureList.length:",r.length);let l=60/s,n=0;for(let t=0;t<r.length;t++){let a=r[t];if(!a||!a[0])continue;let s=a[0].staffEntries;if(s&&0!==s.length)for(let r=0;r<s.length;r++){var o,i;let a=s[r];if(!a||!a.graphicalVoiceEntries)continue;let c=a.graphicalVoiceEntries[0];if(!c||!c.notes||0===c.notes.length)continue;let d=c.notes[0],h=null===(o=d.getSVGGElement)||void 0===o?void 0:o.call(d);if(h){let a=h.getBoundingClientRect(),s=null===(i=u.current)||void 0===i?void 0:i.getBoundingClientRect();if(s){let o=f.current+n*l;e.push({x:a.left-s.left+a.width/2,y:a.top-s.top,width:a.width,stepIndex:n,time:o}),console.log("\uD83C\uDFA8 [VisualEngine] Position ".concat(n," (measure ").
1concat(t,", entry ").concat(r,"): x=").concat((a.left-s.left).toFixed(0),", time=").concat(o.toFixed(2))),n++}}}}return e},[t,a,s]),m=(0,n.useCallback)(()=>{if(console.log("\uD83C\uDFA8 [VisualEngine] initializePlayhead called, osmdInstance:",t),!t||!t.container){console.warn("\uD83C\uDFA8 [VisualEngine] No OSMD instance or container available");return}let e=t.container;console.log("\uD83C\uDFA8 [VisualEngine] OSMD container found:",e);let n=e.querySelector(".visual-engine-container");if(!n){(n=document.createElement("div")).className="visual-engine-container",n.style.position="relative",n.style.width="100%",n.style.height="100%",n.style.pointerEvents="none";let t=e.querySelector("svg");t&&(t.style.position="relative"),e.style.position="relative",e.appendChild(n)}u.current=n;let a=n.querySelector(".smooth-playhead");a||((a=document.createElement("div")).className="smooth-playhead",n.appendChild(a)),c.current=a,console.log("\uD83C\uDFA8 [VisualEngine] Playhead element created:",a);let s=e.querySelectorAll(".cursor");if(s.forEach(e=>{e.style.setProperty("display","none","important"),e.style.setProperty("visibility","hidden","important")}),console.log("\uD83C\uDFA8 [VisualEngine] Default OSMD cursors hidden:",s.length),h.current=p(),console.log("\uD83C\uDFA8 [VisualEngine] Extracted note positions:",h.current.length),!r&&h.current.length>0){let e=h.current.find(e=>e.stepIndex===l)||h.current[0];c.current&&(c.current.style.left="".concat(e.x,"px"),c.current.style.top="0px",c.current.style.height="100%",c.current.style.opacity="1")}},[t,p,r,l]),x=(0,n.useCallback)(e=>{if(!c.current||0===h.current.length)return;let t=h.current.find(t=>t.stepIndex===e);if(t)c.current.style.left="".concat(t.x,"px"),c.current.style.top="0px",c.current.style.height="100%",c.current.style.opacity="1";else if(-1===e){let e=h.current[0];e&&(c.current.style.left="".concat(e.x,"px"),c.current.style.top="0px",c.current.style.height="100%",c.current.style.opacity="1")}},[]),g=(0,n.useCallback)(()=>{if(!c.current||0===h.current.length){console.warn("\uD83C\uDFA8 [VisualEngine] Missing prerequisites - playhead:",!!c.current,"positions:",h.current.length);return}let e=o(),t=h.current,r=null,l=null;for(let n=0;n<t.length;n++)if(t[n].time<=e)r=t[n],l=t[n+1]||null;else break;if(r){if(l){let t=l.time-r.time,n=Math.max(0,Math.min(1,(e-r.time)/t)),a=Math.abs(l.y-r.y)>50;if(a&&n<.95)c.current.style.left="".concat(r.x,"px"),c.current.style.opacity="1";else if(a&&n>=.95)c.current.style.left="".concat(l.x,"px"),c.current.style.opacity="1";else{let e=r.x+(l.x-r.x)*n;c.current.style.left="".concat(e,"px"),c.current.style.opacity="1"}c.current.style.top="0px",c.current.style.height="100%"}else c.current.style.left="".concat(r.x,"px"),c.current.style.top="0px",c.current.style.height="100%",c.current.style.opacity="1"}else{let e=t[0];e&&(c.current.style.left="".concat(e.x,"px"),c.current.style.top="0px",c.current.style.height="100%",c.current.style.opacity="1")}d.current=requestAnimationFrame(g)},[r,o]),b=(0,n.useCallback)((e,r,l,n,a)=>{try{var s,o,i;if(!t||!t.graphic)return;let c=t.graphic.MeasureList;if(!c)return;let u=-1,d=-1,h=0;e:for(let t=0;t<c.length;t++){let r=c[t];if(!r||!r[0])continue;let l=r[0].staffEntries;if(l)for(let r=0;r<l.length;r++){if(h===e){u=t,d=r;break e}h++}}if(-1===u){console.warn("\uD83C\uDFA8 [VisualEngine] Could not find measure for stepIndex ".concat(e));return}let f=c[u],p=[];for(let e=0;e<f.length;e++){let t=f[e];if(!t||!t.staffEntries)continue;let r=t.staffEntries[d];if(r&&r.graphicalVoiceEntries)for(let t=0;t<r.graphicalVoiceEntries.length;t++){let l=r.graphicalVoiceEntries[t];if(l&&l.notes)for(let r=0;r<l.notes.length;r++){let n=l.notes[r];if(!n)continue;let a=null===(s=n.getSVGGElement)||void 0===s?void 0:s.call(n);if(a){let l;try{let e=n.sourceNote;if(e&&e.pitch){let t=e.pitch.fundamentalNote,r=e.pitch.octave,n=["C","D","E","F","G","A","B"][t]||"C",a="";if("function"==typeof e.pitch.getHalfTone){let l=e.pitch.getHalfTone(),s=[0,2,4,5,7,9,11][t]+(r+1)*12,o=l-s;1===o?a="#":2===o?a="##":-1===o?a="b":-2===o&&(a="bb"),console.log("\uD83C\uDFB5 [VisualEngine] Via getHalfTone: ".concat(n).concat(a).concat(r," (halfTone=").concat(l,", natural=").concat(s,", alt=").concat(o,")"))}else{let t=e.pitch.accidental,l="number"==typeof t?t:0;1===l?a="#":2===l?a="##":-1===l?a="b":-2===l&&(a="bb"),console.log("\uD83C\uDFB5 [VisualEngine] Via accidental prop: ".concat(n).concat(a).concat(r," (alter=").concat(t,")"))}l="".concat(n).concat(a).concat(r)}}catch(e){console.warn("\uD83C\uDFB5 [VisualEngine] Pitch extraction failed:",e)}p.push({svgElement:a,graphicalNote:n,staffIndex:e,voiceIndex:t,noteIndexInVoice:r,pitch:l})}}}}console.log("\uD83C\uDFA8 [VisualEngine] Found ".concat(p.length," notes at step ").concat(e,", beat ").concat(d,":"),p.map(e=>e.pitch||"unknown").join(", "));let m=null;if(a){let e=ea(a);if(null!==e&&(m=p.find(t=>{if(!t.pitch)return!1;let r=ea(t.pitch);return null!==r&&r===e}))&&console.log("\uD83C\uDFA8 [VisualEngine] Found note by MIDI: ".concat(a," (MIDI ").concat(e,") -> ").concat(m.pitch)),!m){let e=a.toUpperCase().replace("X","##");(m=p.find(t=>!!t.pitch&&t.pitch.toUpperCase().replace("X","##")===e))&&console.log("\uD83C\uDFA8 [VisualEngine] Found note by exact string: ".concat(a))}}if(!m&&(1===p.length?(m=p[0],console.log("\uD83C\uDFA8 [VisualEngine] Single note fallback: using only note at step ".concat(e))):r>=0&&r<p.length&&(m=p[r],console.log("\uD83C\uDFA8 [VisualEngine] Index fallback: note ".concat(r," at step ").concat(e,'
1(pitch matching failed for "').concat(a,'")')))),!m){console.warn('\uD83C\uDFA8 [VisualEngine] Could not find note "'.concat(a,'" at step ').concat(e," - no visual feedback applied"));return}let x="#333333";"success"===l?x="perfect"===n?"#00E676":"good"===n?"#00C853":"miss"===n?"#FF9100":"#00E676":"miss"===l?x="#FF9100":"wrong"===l&&(x="#FF1744");let g=m.graphicalNote;if(g&&"function"==typeof g.setColor)g.setColor(x,{applyToNoteheads:!0,applyToStem:!1,applyToBeams:!1,applyToFlag:!1,applyToLedgerLines:!1,applyToModifiers:!0,applyToSlurs:!1,applyToTies:!1}),console.log("\uD83C\uDFA8 [VisualEngine] Applied color ".concat(x," via setColor() to note ").concat(m.pitch," at step ").concat(e));else{let t=null!==(o=null==g?void 0:g.vfnoteIndex)&&void 0!==o?o:0;if(g&&"function"==typeof g.getNoteheadSVGs){let r=g.getNoteheadSVGs(),l=null!==(i=null==r?void 0:r.length)&&void 0!==i?i:0,n=l>1?l-1-t:t;if(r&&r.length>n&&n>=0){let l=r[n];l&&(l.querySelectorAll("path").forEach(e=>{e.setAttribute("fill",x),e.setAttribute("stroke",x)}),console.log("\uD83C\uDFA8 [VisualEngine] Applied color ".concat(x," via getNoteheadSVGs() to note ").concat(m.pitch," (vfnoteIndex=").concat(t,", invertedIndex=").concat(n,") at step ").concat(e)))}}else{let r=m.svgElement,l=r.querySelector(".vf-note");if(l){let r=l.querySelectorAll(".vf-notehead"),n=r.length,a=n>1?n-1-t:t;r.length>a&&a>=0?(r[a].querySelectorAll("path").forEach(e=>{e.setAttribute("fill",x),e.setAttribute("stroke",x)}),console.log("\uD83C\uDFA8 [VisualEngine] Applied color ".concat(x," via querySelector to notehead (vfnoteIndex=").concat(t,", invertedIndex=").concat(a,") at step ").concat(e))):(r.forEach(e=>{e.querySelectorAll("path").forEach(e=>{e.setAttribute("fill",x),e.setAttribute("stroke",x)})}),console.log("\uD83C\uDFA8 [VisualEngine] Applied color ".concat(x," to all noteheads (single note case) at step ").concat(e)))}else r.querySelectorAll("path").forEach(e=>{e.setAttribute("fill",x),e.setAttribute("stroke",x)}),console.log("\uD83C\uDFA8 [VisualEngine] Applied color ".concat(x," via legacy fallback at step ").concat(e))}g&&"function"==typeof g.getModifierSVGs&&g.getModifierSVGs().forEac
1h(e=>{e.querySelectorAll("path").forEach(e=>{e.setAttribute("fill",x)})})}}catch(e){console.error("\uD83C\uDFA8 [VisualEngine] Error applying note feedback:",e)}},[t]),v=(0,n.useCallback)((e,r)=>{try{if(!t||!t.graphic)return;let o=t.graphic.MeasureList;if(!o)return;let i=-1,c=-1,u=0;e:for(let t=0;t<o.length;t++){let r=o[t];if(!r||!r[0])continue;let l=r[0].staffEntries;if(l)for(let r=0;r<l.length;r++){if(u===e){i=t,c=r;break e}u++}}if(-1===i)return;let d=o[i],h=r.map(e=>ea(e)).filter(e=>null!==e);for(let t=0;t<d.length;t++){let r=d[t];if(!r||!r.staffEntries)continue;let o=r.staffEntries[c];if(o&&o.graphicalVoiceEntries)for(let t=0;t<o.graphicalVoiceEntries.length;t++){let r=o.graphicalVoiceEntries[t];if(r&&r.notes)for(let t=0;t<r.notes.length;t++){var l,n,a,s;let o=r.notes[t];if(!o)continue;let i=null===(l=o.getSVGGElement)||void 0===l?void 0:l.call(o);if(!i)continue;let c=!1,u=i.querySelector(".vf-note");if(u){let e=null!==(n=null==o?void 0:o.vfnoteIndex)&&void 0!==n?n:0,t=u.querySelectorAll(".vf-notehead"),r=t.length,l=r>1?r-1-e:e;if(t.length>l&&l>=0){let e=t[l].querySelector("path");if(e){let t=e.getAttribute("fill");t&&"#000000"!==t&&"black"!==t&&"#333333"!==t&&(c=!0)}}}if((i.classList.contains("hit-success")||i.classList.contains("hit-miss")||i.classList.contains("hit-wrong"))&&(c=!0),c)continue;let d=!1;try{let e=o.sourceNote;if(e&&e.pitch){let t=e.pitch.fundamentalNote,r=e.pitch.octave,l=e.pitch.accidental,n=["C","D","E","F","G","A","B"][t]||"C",a="number"==typeof l?l:0,s="";1===a?s="#":2===a?s="##":-1===a?s="b":-2===a&&(s="bb");let o="".concat(n).concat(s).concat(r),i=ea(o);null!==i&&(d=h.includes(i))}}catch(e){}if(!d){let t="#FF1744";if(o&&"function"==typeof o.setColor)o.setColor(t,{applyToNoteheads:!0,applyToStem:!1,applyToBeams:!1,applyToFlag:!1,applyToLedgerLines:!1,applyToModifiers:!0,applyToSlurs:!1,applyToTies:!1});else{let e=null!==(a=null==o?void 0:o.vfnoteIndex)&&void 0!==a?a:0;if(o&&"function"==typeof o.getNoteheadSVGs){let r=o.getNoteheadSVGs(),l=null!==(s=null==r?void 0:r.length)&&void 0!==s?s:0,n=l>1?l-1-e:e;if(r&&r.length>n&&n>=0){let e=r[n];e&&e.querySelectorAll("path").forEach(e=>{e.setAttribute("fill",t),e.setAttribute("stroke",t)})}}else{let r=i.querySelector(".vf-note");if(r){let l=r.querySelectorAll(".vf-notehead"),n=l.length,a=n>
11?n-1-e:e;l.length>a&&a>=0&&l[a].querySelectorAll("path").forEach(e=>{e.setAttribute("fill",t),e.setAttribute("stroke",t)})}}}console.log("\uD83C\uDFA8 [VisualEngine] Marked note as not played at step ".concat(e))}}}}}catch(e){console.error("\uD83C\uDFA8 [VisualEngine] Error marking missed notes:",e)}},[t]),y=(0,n.useCallback)(e=>{console.log("\uD83C\uDFA8 [VisualEngine] start() called with startTime:",e),f.current=e,m(),d.current&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(g),console.log("\uD83C\uDFA8 [VisualEngine] Animation frame requested:",d.current)},[m,g]),w=(0,n.useCallback)(()=>{d.current&&(cancelAnimationFrame(d.current),d.current=null),c.current&&(c.current.style.opacity="0")},[]),N=(0,n.useCallback)(()=>{if(t&&t.graphic){var e,r;let l="#000000",n=t.graphic.MeasureList;if(n)for(let e=0;e<n.length;e++){let t=n[e];if(t)for(let e=0;e<t.length;e++){let n=t[e];if(n&&n.staffEntries)for(let e=0;e<n.staffEntries.length;e++){let t=n.staffEntries[e];if(t&&t.graphicalVoiceEntries)for(let e=0;e<t.graphicalVoiceEntries.length;e++){let n=t.graphicalVoiceEntries[e];if(n&&n.notes)for(let e=0;e<n.notes.length;e++){let t=n.notes[e];if(t){if("function"==typeof t.setColor)t.setColor(l,{applyToNoteheads:!0,applyToStem:!0,applyToBeams:!0,applyToFlag:!0,applyToLedgerLines:!0,applyToModifiers:!0,applyToSlurs:!1,applyToTies:!1});else{let e=null===(r=t.getSVGGElement)||void 0===r?void 0:r.call(t);e&&(e.classList.remove("hit-success","hit-success-perfect","hit-success-good","hit-miss","hit-wrong","hit-not-played"),e.querySelectorAll(".vf-notehead path").forEach(e=>{e.setAttribute("fill",l),e.setAttribute("stroke",l)}),e.querySelectorAll(".vf-modifiers path").forEach(e=>{e.setAttribute("fill",l)}))}}}}}}}let a=null===(e=t.container)||void 0===e?void 0:e.querySelector("svg");a&&a.querySelectorAll(".hit-success, .hit-success-perfect, .hit-success-good, .hit-miss, .hit-wrong, .hit-not-played").forEach(e=>{e.classList.remove("hit-success","hit-success-perfect","hit-success-good","hit-miss","hit-wrong","hit-not-played")})}},[t]),j=(0,n.useCallback)(e=>{if(!t||!t.graphic)return;let r="#000000",l=t.graphic.MeasureList;if(!l)return;let n=0,a=-1,s=-1;e:for(let t=0;t<l.length;t++){let r=l[t];if(!r||!r[0])continue;let o=r[0].staffEntries;if(o)for(let r=0;r<o.length;r++){if(n===e){a=t,s=r;break e}n++}}if(-1===a)return;let o=l[a];for(let e=0;e<o.length;e++){let t=o[e];if(!t||!t.staffEntries)continue;let l=t.staffEntries[s];if(l&&l.graphicalVoiceEntries)for(let e=0;e<l.graphicalVoiceEntries.length;e++){let t=l.graphicalVoiceEntries[e];if(t&&t.notes)for(let e=0;e<t.notes.length;e++){let l=t.notes[e];if(l){if("function"==typeof l.setColor)l.setColor(r,{applyToNoteheads:!0,applyToStem:!0,applyToBeams:!0,applyToFlag:!0,applyToLedgerLines:!0,applyToModifiers:!0,applyToSlurs:!1,applyToTies:!1});else{var i;let e=null===(i=l.getSVGGElement)||void 0===i?void 0:i.call(l);e&&(e.classList.remove("hit-success","hit-success-perfect","hit-success-good","hit-miss","hit-wrong","hit-not-played"),e.querySelectorAll(".vf-notehead path").forEach(e=>{e.setAttribute("fill",r),e.setAttribute("stroke",r)}),e.querySelectorAll(".vf-modifiers path").forEach(e=>{e.setAttribute("fill",r)}))}}}}}console.log("\uD83C\uDFA8 [VisualEngine] Cleared feedback for step ".concat(e," only"))},[t]),k=(0,n.useCallback)(()=>{if(w(),c.current&&h.current.length>0){let e=h.current[0];c.current.style.left="".concat(e.x,"px"),c.current.style.opacity="1"}N()},[t,w,N]);return(0,n.useEffect)(()=>()=>{d.current&&cancelAnimationFrame(d.current)},[]),(0,n.useEffect)(()=>{console.log("\uD83C\uDFA8 [VisualEngine] useEffect triggered - isPlaying:",r,"osmdInstance:",!!t),r&&t?(console.log("\uD83C\uDFA8 [VisualEngine] Starting animation from useEffect"),d.current||(d.current=requestAnimationFrame(g),console.log("\uD83C\uDFA8 [VisualEngine] Animation frame started:",d.current))):(console.log("\uD83C\uDFA8 [VisualEngine] Stopping animation from useEffect"),d.current&&(cancelAnimationFrame(d.current),d.current=null),t&&h.current.length>0&&x(l))},[r,t,g,l,x]),{start:y,stop:w,reset:k,clearFeedback:N,clearStepFeedback:j,applyNoteFeedback:b,markMissedNotes:v,initializePlayhead:m,setPosition:x}};r(55287);let eo=/^([A-G](?:#{1,2}|b{1,2}|x)?)(\d)$/,ei=["all","top","inner","bass"];function ec(e,t){let r=[...e].sort((e,t)=>
1{var r,l;return(null!==(r=ed(e))&&void 0!==r?r:0)-(null!==(l=ed(t))&&void 0!==l?l:0)});return"all"===t||0===r.length?r:"top"===t?[r[r.length-1]]:"bass"===t?[r[0]]:r.slice(1,-1)}let eu=e=>{try{if(!e)return{beats:4,beatType:4};let l=new DOMParser().parseFromString(e,"text/xml").querySelector("time");if(l){var t,r;let e=null===(t=l.querySelector("beats"))||void 0===t?void 0:t.textContent,n=null===(r=l.querySelector("beat-type"))||void 0===r?void 0:r.textContent;if(e&&n)return{beats:parseInt(e),beatType:parseInt(n)}}}catch(e){}return{beats:4,beatType:4}},ed=e=>{let t=e.match(eo);if(!t)return null;let[,r,l]=t;try{return(0,D.w)(r,parseInt(l,10))}catch(e){return null}},eh=e=>{let{xmlInput:t,onStepChange:r,onValidation:u,initialStep:d=0,allowMouseInput:h=!0,previewMode:f=!1,embedded:x=!1,initialPhase:g,onPhaseChange:b,onPhaseComplete:v,homeQuality:y="6",tonicPc:k=0,blurb:C,keyControl:E,nextKeyLabel:S}=e,{t:T}=(0,X.Bd)("quests"),[A,M]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=()=>{let e="ontouchstart"in window||navigator.maxTouchPoints>0,t=window.innerWidth<768;M(e&&t)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let[I,F]=(0,n.useState)(null!=g?g:"follow"),H="perform"===I?"performance":"practice",[U,Y]=(0,n.useState)(!1),[Z,J]=(0,n.use
1State)(0),[ee,et]=(0,n.useState)(null),[er,ea]=(0,n.useState)("all"),[eo,eh]=(0,n.useState)(!1),[ef,ep]=(0,n.useState)(60),[em,ex]=(0,n.useState)(!0),[eg,eb]=(0,n.useState)(!0),[ev,ey]=(0,n.useState)(!1),[ew,eN]=(0,n.useState)({beats:4,beatType:4}),[ej,ek]=(0,n.useState)(0),[eC,eE]=(0,n.useState)(4),[eS,eT]=(0,n.useState)([]),[eA,eM]=(0,n.useState)(!1),[eI,eV]=(0,n.useState)(()=>{let e=localStorage.getItem("harmonicQuest_latencyOffset");return e?parseFloat(e):0}),[eq,eP]=(0,n.useState)(!1),[eD,eF]=(0,n.useState)(0),[eR,eB]=(0,n.useState)([]),eL=(0,n.useRef)([]),eO={PERFECT:.05,GOOD:.1,MISS:.1},e_=(0,n.useCallback)(()=>Howler.ctx?Howler.ctx.currentTime:0,[]),eG=(0,n.useRef)(0),ez=(0,n.useRef)(0),eH=(0,n.useRef)(new Map),eU=(0,n.useRef)([]),eW=(0,n.useRef)(null),eK=(0,n.useRef)(null),[eQ,eX]=(0,n.useState)(!1),e$=(0,n.useRef)(new Set),eY=(0,n.useRef)(new Set),[eZ,eJ]=(0,n.useState)(!1),e0=(0,n.useRef)(null),[e1,e2]=(0,n.useState)([]),[e5,e4]=(0,n.useState)(d),[e3,e8]=(0,n.useState)(!1),[e6,e7]=(0,n.useState)(!1),[e9,te]=(0,n.useState)(!1),tt=es({osmdInstance:eW.current,isPlaying:ev&&e5>=0,currentStepIndex:e5,steps:e1,tempo:ef,getAudioTime:e_,latencyOffset:eI});(0,n.useEffect)(()=>{eQ&&eW.current&&(tt.initializePlayhead(),tt.setPosition(e5))},[eQ,e5,tt]);let{startSession:tr,endSession:tl,recordAttempt:tn}=V(),ta=(0,n.useCallback)((e,t)=>{let r,l=null,n=1/0;for(let e of eU.current){let r=t+eI-e.targetTime;if(r>=-.15&&r<=1.2){let t=Math.abs(r);t<n&&(n=t,l=e)}}if(!l)return{status:"OUT_OF_WINDOW"};let a=ed(e),s=!1,o=-1;if(null!==a&&l.expectedMidi.length>0)s=-1!==(o=l.expectedMidi.indexOf(a));else{let t=e=>e.toUpperCase().replace("X","##"),r=t(e);s=-1!==(o=l.expectedNotes.findIndex(e=>t(e)===r))}if(!s)return l.extraNotes.includes(e)||l.extraNotes.push(e),{status:"WRONG_NOTE",stepIndex:l.stepIndex};let i=l.expectedNotes[o]||e;return l.hitNotes.has(i)?{status:"ALREADY_HIT",stepIndex:l.stepIndex}:(l.hitNotes.add(i),r=n<eO.PERFECT?"perfect":n<eO.GOOD?"good":"miss",l.noteTiming.set(i,{time:t,delta:n,precision:r}),"performance"===H&&tt.applyNoteFeedback(l.stepIndex,o,"miss"===r?"miss":"success",r,i),{status:"HIT",stepIndex:l.stepIndex,precision:r})},[eI,.15,1.2,eO,H,tt]),ts=(0,n.useCallback)(e=>{if("performance"!==H||!ev)return;let t=ew.beats;if(e<=t){if(e4(-1),ek(e),e===t&&(eG.current=-1,eU.current=[],e1.length>0)){let e=e_(),t=60/ef,r=e1[0].notes,l=r.map(ed).filter(e=>null!==e);eU.current.push({stepIndex:0,expectedNotes:r,expectedMidi:l,targetTime:e+t,hitNotes:new Set,extraNotes:[],noteTiming:new Map})}return}let r=e-t-1;if(e===t+1){let e=e_();ez.current=e,tt.start(e)}let l=r-1,n=e_();if(l>=0&&l<e1.length){let e=eU.current.find(e=>e.stepIndex===l);if(e){let t=e.expectedNotes.every(t=>e.hitNotes.has(t)),r=0===e.extraNotes.length,n=t&&r,a=[...Array.from(e.hitNotes),...e.extraNotes];t||tt.markMissedNotes(l,Array.from(e.hitNotes)),eT(t=>[...t,{stepIndex:l,expected:e.expectedNotes,played:a,correct:n}]),eU.current=eU.current.filter(e=>e.stepIndex!==l)}else console.error("â ï¸ No target chord found for step ".concat(l,"!")),eT(e=>{var t;return[...e,{stepIndex:l,expected:(null===(t=e1[l])||void 0===t?void 0:t.notes)||[],played:[],correct:!1}]}),tt.markMissedNotes(l,[])}if(ez.current=n,eG.current=r,r>=0&&r<e1.length){e4(r);let e=r+1;if(e<e1.length){let t=60/ef,r=e1[e].notes,l=r.map(ed).filter(e=>null!==e);if(!eU.current.find(t=>t.stepIndex===e)){let a={stepIndex:e,expectedNotes:r,expectedMidi:l,targetTime:n+t,hitNotes:new Set,extraNotes:[],noteTiming:new Map};eU.current.push(a)}}}r===e1.length&&(eH.current.clear(),eU.current=[],ez.current=0,ey(!1),eM(!0),tt.stop())},[H,ev,e1,ew.beats,e_,eI,ef]),to=(0,m.g)({bpm:ef,beatsPerMeasure:ew.beats,enabled:"performance"===H&&em&&ev,onBeat:ts}),ti=(0,n.useCallback)(()=>{eP(!0),eF(0),eB([]),eL.current=[]},[]),tc=(0,n.useCallback)(e=>{e>=1&&e<=4?eF(-e):e>=5&&e<=8?(eL.current.push(e_()),eF(e-4)):9===e&&setTimeout(()=>{if(4===eR.length&&4===eL.current.length){let e=eR.map((e,t)=>eL.current[t]-e),t=e.reduce((e,t)=>e+t,0)/e.length;eV(t),localStorage.setItem("harmonicQuest_latencyOffset",t.toString()),eP(!1),eF(0)}},300)},[eR,e_]),tu=(0,m.g)({bpm:60,beatsPerMeasure:9,enabled:eq,onBeat:tc}),td=(0,n.useCallback)(()=>
1{if(eD>0&&eD<=4&&eR.length<4){let e=e_();eB(t=>{let r=[...t,e];return 4===r.length&&4===eL.current.length&&setTimeout(()=>{let e=r.map((e,t)=>eL.current[t]-e),t=e.reduce((e,t)=>e+t,0)/e.length;eV(t),localStorage.setItem("harmonicQuest_latencyOffset",t.toString()),tu.stop(),eP(!1),eF(0)},500),r})}},[eD,eR.length,e_,tu]);(0,n.useCallback)(()=>{eV(0),localStorage.setItem("harmonicQuest_latencyOffset","0")},[]);let[th,tf]=(0,n.useState)([]),[tp,tm]=(0,n.useState)(null),[tx,tg]=(0,n.useState)(!1),[tb,tv]=(0,n.useState)(!1),[ty,tw]=(0,n.useState)(!1),tN=(0,n.useRef)(null),tj=(0,n.useRef)(null),tk=(0,n.useRef)(null),tC=(0,n.useRef)(null),tE=(0,n.useRef)(null),tS=(0,n.useRef)(null),tT=(0,n.useRef)([]);(0,n.useEffect)(()=>{if(!t){e2([{id:"step-1",notes:["C4","E4","G4"],durationMs:1e3},{id:"step-2",notes:["D4","F4","A4"],durationMs:1e3},{id:"step-3",notes:["E4","G4","B4"],durationMs:1e3}]);return}try{let e=(0,P.q6)(t);e2(e);let r=eu(t);eN(r)}catch(e){e2([{id:"step-1",notes:["C4","E4","G4"],durationMs:1e3},{id:"step-2",notes:["D4","F4","A4"],durationMs:1e3},{id:"step-3",notes:["E4","G4","B4"],durationMs:1e3}])}},[t]),(0,n.useEffect)(()=>((async()=>{try{await p.waitForLoad(),tN.current=new q.Howl({src:["/sounds/correct.mp3"],volume:.2,html5:!1}),tj.current=new q.Howl({src:["/sounds/wrong.mp3"],volume:.2,html5:!1}),tw(!0)}catch(e){}})(),()=>{p.stopAllSounds(),tN.current&&tN.current.unload(),tj.current&&tj.current.unload(),tk.current&&clearTimeout(tk.current),tC.current&&clearTimeout(tC.current),tE.current&&clearTimeout(tE.current),tS.current&&clearTimeout(tS.current)}),[]),(0,n.useEffect)(()=>{let e=!0;if(!f&&e)return tr("harmonic-quest"),()=>{e=!1,tl()}},[f]),(0,n.useEffect)(()=>{r&&r(e5)},[e5,r]),(0,n.useEffect)(()=>{let e=()=>{tt.reset(),e$.current.clear(),eY.current.clear(),eJ(!1),J(0),e0.current&&(clearTimeout(e0.current),e0.current=null),e4(0),tf([]),tm(null),tg(!1),e8(!1),e7(!1),tv(!1),tk.current&&clearTimeout(tk.current),tS.current&&clearTimeout(tS.current),tE.current&&clearTimeout(tE.current),tC.current&&clearTimeout(tC.current),p.stopAllSounds(),setTimeout(()=>{if(ty&&e1.length>0){e8(!0);let e=e1[0];e.notes.forEach(e=>{p.playNote(e,.8,!0)});let t=2*e.durationMs;tS.current=setTimeout(()=>{e.notes.forEach(e=>{p.fadeOutNote(e,.9*t)})},.95*t),tk.current=setTimeout(()=>{e8(!1)},t)}},300)};return window.addEventListener("resetAndAutoPlay",e),()=>window.removeEventListener("resetAndAutoPlay",e)},[ty,e1,tt]);let tA=e1[e5]||{id:"",notes:[],durationMs:0},tM=(0,n.useMemo)(()=>Math.max(-1,...tA.notes.map(e=>{var t;return null!==(t=ed(e))&&void 0!==t?t:-1})),[tA]),tI=(0,n.useCallback)(e=>"recall"!==I||ed(e)===tM,[I,tM]),tV=(0,n.useMemo)(()=>"recall"===I?function(e){var t,r,l,n,a,s,o,i,c,u,d,h,f,p,m,x;let g=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("undefined"==typeof DOMParser)return e;let b=new DOMParser().parseFromString(e,"text/xml");if(b.querySelector("parsererror"))return e;let v=Math.max(0,null!==(t=g.revealed)&&void 0!==t?t:0),y=!1,w=Array.from(b.querySelectorAll("part"));for(let e of w.length>0?w:[b.documentElement]){let t=1,g=4,w=4,N=0,j=null;for(let k of Array.from(e.children).filter(e=>"measure"===e.tagName)){let e=Array.from(k.children).find(e=>"attributes"===e.tagName);if(e){let o=e.querySelector("divisions");o&&(t=parseInt(null!==(r=o.textContent)&&void 0!==r?r:"1",10)||t);let i=e.querySelector("time");i&&(g=parseInt(null!==(a=null===(l=i.querySelector("beats"))||void 0===l?void 0:l.textContent)&&void 0!==a?a:"4",10)||g,w=parseInt(null!==(s=null===(n=i.querySelector("beat-type"))||void 0===n?void 0:n.textContent)&&void 0!==s?s:"4",10)||w)}let C=[],E=0,S=null;for(let e of Array.from(k.children))if("note"===e.tagName){if(L(e,"chord")&&S){S.notes.push(e);continue}let t=L(e,"grace"),r=t?0:parseInt(null!==(o=B(e,"duration"))&&void 0!==o?o:"0",10)||0;S={notes:[e],staff:null!==(i=B(e,"staff"))&&void 0!==i?i:"1",voice:null!==(c=B(e,"voice"))&&void 0!==c?c:"1",offset:E,duration:r,rest:L(e,"rest"),grace:t,step:-1,hidden:!1},C.push(S),E+=r}else"backup"===e.tagName?(E-=parseInt(null!==(u=B(e,"duration"))&&void 0!==u?u:"0",10)||0,S=null):"forward"===e.tagName&&(E+=parseInt(null!==(d=B(e,"duration"))&&void 0!==d?d:"0",10)||0,S=null);null===j&&(j=null!==(f=null===(h=C.find(e=>"1"===e.staff&&!e.rest&&!e.grace))||void 0===h?void 0:h.voice)&&void 0!==f?f:null);let T=[];for(let e of C)"1"!==e.staff||e.voice!==j||e.rest||e.grace||(e.step=N++,T.push({offset:e.offset,step:e.step}));for(let e of C){if(e.step>=0||e.rest)continue;let t=T.filter(t=>t.offset<=e.offset);e.step=t.length>0?t[t.length-1].step:null!==(m=null===(p=T[0])||void 0===p?void 0:p.step)&&void 0!==m?m:N}for(let e of C)e.hidden=!e.rest&&e.step>=v;let A=new Map;for(let e of C){if("1"===e.staff&&e.voice===j)continue;let t="".concat(e.staff,"|").concat(e.voice);A.has(t)||A.set(t,[]),A.get(t).push(e)}let M=new Map,I={next:0};for(let e of A.values())!function(e,t,r){let l=null;for(let n of e){if(n.rest||n.grace){l=null;continue}let e=function(e){for(let n of e.notes)for(let e of Array.from(n.children)){var t,r,l;if("beam"===e.tagName&&(null!==(r=e.getAttribute("number"))&&void 0!==r?r:"1")==="1")return null!==(l=null===(t=e.textContent)||void 0===t?void 0:t.trim())&&void 0!==l?l:null}return null}(n);"begin"===e&&(l=r.next++),e&&null!==l&&t.set(n,l),"end"!==e&&e||(l=null)}}(e,M,I);for(let e of C)if(e.hidden&&"1"===e.staff){if(y=!0,e.voice===j)!function(e){let t=e.notes[0];if(1===e.notes.length)return;let r=e.notes.reduce((e,t)=>
1R(t)>R(e)?t:e,t);if(r!==t){var l,n,a,s;let e=t.querySelector("pitch"),o=r.querySelector("pitch");e&&o&&(null===(l=e.parentNode)||void 0===l||l.replaceChild(o.cloneNode(!0),e));let i=t.querySelector("accidental"),c=r.querySelector("accidental");if(i&&(null===(n=i.parentNode)||void 0===n||n.removeChild(i)),c){let e=null!==(s=t.querySelector("stem"))&&void 0!==s?s:t.querySelector("staff");e?null===(a=e.parentNode)||void 0===a||a.insertBefore(c.cloneNode(!0),e):t.appendChild(c.cloneNode(!0))}}e.notes.slice(1).forEach(e=>{var t;return null===(t=e.parentNode)||void 0===t?void 0:t.removeChild(e)}),e.notes=[t]}(e);else{let t=e.notes[0];e.grace||null===(x=t.parentNode)||void 0===x||x.insertBefore(function(e,t,r,l){let n=e.createElement("forward"),a=(t,r)=>{let l=e.createElement(t);l.textContent=r,n.appendChild(l)};return a("duration",String(t)),a("voice",r),a("staff",l),n}(b,e.duration,e.voice,e.staff),t),e.notes.forEach(e=>{var t;return null===(t=e.parentNode)||void 0===t?void 0:t.removeChild(e)}),e.notes=[]}}for(let e of A.values()){if(!e.some(e=>e.hidden))continue;let r=new Set(e.filter(e=>!e.hidden&&!e.rest));if(!function(e,t,r){let l=[],n=()=>{0!==l.length&&(l.forEach((e,t)=>{let r=1===l.length?null:0===t?"begin":t===l.length-1?"end":"continue";for(let t of e.notes)for(let e of Array.from(t.children)){var n;"beam"===e.tagName&&(null===r?t.removeChild(e):(null!==(n=e.getAttribute("number"))&&void 0!==n?n:"1")==="1"&&(e.textContent=r))}}),l=[])};for(let a of e){let e=r.get(a);if(!t.has(a)||void 0===e){n();continue}l.length>0&&r.get(l[l.length-1])!==e&&n(),l.push(a)}n()}(e,r,M),"1"===e[0].staff)continue;y=!0;let l=[],n=()=>{if(0===l.length)return;let e=l[0].offset,r=l[l.length-1].offset+l[l.length-1].duration,n=l[0].notes[0];for(let s of function(e,t,r,l,n){let a=4/n*l*r;if(0===e&&t===a)return[{duration:a,type:"whole",dots:0,measure:!0}];let s=8===n&&l%3==0&&l>=6,o=s?3*r/2:4*r/n,i=[];if(s){12===l&&i.push({duration:2*o,align:2*o}),i.push({duration:o,align:o});for(let e=r/2;e>=r/8;e/=2)i.push({duration:e,align:e})}else{4===l&&i.push({duration:2*o,align:2*o}),i.push({duration:o,align:o});for(let e=o/2;e>=r/8;e/=2)i.push({duration:e,align:e})}let c=i.filter(e=>Number.isInteger(e.duration)&&e.duration>0),u=[],d=e;for(;d<t;){let e=c.find(e=>d%e.align==0&&d+e.duration<=t),l=e?e.duration:t-d;u.push({duration:l,...function(e,t){let r=e/t,l=O[O.length-1];for(let e of O)Math.abs(e[0]-r)<Math.abs(l[0]-r)&&(l=e);return{type:l[1],dots:l[2]}}(l,r)}),d+=l}return u}(e,r,t,g,w)){var a;null===(a=n.parentNode)||void 0===a||a.insertBefore(function(e,t,r,l){let n=e.createElement("note"),a=e.createElement("rest");t.measure&&a.setAttribute("measure","yes"),n.appendChild(a);let s=(t,r)=>{let l=e.createElement(t);void 0!==r&&(l.textContent=r),n.appendChild(l)};s("duration",String(t.duration)),s("voice",r),s("type",t.type);for(let e=0;e<t.dots;e++)s("dot");return s("staff",l),n}(b,s,l[0].voice,l[0].staff),n)}l.forEach(e=>e.notes.forEach(e=>{var t;return null===(t=e.parentNode)||void 0===t?void 0:t.removeChild(e)})),l=[]};for(let t of e){if(t.grace){t.hidden&&t.notes.forEach(e=>{var t;return null===(t=e.parentNode)||void 0===t?void 0:t.removeChild(e)});continue}if(!(t.hidden||t.rest)){n();continue}let e=l[l.length-1];e&&e.offset+e.duration!==t.offset&&n(),l.push(t)}n()}}}return y?new XMLSerializer().serializeToString(b):e}(t):t,[I,t]),tq=(0,n.useMemo)(()=>{var e,t;return e1[0]&&null!==(t=null===(e=function(e){var t;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},l=e.map(W).filter(e=>null!==e),n=new Set(l.map(e=>e.pc));if(n.size<2)return null;let a=((null!==(t=r.tonicPc)&&void 0!==t?t:0)%12+12)%12,s=l.some(e=>e.alter<0)||!l.some(e=>e.alter>0),o=l.reduce((e,t)=>t.midi<e.midi?t:e,l[0]),i=(e,t)=>{let r=function(e,t,r){let l=t.find(t=>t.pc===e);if(l)return{root:function(e){let t=0===e.alter?"":e.alter>0?"#".repeat(e.alter):"b".repeat(-e.alter);return"".concat(e.letter).concat(t)}(l),rootStep:l.letter,rootAlter:l.alter};let n=(r?["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"]:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"])[e];return{root:n,rootStep:n[0],rootAlter:n.length>1?"b"===n[1]?-1:1:0}}(e,l,s);return{...r,quality:t,text:"".concat(r.root).concat(z[t])}};
1if(r.homeQuality&&K(n,a,r.homeQuality))return i(a,r.homeQuality);if(K(n,o.pc,"dim7"))return i(o.pc,"dim7");let c=e=>e===a?0:e===o.pc?1:2+e,u=null;for(let e=0;e<12;e++)for(let t=0;t<G.length;t++){let r=G[t];if(!K(n,e,r))continue;let l=_[r].length;(null===u||l<u.size||l===u.size&&c(e)<c(u.rootPc)||l===u.size&&c(e)===c(u.rootPc)&&t<u.qIndex)&&(u={rootPc:e,quality:r,size:l,qIndex:t})}return u?i(u.rootPc,u.quality):null}(e1[0].notes,{homeQuality:y,tonicPc:k}))||void 0===e?void 0:e.text)&&void 0!==t?t:null},[e1,y,k]),tP=h&&"listen"!==I,tD=(0,n.useCallback)(function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(e6||tx)return;let{note:r,octave:l}=(0,D.T)(e),n="".concat(r).concat(l);if(eg&&t&&p.playNote(n),eq&&t){td();return}if("performance"===H&&ev){if(t){let e=ta(n,e_());"HIT"===e.status||e.status,"HIT"===e.status?(0,en.Ac)():"WRONG_NOTE"===e.status&&(0,en.Rm)()}}else if("listen"!==I){if(t){if(e0.current&&(clearTimeout(e0.current),e0.current=null),tA.notes.map(ed).filter(e=>null!==e).includes(e)){if(e$.current.has(e))return;if(e$.current.add(e),eW.current){let t=tA.notes.find(t=>{let r=ed(t);return null!==r&&r===e});if(t&&tI(t)){let e=tA.notes.indexOf(t);tt.applyNoteFeedback(e5,e,"success","perfect",t)}}(0,en.Ac)(),tf(e=>e.includes(n)?e:[...e,n])}else eY.current.has(e)||(eY.current.add(e),eJ(!0),J(e=>e+1),(0,en.Rm)())}else eY.current.has(e)&&eY.current.delete(e),tA.notes.map(ed).filter(e=>null!==e).includes(e)&&e$.current.delete(e),eZ&&0===eY.current.size&&(e0.current=setTimeout(()=>{e$.current.clear(),eY.current.clear(),eJ(!1),tf([]),tt.clearStepFeedback(e5)},800))}},[e6,tx,H,I,ev,eg,e_,eq,td,ta,tA,e5,tt,eZ,tI]),{midiInputs:tF,selectedInput:tR,setSelectedInput:tB,error:tL}=(0,N.Z)(tD),tO=(0,n.useCallback)(e=>{if(!tP||e6||tx)return;let{note:t,octave:r}=(0,D.T)(e),l="".concat(t).concat(r);if(p.playNote(l),"performance"===H&&ev){let e=ta(l,e_());"HIT"===e.status||e.status,"HIT"===e.status?(0,en.Ac)():"WRONG_NOTE"===e.status&&(0,en.Rm)()}else{let e=ed(l),t=tA.notes.map(ed).filter(e=>null!==e);if(null!==e&&t.includes(e)){if(null!==e&&e$.current.has(e)){e$.current.delete(e),tf(t=>t.filter(t=>ed(t)!==e)),tt.clearStepFeedback(e5);return}if(null!==e&&e$.current.add(e),eW.current){let t=tA.notes.find(t=>{let r=ed(t);return null!==r&&r===e});if(t&&tI(t)){let e=tA.notes.indexOf(t);tt.applyNoteFeedback(e5,e,"success","perfect",t)}}(0,en.Ac)(),tf(e=>e.includes(l)?e:[...e,l])}else null===e||eY.current.has(e)||(eY.current.add(e),J(e=>e+1),(0,en.Rm)())}},[tP,e6,tx,H,ev,e_,ta,tA,e5,tt,tI]),t_=(0,n.useCallback)(()=>{if(!ty||e3||0===e1.length)return;e8(!0),tA.notes.forEach(e=>{p.playNote(e,.8,!0)});let e=e5===e1.length-1,t=e?1.2*tA.durationMs:2*tA.durationMs;tS.current=setTimeout(()=>{tA.notes.forEach(r=>{p.fadeOutNote(r,e?.5*t:.7*t)})},e?.6*t:.95*t),tk.current=setTimeout(()=>{e8(!1)},t)},[tA,e5,e1.length,ty,e3]),tG=(0,n.useCallback)(()=>{if(!ty||e3||e9||0===e1.length)return;te(!0),tT.current.forEach(e=>clearTimeout(e)),tT.current=[];let e=[...tA.notes].sort((e,t)=>{var r,l;return(null!==(r=ed(e))&&void 0!==r?r:0)-(null!==(l=ed(t))&&void 0!==l?l:0)}),t=(e.length-1)*250+600;e.forEach((e,t)=>{let r=setTimeout(()=>{var t;p.playNote(e,.85,!1);let r=ed(e);null!==r&&(null===(t=eK.current)||void 0===t||t.flashNotes(e5,[r],500))},250*t);tT.current.push(r);let l=setTimeout(()=>{p.fadeOutNote(e,300)},250*t+600-100);tT.current.push(l)});let r=setTimeout(()=>{te(!1)},t);tT.current.push(r)},[tA,e5,ty,e3,e9,e1.length]),tz=(0,n.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"all";if(!ty||e3||e6||0===e1.length)return;ea(e),e7(!0);let t=r=>{if(r>=e1.length){e7(!1);return}e4(r);let l=ec(e1[r].notes,e);if(l.forEach(e=>{p.playNote(e,.8,!0)}),"all"!==e){var n;let e=l.map(ed).filter(e=>null!==e);null===(n=eK.current)||void 0===n||n.flashNotes(r,e,Math.max(300,1.4*e1[r].durationMs))}let a=2*e1[r].durationMs,s=Math.min(.4*a,600),o=Math.max(120,a-s),i=Math.max(0,o-80);tS.current=setTimeout(()=>{l.forEach(e=>{p.fadeOutNote(e,Math.max(200,.6*a))})},i),tk.current=setTimeout(()=>{t(r+1)},o)};t(0)},[ty,e3,e6,e1]),tH=(0,n.useCallback)(()=>{tk.current&&clearTimeout(tk.current),tS.current&&clearTimeout(tS.current),p.stopAllSounds(),e7(!1)},[]),tU=(0,n.useCallback)(()=>{ey(!1),to.stop(),e4(-1),ek(0),eT([]),eM(!1),eG.current=-1,eH.current.clear(),eU.current=[],ez.current=0,tt.reset(),tt.initializePlayhead(),tt.setPosition(-1)},[to,tt]),tW=(0,n.useCallback)(()=>{ty&&0!==e1.length&&(tt.reset(),e4(-1),ek(1),eT([]),eM(!1),eG.current=-1,eH.current.clear(),eU.current=[],ez.current=0,tt.initializePlayhead(),ey(!0),to.start())},[ty,e1.length,to,e_,tt]),tK=(0,n.useCallback)(()=>{ey(!1),to.stop(),eH.current.clear(),eU.current=[],ez.current=0,tt.stop(),eS.length>0&&eM(!0)},[to,eS.length,tt]),tQ=(0,n.useCallback)(()=>{tt.reset(),e4(0),tf([]),tm(null),tg(!1),e8(!1),e7(!1),ey(!1),eT([]),eM(!1),tv(!1),J(0),et(null),eG.current=0,eH.current.clear(),ez.current=0,e$.current.clear(),eY.current.clear(),eJ(!1),tk.current&&clearTimeout(tk.current),tS.current&&clearTimeout(tS.current),tE.current&&clearTimeout(tE.current),tC.current&&clearTimeout(tC.current),e0.current&&clearTimeout(e0.current),tT.current.forEach(e
1=>clearTimeout(e)),tT.current=[],te(!1),p.stopAllSounds(),to.stop()},[to,tt]),tX=(0,n.useCallback)(e=>{tQ(),Y(!1),F(e),null==b||b(e)},[tQ,b]);(0,n.useEffect)(()=>{if("recall"!==I||!ty||0===e1.length)return;let e=setTimeout(()=>{window.dispatchEvent(new CustomEvent("resetAndAutoPlay"))},400);return()=>clearTimeout(e)},[I,ty,e1.length]);let t$=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(e6){t$.current=!0;return}t$.current&&"listen"===I&&(Y(!0),null==v||v("listen")),t$.current=!1},[e6,I,v]),(0,n.useEffect)(()=>{eA&&"performance"===H&&0!==eS.length&&eS.filter(e=>e.correct).length/eS.length>=.8&&(null==v||v("perform"))},[eA]);let tY=(0,n.useCallback)(e=>{let t=e1[e];if(!t)return;t.notes.forEach(e=>{p.playNote(e,.8,!0)});let r=2*t.durationMs;tS.current=setTimeout(()=>{t.notes.forEach(e=>{p.fadeOutNote(e,.9*r)})},.95*r),tk.current=setTimeout(()=>{e8(!1)},r),e8(!0)},[e1]),tZ=(0,n.useCallback)((e,t)=>{e<0||e>=e1.length||(tf([]),tm(null),tg(!1),e$.current.clear(),eY.current.clear(),eJ(!1),J(0),et(null),e0.current&&(clearTimeout(e0.current),e0.current=null),tk.current&&clearTimeout(tk.current),tS.current&&clearTimeout(tS.current),tE.current&&clearTimeout(tE.current),tA.notes.forEach(e=>{p.fadeOutNote(e,500)}),e4(e),t&&setTimeout(()=>tY(e),100))},[e1.length,tA,tY]),tJ=(0,n.useCallback)(function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];tZ(e5+1,e)},[tZ,e5]),t0=(0,n.useMemo)(()=>ec(tA.notes,"all"),[tA]),t1=(0,n.useCallback)(e=>{var t;let r=t0.length;if(0===r||!ty)return;let l=null===ee?1===e?0:r-1:Math.max(0,Math.min(r-1,ee+e));et(l);let n=t0[l];p.playNote(n,.9,!1);let a=ed(n);null!==a&&(null===(t=eK.current)||void 0===t||t.flashNotes(e5,[a],900)),setTimeout(()=>p.fadeOutNote(n,400),900)},[t0,ee,ty,e5]),t2=(0,n.useCallback)(function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];tZ(e5-1,e)},[tZ,e5]),t5=(0,n.useCallback)(()=>{let e;if(!tA||0===th.length)return;let t=th.map(ed).filter(e=>null!==e),r=tA.notes.map(ed).filter(e=>null!==e),l=t.filter(e=>r.includes(e)),n=0===r.length?0:l.length/r.length*100;tm(e=l.length===r.length&&t.length===r.length?"correct":n>=50?"partial":"incorrect"),"practice"===H&&eW.current&&(tA.notes.forEach((e,r)=>{if(!tI(e))return;let l=ed(e);null!==l&&t.includes(l)?tt.applyNoteFeedback(e5,r,"success","perfect",e):tt.applyNoteFeedback(e5,r,"wrong",void 0,e)}),th.forEach(e=>{let t=ed(e);null!==t&&r.includes(t)})),f||"correct"!==e||tn(1),"correct"===e?(tg(!0),(0,en.Ac)(),tf([]),e5===e1.length-1?(tN.current&&tN.current.play(),null==v||v(I),tE.current=setTimeout(()=>{tv(!0)},500)):tE.current=setTimeout(()=>{tJ("recall"===I)},250)):(tj.current&&tj.current.play(),(0,en.Rm)(),setTimeout(()=>{"practice"===H&&tt.clearStepFeedback(e5),tm(null)},800)),u&&u(e)},[tA,th,f,tn,e5,e1.length,tJ,u,H,I,tt,tI,v]);return((0,n.useEffect)(()=>{if(tx||e3||e6||!tA||0===th.length)return;let e=th.map(ed).filter(e=>null!==e),t=tA.notes.map(ed).filter(e=>null!==e);if(eZ||e.length!==t.length)return;let r=setTimeout(()=>{t5()},150);return tC.current=r,()=>clearTimeout(r)},[th,tA,tx,e3,e6,t5,eZ]),(0,j.B)({onSpacebar:t_,disabled:!ty||e3||e6}),(0,n.useEffect)(()=>{let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement)){if("ArrowLeft"===e.key)t2();else if("ArrowRight"===e.key)tJ();else if("ArrowUp"===e.key||"ArrowDown"===e.key)"practice"!==H||e6||(e.preventDefault(),t1("ArrowUp"===e.key?1:-1));else{if("r"===e.key.toLowerCase())return;"Enter"===e.key?(e.preventDefault(),"practice"===H?(tt.reset(),e4(0),tf([]),tm(null),tg(!1),e8(!1),e7(!1),eT([]),eM(!1),e$.current.clear(),eY.current.clear(),eJ(!1),tk.current&&clearTimeout(tk.current),tS.current&&clearTimeout(tS.current),tE.current&&clearTimeout(tE.current),tC.current&&clearTimeout(tC.current),e0.current&&clearTimeout(e0.current),tT.current.forEach(e=>clearTimeout(e)),tT.current=[],te(!1),p.stopAllSounds()):tU()):"p"===e.key.toLowerCase()?"practice"===H&&(e6?tH():tz("all")):"m"!==e.key.toLowerCase()||"practice"!==H||e3||e9||e6||tG()}}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[tJ,t2,H,e6,tz,tH,t_,tU,e3,e9,tG,t1]),(0,n.useEffect)(()=>{let e={a:0,w:1,s:2,e:3,d:4,f:5,t:6,g:7,y:8,h:9,u:10,j:11,k:12,l:14},t=t=>{if(t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement||eq||eo||tb||eA)return;let r=t.key.toLowerCase();if("z"===r){t.preventDefault(),eE(e=>Math.max(2,e-1));return}if("x"===r){t.preventDefault(),eE(e=>Math.min(5,e+1));return}let l=e[r];void 0!==l&&(t.preventDefault(),tO((eC+1)*12+l))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[eC,tO,eq,eo,tb,eA]),0===e1.length)?(0,l.jsx)("div",{className:"flex flex-col items-center justify-center p-8",children:(0,l.jsx)("div",{className:"text-center",children:t?"Parsing MusicXML...":"No MusicXML provided"})}):A?(0,l.jsx)("div",{className:"flex flex-col items-center justify-center min-h-[60vh] w-full max-w-2xl mx-auto p-6",children:(0,l.jsxs)("div",{className:"bg-card border border-border rounded-xl p-8 text-center",children:[(0,l.jsx)("div",{className:"text-5xl mb-4",children:"\uD83C\uDFB9"}),(0,l.jsx)("h2",{className:"text-2xl font-bold mb-3 ear-title",children:T("hq.phone.title",{defaultValue:"Harmonic Quest lives in the app on a phone"})}),(0,l.jsx)("p",{className:"text-muted-foreground mb-6",children:T("hq.phone.body",{defaultValue:"The notation and the full keyboard need a wide screen. On a phone, the Earonman app has a layout built for it, with MIDI on Android."})}),(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[(0,l.jsx)("a",{href:$.qc,className:"px-5 py-3 rounded-full bg-action text-white font-semibold",rel:"noopener noreferrer",children:T("hq.phone.ios",{defaultValue:"Open in the iOS app"})}),(0,l.jsx)("a",{href:$.Wh,className:"px-5 py-3 rounded-full border border-border font-semibold",rel:"noopener noreferrer",children:T("hq.phone.android",{defaultValue:"Get it on Android"})})]})]})}):(0,l.jsxs)("div",{className:x?"w-full":"w-full min-h-screen pb-32",children:[(0,l.jsxs)("div",{className:"max-w-7xl mx-auto px-4 relative",children:[(0,l.jsx)("div",{className:"w-full mb-4",children:(0,l.jsx)(el,{ref:eK,xmlInput:tV,currentStepIndex:e5,followPlayhead:ev,showPlayhead:"performance"===H,width:Math.min(1200,window.innerWidth-100),height:320,onOSMDReady:e=>
1{eW.current=e,eX(!0)}})}),(0,l.jsxs)("div",{className:"w-full mb-4 flex flex-wrap items-center justify-between gap-3",children:[(0,l.jsx)("div",{role:"tablist","aria-label":T("hq.phasesLabel",{defaultValue:"Learning phase"}),className:"ear-glass backdrop-blur-xl rounded-full shadow border border-border/30 p-1 flex items-center gap-0.5",children:Q.ZG.map((e,t)=>{let r=I===e,n={listen:T("hq.phases.listen",{defaultValue:"Listen"}),follow:T("hq.phases.follow",{defaultValue:"Follow"}),recall:T("hq.phases.recall",{defaultValue:"By ear"}),perform:T("hq.phases.perform",{defaultValue:"In tempo"})};return(0,l.jsxs)("button",{role:"tab","aria-selected":r,onClick:()=>{r||tX(e)},className:"px-4 py-1.5 rounded-full text-xs font-bold uppercase tracking-wider transition-all duration-200 flex items-center gap-1.5 ".concat(r?"perform"===e?"bg-purple-600 text-white shadow":"bg-action text-white shadow":"text-muted-foreground hover:text-foreground hover:bg-card"),children:[(0,l.jsx)("span",{className:"w-4 h-4 rounded-full text-[10px] flex items-center justify-center ".concat(r?"bg-white/25":"bg-muted"),children:t+1}),n[e]]},e)})}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[tq&&(0,l.jsx)("span",{className:"px-3 py-1.5 rounded-full bg-card border border-border/60 text-sm font-semibold font-mono text-foreground",title:T("hq.oneChordTitle",{defaultValue:"The whole movement is this one chord"}),children:T("hq.oneChord",{chord:tq,defaultValue:"One chord: {{chord}}"})}),E,(0,l.jsx)("button",{onClick:()=>eh(!0),className:"p-2 rounded-full text-muted-foreground hover:text-foreground hover:bg-card transition-all",title:T("hq.help",{defaultValue:"How Harmonic Quest works"}),"aria-label":T("hq.help",{defaultValue:"How Harmonic Quest works"}),children:(0,l.jsx)(c.gZZ,{className:"text-base"})})]})]}),e1.length>1&&(0,l.jsxs)("div",{className:"w-full mb-4 flex items-center gap-3",children:[(0,l.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",role:"group","aria-label":T("hq.stepsLabel",{defaultValue:"Chords of the movement"}),children:e1.map((e,t)=>(0,l.jsx)("button",{type:"button","aria-label":T("hq.stepA11y",{index:t+1,total:e1.length,defaultValue:"Chord {{index}} of {{total}}"}),"aria-current":t===e5?"step":void 0,onClick:()=>{"performance"===H||e6||tZ(t,!0)},className:"h-2.5 rounded-full transition-all duration-200 ".concat(t===e5?"w-6 bg-action":t<e5?"w-2.5 bg-action/40 hover:bg-action/60":"w-2.5 bg-border hover:bg-muted-foreground/50")},e.id||t))}),(0,l.jsxs)("span",{className:"text-xs text-muted-foreground tabular-nums",children:[e5+1,"/",e1.length]}),null!==ee&&t0[ee]&&(0,l.jsxs)("span",{className:"ml-auto text-xs font-mono px-2 py-0.5 rounded-md bg-action/15 text-foreground","aria-live":"polite",children:[T("hq.voice.label",{index:ee+1,total:t0.length,defaultValue:"Voice {{index}} of {{total}}"}),"recall"!==I&&" \xb7 ".concat(t0[ee])]})]}),"listen"===I&&(0,l.jsxs)("div",{className:"w-full mb-6 rounded-2xl border border-border bg-card/60 p-5 flex flex-col md:flex-row md:items-center gap-4",children:[(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsx)("p",{className:"text-sm font-bold uppercase tracking-wider text-muted-foreground mb-1",children:T("hq.listen.heading",{defaultValue:"What is happening"})}),(0,l.jsx)("p",{className:"text-foreground",children:C||T("hq.listen.defaultBlurb",{defaultValue:"One chord in motion: the home chord climbs the scale and the diminished fills the steps between. The top voice sings the scale; the inner voices move by half steps."})}),tq&&(0,l.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:T("hq.listen.oneChord",{chord:tq,defaultValue:"Hear the whole movement as one chord: {{chord}}. The diminished between the steps is the motion, not a new chord."})}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:T("hq.listen.linesIntro",{defaultValue:"Then take it apart: the top voice on its own, the inner voices, the bass. Arrow up and down plays one voice of the chord under the spotlight."})})]}),(0,l.jsxs)("div",{className:"flex flex-col items-stretch gap-2 md:w-64",children:[ei.map(e=>
1{let t=e6&&er===e,r=T("hq.listen.lines.".concat(e),{defaultValue:{all:"Whole movement",top:"Top voice",inner:"Inner voices",bass:"Bass"}[e]});return(0,l.jsxs)(o.$,{onClick:()=>t?tH():tz(e),disabled:!ty||0===e1.length||e6&&!t,className:"".concat("all"===e?"h-12 text-base":"h-10 text-sm"," font-semibold justify-start ").concat(t?"bg-red-600 hover:bg-red-500 text-white":"all"===e?"bg-action hover:bg-action/90 text-white":"bg-card hover:bg-muted text-foreground border border-border"),children:[t?(0,l.jsx)(c.kwt,{className:"mr-2"}):(0,l.jsx)(c.gSK,{className:"mr-2 opacity-80"}),t?T("hq.listen.stop",{defaultValue:"Stop"}):r]},e)}),U&&(0,l.jsxs)(o.$,{onClick:()=>tX("follow"),variant:"outline",className:"h-11 text-base",children:[T("hq.listen.next",{defaultValue:"Now play it: Follow"})," â"]})]})]}),"recall"===I&&(0,l.jsxs)("div",{className:"w-full mb-4 min-h-[28px] flex items-center gap-3 text-sm",children:[(0,l.jsx)("span",{className:"text-muted-foreground",children:T("hq.recall.prompt",{defaultValue:"Hear the chord (Space), then play it. Only the top voice is written."})}),Z>=2&&tA.notes.length>0&&(0,l.jsxs)("span",{className:"font-mono text-foreground bg-muted rounded-md px-2 py-0.5",children:[T("hq.recall.hint",{defaultValue:"Hint:"})," ",[...tA.notes].sort((e,t)=>{var r,l;return(null!==(r=ed(e))&&void 0!==r?r:0)-(null!==(l=ed(t))&&void 0!==l?l:0)}).map(e=>{let t=ed(e),r=null!==t&&e$.current.has(t);return(0,l.jsxs)("span",{className:r?"text-green-500":"",children:[e," "]},e)})]})]}),(0,l.jsx)("div",{className:"w-full mb-6",children:(0,l.jsx)("div",{className:"bg-white dark:bg-card/50 rounded-2xl shadow-2xl border border-slate-400 dark:border-border overflow-hidden box-border",children:(0,l.jsx)("div",{className:"p-6",children:(0,l.jsx)(w,{firstNote:"C2",lastNote:"B5",onPlayNote:tO,disabled:!tP||e6||tx,showKeyboardShortcuts:!0,keyboardOctave:eC})})})}),(0,l.jsx)(a.N,{children:eq&&(0,l.jsx)(s.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/70 backdrop-blur-sm flex items-center justify-center z-[120] px-4",onClick:()=>{eP(!1),tu.stop()},children:(0,l.jsx)(s.P.div,{initial:{scale:.95,y:20},animate:{scale:1,y:0},exit:{scale:.95,y:20},transition:{type:"spring",duration:.3},onClick:e=>e.stopPropagation(),className:"bg-gradient-to-br from-slate-50 to-slate-100 dark:from-slate-900 dark:to-slate-950 rounded-2xl p-8 max-w-md w-full shadow-2xl border border-border",children:(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsx)("div",{className:"text-6xl mb-4",children:"\uD83C\uDFAF"}),(0,l.jsx)("h2",{className:"text-2xl font-bold mb-3 ear-title",children:"Latency Calibration"}),0===eD?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"text-muted-foreground mb-4",children:"This wizard will help calibrate your MIDI input latency."}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground mb-6",children:["You'll hear a 4-beat count-in, then 4 recording clicks. ",(0,l.jsx)("strong",{children:"Tap any key on your MIDI keyboard exactly on each of the 4 recording beats."})]}),(0,l.jsx)(o.$,{onClick:()=>{eF(-1),tu.start()},className:"w-full h-12 bg-purple-600 hover:bg-purple-700 text-white text-base",children:"Start Calibration"})]}):eD<0?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"mb-6",children:[(0,l.jsxs)("div",{className:"text-5xl font-bold text-blue-600 dark:text-action mb-2 animate-pulse",children:[Math.abs(eD)," / 4"]}),(0,l.jsx)("p",{className:"text-muted-foreground",children:"Count-in... Get ready!"})]}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground",children:"After count-in, start tapping on each beat"})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"mb-6",children:[(0,l.jsx)("div",{className:"text-5xl font-bold text-purple-600 dark:text-purple-400 mb-2",children:4===eR.length?"â":"".concat(eD," / 4")}),(0,l.jsx)("p",{className:"text-muted-foreground",children:4===eR.length?"Calculating offset...":eR.length===eD?"â Tap recorded!":"Tap on the beat!"})]}),(0,l.jsx)("div",{className:"flex gap-2 justify-center mb-6",children:[1,2,3,4].map(e=>(0,l.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center border-2 transition-all ".concat(e<eD?"bg-green-500/20 border-green-500 text-green-600":e===eD?"bg-purple-500/20 border-purple-500 text-purple-600 animate-pulse":"bg-slate-500/10 border-slate-500/30 text-slate-400"),children:e<=eR.length?"â":e},e))}),(0,l.jsx)("p",{className:"text-xs text-muted-foreground",children:"Tap any MIDI key when you hear the click"})]})]})})})}),(0,l.jsx)(a.N,{children:eA&&"performance"===H&&(0,l.jsx)(s.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-[110] px-4",onClick:()=>eM(!1),children:(0,l.jsx)(s.P.div,{initial:{scale:.95,y:20},animate:{scale:1,y:0},exit:{scale:.95,y:20},transition:{type:"spring",duration:.3},onClick:e=>e.stopPropagation(),className:"bg-gradient-to-br from-slate-50 to-slate-100 dark:from-slate-900 dark:to-slate-950 rounded-2xl p-8 max-w-md w-full shadow-2xl border border-border",children:(()=>{let e=eS.length,t=eS.filter(e=>e.correct).length,r=e>0?Math.round(t/e*100):0,n=r>=95?{emoji:"\uD83C\uDFBC",grade:"Maestro!",color:"text-yellow-500"}:r>=85?{emoji:"\uD83C\uDFB9",grade:"Virtuoso",color:"text-green-500"}:r>=70?{emoji:"\uD83C\uDFB5",grade:"Melodic",color:"text-blue-500"}:r>=50?{emoji:"\uD83C\uDFB6",grade:"Harmonic",color:"text-purple-500"}:{emoji:"\uD83C\uDFB9",grade:"Keep Practicing",color:"text-orange-500"};return(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsx)("div",{className:"text-6xl mb-4",children:n.emoji}),(0,l.jsx)("h2",{className:"text-3xl font-bold mb-2 ".concat(n.color),children:n.grade}),(0,l.jsxs)("p",{className:"text-5xl font-bold mb-6 ear-title",children:[r,"%"]}),(0,l.jsx)("div",{className:"bg-slate-100 dark:bg-card rounded-xl p-4 mb-6",children:(0,l.jsxs)("div",{className:"flex justify-around text-center",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-green-500",children:t}),(0,l.jsx)("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Correct"})]}),(0,l.jsx)("div",{className:"w-px bg-slate-300 dark:bg-slate-600"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-red-500",children:e-t}),(0,l.jsx)("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Missed"})]}),(0,l.jsx)("div",{className:"w-px bg-slate-300 dark:bg-slate-600"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-2xl font-bold text-slate-600 dark:text-slate-300",children:e}),(0,l.jsx)("div",{className:"text-xs text-muted-foreground uppercase tracking-wider",children:"Total"})]})]})}),(0,l.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,l.jsx)(o.$,{onClick:()=>{eM(!1),tU()},className:"w-full h-12 bg-purple-600 hover:bg-purple-500 text-white text-base",children:"Try Again"}),(0,l.jsx)(o.$,{onClick:()=>{eM(!1),window.dispatchEvent(new CustomEvent("changeHarmonicQuestKey"))},variant:"outline",className:"w-full h-12 text-base hover:bg-muted",children:S?T("hq.done.nextKey",{key:S,defaultValue:"Same shape in {{key}}"}):T("hq.done.otherKey",{defaultValue:"Practice in a different key"})})]})]})})()})})}),(0,l.jsx)(a.N,{children:tb&&"practice"===H&&(0,l.jsx)(s.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-[110] px-4",onClick:()=>tv(!1),children:(0,l.jsx)(s.P.div,{initial:{scale:.95,y:20},animate:{scale:1,y:0},exit:{scale:.95,y:20},transition:{type:"spring",duration:.3},onClick:e=>e.stopPropagation(),className:"bg-gradient-to-br from-slate-50 to-slate-100 dark:from-slate-900 dark:to-slate-950 rounded-2xl p-8 max-w-md w-full shadow-2xl border border-border",children:(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsx)("div",{className:"text-6xl mb-4",children:"\uD83C\uDF89"}),(0,l.jsx)("h2",{className:"text-3xl font-bold mb-3 ear-title",children:"recall"===I?T("hq.done.recallTitle",{defaultValue:"By ear. All of it."}):T("hq.done.followTitle",{defaultValue:"Played through!"})}),(0,l.jsx)("p",{className:"text-muted-foreground mb-8",children:"recall"===I?T("hq.done.recallBody",{defaultValue:"The voicings are in your ear now. Next: keep them together on the click, or take the same shape to the next key."}):T("hq.done.followBody",{defaultValue:"The shape is under your hands. Next: play it without the notes."})}),(0,l.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,l.jsx)(o.$,{onClick:()=>tX("recall"===I?"perform":"recall"),className:"w-full h-12 bg-gradient-to-r from-emerald-600 to-emerald-500 hover:from-emerald-700 hover:to-emerald-600 text-white text-base font-medium shadow-lg shadow-emerald-500/25",children:"recall"===I?T("hq.done.toPerform",{defaultValue:"Next: in tempo with the click"}):T("hq.done.toRecall",{defaultValue:"Next: play it by ear"})}),(0,l.jsx)(o.$,{onClick:()=>{tt.clearFeedback(),window.dispatchEvent(new CustomEvent("changeHarmonicQuestKey")),tv(!1)},className:"w-full h-12 bg-gradient-to-r from-amber-600 to-orange-500 hover:from-amber-700 hover:to-orange-600 text-white text-base font-medium shadow-lg shadow-amber-500/25",children:S?T("hq.done.nextKey",{key:S,defaultValue:"Same shape in {{key}}"}):T("hq.done.otherKey",{defaultValue:"Practice in a different key"})}),(0,l.jsx)(o.$,{onClick:()=>{tQ()},variant:"outline",className:"w-full h-12 text-base",children:T("hq.done.repeat",{defaultValue:"Repeat"})})]})]})})})}),(0,l.jsx)(a.N,{children:eo&&(0,l.jsx)(s.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/70 backdrop-blur-sm flex items-center justify-center z-[120] px-4",onClick:()=>eh(!1),children:(0,l.jsxs)(s.P.div,{initial:{scale:.95,y:20},animate:{scale:1,y:0},exit:{scale:.95,y:20},transition:{type:"spring",duration:.3},onClick:e=>e.stopPropagation(),className:"bg-gradient-to-br from-slate-50 to-slate-100 dark:from-slate-900 dark:to-slate-950 rounded-2xl p-6 max-w-2xl w-full shadow-2xl border border-border max-h-[85vh] overflow-y-auto",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold ear-title",children:"\uD83C\uDFB9 How to Use Harmonic Quest"}),(0,l.jsx)("button",{onClick:()=>eh(!1),className:"p-2 rounded-full hover:bg-slate-200 dark:hover:bg-card transition-all text-slate-500",children:"â"})]}),(0,l.jsxs)("div",{className:"mb-6",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,l.jsx)("div",{className:"px-3 py-1 rounded-full bg-action text-white text-xs font-bold uppercase tracking-wider",children:"Listen \xb7 Follow \xb7 By ear"}),(0,l.jsx)("span",{className:"text-sm text-muted-foreground",children:"Hear the lines, play with the notes, then without them"})]}),(0,l.jsxs)("div",{className:"bg-slate-100 dark:bg-card rounded-xl p-4 space-y-3",children:[(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-action/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("span",{className:"text-blue-500 font-bold text-sm",children:"1"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Listen to the chord"}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Press ",(0,l.jsx)("span",{className:"px-1.5 py-0.5 bg-slate-200 dark:bg-surface2 rounded text-xs font-mono",children:"Space"})," to hear the current chord harmonically, or ",(0,l.jsx)("span",{className:"px-1.5 py-0.5 bg-slate-200 dark:bg-surface2 rounded text-xs font-mono",children:"M"})," to hear it melodically (arpeggio)"]})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-action/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("span",{className:"text-blue-500 font-bold text-sm",children:"2"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Play the notes on your MIDI keyboard"}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Match all notes shown in the notation. ",(0,l.jsx)("span",{className:"text-green-500 font-medium",children:"Green glow"})," = correct, ",(0,l.jsx)("span",{className:"text-red-500 font-medium",children:"red glow"})," = wrong note"]})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-action/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("span",{className:"text-blue-500 font-bold text-sm",children:"3"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Advance to next step"}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Once all notes are correct, you auto-advance. Or use ",(0,l.jsx)("span",{className:"px-1.5 py-0.5 bg-slate-200 dark:bg-surface2 rounded text-xs font-mono",children:"â"})," to skip, ",(0,l.jsx)("span",{className:"px-1.5 py-0.5 bg-slate-200 dark:bg-surface2 rounded text-xs font-mono",children:"â"})," to go back"]})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-orange-500/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)(c.gSK,{className:"text-orange-500 text-xs"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Play entire progression"}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Press ",(0,l.jsx)("span",{className:"px-1.5 py-0.5 bg-slate-200 dark:bg-surface2 rounded text-xs font-mono",children:"P"})," to hear all chords played in sequence"]})]})]})]})]}),(0,l.jsxs)("div",{className:"mb-6",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,l.jsx)("div",{className:"px-3 py-1 rounded-full bg-purple-600 text-white text-xs font-bold uppercase tracking-wider",children:"In tempo"}),(0,l.jsx)("span",{className:"text-sm text-muted-foreground",children:"Play in real-time with tempo"})]}
1),(0,l.jsxs)("div",{className:"bg-slate-100 dark:bg-card rounded-xl p-4 space-y-3",children:[(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-purple-500/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("span",{className:"text-purple-500 font-bold text-sm",children:"1"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Set your tempo (BPM)"}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground",children:"Adjust the tempo to your comfort level. Enable/disable metronome click as needed"})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-purple-500/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("span",{className:"text-purple-500 font-bold text-sm",children:"2"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Start performance"}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground",children:"Press play to start. You'll get a 4-beat count-in, then play each chord exactly on the beat"})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-purple-500/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)("span",{className:"text-purple-500 font-bold text-sm",children:"3"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Get your results"}),(0,l.jsxs)("p",{className:"text-sm text-muted-foreground",children:["After completing, you'll see timing accuracy for each chord: ",(0,l.jsx)("span",{className:"text-green-500",children:"\uD83C\uDFAF Perfect"}),", ",(0,l.jsx)("span",{className:"text-green-400",children:"â Good"}),", ",(0,l.jsx)("span",{className:"text-orange-400",children:"â¡ Early/Late"}),", or ",(0,l.jsx)("span",{className:"text-red-400",children:"â Wrong"})]})]})]}),(0,l.jsxs)("div",{className:"flex gap-3",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-cyan-500/20 flex items-center justify-center flex-shrink-0",children:(0,l.jsx)(c.BHn,{className:"text-cyan-500 text-xs"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-foreground",children:"Calibrate latency (optional)"}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground",children:"If timing feels off, use the Calibrate button to adjust for your MIDI keyboard's input latency"})]})]})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"text-sm font-bold text-muted-foreground uppercase tracking-wider mb-3",children:"â¨ï¸ Keyboard Shortcuts"}),(0,l.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:[{key:"Space",action:"Play chord"},{key:"M",action:"Play melodic"},{key:"Enter",action:"Restart"},{key:"â",action:"Previous step"},{key:"â",action:"Next step"},{key:"â â",action:"One voice at a time"},{key:"P",action:"Play the whole movement"},{key:"A-L",action:"Play notes"},{key:"Z",action:"Octave down"},{key:"X",action:"Octave up"}].map(e=>{let{key:t,action:r}=e;return(0,l.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,l.jsx)("span",{className:"px-2 py-1 bg-slate-200 dark:bg-surface2 rounded text-xs font-mono font-bold min-w-[40px] text-center",children:t}),(0,l.jsx)("span",{className:"text-muted-foreground",children:r})]},t)})})]}),(0,l.jsx)("div",{className:"mt-6 pt-4 border-t border-border",children:(0,l.jsx)(o.$,{onClick:()=>eh(!1),className:"w-full bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-500 hover:to-purple-500 text-white",children:"Got it! Let's practice"})})]})})}),(0,l.jsxs)("div",{className:"mt-4 flex flex-col items-center gap-1",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 text-xs bg-muted/30 px-3 py-2 rounded-full border border-border/30",children:[(0,l.jsx)("span",{className:"text-muted-foreground/60",children:"MIDI:"}),(0,l.jsxs)("select",{className:"bg-transparent border-none text-foreground/80 focus:outline-none text-xs font-medium cursor-pointer",value:(null==tR?void 0:tR.id)||"",onChange:e=>{tB((null==tF?void 0:tF.find(t=>
1t.id===e.target.value))||null)},children:[(0,l.jsx)("option",{value:"",children:"None"}),tF&&tF.length>0?tF.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name||e.manufacturer||e.id},e.id)):(0,l.jsx)("option",{disabled:!0,value:"",children:"No devices found"})]})]}),(!tF||0===tF.length)&&(0,l.jsx)("p",{className:"text-[10px] text-muted-foreground/60",children:"No devices? Try refreshing the page."})]}),!x&&(0,l.jsxs)("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex flex-col items-center w-full max-w-3xl pointer-events-none",children:[(0,l.jsx)(a.N,{mode:"wait",children:"performance"===H&&ev&&(0,l.jsx)("div",{className:"mb-4 h-12 flex items-center justify-center w-full pointer-events-none",children:(0,l.jsxs)(s.P.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"px-4 py-2 rounded-full ear-glass border border-border/50 text-slate-300 backdrop-blur-md shadow-lg flex items-center gap-3",children:[(0,l.jsx)("div",{className:"w-2 h-2 bg-red-500 rounded-full animate-pulse"}),(0,l.jsx)("span",{className:"text-sm font-mono",children:-1===e5?"Count-in: ".concat(ej):"Step ".concat(e5+1," / ").concat(e1.length)})]})})}),(0,l.jsxs)("div",{className:"flex items-center gap-4 text-[10px] font-medium uppercase tracking-wider transition-opacity duration-300 ".concat("practice"===H?"text-slate-500 opacity-100":"text-slate-600 opacity-50"),children:[(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"Enter"})," Restart"]}),(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"â"})," Prev"]}),(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"Space"})," Play"]}),(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"M"})," Melodic"]}),(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"â"})," Next"]}),(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"â"}),"/",(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"â"})," Voice"]}),(0,l.jsxs)("span",{className:"flex items-center gap-1",children:[(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"Z"}),"/",(0,l.jsx)(i.u,{className:"h-4 text-[9px]",children:"X"})," Octave"]})]})]})]}),"practice"===H&&(0,l.jsx)("div",{className:"fixed left-2 z-50 pointer-events-auto flex flex-col gap-2",style:{top:"50vh",transform:"translateY(-120px)"},children:(0,l.jsxs)("div",{className:"ear-glass backdrop-blur-xl rounded-xl shadow-xl border border-border/30 p-1.5 lg:p-2 flex flex-col items-stretch gap-1 lg:gap-1.5 w-[72px] lg:w-[90px]",children:[(0,l.jsxs)("button",{onClick:t_,disabled:!ty||e3||e6,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(e3?"bg-green-600 text-white shadow-lg":"text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50"),title:"Play Current (Space)",children:[(0,l.jsx)(c.gSK,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:"Play"})]}),(0,l.jsxs)("button",{onClick:tG,disabled:!ty||e3||e9||e6,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(e9?"bg-cyan-600 text-white shadow-lg":"text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50"),title:"Play Melodically (M)",children:[(0,l.jsx)(c.BHn,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:"Melodic"})]}),(0,l.jsxs)("button",{onClick:()=>e6?tH():tz("all"),disabled:!ty||e3||0===e1.length,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(e6?"bg-red-600 text-white shadow-lg":"text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50"),title:e6?"Stop":"Play All",children:[e6?(0,l.jsx)(c.kwt,{className:"w-3 h-3 lg:w-4 lg:h-4"}):(0,l.jsx)(c.gSK,{className:"w-3 h-3 lg:w-4 lg:h-4 opacity-60"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:e6?"Stop":"All"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("div",{className:"flex gap-1",children:[(0,l.jsxs)("button",{onClick:()=>t2(),disabled:0===e5||e6,className:"flex-1 py-1.5 lg:py-2 px-1 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Previous (â)",children:[(0,l.jsx)(c.QVr,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[7px] lg:text-[9px] font-bold uppercase",children:"Prev"})]}),(0,l.jsxs)("button",{onClick:()=>tJ(),disabled:e5===e1.length-1||e6,className:"flex-1 py-1.5 lg:py-2 px-1 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Next (â)",children:[(0,l.jsx)(c.Z0P,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[7px] lg:text-[9px] font-bold uppercase",children:"Next"})]})]}),(0,l.jsxs)("div",{className:"flex gap-1",children:[(0,l.jsxs)("button",{onClick:()=>t1(-1),disabled:!ty||e6||0===e1.length,className:"flex-1 py-1.5 lg:py-2 px-1 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:T("hq.voice.down",{defaultValue:"Voice down (â)"}),children:[(0,l.jsx)(c.$TP,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[7px] lg:text-[9px] font-bold uppercase",children:"Voice"})]}),(0,l.jsxs)("button",{onClick:()=>t1(1),disabled:!ty||e6||0===e1.length,className:"flex-1 py-1.5 lg:py-2 px-1 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:T("hq.voice.up",{defaultValue:"Voice up (â)"}),children:[(0,l.jsx)(c.uCC,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[7px] lg:text-[9px] font-bold uppercase",children:"Voice"})]})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("button",{onClick:()=>{tt.reset(),e4(0),tf([]),tm(null),tg(!1),e8(!1),e7(!1),eT([]),eM(!1),e$.current.clear(),eY.current.clear(),eJ(!1),tk.current&&clearTimeout(tk.current),tS.current&&clearTimeout(tS.current),tE.current&&clearTimeout(tE.current),tC.current&&clearTimeout(tC.current),e0.current&&clearTimeout(e0.current),tT.current.forEach(e
1=>clearTimeout(e)),tT.current=[],te(!1),p.stopAllSounds()},disabled:e3||e6,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Restart (Enter)",children:[(0,l.jsx)(c.Swo,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:"Restart"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("button",{onClick:()=>eb(!eg),className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(eg?"text-action hover:text-action hover:bg-action/20":"text-slate-500 hover:text-slate-400 hover:bg-card"),title:eg?"Sound ON":"Sound OFF",children:[eg?(0,l.jsx)(c.pPd,{className:"w-3 h-3 lg:w-4 lg:h-4"}):(0,l.jsx)(c.FZ2,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:eg?"Sound":"Muted"})]})]})}),"performance"===H&&(0,l.jsx)("div",{className:"fixed left-2 z-50 pointer-events-auto flex flex-col gap-2",style:{top:"50vh",transform:"translateY(-140px)"},children:(0,l.jsxs)("div",{className:"ear-glass backdrop-blur-xl rounded-xl shadow-xl border border-border/30 p-1.5 lg:p-2 flex flex-col items-stretch gap-1 lg:gap-1.5 w-[72px] lg:w-[90px]",children:[(0,l.jsxs)("button",{onClick:()=>{ev?tK():tW()},className:"w-full py-2 lg:py-2.5 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(ev?"bg-red-600 text-white shadow-lg":"bg-purple-600 text-white shadow-lg hover:bg-purple-500"),title:ev?"Stop":"Start Performance",children:[ev?(0,l.jsx)(c.kwt,{className:"w-4 h-4 lg:w-5 lg:h-5"}):(0,l.jsx)(c.gSK,{className:"w-4 h-4 lg:w-5 lg:h-5"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:ev?"Stop":"Start"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("div",{className:"w-full py-1 lg:py-1.5 rounded-lg flex flex-col items-center gap-0.5",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between w-full px-1",children:[(0,l.jsx)("button",{onClick:()=>ep(e=>Math.max(40,e-5)),disabled:ev,className:"w-5 h-5 lg:w-6 lg:h-6 rounded bg-card text-slate-400 hover:text-white hover:bg-surface2 disabled:opacity-50 flex items-center justify-center text-sm lg:text-base font-bold",children:"-"}),(0,l.jsx)("span",{className:"text-sm lg:text-base font-mono text-white font-bold",children:ef}),(0,l.jsx)("button",{onClick:()=>ep(e=>Math.min(200,e+5)),disabled:ev,className:"w-5 h-5 lg:w-6 lg:h-6 rounded bg-card text-slate-400 hover:text-white hover:bg-surface2 disabled:opacity-50 flex items-center justify-center text-sm lg:text-base font-bold",children:"+"})]}),(0,l.jsx)("span",{className:"text-[7px] lg:text-[9px] font-bold uppercase tracking-wide text-slate-500",children:"BPM"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("button",{onClick:()=>ex(!em),disabled:ev,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(em?"text-green-400 hover:text-green-300 hover:bg-green-500/20":"text-slate-500 hover:text-slate-400 hover:bg-card"," disabled:opacity-50"),title:em?"Click ON":"Click OFF",children:[(0,l.jsx)(c.BHn,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:em?"Click":"No Click"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("button",{onClick:tU,disabled:ev,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Restart Performance",children:[(0,l.jsx)(c.Swo,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:"Restart"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("button",{onClick:()=>eb(!eg),className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 transition-all duration-300 ".concat(eg?"text-action hover:text-action hover:bg-action/20":"text-slate-500 hover:text-slate-400 hover:bg-card"),title:eg?"Sound ON":"Sound OFF",children:[eg?(0,l.jsx)(c.pPd,{className:"w-3 h-3 lg:w-4 lg:h-4"}):(0,l.jsx)(c.FZ2,{className:"w-3 h-3 lg:w-4 lg:h-4"}),(0,l.jsx)("span",{className:"text-[8px] lg:text-[10px] font-bold uppercase tracking-wide",children:eg?"Sound":"Muted"})]}),(0,l.jsx)("div",{className:"w-full h-px bg-surface2 my-0.5"}),(0,l.jsxs)("button",{onClick:ti,disabled:ev,className:"w-full py-1.5 lg:py-2 px-2 rounded-lg flex flex-col items-center justify-center gap-0.5 text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Latency: ".concat(eI>=0?"+":"").concat((1e3*eI).toFixed(0),"ms"),children:[(0,l.jsxs)("span",{className:"text-[9px] lg:text-[11px] font-mono text-slate-300",children:[eI>=0?"+":"",(1e3*eI).toFixed(0),"ms"]}),(0,l.jsx)("span",{className:"text-[7px] lg:text-[9px] font-bold uppercase tracking-wide",children:"Calibrate"})]})]})})]})};var ef=r(46743);r(56310);var ep=r(26049),em=r.n(ep);let ex=e=>{let{onPlayNote:t,noteRange:r,width:n,disabled:a}=e,s=r.first,o=r.last,i=ef.NH.create({firstNote:s,lastNote:o,keyboardConfig:ef.NH.HOME_ROW}),c=Math.min(n+32,700);return(0,l.jsx)("div",{style:{width:"100%",maxWidth:c,backgroundColor:"#ffffff",borderRadius:"8px",padding:"16px",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05)",display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem auto",overflow:"hidden"},children:(0,l.jsx)("div",{style:{width:"100%",maxWidth:n,margin:"0 auto"},children:(0,l.jsx)(ef.yB,{noteRange:{first:s,last:o},playNote:e=>{if(a)return;let{note:r,octave:l}=(0,D.T)(e);u.JD.playUserNote("".concat(r).concat(l)),t(e)},stopNote:e=>{},width:n,keyboardShortcuts:i,disabled:a,renderNoteLabel:e=>{let{midiNumber:t,isAccidental:r}=e;return 60!==t||r?null:(0,l.jsx)("div",{className:em().middleCMarker,children:(0,l.jsx)("div",{className:em().middleCText,children:"C"})})}})})})};var eg=r(1628),eb=r(56901),ev=r(56114);let ey={bass:["G/4","F/4","E/4","D/4","C/4","B/3","A/3","G/3","F/3","E/3","D/3","C/3","B/2","A/2","G/2","F/2","E/2","D/2","C/2"],treble:["B/5","A/5","G/5","F/5","E/5","D/5","C/5","B/4","A/4","G/4","F/4","E/4","D/4","C/4","B/3","A/3","G/3","F/3","E/3"]}
1,ew=["","#","b"],eN=e=>{let{step:t,userNotes:r,showAnswer:a=!1,readOnly:s=!1,highlightCurrentStep:o=!1,onNoteSelect:i}=e,c=(0,n.useRef)(null),[u,d]=(0,n.useState)(null),[h,f]=(0,n.useState)(""),[p,m]=(0,n.useState)("treble"),x=e=>{if(!e||"string"!=typeof e)return console.error("Invalid note input:",e),null;if(e.includes("/"))return e;let t=e.match(/([A-G])(#|b)?(\d)/i);if(!t)return console.error("Failed to parse note:",e),null;let[,r,l,n]=t;return"".concat(r).concat(l||"","/").concat(n)};t.notes.map(e=>{let t=x(e);if(!t)return null;let r=parseInt(t.split("/")[1]);return{note:t,clef:r>=4?"treble":"bass"}}).filter(e=>null!==e),r.map(e=>{let t=x(e);if(!t)return null;let r=parseInt(t.split("/")[1]);return{note:t,clef:r>=4?"treble":"bass"}}).filter(e=>null!==e);let g=e=>e<=125?"treble":e>=145?"bass":e-100<170-e?"treble":"bass",b=(e,t)=>{let r=g(t),l=Math.floor((t-("treble"===r?0:170))/6.25),n=ey[r],a=Math.min(Math.max(0,l),n.length-1),s=n[a];if(h&&s){let[e,t]=s.split("/"),r=e[0];return"".concat(r).concat(h,"/").concat(t).toUpperCase()}return s},v=n.useMemo(()=>t.notes.map(e=>{let t=x(e);if(!t)return null;let r=parseInt(t.split("/")[1]);return{note:t,clef:r>=4?"treble":"bass"}}).filter(e=>null!==e),[t.notes]),y=n.useMemo(()=>r.map(e=>{let t=x(e);if(!t)return null;let r=parseInt(t.split("/")[1]);return{note:t,clef:r>=4?"treble":"bass"}}).filter(e=>null!==e),[r]);return(0,n.useEffect)(()=>{if(!c.current)return;let e=c.current;e.innerHTML="";
1let t=new ev.Renderer(e,ev.Renderer.Backends.SVG);t.resize(340,350);let r=t.getContext(),l=new ev.Stave(20,0,300);l.addClef("treble").setEndBarType(3);let n=new ev.Stave(20,170,300);n.addClef("bass").setEndBarType(3),l.setBegBarType(5),n.setBegBarType(5),l.setContext(r).draw(),n.setContext(r).draw();let h=new ev.StaveConnector(l,n).setType(3),f=new ev.StaveConnector(l,n).setType(1);if(h.setContext(r).draw(),f.setContext(r).draw(),a&&v.length>0){let e=v.filter(e=>"treble"===e.clef).map(e=>e.note),t=v.filter(e=>"bass"===e.clef).map(e=>e.note);if(e.length>0)try{let t=e.filter(e=>{if(!e||"string"!=typeof e||!e.includes("/"))return console.warn("Invalid treble answer note format:",e),!1;let[t,r]=e.split("/");return!(!t||!r||isNaN(parseInt(r)))||(console.warn("Invalid treble answer note components:",{noteName:t,octave:r,note:e}),!1)});if(0===t.length){console.warn("No valid treble answer notes to render");return}let n=t.map(e=>{let[t,r]=e.split("/"),l=t.replace("B","b").toLowerCase().charAt(0);return/[a-g]/.test(l)?"".concat(l,"/").concat(r):(console.warn("Invalid note letter:",l,"from note:",e),"c/4")});if(0===n.length){console.warn("No valid treble answer keys to create chord");return}let a=new ev.StaveNote({keys:n,duration:"q",clef:"treble"});t.forEach((e,t)=>{let[r]=e.split("/");r.includes("#")?a.addModifier(new ev.Accidental("#"),t):r.includes("B")&&"B"!==r&&a.addModifier(new ev.Accidental("b"),t)}),a.setStyle({fillStyle:o?"orange":"green",strokeStyle:o?"red":"green"});let s=new ev.Voice({num_beats:1,beat_value:4});if(s.setStrict(!1),s.addTickables([a]),0===s.getTickables().length)return;new ev.Formatter().joinVoices([s]).format([s],250),s.draw(r,l)}catch(e){}if(t.length>0)try{let e=t.filter(e=>{if(!e||"string"!=typeof e||!e.includes("/"))return console.warn("Invalid bass answer note format:",e),!1;let[t,r]=e.split("/");return!(!t||!r||isNaN(parseInt(r)))||(console.warn("Invalid bass answer note components:",{noteName:t,octave:r,note:e}),!1)});if(0===e.length){console.warn("No valid bass answer notes to render");return}let l=e.map(e=>{let[t,r]=e.split("/"),l=t.replace("B","b").toLowerCase().charAt(0);return/[a-g]/.test(l)?"".concat(l,"/").concat(r):(console.warn("Invalid note letter:",l,"from note:",e),"c/3")});if(0===l.length){console.warn("No valid bass answer keys to create chord");return}let a=new ev.StaveNote({keys:l,duration:"q",clef:"bass"});e.forEach((e,t)=>{let[r]=e.split("/");r.includes("#")?a.addModifier(new ev.Accidental("#"),t):r.includes("B")&&"B"!==r&&a.addModifier(new ev.Accidental("b"),t)}),a.setStyle({fillStyle:o?"orange":"green",strokeStyle:o?"red":"green"});let s=new ev.Voice({num_beats:1,beat_value:4});if(s.setStrict(!1),s.addTickables([a]),0===s.getTickables().length)return;new ev.Formatter().joinVoices([s]).format([s],250),s.draw(r,n)}catch(e){}}if(y.length>0){let e=y.filter(e=>"treble"===e.clef).map(e=>e.note),t=y.filter(e=>"bass"===e.clef).map(e=>e.note);if(e.length>0)try{let t=e.filter(e=>{if(!e||"string"!=typeof e||!e.includes("/"))return console.warn("Invalid treble note format:",e),!1;let[t,r]=e.split("/");return!(!t||!r||isNaN(parseInt(r)))||(console.warn("Invalid treble note components:",{noteName:t,octave:r,note:e}),!1)});if(0===t.length){console.warn("No valid treble notes to render");return}let n=t.map(e=>{let[t,r]=e.split("/"),l=t.replace("B","b").toLowerCase().charAt(0);return/[a-g]/.test(l)?"".concat(l,"/").concat(r):(console.warn("Invalid note letter:",l,"from note:",e),"c/4")});if(0===n.length){console.warn("No valid treble keys to create chord");return}let s=new ev.StaveNote({keys:n,duration:"q",clef:"treble"});t.forEach((e,t)=>{let[r]=e.split("/");r.includes("#")?s.addModifier(new ev.Accidental("#"),t):r.includes("B")&&"B"!==r&&s.addModifier(new ev.Accidental("b"),t)}),s.setStyle({fillStyle:a?"blue":"black"});let o=new ev.Voice({num_beats:1,beat_value:4});if(o.setStrict(!1),o.addTickables([s]),0===o.getTickables().length)return;new ev.Formatter().joinVoices([o]).format([o],250),o.draw(r,l)}catch(e){}if(t.length>0)try{let e=t.filter(e=>{if(!e||"string"!=typeof e||!e.includes("/"))return console.warn("Invalid bass note format:",e),!1;let[t,r]=e.split("/");return!(!t||!r||isNaN(parseInt(r)))||(console.warn("Invalid bass note components:",{noteName:t,octave:r,note:e}),!1)});if(0===e.length){console.warn("No valid bass notes to render");return}let l=e.map(e=>{let[t,r]=e.split("/"),l=t.replace("B","b").toLowerCase().charAt(0);return/[a-g]/.test(l)?"".concat(l,"/").concat(r):(console.warn("Invalid note letter:",l,"from note:",e),"c/3")});if(0===l.length){console.warn("No valid bass keys to create chord");return}let s=new ev.StaveNote({keys:l,duration:"q",clef:"bass"});e.forEach((e,t)=>{let[r]=e.split("/");r.includes("#")?s.addModifier(new ev.Accidental("#"),t):r.includes("B")&&"B"!==r&&s.addModifier(new ev.Accidental("b"),t)}),s.setStyle({fillStyle:a?"blue":"black"});let o=new ev.Voice({num_beats:1,beat_value:4});if(o.setStrict(!1),o.addTickables([s]),0===o.getTickables().length)return;new ev.Formatter().joinVoices([o]).format([o],250),o.draw(r,n)}catch(e){}}if(u&&!s){let e=x(u);if(e)try{if(!e||"string"!=typeof e||!e.includes("/")){console.warn("Invalid cursor note format:",e);return}let[t,a]=e.split("/");if(!t||!a||isNaN(parseInt(a))){console.warn("Invalid cursor note components:",{noteName:t,octave:a,vexCursorNote:e});return}let s="treble"===p?l:n,o=t.replace("B","b").toLowerCase().charAt(0);if(!/[a-g]/.test(o)){console.warn("Invalid cursor note letter:",o,"from note:",e);return}let i="".concat(o,"/").concat(a),c=new ev.StaveNote({keys:[i],duration:"q",clef:p}).setStyle({fillStyle:"rgba(0, 0, 255, 0.3)"});t.includes("#")?c.addModifier(new ev.Accidental("#")):t.includes("B")&&"B"!==t&&c.addModifier(new ev.Accidental("b"));let u=new ev.Voice({num_beats:1,beat_value:4});if(u.setStrict(!1),u.addTickables([c]),0===u.getTickables().length){console.warn("Cursor voice has no tickables");return}new ev.Formatter().joinVoices([u]).format([u],250),u.draw(r,s)}catch(t){console.error("Error formatting cursor voice:",t,{cursorNote:u,vexCursorNote:e,cursorClef:p})}}let w=e.querySelector("svg");w&&!s&&i&&(w.style.cursor="pointer",w.onmousemove=e=>{let t=w.getBoundingClientRect(),r=e.clientX-t.left,l=e.clientY-t.top;
1m(g(l));let n=x(b(r,l));n&&n!==u&&d(n)},w.onmouseleave=()=>{d(null)},w.onclick=e=>{let t=w.getBoundingClientRect(),r=e.clientX-t.left,l=e.clientY-t.top;g(l);let n=x(b(r,l));if(n){let[e,t]=n.split("/");i("".concat(e).concat(t))}})},[v,y,a,u,h,p,s,o,i]),(0,l.jsxs)("div",{className:"harmonic-quest-notation flex flex-col items-center",children:[(0,l.jsxs)("div",{className:"mb-2 w-full flex justify-between items-center",style:{minHeight:"40px"},children:[(0,l.jsx)("div",{className:"flex space-x-2",children:s?(0,l.jsx)("div",{className:"h-8"}):ew.map(e=>(0,l.jsx)("button",{onClick:()=>{f(e)},className:"px-3 py-1 rounded ".concat(h===e?"bg-action text-white":"bg-gray-200 text-black hover:bg-gray-300"),children:""===e?"â®":"#"===e?"â¯":"â"},e))}),!s&&(0,l.jsx)("button",{onClick:()=>{f(""),i&&i("clear")},className:"px-3 py-1 rounded bg-red-500 text-white hover:bg-red-600",children:"Clear"})]}),(0,l.jsx)("div",{ref:c,id:"harmonic-quest-notation-container",style:{backgroundColor:"white",width:"".concat(340,"px"),height:"350px",borderRadius:"4px",padding:"10px"}}),(0,l.jsx)("div",{className:"mt-2 text-sm text-muted-foreground",style:{minHeight:"20px"},children:!s&&(0,l.jsxs)(l.Fragment,{children:["Click to add/remove notes.",a&&(0,l.jsxs)("span",{className:"ml-2",children:[(0,l.jsx)("span",{className:"text-green-500",children:"â "})," Expected notes,",(0,l.jsx)("span",{className:"text-blue-500 ml-1",children:"â "})," Your notes"]})]})})]})},ej=e=>{let{xmlInput:t,onStepChange:a,onValidation:s,initialStep:i=0,allowMouseInput:u=!0,previewMode:d=!1,mode:h="exercise"}=e,{startSession:f,endSession:m,recordAttempt:x}=V(),{startExercise:g,exerciseAccess:b}=(0,eb.R)(),[v,y]=(0,n.useState)([]),[w,k]=(0,n.useState)(i),[C,E]=(0,n.useState)(!1),[S,T]=(0,n.use
1State)(!1),[A,M]=(0,n.useState)([]),[I,q]=(0,n.useState)(null),[F,R]=(0,n.useState)(!1),[B,L]=(0,n.useState)(!1),{playCorrect:O,playWrong:_}=(0,eg.J)(),G=(0,n.useRef)(null),z=(0,n.useRef)(null),H=(0,n.useRef)(null),U=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!t){y([{id:"step-1",notes:["C4","E4","G4"],durationMs:1e3},{id:"step-2",notes:["D4","F4","A4"],durationMs:1e3},{id:"step-3",notes:["E4","G4","B4"],durationMs:1e3}]);return}try{let e=(0,P.q6)(t);y(e),console.debug("[HQ Exercise] Parsed steps",e)}catch(e){y([{id:"step-1",notes:["C4","E4","G4"],durationMs:1e3},{id:"step-2",notes:["D4","F4","A4"],durationMs:1e3},{id:"step-3",notes:["E4","G4","B4"],durationMs:1e3}])}},[t]),(0,n.useEffect)(()=>((async()=>{try{await p.waitForLoad(),L(!0)}catch(e){}})(),()=>{p.cleanup(),G.current&&clearTimeout(G.current),z.current&&clearTimeout(z.current),H.current&&clearTimeout(H.current),U.current&&clearTimeout(U.current)}),[]),(0,n.useEffect)(()=>{let e=!0;if(!d&&e)return f("harmonic-quest"),()=>{e=!1,m()}},[d]),(0,n.useEffect)(()=>{a&&a(w)},[w,a]);let W=v[w]||{id:"",notes:[],durationMs:0};console.debug("[HQ Exercise] Current step",{index:w,step:W});let K=(0,n.useCallback)(e=>e&&e.notes&&0!==e.notes.length?e.notes.reduce((e,t)=>{let r=e.match(/([A-G][#b]?)(\d+)/),l=t.match(/([A-G][#b]?)(\d+)/);if(!r||!l)return e;let[,n,a]=r,[,s,o]=l;if(parseInt(o)<parseInt(a))return t;if(parseInt(o)>parseInt(a))return e;let i={C:0,"C#":1,Cb:-1,D:2,"D#":3,Db:1,E:4,"E#":5,Eb:3,F:5,"F#":6,Fb:4,G:7,"G#":8,Gb:6,A:9,"A#":10,Ab:8,B:11,"B#":12,Bb:10};return i[s]<i[n]?t:e}):null,[]),Q=(0,n.useCallback)(e=>{let t=K(e);return t?{...e,notes:[t]}:e},[K]),X=K(W);(0,n.useEffect)(()=>{X&&M(e=>0===e.length||e[0]!==X?[X,...e.filter(e=>e!==X)]:e)},[X]);let $=(0,n.useCallback)(function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(!t||S||F)return;let{note:r,octave:l}=(0,D.T)(e),n="".concat(r).concat(l);p.playNote(n),M(e=>e.includes(n)?e.filter(e=>e!==n):[...e,n])},[S,F]),{midiInputs:Y,selectedInput:Z,setSelectedInput:J,error:ee}=(0,N.Z)($),et=(0,n.useCallback)(e=>{if(!u||S||F)return;let{note:t,octave:r}=(0,D.T)(e),l="".concat(t).concat(r);p.playNote(l),M(e=>e.includes(l)?e.filter(e=>e!==l):[...e,l])},[u,S,F]),er=(0,n.useCallback)(async()=>{if(!B||C||0===v.length)return;try{if(!await g()){let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Daily exercise limit reached. Upgrade to Pro for unlimited practice!",variant:"warning"});return}}catch(t){let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Unable to start exercise. Please try again.",variant:"error"});return}E(!0),W.notes.forEach(e=>{p.playNote(e,.8,!0)});let e=w===v.length-1,t=e?1.2*W.durationMs:2*W.durationMs;U.current=setTimeout(()=>{W.notes.forEach(r=>{p.fadeOutNote(r,e?.2*t:.4*t)})},e?.6*t:.95*t),G.current=setTimeout(()=>{E(!1)},t)},[W,w,v.length,B,C,g]),el=(0,n.useCallback)(async()=>{if(!B||C||S||0===v.length)return;try{if(!await g()){let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Daily exercise limit reached. Upgrade to Pro for unlimited practice!",variant:"warning"});return}}catch(t){console.error("Error checking subscription access:",t);let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Unable to start exercise. Please try again.",variant:"error"});return}T(!0);let e=t=>{if(t>=v.length){T(!1);return}k(t),v[t].notes.forEach(e=>{p.playNote(e,.8,!0)});let r=2*v[t].durationMs;U.current=setTimeout(()=>{v[t].notes.forEach(e=>{p.fadeOutNote(e,.4*r)})},.95*r),G.current=setTimeout(()=>{e(t+1)},r+400)};e(0)},[B,C,S,v,g]),en=(0,n.useCallback)(()=>{G.current&&clearTimeout(G.current),U.current&&clearTimeout(U.current),p.stopAllSounds(),T(!1),E(!1)},[]),ea=(0,n.useCallback)(async()=>{if(w<v.length-1){try{if(!await g()){let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Daily exercise limit reached. Upgrade to Pro for unlimited practice!",variant:"warning"});return}}catch(t){console.error("Error checking subscription access:",t);let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Unable to start exercise. Please try again.",variant:"error"});return}G.current&&clearTimeout(G.current),U.current&&clearTimeout(U.current),H.current&&clearTimeout(H.current),p.stopAllSounds();let e=w+1;k(e),M([]),q(null),R(!1),setTimeout(()=>{let t=v[e];
1if(t){t.notes.forEach(e=>{p.playNote(e,.8,!0)});let e=2*t.durationMs;U.current=setTimeout(()=>{t.notes.forEach(t=>{p.fadeOutNote(t,.4*e)})},.95*e),G.current=setTimeout(()=>{E(!1)},e),E(!0)}},100)}},[w,v,g]),es=(0,n.useCallback)(async()=>{if(w>0){try{if(!await g()){let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Daily exercise limit reached. Upgrade to Pro for unlimited practice!",variant:"warning"});return}}catch(t){console.error("Error checking subscription access:",t);let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Unable to start exercise. Please try again.",variant:"error"});return}G.current&&clearTimeout(G.current),U.current&&clearTimeout(U.current),H.current&&clearTimeout(H.current),p.stopAllSounds();let e=w-1;k(e),M([]),q(null),R(!1),setTimeout(()=>{let t=v[e];if(t){t.notes.forEach(e=>{p.playNote(e,.8,!0)});let e=2*t.durationMs;U.current=setTimeout(()=>{t.notes.forEach(t=>{p.fadeOutNote(t,.4*e)})},.95*e),G.current=setTimeout(()=>{E(!1)},e),E(!0)}},100)}},[w,v,g]),eo=(0,n.useCallback)(()=>{let e;if(!W||0===A.length)return;let t=A.filter(e=>W.notes.includes(e)),r=t.length/W.notes.length*100;q(e=t.length===W.notes.length&&A.length===W.notes.length?"correct":r>=50?"partial":"incorrect"),R(!0),d||x("correct"===e?1:"partial"===e?.5:0),"correct"===e?(w===v.length-1&&O(),w<v.length-1&&(H.current=setTimeout(()=>{ea()},1e3))):_(),s&&s(e)},[W,A,ea,s,d,x,O,_,w,v.length]);if((0,n.useEffect)(()=>{if(!F&&!C&&!S&&W&&0!==A.length&&(1!==A.length||X!==A[0])&&A.length===W.notes.length&&A.every(e=>W.notes.includes(e))){let e=setTimeout(()=>{eo()},500);return()=>clearTimeout(e)}},[A,W,F,C,S,X]),(0,j.B)({onSpacebar:er,disabled:!B||C||S}),(0,n.useEffect)(()=>{let e=e=>{"ArrowLeft"===e.key?es():"ArrowRight"===e.key&&ea()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ea,es]),0===v.length)return(0,l.jsx)("div",{className:"flex flex-col items-center justify-center p-8",children:(0,l.jsx)("div",{className:"text-center",children:t?"Parsing MusicXML...":"No MusicXML provided"})});let ei=Q(W);return(0,l.jsxs)("div",{className:"flex flex-col items-center space-y-4 w-full max-w-4xl mx-auto pb-32",children:[(0,l.jsxs)("div",{className:"w-full px-4",children:[(0,l.jsxs)("div",{className:"flex justify-between text-xs text-muted-foreground mb-1",children:[(0,l.jsxs)("span",{children:["Step ",w+1," / ",v.length]}),(0,l.jsxs)("span",{children:[Math.round(w/(v.length-1)*100),"%"]})]}),(0,l.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,l.jsx)("div",{className:"bg-primary h-1.5 rounded-full transition-all duration-300",style:{width:"".concat(w/(v.length-1)*100,"%")}})})]}),(0,l.jsxs)("div",{className:"w-full bg-white/5 rounded-lg p-6",children:[(0,l.jsx)("div",{className:"flex flex-col items-center mb-4",children:(0,l.jsx)(eN,{step:ei,userNotes:A,showAnswer:F,readOnly:S,highlightCurrentStep:C||S,onNoteSelect:e=>{if("clear"===e){X?M([X]):M([]);return}M(t=>t.includes(e)?e===X?t:t.filter(t=>t!==e):[...t,e]),p.playNote(e)}})}),(0,l.jsxs)("div",{className:"mt-4 p-4 bg-white/5 rounded",children:[(0,l.jsx)("h3",{className:"text-lg font-medium mb-2",children:"Notes"}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-sm font-medium",children:"Bass note: "}),(0,l.jsx)("span",{className:"text-sm",children:ei.notes.join(", ")})]}),(0,l.jsxs)("div",{className:"ml-4",children:[(0,l.jsx)("span",{className:"text-sm font-medium",children:"Your input: "}),(0,l.jsx)("span",{className:"text-sm",children:A.length>0?A.join(", "):"No notes selected"})]})]})]}),(0,l.jsx)("div",{className:"mt-4 h-16 flex items-center justify-center",children:I&&(0,l.jsx)("div",{className:"p-4 rounded ".concat("correct"===I?"bg-success/10 border border-success text-success":"partial"===I?"bg-warning/10 border border-warning text-warning":"bg-error/10 border border-error text-error"),children:"correct"===I?"Perfect! All notes correct.":"partial"===I?"Good try! Some notes are correct.":"Try again. No matching notes."})})]}),Y.length>0&&(0,l.jsxs)("div",{className:"w-full flex items-center gap-2",children:[(0,l.jsx)("label",{className:"text-sm",children:"MIDI Input:"}),(0,l.jsxs)("select",{className:"flex-1 p-2 rounded bg-white/10",value:(null==Z?void 0:Z.id)||"",onChange:e=>{J(Y.find(t=>
1t.id===e.target.value)||null)},children:[(0,l.jsx)("option",{value:"",children:"None"}),Y.map(e=>(0,l.jsx)("option",{value:e.id,children:e.name||e.manufacturer||e.id},e.id))]})]}),(0,l.jsx)("div",{className:"w-full overflow-x-auto",children:(0,l.jsx)(ex,{noteRange:{first:ef.WX.fromNote("c2"),last:ef.WX.fromNote("b5")},onPlayNote:et,width:Math.min(600,window.innerWidth-40),disabled:!u||S||F})}),(0,l.jsxs)("div",{className:"w-full flex items-center justify-between gap-2 px-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(o.$,{onClick:()=>{X?M([X]):M([]),q(null),R(!1)},variant:"outline",size:"sm",disabled:A.length<=1||C||S,className:"text-xs",children:"Clear"}),(0,l.jsx)(o.$,{onClick:()=>R(!0),variant:"outline",size:"sm",disabled:F||C||S,className:"text-xs",children:"Show"})]}),(0,l.jsx)(o.$,{onClick:eo,size:"sm",disabled:0===A.length||F||C||S,className:"px-6",children:"Check"})]}),(0,l.jsx)("div",{className:"fixed left-1 z-50 pointer-events-auto flex flex-col gap-2 w-8",style:{top:"50vh",transform:"translateY(-70px)"},children:(0,l.jsxs)("div",{className:"ear-glass backdrop-blur-xl rounded-xl shadow-xl border border-border/30 p-1 flex flex-col items-center gap-0.5 w-full",children:[(0,l.jsx)("button",{onClick:er,disabled:!B||C||S,className:"w-full py-2 rounded-lg flex items-center justify-center transition-all duration-300 ".concat(C?"bg-action text-white shadow-lg":"text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50"),title:"Play Current (Space)",children:(0,l.jsx)(c.gSK,{className:"w-3 h-3"})}),(0,l.jsx)("button",{onClick:S?en:el,disabled:!B||C||0===v.length,className:"w-full py-2 rounded-lg flex items-center justify-center transition-all duration-300 ".concat(S?"bg-red-600 text-white shadow-lg":"text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50"),title:S?"Stop":"Play All",children:S?(0,l.jsx)(c.kwt,{className:"w-3 h-3"}):(0,l.jsx)(c.gSK,{className:"w-3 h-3 opacity-60"})}),(0,l.jsx)("div",{className:"w-4 h-px bg-surface2 my-0.5"}),(0,l.jsx)("button",{onClick:es,disabled:0===w||S,className:"w-full py-2 rounded-lg flex items-center justify-center text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Previous (â)",children:(0,l.jsx)(c.QVr,{className:"w-3 h-3"})}),(0,l.jsx)("button",{onClick:ea,disabled:w===v.length-1||S,className:"w-full py-2 rounded-lg flex items-center justify-center text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Next (â)",children:(0,l.jsx)(c.Z0P,{className:"w-3 h-3"})}),(0,l.jsx)("div",{className:"w-4 h-px bg-surface2 my-0.5"}),(0,l.jsx)("button",{onClick:async()=>{try{if(!await g()){let{notify:e}=await r.e(24224).then(r.bind(r,24224));e({description:"Daily exercise limit reached. Upgrade to Pro for unlimited practice!",variant:"warning"});return}}catch(e){console.error("Error checking subscription access:",e);return}k(0);let e=K(v[0]||W);e?M([e]):M([]),q(null),R(!1),E(!1),T(!1),G.current&&clearTimeout(G.current),U.current&&clearTimeout(U.current),H.current&&clearTimeout(H.current),z.current&&clearTimeout(z.current),p.stopAllSounds(),setTimeout(()=>{er()},300)},disabled:C||S,className:"w-full py-2 rounded-lg flex items-center justify-center text-slate-400 hover:text-slate-200 hover:bg-card disabled:opacity-50 transition-all",title:"Restart (Enter)",children:(0,l.jsx)(c.Swo,{className:"w-3 h-3"})})]})})]})},ek=e=>{let{mode:t="exercise",...r}=e;if("practice"===t)return(0,l.jsx)(eh,{...r,mode:t});{let{initialPhase:e,onPhaseChange:n,onPhaseComplete:a,homeQuality:s,tonicPc:o,blurb:i,keyControl:c,nextKeyLabel:u,...d}=r;return(0,l.jsx)(ej,{...d,mode:t})}}},32528:(e,t,r)=>{"use strict";function l(e){let t=Math.floor(e/12)-1;return{note:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"][e%12],octave:t}}function n(e,t){let r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];if(e.includes("bb")){let l=e.replace("bb",""),n=r.indexOf(l);if(n<0)throw Error("Invalid note name");let a=n-2,s=0;return a<0&&(a+=12,s=-1),(t+1+s)*12+a}if(e.includes("b")){let l=e.replace("b",""),n=r.indexOf(l);if(n<0)throw Error("Invalid note name");let a=n-1,s=0;return a<0&&(a+=12,s=-1),(t+1+s)*12+a}if(e.includes("##")||e.includes("x")){let l=e.replace(/##|x/g,""),n=r.indexOf(l);if(n<0)throw Error("Invalid note name");let a=n+2;return(t+1+Math.floor(a/12))*12+a%12}if(e.includes("#")){let l=e.replace(/#/g,""),n=r.indexOf(l);if(n<0)throw Error("Invalid note name");let a=n+(e.match(/#/g)||[]).length;return(t+1+Math.floor(a/12))*12+a%12}let l=r.indexOf(e);if(l<0)throw Error("Invalid note name");return(t+1)*12+l}r.d(t,{T:()=>l,w:()=>n})},55287:()=>{},26049:e=>{e.exports={pianoWrapper:"PianoComponent_pianoWrapper__lpi_D",pianoContainer:"PianoComponent_pianoContainer__Iug8g",middleCMarker:"PianoComponent_middleCMarker__ng
1XCV",middleCText:"PianoComponent_middleCText__GtTTE"}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.