audio-mixer-ui 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1217,7 +1217,13 @@ class ze {
1217
1217
  return this.playbackManager.getLeadInSettings();
1218
1218
  }
1219
1219
  // Transport controls (maintain DummyAudioEngine interface)
1220
- play(t = {}) {
1220
+ async play(t = {}) {
1221
+ if (this.audioContext && this.audioContext.state === "suspended")
1222
+ try {
1223
+ await this.audioContext.resume();
1224
+ } catch (s) {
1225
+ console.warn("Failed to resume AudioContext before play:", s);
1226
+ }
1221
1227
  const a = this.getCurrentToggleStates();
1222
1228
  t.leadInBars !== void 0 && this.setLeadInBars(t.leadInBars), this.playbackManager.play({
1223
1229
  leadIn: t.leadIn !== void 0 ? t.leadIn : a.leadIn,
@@ -1 +1 @@
1
- (function(P,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("pinia"),require("audio-mixer-engine")):typeof define=="function"&&define.amd?define(["exports","vue","pinia","audio-mixer-engine"],t):(P=typeof globalThis<"u"?globalThis:P||self,t(P.AudioMixerUI={},P.Vue,P.Pinia,P.AudioMixerEngine))})(this,function(P,t,X,le){"use strict";var pe=function(){if(typeof Map<"u")return Map;function a(e,s){var n=-1;return e.some(function(i,r){return i[0]===s?(n=r,!0):!1}),n}return function(){function e(){this.__entries__=[]}return Object.defineProperty(e.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),e.prototype.get=function(s){var n=a(this.__entries__,s),i=this.__entries__[n];return i&&i[1]},e.prototype.set=function(s,n){var i=a(this.__entries__,s);~i?this.__entries__[i][1]=n:this.__entries__.push([s,n])},e.prototype.delete=function(s){var n=this.__entries__,i=a(n,s);~i&&n.splice(i,1)},e.prototype.has=function(s){return!!~a(this.__entries__,s)},e.prototype.clear=function(){this.__entries__.splice(0)},e.prototype.forEach=function(s,n){n===void 0&&(n=null);for(var i=0,r=this.__entries__;i<r.length;i++){var o=r[i];s.call(n,o[1],o[0])}},e}()}(),ce=typeof window<"u"&&typeof document<"u"&&window.document===document,J=function(){return typeof global<"u"&&global.Math===Math?global:typeof self<"u"&&self.Math===Math?self:typeof window<"u"&&window.Math===Math?window:Function("return this")()}(),$e=function(){return typeof requestAnimationFrame=="function"?requestAnimationFrame.bind(J):function(a){return setTimeout(function(){return a(Date.now())},1e3/60)}}(),Oe=2;function Fe(a,e){var s=!1,n=!1,i=0;function r(){s&&(s=!1,a()),n&&h()}function o(){$e(r)}function h(){var v=Date.now();if(s){if(v-i<Oe)return;n=!0}else s=!0,n=!1,setTimeout(o,e);i=v}return h}var Ue=20,Ke=["top","right","bottom","left","width","height","size","weight"],Ge=typeof MutationObserver<"u",qe=function(){function a(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=Fe(this.refresh.bind(this),Ue)}return a.prototype.addObserver=function(e){~this.observers_.indexOf(e)||this.observers_.push(e),this.connected_||this.connect_()},a.prototype.removeObserver=function(e){var s=this.observers_,n=s.indexOf(e);~n&&s.splice(n,1),!s.length&&this.connected_&&this.disconnect_()},a.prototype.refresh=function(){var e=this.updateObservers_();e&&this.refresh()},a.prototype.updateObservers_=function(){var e=this.observers_.filter(function(s){return s.gatherActive(),s.hasActive()});return e.forEach(function(s){return s.broadcastActive()}),e.length>0},a.prototype.connect_=function(){!ce||this.connected_||(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),Ge?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},a.prototype.disconnect_=function(){!ce||!this.connected_||(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},a.prototype.onTransitionEnd_=function(e){var s=e.propertyName,n=s===void 0?"":s,i=Ke.some(function(r){return!!~n.indexOf(r)});i&&this.refresh()},a.getInstance=function(){return this.instance_||(this.instance_=new a),this.instance_},a.instance_=null,a}(),ge=function(a,e){for(var s=0,n=Object.keys(e);s<n.length;s++){var i=n[s];Object.defineProperty(a,i,{value:e[i],enumerable:!1,writable:!1,configurable:!0})}return a},j=function(a){var e=a&&a.ownerDocument&&a.ownerDocument.defaultView;return e||J},be=te(0,0,0,0);function ee(a){return parseFloat(a)||0}function ve(a){for(var e=[],s=1;s<arguments.length;s++)e[s-1]=arguments[s];return e.reduce(function(n,i){var r=a["border-"+i+"-width"];return n+ee(r)},0)}function He(a){for(var e=["top","right","bottom","left"],s={},n=0,i=e;n<i.length;n++){var r=i[n],o=a["padding-"+r];s[r]=ee(o)}return s}function je(a){var e=a.getBBox();return te(0,0,e.width,e.height)}function We(a){var e=a.clientWidth,s=a.clientHeight;if(!e&&!s)return be;var n=j(a).getComputedStyle(a),i=He(n),r=i.left+i.right,o=i.top+i.bottom,h=ee(n.width),v=ee(n.height);if(n.boxSizing==="border-box"&&(Math.round(h+r)!==e&&(h-=ve(n,"left","right")+r),Math.round(v+o)!==s&&(v-=ve(n,"top","bottom")+o)),!Ye(a)){var c=Math.round(h+r)-e,g=Math.round(v+o)-s;Math.abs(c)!==1&&(h-=c),Math.abs(g)!==1&&(v-=g)}return te(i.left,i.top,h,v)}var Ze=function(){return typeof SVGGraphicsElement<"u"?function(a){return a instanceof j(a).SVGGraphicsElement}:function(a){return a instanceof j(a).SVGElement&&typeof a.getBBox=="function"}}();function Ye(a){return a===j(a).document.documentElement}function Qe(a){return ce?Ze(a)?je(a):We(a):be}function Xe(a){var e=a.x,s=a.y,n=a.width,i=a.height,r=typeof DOMRectReadOnly<"u"?DOMRectReadOnly:Object,o=Object.create(r.prototype);return ge(o,{x:e,y:s,width:n,height:i,top:s,right:e+n,bottom:i+s,left:e}),o}function te(a,e,s,n){return{x:a,y:e,width:s,height:n}}var Je=function(){function a(e){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=te(0,0,0,0),this.target=e}return a.prototype.isActive=function(){var e=Qe(this.target);return this.contentRect_=e,e.width!==this.broadcastWidth||e.height!==this.broadcastHeight},a.prototype.broadcastRect=function(){var e=this.contentRect_;return this.broadcastWidth=e.width,this.broadcastHeight=e.height,e},a}(),et=function(){function a(e,s){var n=Xe(s);ge(this,{target:e,contentRect:n})}return a}(),tt=function(){function a(e,s,n){if(this.activeObservations_=[],this.observations_=new pe,typeof e!="function")throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=e,this.controller_=s,this.callbackCtx_=n}return a.prototype.observe=function(e){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if(!(typeof Element>"u"||!(Element instanceof Object))){if(!(e instanceof j(e).Element))throw new TypeError('parameter 1 is not of type "Element".');var s=this.observations_;s.has(e)||(s.set(e,new Je(e)),this.controller_.addObserver(this),this.controller_.refresh())}},a.prototype.unobserve=function(e){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if(!(typeof Element>"u"||!(Element instanceof Object))){if(!(e instanceof j(e).Element))throw new TypeError('parameter 1 is not of type "Element".');var s=this.observations_;s.has(e)&&(s.delete(e),s.size||this.controller_.removeObserver(this))}},a.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},a.prototype.gatherActive=function(){var e=this;this.clearActive(),this.observations_.forEach(function(s){s.isActive()&&e.activeObservations_.push(s)})},a.prototype.broadcastActive=function(){if(this.hasActive()){var e=this.callbackCtx_,s=this.activeObservations_.map(function(n){return new et(n.target,n.broadcastRect())});this.callback_.call(e,s,e),this.clearActive()}},a.prototype.clearActive=function(){this.activeObservations_.splice(0)},a.prototype.hasActive=function(){return this.activeObservations_.length>0},a}(),ye=typeof WeakMap<"u"?new WeakMap:new pe,ke=function(){function a(e){if(!(this instanceof a))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var s=qe.getInstance(),n=new tt(e,s,this);ye.set(this,n)}return a}();["observe","unobserve","disconnect"].forEach(function(a){ke.prototype[a]=function(){var e;return(e=ye.get(this))[a].apply(e,arguments)}});var at=function(){return typeof J.ResizeObserver<"u"?J.ResizeObserver:ke}();function O(a){const e=t.ref(0),s=t.ref(0);let n=null;const i=()=>{n&&(n.disconnect(),n=null)},r=()=>{i();const o=t.unref(a);if(!o)return;n=new at(v=>{const c=v[0];c&&(e.value=c.contentRect.width,s.value=c.contentRect.height)}),n.observe(o);const h=o.getBoundingClientRect();e.value=h.width,s.value=h.height};return t.watch(()=>t.unref(a),r,{immediate:!0}),t.onScopeDispose(i),{width:t.readonly(e),height:t.readonly(s)}}const L=(a,e)=>{const s=a.__vccOpts||a;for(const[n,i]of e)s[n]=i;return s},st=["aria-valuemin","aria-valuemax","aria-valuenow","aria-label","aria-orientation","tabindex"],nt={key:0,class:"level"},Y=L({__name:"AudioSlider",props:t.mergeModels({min:{type:Number,default:0},max:{type:Number,default:1},step:{type:Number,default:.01},keystep:{type:Number,default:null},colour:{type:String,default:"grey"},style:{type:String,default:"volume"},thumbLength:{type:Number,default:1},showLevel:{type:Boolean,default:!1},level:{type:Number,default:.5},tabindex:{type:String,default:"0"}},{value:{default:.75},valueModifiers:{}}),emits:["update:value"],setup(a){t.useCssVars(p=>({"2096b4c3":N.value,"757f26aa":w.value,"744b71b7":M.value,d898db12:f.value,"3a8d2f7c":S.value}));const e=a,s=t.useTemplateRef("root"),{width:n,height:i}=O(s),r=t.computed(()=>Math.min(n.value,i.value)),o=t.computed(()=>Math.max(n.value,i.value)),h=t.computed(()=>n.value>i.value),v=t.computed(()=>h.value?"h-slide":"v-slide"),c=t.useModel(a,"value");t.computed(()=>Math.pow(1-c.value,.5)*180+20),t.computed(()=>Math.pow(c.value,.5)*180+20);const g=t.computed(()=>r.value*.8),B=t.computed(()=>r.value*e.thumbLength*.8),w=t.computed(()=>(h.value?B:g).value+"px"),N=t.computed(()=>(h.value?g:B).value+"px"),f=t.computed(()=>r.value*.1+"px"),S=t.computed(()=>(o.value-B.value)*(c.value-e.min)/(e.max-e.min)+"px"),M=t.computed(()=>h.value?"90deg":"0deg"),C=t.ref(!1),T=t.ref(0),V=p=>{if(!s.value)return c.value;const b=s.value.getBoundingClientRect(),x=p.clientX,Q=p.clientY;let K;if(h.value){const q=x-b.left-g.value/2,H=b.width-g.value;K=Math.max(0,Math.min(1,q/H))}else{const q=b.bottom-Q-g.value/2,H=b.height-g.value;K=Math.max(0,Math.min(1,q/H))}const R=e.min+K*(e.max-e.min);return e.step>0?Math.round(R/e.step)*e.step:R},D=p=>{p.preventDefault(),C.value=!0,T.value=c.value,s.value&&s.value.focus(),c.value=V(p),s.value&&s.value.setPointerCapture&&s.value.setPointerCapture(p.pointerId),document.addEventListener("pointermove",I),document.addEventListener("pointerup",A),document.addEventListener("pointercancel",A)},I=p=>{C.value&&(p.preventDefault(),c.value=V(p))},A=p=>{if(C.value){if(p.preventDefault(),C.value=!1,s.value&&s.value.releasePointerCapture)try{s.value.releasePointerCapture(p.pointerId)}catch{}document.removeEventListener("pointermove",I),document.removeEventListener("pointerup",A),document.removeEventListener("pointercancel",A)}},z=p=>{if(s.value&&s.value.getAttribute("tabindex")==="-1")return;const b=e.keystep!==null?e.keystep:e.step||.01;let x=c.value;switch(p.key){case"ArrowLeft":case"ArrowDown":p.preventDefault(),x=Math.max(e.min,c.value-b);break;case"ArrowRight":case"ArrowUp":p.preventDefault(),x=Math.min(e.max,c.value+b);break;default:return}c.value=x},u=p=>Math.min(1,Math.max(0,e.level*10-p+1));return(p,b)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(v.value),ref_key:"root",ref:s,role:"slider","aria-valuemin":a.min,"aria-valuemax":a.max,"aria-valuenow":c.value,"aria-label":`${a.style} control`,"aria-orientation":h.value?"horizontal":"vertical",tabindex:a.tabindex,onPointerdown:D,onKeydown:z,style:{userSelect:"none",touchAction:"none"}},[b[0]||(b[0]=t.createElementVNode("div",{class:"track"},null,-1)),a.showLevel?(t.openBlock(),t.createElementBlock("div",nt,[(t.openBlock(),t.createElementBlock(t.Fragment,null,t.renderList(10,x=>t.createElementVNode("div",{class:t.normalizeClass(["focus","led"+x])},[t.createElementVNode("div",{class:"on",style:t.normalizeStyle({opacity:u(x)})},null,4)],2)),64))])):t.createCommentVNode("",!0),t.createElementVNode("div",{class:t.normalizeClass(["thumb",{dragging:C.value,[a.colour]:!0,[a.style]:!0}])},null,2)],42,st))}},[["__scopeId","data-v-42160c3a"]]),de=L({__name:"TitleText",props:{align:{type:String,default:"left"},overflow:{type:String,default:"crop",validator:a=>["crop","scroll"].includes(a)}},setup(a){t.useCssVars(B=>({"9d94564a":v.value,"6241cf7e":c.value+"px"}));const e=a,s=t.useTemplateRef("el"),n=t.useTemplateRef("textEl"),{width:i,height:r}=O(s),o=t.computed(()=>Math.min(i.value,r.value)),h=t.computed(()=>i.value>r.value?"h-text":"v-text"),v=t.computed(()=>o.value*3/4+"px"),c=t.ref(0),g=t.ref(!1);return t.watchEffect(()=>{if(!n.value||!s.value||e.overflow!=="scroll"){g.value=!1,c.value=0;return}const B=h.value==="h-text"?i.value:r.value,w=h.value==="h-text"?n.value.scrollWidth:n.value.scrollHeight,N=B-20;w>N?(g.value=!0,c.value=w-N):(g.value=!1,c.value=0)}),(B,w)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"el",ref:s,class:"outer"},[t.createElementVNode("div",{ref_key:"textEl",ref:n,class:t.normalizeClass({[h.value]:!0,[a.align]:!0,scrolling:g.value})},[t.renderSlot(B.$slots,"default",{},void 0,!0)],2)],512))}},[["__scopeId","data-v-8efcf3aa"]]),it={class:"s-label"},rt={class:"m-label"},Me=L({__name:"TriState",props:{mute:{default:!1},muteModifiers:{},solo:{default:!1},soloModifiers:{}},emits:["update:mute","update:solo"],setup(a){const e=t.useModel(a,"mute"),s=t.useModel(a,"solo"),n=t.useTemplateRef("outer"),{width:i,height:r}=O(n),o=t.computed(()=>i.value>r.value*1.9);function h(){e.value=!e.value,s.value=!1}function v(){s.value=!s.value,e.value=!1}return(c,g)=>(t.openBlock(),t.createElementBlock("div",{class:"outer",ref_key:"outer",ref:n},[t.createElementVNode("div",{title:"Solo",class:t.normalizeClass(["solo",{on:s.value}]),onClick:v},null,2),t.createElementVNode("div",it,t.toDisplayString(o.value?"SOLO":"S"),1),t.createElementVNode("div",{title:"Mute",class:t.normalizeClass(["mute",{on:e.value}]),onClick:h},null,2),t.createElementVNode("div",rt,t.toDisplayString(o.value?"MUTE":"M"),1)],512))}},[["__scopeId","data-v-7e3c1495"]]),ae={enabled:!1,features:{beatAnimation:!0,randomLevelIndicators:!0,debugMode:!1}},ot=()=>ae.enabled,ue=a=>ae.enabled&&ae.features[a],F=X.defineStore("audioState",{state:()=>({isPlaying:!1,currentTime:0,playbackSpeed:1,currentBar:1,currentBeat:1,currentRepeat:0,masterVolume:.75,metronomeVolume:.7,partVolumes:{},partMuted:{},partSolo:{},isLeadInActive:!1,isStartingNotesActive:!1,leadInBars:1,metronomeEnabled:!1,leadInEnabled:!0,isLoaded:!1}),getters:{isPlayingOrLeadIn:a=>a.isPlaying||a.isLeadInActive,formattedTime:a=>{const e=Math.floor(a.currentTime/60),s=Math.floor(a.currentTime%60);return`${e}:${s.toString().padStart(2,"0")}`},getPartVolume:a=>e=>a.partVolumes[e]??.75,isPartMuted:a=>e=>a.partMuted[e]??!1,isPartSolo:a=>e=>a.partSolo[e]??!1,isAnySolo:a=>Object.values(a.partSolo).some(e=>e===!0),currentPosition:a=>{let e=`${a.currentBar}.${a.currentBeat}`;return a.currentRepeat>0&&(e+=` (R${a.currentRepeat})`),e}},actions:{setPlaybackState(a){this.isPlaying=a},setCurrentTime(a){this.currentTime=a},setPlaybackSpeed(a){this.playbackSpeed=a},setCurrentBar(a,e=1,s=0){typeof a=="number"&&(this.currentBar=a),typeof e=="number"&&(this.currentBeat=e),typeof s=="number"&&(this.currentRepeat=s)},setMasterVolume(a){this.masterVolume=Math.max(0,Math.min(1,a))},setMetronomeVolume(a){this.metronomeVolume=Math.max(0,Math.min(1,a))},setPartVolume(a,e){this.partVolumes[a]=Math.max(0,Math.min(1,e))},setPartMuted(a,e){this.partMuted[a]=e},setPartSolo(a,e){this.partSolo[a]=e},setLeadInActive(a,e=1){this.isLeadInActive=a,this.leadInBars=e},setStartingNotesActive(a){this.isStartingNotesActive=a},setMetronomeEnabled(a){this.metronomeEnabled=a},setLeadInEnabled(a){this.leadInEnabled=a},initializeParts(a){this.partVolumes={},this.partMuted={},this.partSolo={},a.forEach(e=>{this.partVolumes[e.name]=e.volume||.75,this.partMuted[e.name]=!1,this.partSolo[e.name]=!1})},setLoaded(a){this.isLoaded=a}}}),U=X.defineStore("musicData",{state:()=>({beats:[],practiceMarks:{},customPracticeMarks:{},parts:[],title:"",totalDuration:0,maxBar:0,timeSignature:4,baseTempo:80}),getters:{practiceMarkLetters:a=>Object.keys(a.practiceMarks).sort(),getBarForMark:a=>e=>a.practiceMarks[e],allBars:a=>{const e=new Set;return a.beats.forEach(s=>{s.beat===1&&e.add(s.bar)}),Array.from(e).sort((s,n)=>s-n)},hasRepeats:a=>e=>a.beats.some(s=>s.bar===e&&s.repeat>0),getRepeatCountForBar:a=>e=>{const s=new Set;return a.beats.forEach(n=>{n.bar===e&&s.add(n.repeat)}),s.size},allPracticeMarks:a=>({...a.practiceMarks,...a.customPracticeMarks}),allPracticeMarksSorted:a=>{const e={...a.practiceMarks,...a.customPracticeMarks};return Object.entries(e).sort(([,s],[,n])=>s-n).map(([s])=>s)},barHasMark:a=>e=>{const s={...a.practiceMarks,...a.customPracticeMarks};return Object.values(s).includes(e)},isCustomMark:a=>e=>e in a.customPracticeMarks,nextAvailableLetter:a=>{const e=new Set([...Object.keys(a.practiceMarks),...Object.keys(a.customPracticeMarks)]);for(let s=0;s<26;s++){const n=String.fromCharCode(65+s);if(!e.has(n))return n}return null}},actions:{loadMusicData(a){this.title=a.title||"Untitled",this.beats=a.beats||[],this.practiceMarks=a.practiceMarks||a.marks||{},this.parts=(a.parts||[]).map(e=>({...e,solo:e.solo||!1,mute:e.mute||!1})),this.calculateDuration(),this.calculateMaxBar(),this.extractTimeSignature(),this.loadCustomMarksFromStorage()},calculateDuration(){this.beats.length>0&&(this.totalDuration=Math.max(...this.beats.map(a=>a.time)))},calculateMaxBar(){this.beats.length>0&&(this.maxBar=Math.max(...this.beats.map(a=>a.bar)))},extractTimeSignature(){this.beats.length>0&&this.beats[0].timeSig&&(this.timeSignature=this.beats[0].timeSig),this.beats.length>0&&this.beats[0].tempo&&(this.baseTempo=this.beats[0].tempo)},setPracticeMark(a,e){this.practiceMarks[a]=e},removePracticeMark(a){delete this.practiceMarks[a]},addCustomMark(a){const e=this.nextAvailableLetter;return e&&!this.barHasMark(a)?(this.customPracticeMarks[e]=a,this.saveCustomMarksToStorage(),e):null},removeCustomMark(a){a in this.customPracticeMarks&&(delete this.customPracticeMarks[a],this.saveCustomMarksToStorage())},getStorageKey(){return`customPracticeMarks_${this.title}`},saveCustomMarksToStorage(){this.title&&localStorage.setItem(this.getStorageKey(),JSON.stringify(this.customPracticeMarks))},loadCustomMarksFromStorage(){if(this.title){const a=localStorage.getItem(this.getStorageKey());if(a)try{this.customPracticeMarks=JSON.parse(a)}catch{this.customPracticeMarks={}}else this.customPracticeMarks={}}},updateBeats(a){console.log("Updating beats in music data store"),this.beats=a,this.calculateDuration(),this.calculateMaxBar(),this.extractTimeSignature()},setTotalDuration(a){console.log("Setting total duration in music data store to:",a),this.totalDuration=a},isValidBar(a,e=0){return this.beats.some(s=>s.bar===a&&s.repeat===e)},setParts(a){this.parts=a.map(e=>({name:e.name,volume:e.volume||.75,solo:e.solo||!1,mute:e.mute||!1}))},clear(){this.beats=[],this.practiceMarks={},this.customPracticeMarks={},this.parts=[],this.title="",this.totalDuration=0,this.maxBar=0,this.timeSignature=4,this.baseTempo=80}}}),se=X.defineStore("playbackState",{state:()=>({transportState:"stopped",autoPlay:!1,loopEnabled:!1,loopStart:1,loopEnd:null,leadInEnabled:!0,leadInBars:1,startingNotesEnabled:!0,startingNotesSequential:!0,metronomeEnabled:!1,metronomeVolume:.5,showTransportControls:!0,showPartControls:!0,showNavigationControls:!0,lastBarPosition:1,lastPracticeMarkUsed:null,lastPlayStartBar:null,lastPlayStartRepeat:null,lastPlayStartTime:null,lastNavigationAction:null,fixedNavigationPoints:[],navigationPoints:[]}),getters:{isPlaying:a=>a.transportState==="playing",isPaused:a=>a.transportState==="paused",isStopped:a=>a.transportState==="stopped",isLoopConfigured:a=>a.loopEnabled&&a.loopStart&&a.loopEnd&&a.loopEnd>a.loopStart,loopRange:a=>!a.loopEnabled||!a.loopStart||!a.loopEnd?null:`${a.loopStart}-${a.loopEnd}`,getNavigationPoints:a=>a.navigationPoints},actions:{setTransportState(a){["stopped","playing","paused"].includes(a)&&(this.transportState=a)},play(){this.setTransportState("playing")},pause(){this.setTransportState("paused")},stop(){this.setTransportState("stopped")},setAutoPlay(a){this.autoPlay=a},setLoop(a,e=null,s=null){this.loopEnabled=a,e!==null&&(this.loopStart=e),s!==null&&(this.loopEnd=s)},setLoopStart(a){this.loopStart=a,this.loopEnd&&this.loopEnd<=a&&(this.loopEnd=a+4)},setLoopEnd(a){this.loopEnd=a,this.loopStart&&this.loopStart>=a&&(this.loopStart=Math.max(1,a-4))},setLeadInEnabled(a){this.leadInEnabled=a},setLeadInBars(a){this.leadInBars=Math.max(1,Math.min(4,a))},setStartingNotesEnabled(a){this.startingNotesEnabled=a},setStartingNotesSequential(a){this.startingNotesSequential=a},setMetronomeEnabled(a){this.metronomeEnabled=a},setMetronomeVolume(a){this.metronomeVolume=Math.max(0,Math.min(1,a))},setTransportControlsVisible(a){this.showTransportControls=a},setPartControlsVisible(a){this.showPartControls=a},setNavigationControlsVisible(a){this.showNavigationControls=a},updateLastBarPosition(a){this.lastBarPosition=a},updateLastPracticeMarkUsed(a){this.lastPracticeMarkUsed=a},buildFixedNavigationPoints(){const a=[],e=U();a.push({time:0,bar:1,repeat:1,label:"Start"});const s=e.beats.filter(n=>n.beat===1);for(const[n,i]of Object.entries(e.allPracticeMarks))s.filter(r=>r.bar===i).forEach(r=>{a.push({time:r.time,bar:r.bar,repeat:r.repeat,label:`Mark ${n}`})});if(e.beats.length>0){const n=Math.max(...e.beats.map(i=>i.time));a.push({time:n,label:"End"})}this.fixedNavigationPoints=a.sort((n,i)=>n.time-i.time),this.navigationPoints=[...this.fixedNavigationPoints]},rebuildNavigationPoints(){setTimeout(()=>{const a=U(),e=[...this.fixedNavigationPoints];this.lastPlayStartBar!==null&&a.beats.filter(i=>i.beat===1&&i.bar===this.lastPlayStartBar).forEach(i=>{e.push({time:i.time,bar:i.bar,repeat:i.repeat,label:"Last Play Start"})});const s=e.sort((n,i)=>n.time-i.time);this.navigationPoints=s.filter((n,i,r)=>i===0||n.time!==r[i-1].time)},50)},setLastPlayStart(a,e,s){this.lastPlayStartBar=a,this.lastPlayStartRepeat=e,this.lastPlayStartTime=s,this.rebuildNavigationPoints()},setNavigationAction(a){this.lastNavigationAction=a},resetToDefaults(){this.transportState="stopped",this.autoPlay=!1,this.loopEnabled=!1,this.loopStart=1,this.loopEnd=null,this.leadInEnabled=!0,this.leadInBars=1,this.startingNotesEnabled=!0,this.startingNotesSequential=!0,this.metronomeEnabled=!1,this.metronomeVolume=.5}}});function Se(a){return{all:a=a||new Map,on:function(e,s){var n=a.get(e);n?n.push(s):a.set(e,[s])},off:function(e,s){var n=a.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):a.set(e,[]))},emit:function(e,s){var n=a.get(e);n&&n.slice().map(function(i){i(s)}),(n=a.get("*"))&&n.slice().map(function(i){i(e,s)})}}}const Ee=["spessasynth","lightweight"];class lt{constructor(){this._engineType="spessasynth"}setEngineType(e){if(!Ee.includes(e))throw new Error(`Invalid audio engine type: "${e}". Must be one of: ${Ee.join(", ")}`);this._engineType=e}getEngineType(){return this._engineType}resetToDefault(){this._engineType="spessasynth"}}const Be=new lt;class ct{constructor(){this.eventBus=Se(),this.currentTime=0,this.isPlaying=!1,this.playbackSpeed=1,this.masterVolume=.75,this.metronomeVolume=.7,this.parts=new Map,this.playbackTimer=null,this.lastTimestamp=0,this.audioContext=null,this.audioEngine=null,this.playbackManager=null,this.musicData=null,this.beats=[],this.practiceMarks={},this.songDuration=0,this.maxBar=0,this.masterGain=null,this.metronomeGain=null,this.partGainNodes=new Map,this.partAnalyserNodes=new Map,this.isInitialized=!1}sanitizePartName(e){return!e||typeof e!="string"?"unknown":e.replace(/[\x00-\x1F\x7F-\x9F]/g,"").toLowerCase().trim()}async initializeAudioSystem(e={}){if(this.isInitialized)return;this.audioContext=new(window.AudioContext||window.webkitAudioContext),this.audioContext.state==="suspended"&&await this.audioContext.resume();const s=Be.getEngineType();if(s==="lightweight"?(this.audioEngine=new le.LightweightAudioEngine(this.audioContext),console.log("Using LightweightAudioEngine")):(this.audioEngine=new le.SpessaSynthAudioEngine(this.audioContext),console.log("Using SpessaSynthAudioEngine")),this.audioEngine.on("initProgress",n=>{this.eventBus.emit("initProgress",n)}),s==="spessasynth"){const n=e.soundfontUrl?[e.soundfontUrl]:["/FluidR3Mono_GM.sf3","/FluidR3_GM.sf2","/soundfont.sf2"];let i=!1,r=null;for(const o of n)try{await this.audioEngine.initialize(o),console.log(`Loaded soundfont: ${o}`),i=!0;break}catch(h){console.warn(`Failed to load soundfont ${o}:`,h.message),r=h}if(!i){const o="No soundfont could be loaded";throw this.eventBus.emit("initProgress",{stage:"error",message:o,error:r}),new Error(o)}}else try{await this.audioEngine.initialize(),console.log("LightweightAudioEngine initialized")}catch(n){const i="Failed to initialize LightweightAudioEngine";throw this.eventBus.emit("initProgress",{stage:"error",message:i,error:n}),new Error(i)}this.setupMasterAudioGraph(),this.isInitialized=!0,console.log("AudioEngineService initialized successfully")}setupMasterAudioGraph(){this.masterGain=this.audioContext.createGain(),this.masterGain.gain.value=this.masterVolume,this.masterGain.connect(this.audioContext.destination),this.metronomeGain=this.audioContext.createGain(),this.metronomeGain.gain.value=.7,this.metronomeGain.connect(this.audioContext.destination)}async initialize(e,s={}){if(this.isInitialized||await this.initializeAudioSystem(s),this.cleanup(),this.musicData=e,e.midiData)console.log(e),await this.setupMidiPlayback(e.midiData,e.metadata);else{if(this.beats=e.beats||[],this.practiceMarks=e.marks||e.practiceMarks||{},this.beats.length>0){const n=this.beats[this.beats.length-1],i=n.tempo>0?60/n.tempo:.75;this.songDuration=n.time+i,this.maxBar=Math.max(...this.beats.map(r=>r.bar))}else this.songDuration=0,this.maxBar=0;this.setupLegacyParts(e.parts||[]),this.eventBus.emit("initialized",{parts:Array.from(this.parts.values())})}}async setupMidiPlayback(e,s){try{this.playbackManager=new le.PlaybackManager(this.audioEngine,{metronome:{enabled:!0,tickInstrument:115,accentInstrument:116,volume:.7},leadIn:{enabled:!0,bars:1},startup:{delayMs:25}});const n=await this.playbackManager.calibrateAudioLatency({measurements:1,sampleIntervalMs:10,threshold:.01,timeout:3e3,silent:!0});console.log(`Measured audio latency: ${n} ms`),this.setupPlaybackManagerEventDelegation(),await this.playbackManager.load(e,s);const i=this.playbackManager.getPartNames();this.setupMidiParts(i),this.eventBus.emit("initialized",{parts:Array.from(this.parts.values())}),await this.setupPartAudioRouting(i),this.setupMetronomeAudioRouting(),this.extractMusicDataFromPlayer(),this.updateSongDurationFromPlayer(),console.log("MIDI playback with PlaybackManager setup complete")}catch(n){throw console.error("Failed to setup MIDI playback:",n),n}}setupMidiParts(e){e.forEach(s=>{const n=this.sanitizePartName(s);this.parts.set(n,{name:s,sanitizedName:n,volume:.75,muted:!1,solo:!1})})}async setupPartAudioRouting(){for(const[e,s]of this.playbackManager.getPartOutputs()){const n=this.audioContext.createGain();n.gain.value=1;const i=this.audioContext.createAnalyser();i.fftSize=256,i.smoothingTimeConstant=.3,s.connect(n),n.connect(i),i.connect(this.masterGain);const r=this.sanitizePartName(e);this.partGainNodes.set(r,n),this.partAnalyserNodes.set(r,i),console.log(`Audio routing established for part: ${e}`)}}setupMetronomeAudioRouting(){this.playbackManager.getMetronomeOutput().connect(this.metronomeGain),console.log("Metronome audio routing established")}extractMusicDataFromPlayer(){try{this.beats=this.playbackManager.getBeats(),this.practiceMarks=this.playbackManager.getPracticeMarks(),this.beats.length>0?this.maxBar=Math.max(...this.beats.map(e=>e.bar)):this.maxBar=0,console.log(`Extracted ${this.beats.length} beats and ${Object.keys(this.practiceMarks).length} practice marks from player`),this.eventBus.emit("musicDataExtracted",{beats:this.beats,practiceMarks:this.practiceMarks,maxBar:this.maxBar})}catch(e){console.warn("Could not extract music data from player:",e),this.beats=[],this.practiceMarks={},this.maxBar=0}}updateSongDurationFromPlayer(){let e=this.playbackManager.getTotalDuration();e&&e>0?(this.songDuration=e,this.musicData&&(this.musicData.duration=e),this.eventBus.emit("durationUpdated",{duration:e})):console.warn("Could not get duration from player")}snapTimeToBarStart(e){try{const s=this.getBarFromTime(e);if(s){const n=this.getTimeFromBar(s.bar,s.repeat);if(n!==null)return n}}catch(s){console.warn("Failed to snap time to bar start:",s)}return e}emitTimeAndBarUpdates(e){this.eventBus.emit("timeChanged",{currentTime:e});const s=this.getBarFromTime(e);s&&this.eventBus.emit("barChanged",s)}setupPlaybackManagerEventDelegation(){this.playbackManager.on("timeupdate",({audioTime:e,leadInProgress:s})=>{this.currentTime=e,this.eventBus.emit("timeChanged",{currentTime:e,leadInProgress:s})}),this.playbackManager.on("beatAudible",({bar:e,beat:s,isLeadIn:n,repeat:i,time:r})=>{this.eventBus.emit("barChanged",{bar:e,beat:s,repeat:i,time:r,isLeadIn:n})}),this.playbackManager.on("leadInStarted",({totalBeats:e,duration:s,bars:n})=>{this.eventBus.emit("leadInStarted",{bars:n,totalBeats:e,duration:s})}),this.playbackManager.on("leadInEnded",()=>{this.eventBus.emit("leadInCompleted")}),this.playbackManager.on("playbackStarted",()=>{this.isPlaying=!0,this.eventBus.emit("playbackStateChanged",{isPlaying:!0,currentTime:this.currentTime})}),this.playbackManager.on("playbackPaused",()=>{this.isPlaying=!1,this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime})}),this.playbackManager.on("playbackStopped",()=>{this.isPlaying=!1,this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime})}),this.playbackManager.on("playbackEnded",()=>{this.isPlaying=!1,this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime}),this.eventBus.emit("songEnded",{finalTime:this.currentTime})})}setupLegacyParts(e){e&&e.forEach(s=>{const n=this.sanitizePartName(s.name);this.parts.set(n,{name:s.name,sanitizedName:n,volume:s.volume||.75,muted:!1,solo:!1})})}getCurrentToggleStates(){const e=this.getLeadInSettings();return{metronome:this.metronomeEnabled||!1,leadIn:this.leadInEnabled!==!1,leadInBars:e.bars}}updateToggleStates(e,s){this.setMetronomeEnabled(e),this.leadInEnabled=s}setMetronomeEnabled(e){this.metronomeEnabled=e,this.playbackManager.setMetronomeEnabled(e)}setLeadInBars(e){this.playbackManager.setLeadInBars(e)}setLeadInEnabled(e){this.leadInEnabled=e,this.playbackManager.setLeadInEnabled(e)}getLeadInSettings(){return this.playbackManager.getLeadInSettings()}play(e={}){const s=this.getCurrentToggleStates();e.leadInBars!==void 0&&this.setLeadInBars(e.leadInBars),this.playbackManager.play({leadIn:e.leadIn!==void 0?e.leadIn:s.leadIn,metronome:e.metronome!==void 0?e.metronome:s.metronome})}stop(){this.playbackManager.pause()}pause(){this.stop()}setTime(e){const s=this.snapTimeToBarStart(e);this.currentTime=Math.max(0,s),this.playbackManager.skipToTime(this.currentTime),this.emitTimeAndBarUpdates(this.currentTime)}getCurrentTime(){return this.playbackManager.getCurrentTime()}setBar(e,s=0){const n=Math.max(0,Math.min(this.maxBar,e));this.playbackManager.setBar(n,s);const i=this.getCurrentTime();this.currentTime=i,this.emitTimeAndBarUpdates(i)}goToPracticeMark(e){const s=this.practiceMarks[e];s!==void 0&&(this.setBar(s),this.eventBus.emit("practiceMarkChanged",{mark:e,bar:s}))}setPlaybackSpeed(e){this.playbackSpeed=Math.max(.25,Math.min(2,e)),this.playbackManager.setPlaybackSpeed(e,!1),this.eventBus.emit("speedChanged",{speed:this.playbackSpeed})}setMasterVolume(e){this.masterVolume=Math.max(0,Math.min(1,e)),this.masterGain&&(this.masterGain.gain.value=this.masterVolume),this.eventBus.emit("masterVolumeChanged",{volume:this.masterVolume})}getMasterVolume(){return this.masterVolume}setMetronomeVolume(e){const s=Math.max(0,Math.min(1,e));this.metronomeGain&&(this.metronomeGain.gain.value=s),this.metronomeVolume=s}getMetronomeVolume(){return this.metronomeVolume||.7}setPartVolume(e,s){const n=this.sanitizePartName(e),i=this.parts.get(n);i?(i.volume=Math.max(0,Math.min(1,s)),this.updatePartAudioState(n),this.eventBus.emit("partVolumeChanged",{partName:e,volume:s})):(console.log(`Part not found: "${e}" (sanitized: "${n}")`),console.log("Available parts:",[...this.parts.keys()]))}setPartMuted(e,s){const n=this.sanitizePartName(e),i=this.parts.get(n);i&&(i.muted=s,this.updatePartAudioState(n),this.eventBus.emit("partMutedChanged",{partName:e,muted:s}))}setPartSolo(e,s){const n=this.sanitizePartName(e),i=this.parts.get(n);i&&(i.solo=s,this.updateAllPartsAudioState(),this.eventBus.emit("partSoloChanged",{partName:e,solo:s}))}isPartEffectivelyMuted(e){const s=this.sanitizePartName(e),n=this.parts.get(s);return!n||n.muted?!0:Array.from(this.parts.values()).some(r=>r.solo)&&!n.solo}updatePartAudioState(e){const s=this.parts.get(e),n=this.partGainNodes.get(e);if(s&&n){const i=this.isPartEffectivelyMuted(s.name);n.gain.value=i?0:s.volume}}updateAllPartsAudioState(){for(const[e]of this.parts)this.updatePartAudioState(e)}getParts(){return Array.from(this.parts.values())}getPartLevel(e){const s=this.sanitizePartName(e),n=this.partAnalyserNodes.get(s);if(!n)return 0;try{const i=n.frequencyBinCount,r=new Uint8Array(i);n.getByteFrequencyData(r);let o=0;for(let v=0;v<i;v++){const c=r[v]/255;o+=c*c}const h=Math.sqrt(o/i);return Math.min(1,Math.pow(h*2,.7))}catch(i){return console.warn(`Failed to get level for part ${e}:`,i),0}}playLeadIn(e=1){this.setLeadInBars(e),this.playbackManager.play({leadIn:!0,metronome:!0})}playStartingNotes(){console.log(this.parts);const e=[...this.parts.values()],s=e.some(i=>i.solo),n=e.filter(i=>s?i.solo:!i.muted).map(i=>i.name);console.log(e,s,n),this.playbackManager.previewNextNotes({instrument:"piano",delayBetweenParts:.4,duration:.6,velocity:110,partOrder:n})}on(e,s){this.eventBus.on(e,s)}off(e,s){this.eventBus.off(e,s)}getBarFromTime(e){const s=this.playbackManager.midiPlayer.getBeatFromTime(e);return s?{bar:s.bar,beat:s.beat,repeat:s.repeat||0,time:s.time||e}:null}getTimeFromBar(e,s=0){return this.playbackManager.midiPlayer.getTimeFromBar(e,s)}allSoundsOff(){this.playbackManager&&this.playbackManager.allSoundsOff()}cleanup(){if(this.playbackManager)try{this.playbackManager.pause()}catch{}if(this.playbackManager&&this.metronomeGain)try{const e=this.playbackManager.getMetronomeOutput();e&&e.disconnect(this.metronomeGain)}catch{}if(this.partGainNodes.forEach(e=>{try{e.disconnect()}catch{}}),this.partAnalyserNodes.forEach(e=>{try{e.disconnect()}catch{}}),this.playbackManager){try{this.playbackManager.destroy()}catch{}this.playbackManager=null}this.parts.clear(),this.partGainNodes.clear(),this.partAnalyserNodes.clear(),this.beats=[],this.practiceMarks={},this.songDuration=0,this.maxBar=0}destroy(){this.cleanup(),this.audioEngine&&this.audioEngine.destroy(),this.audioContext&&this.audioContext.state!=="closed"&&this.audioContext.close(),this.eventBus.all.clear()}}const m=new ct;function W(a={}){const e=F(),s=U(),n=se(),i={soundfontUrl:a.soundfontUrl},r=({currentTime:l})=>{e.setCurrentTime(l)},o=({isPlaying:l})=>{e.setPlaybackState(l),n.setTransportState(l?"playing":"stopped"),!l&&e.isLeadInActive&&(e.setLeadInActive(!1),m.emitTimeAndBarUpdates(e.currentTime))},h=l=>{l&&(e.isLeadInActive?l.isLeadIn&&l.beat!==void 0&&e.setCurrentBar(null,l.beat,null):(e.setCurrentBar(l.bar,l.beat,l.repeat),n.updateLastBarPosition(l.bar)))},v=({speed:l})=>{e.setPlaybackSpeed(l)},c=({volume:l})=>{e.setMasterVolume(l)},g=({partName:l,volume:k})=>{e.setPartVolume(l,k)},B=({partName:l,muted:k})=>{e.setPartMuted(l,k)},w=({partName:l,solo:k})=>{e.setPartSolo(l,k)},N=({bars:l})=>{e.setLeadInActive(!0,l)},f=()=>{e.setLeadInActive(!1)},S=()=>{e.setStartingNotesActive(!0)},M=()=>{e.setStartingNotesActive(!1)},C=({mark:l})=>{n.updateLastPracticeMarkUsed(l)},T=({parts:l})=>{e.initializeParts(l),s.setParts(l)},V=({finalTime:l})=>{e.setPlaybackState(!1),n.setTransportState("stopped"),n.setNavigationAction("ended"),console.log(`Song ended at time: ${l}`)},D=({duration:l})=>{console.log("Updating total duration in store to:",l),s.setTotalDuration(l)},I=({beats:l,practiceMarks:k,maxBar:$})=>{console.log(`Updating music data store with ${l.length} beats and ${Object.keys(k).length} practice marks`),s.updateBeats(l),s.practiceMarks=k,s.maxBar=$},A=()=>{m.on("timeChanged",r),m.on("playbackStateChanged",o),m.on("barChanged",h),m.on("speedChanged",v),m.on("masterVolumeChanged",c),m.on("partVolumeChanged",g),m.on("partMutedChanged",B),m.on("partSoloChanged",w),m.on("leadInStarted",N),m.on("leadInCompleted",f),m.on("startingNotesStarted",S),m.on("startingNotesCompleted",M),m.on("practiceMarkChanged",C),m.on("initialized",T),m.on("songEnded",V),m.on("durationUpdated",D),m.on("musicDataExtracted",I)},z=()=>{m.off("timeChanged",r),m.off("playbackStateChanged",o),m.off("barChanged",h),m.off("speedChanged",v),m.off("masterVolumeChanged",c),m.off("partVolumeChanged",g),m.off("partMutedChanged",B),m.off("partSoloChanged",w),m.off("leadInStarted",N),m.off("leadInCompleted",f),m.off("startingNotesStarted",S),m.off("startingNotesCompleted",M),m.off("practiceMarkChanged",C),m.off("initialized",T),m.off("songEnded",V),m.off("durationUpdated",D),m.off("musicDataExtracted",I)};(()=>{t.watchEffect(()=>{const l=e.masterVolume;try{m.getMasterVolume()!==l&&m.setMasterVolume(l)}catch(k){console.warn("Master volume sync skipped during initialization:",k.message)}}),t.watchEffect(()=>{const l=e.metronomeVolume;try{m.getMetronomeVolume()!==l&&m.setMetronomeVolume(l)}catch(k){console.warn("Metronome volume sync skipped during initialization:",k.message)}})})();const p=async l=>{try{if(e.setLoaded(!1),A(),s.loadMusicData(l),await m.initialize(l,i),n.buildFixedNavigationPoints(),!l.midiData&&l.beats&&l.beats.length>0){const k=l.beats[0];e.setCurrentBar(k.bar,k.beat,k.repeat),m.setTime(k.time)}m.updateToggleStates(e.metronomeEnabled,e.leadInEnabled),e.setLoaded(!0)}catch(k){throw console.error("Failed to initialize audio engine:",k),e.setLoaded(!1),k}},b=()=>{const l=e.currentBar,k=e.currentRepeat,$=e.currentTime;n.setLastPlayStart(l,k,$),n.setNavigationAction("play"),m.play()},x=()=>{n.setNavigationAction("pause"),m.stop()},Q=()=>{n.setNavigationAction("pause"),m.pause()},K=l=>{n.setNavigationAction("manual"),m.setTime(l)},R=(l,k=0)=>{n.setNavigationAction("manual"),m.setBar(l,k)},q=l=>{if(s.isCustomMark(l)){const k=s.customPracticeMarks[l];k!==void 0&&m.setBar(k)}else m.goToPracticeMark(l)},H=l=>{m.setPlaybackSpeed(l)},ne=l=>{m.setMasterVolume(l)},ie=(l,k)=>{m.setPartVolume(l,k)},he=(l,k)=>{m.setPartMuted(l,k)},re=(l,k)=>{m.setPartSolo(l,k)},oe=(l=1)=>{m.playLeadIn(l)},fe=()=>{m.playStartingNotes()},d=(l,k=!0,$=0)=>{k&&n.leadInEnabled?(R(l,$),oe(n.leadInBars)):(R(l,$),b())},y=(l,k=!0)=>{const $=s.getBarForMark(l);$&&d($,k)},E=()=>{const l=!e.metronomeEnabled;return e.setMetronomeEnabled(l),m.setMetronomeEnabled(l),l},_=()=>{const l=!e.leadInEnabled;return e.setLeadInEnabled(l),m.updateToggleStates(e.metronomeEnabled,l),l},Z=()=>{m.stop(),e.setLoaded(!1),s.clear(),console.log("Audio mixer reset - ready for new score")};return t.onUnmounted(()=>{z()}),{initialize:p,reset:Z,play:b,stop:x,pause:Q,setTime:K,setBar:R,goToPracticeMark:q,setPlaybackSpeed:H,setMasterVolume:ne,setPartVolume:ie,setPartMuted:he,setPartSolo:re,getPartLevel:l=>m.getPartLevel(l),playLeadIn:oe,playStartingNotes:fe,toggleMetronome:E,toggleLeadIn:_,setMetronomeEnabled:l=>{e.setMetronomeEnabled(l),m.setMetronomeEnabled(l)},playFromBar:d,playFromMark:y,audioState:e,musicData:s,playbackState:n,audioEngine:m}}const dt=["aria-label"],Pe=L({__name:"PartControl",props:t.mergeModels({name:{type:String,required:!0},level:{type:Number,default:0,validator:a=>a>=0&&a<=1}},{volume:{default:.75},volumeModifiers:{},mute:{default:!1},muteModifiers:{},solo:{default:!1},soloModifiers:{}}),emits:["update:volume","update:mute","update:solo"],setup(a){t.useCssVars(f=>({"03f87250":c.value}));const e=a;F();const s=W(),n=t.useModel(a,"volume"),i=t.useModel(a,"mute"),r=t.useModel(a,"solo");t.watch(n,f=>{s.setPartVolume(e.name,f)}),t.watch(i,f=>{s.setPartMuted(e.name,f),f&&(r.value=!1)}),t.watch(r,f=>{s.setPartSolo(e.name,f),f&&(i.value=!1)});const o=t.useTemplateRef("el"),{width:h,height:v}=O(o),c=t.computed(()=>Math.min(h.value,v.value)+"px"),g=t.computed(()=>h.value>v.value?"mobile":h.value<60?"tablet":"desktop");let B=null;const w=t.ref(0);t.onMounted(()=>{B=setInterval(()=>{if(i.value)w.value=0;else try{w.value=s.getPartLevel(e.name)}catch{ue("randomLevelIndicators")?w.value=Math.random()*n.value:w.value=0}},16)}),t.onUnmounted(()=>{B&&(clearInterval(B),B=null)});const N=f=>{if(["ArrowUp","ArrowRight","ArrowDown","ArrowLeft"].includes(f.key)){f.preventDefault(),f.stopPropagation();const S=f.key==="ArrowUp"||f.key==="ArrowRight"?.1:-.1;n.value=Math.max(0,Math.min(1,n.value+S))}else f.key==="m"&&!f.shiftKey?(f.preventDefault(),f.stopPropagation(),i.value=!i.value):f.key==="s"&&!f.shiftKey&&(f.preventDefault(),f.stopPropagation(),r.value=!r.value)};return(f,S)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"el",ref:o,class:t.normalizeClass([g.value,"part"]),tabindex:"0",role:"group","aria-label":`${a.name} part controls`,onKeydown:N},[S[3]||(S[3]=t.createElementVNode("div",{class:"focus"},null,-1)),t.createVNode(Me,{class:"tri",mute:i.value,"onUpdate:mute":S[0]||(S[0]=M=>i.value=M),solo:r.value,"onUpdate:solo":S[1]||(S[1]=M=>r.value=M),tabindex:"-1"},null,8,["mute","solo"]),t.createVNode(de,{align:"left",class:"name"},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(a.name),1)]),_:1}),t.createVNode(Y,{level:w.value,"show-level":!0,class:"vol",value:n.value,"onUpdate:value":S[2]||(S[2]=M=>n.value=M),step:.01,tabindex:"-1"},null,8,["level","value"])],42,dt))}},[["__scopeId","data-v-67bb489c"]]),ut={class:"mark"},mt={class:"rpt"},ht={class:"beat-ind"},ft={class:"beat"},pt={key:1,class:"mark-grid-container"},gt={class:"mark-grid"},bt=["onClick"],we=L({__name:"BarInput",setup(a){t.useCssVars(d=>({aa78c0c8:D.value,"286643ea":I.value}));const e=t.useTemplateRef("el"),s=t.useTemplateRef("rpt"),{width:n,height:i}=O(e),r=U(),o=F(),h=se(),v=W(),c=t.ref("1"),g=t.ref("A"),B=t.ref(0),w=t.ref(2),N=t.ref(!1),f=t.ref(!1),S=t.ref(!1),M=t.ref(!1),C=t.ref(new Set),T=t.ref(!0);let V=null;t.watch(()=>{var d;return((d=r.beats)==null?void 0:d.length)>0},d=>{console.log(d),d&&!N.value&&(c.value=o.currentBar.toString(),B.value=o.currentRepeat,w.value=r.getRepeatCountForBar(o.currentBar),b(o.currentBar),N.value=!0)}),t.watch(()=>o.currentBar,d=>{w.value=r.getRepeatCountForBar(d)}),t.watch(c,()=>{c.value=c.value.replace(/\D/g,""),c.value.length>3&&(c.value=c.value.slice(0,3))}),t.watch(()=>o.currentBar,d=>{c.value=d.toString(),b(d)}),t.watch(()=>o.currentBeat,()=>{T.value=!0,setTimeout(()=>{T.value=!1},50)}),t.watch(f,()=>{f.value&&oe()});const D=t.computed(()=>Math.min(i.value/2.25,n.value/4.5)+"px"),I=t.computed(()=>Math.min(n.value/15,i.value/6.4)+"px"),A=t.computed(()=>r.allPracticeMarksSorted),z=t.computed(()=>!r.barHasMark(o.currentBar)&&r.nextAvailableLetter!==null),u=t.computed(()=>!0),p=t.computed(()=>Object.keys(r.customPracticeMarks).length>0);function b(d){const y=r.allPracticeMarks,E=Object.keys(y).filter(_=>y[_]<=d).sort((_,Z)=>y[Z]-y[_]);E.length>0?g.value=E[0]:g.value=""}function x(){var y;const d=parseInt(c.value);if(~isNaN(d)){Q(d);const E=(y=e.value)==null?void 0:y.querySelector(".bar-input");E&&E.blur(),e.value&&e.value.focus()}}function Q(d){v.setBar(d,0)}function K(d,y){if(y&&y.stopPropagation(),M.value){r.isCustomMark(d)&&H(d);return}g.value=d,f.value=!1,v.goToPracticeMark(d),e.value&&e.value.blur()}function R(d){d&&d.stopPropagation();const y=r.addCustomMark(o.currentBar);y&&(g.value=y,f.value=!1,h.buildFixedNavigationPoints())}function q(d){if(d&&d.stopPropagation(),M.value){const y=C.value.size>0;C.value.forEach(E=>{r.removeCustomMark(E)}),C.value=new Set,M.value=!1,b(o.currentBar),y&&h.buildFixedNavigationPoints()}else M.value=!0,C.value=new Set}function H(d,y){const E=new Set(C.value);E.has(d)?E.delete(d):E.add(d),C.value=E}function ne(){w.value>1&&(S.value=!0),o.currentRepeat<w.value&&v.setBar(o.currentBar,o.currentRepeat+1)}function ie(){w.value>1&&(S.value=!0),o.currentRepeat>1&&v.setBar(o.currentBar,o.currentRepeat-1)}function he(d){d.stopPropagation(),S.value=!1,f.value=!f.value,!f.value&&M.value&&(M.value=!1,C.value=new Set)}function re(d){var y,E;(y=e.value)!=null&&y.contains(d.target)||(f.value=!1,M.value&&(M.value=!1,C.value=new Set)),(E=s.value)!=null&&E.contains(d.target)||(S.value=!1)}function oe(){f.value&&setTimeout(()=>{var E,_;const d=(E=e.value)==null?void 0:E.querySelector(".mark-grid"),y=(_=e.value)==null?void 0:_.querySelector(".mark-option.selected");if(y&&d){const Z=d.getBoundingClientRect(),l=y.getBoundingClientRect(),k=l.left-Z.left-Z.width/2+l.width/2;d.scrollLeft=Math.max(0,d.scrollLeft+k)}},50)}t.onMounted(()=>{document.addEventListener("click",re),ue("beatAnimation")&&(V=setInterval(()=>{const d=o.currentBeat%r.timeSignature+1;o.setCurrentBar(o.currentBar,d,o.currentRepeat)},800))}),t.onUnmounted(()=>{document.removeEventListener("click",re),V&&(clearInterval(V),V=null)});const fe=d=>{var E;const y=(E=e.value)==null?void 0:E.querySelector(".bar-input");if(document.activeElement!==y)if(/^[a-z]$/.test(d.key)&&!d.ctrlKey&&!d.metaKey&&!d.shiftKey){d.preventDefault(),d.stopPropagation();const _=d.key.toUpperCase();A.value.includes(_)&&K(_,null)}else d.key==="ArrowUp"?(d.preventDefault(),d.stopPropagation(),ne()):d.key==="ArrowDown"?(d.preventDefault(),d.stopPropagation(),ie()):d.key==="Enter"?(d.preventDefault(),d.stopPropagation(),x()):d.key==="+"&&(d.preventDefault(),d.stopPropagation(),z.value&&R(null))};return(d,y)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"el",ref:e,class:t.normalizeClass(["outer",{pulse:T.value,"mark-selecting":f.value}]),tabindex:"0",role:"group","aria-label":"Musical navigation",onKeydown:fe},[y[9]||(y[9]=t.createElementVNode("div",{class:"frame"},null,-1)),t.createElementVNode("div",{class:t.normalizeClass(["mark-input",{empty:!g.value,edit:f.value,disabled:!u.value}]),tabindex:"-1",onClick:he},[t.createElementVNode("div",ut,t.toDisplayString(g.value||"-"),1)],2),y[10]||(y[10]=t.createElementVNode("div",{class:"mark-title"},"Mark",-1)),f.value?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.withDirectives(t.createElementVNode("input",{type:"text",class:"bar-input","onUpdate:modelValue":y[0]||(y[0]=E=>c.value=E),inputmode:"decimal",pattern:"\\d*",tabindex:"-1",onChange:x,onKeyup:t.withKeys(x,["enter"])},null,544),[[t.vModelText,c.value]]),y[5]||(y[5]=t.createElementVNode("div",{class:"bar-title"},"Bar",-1)),t.createElementVNode("div",{ref_key:"rpt",ref:s,class:t.normalizeClass(["rpt-input",{edit:S.value,available:w.value>1}])},[t.createElementVNode("div",mt,t.toDisplayString(t.unref(o).currentRepeat||"-"),1),(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["inc",{disabled:t.unref(o).currentRepeat>=w.value}]),viewBox:"0 -100 100 100",onClick:t.withModifiers(ne,["prevent"])},y[3]||(y[3]=[t.createElementVNode("path",{d:"m10-20 40-60 40 60H10Z"},null,-1)]),2)),(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["dec",{disabled:t.unref(o).currentRepeat<=1}]),viewBox:"0 -100 100 100",onClick:t.withModifiers(ie,["prevent"])},y[4]||(y[4]=[t.createElementVNode("path",{d:"m10-80 40 60 40-60H10Z"},null,-1)]),2))],2),y[6]||(y[6]=t.createElementVNode("div",{class:"rpt-title"},"Rpt",-1)),t.createElementVNode("div",ht,[t.createElementVNode("div",ft,t.toDisplayString(t.unref(o).currentBeat),1)]),y[7]||(y[7]=t.createElementVNode("div",{class:"beat-title"},"Beat",-1))],64)),f.value?(t.openBlock(),t.createElementBlock("div",pt,[t.createElementVNode("div",gt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(A.value,E=>(t.openBlock(),t.createElementBlock("div",{key:E,class:t.normalizeClass(["mark-option",{selected:!M.value&&E===g.value,deleting:M.value&&C.value.has(E),custom:t.unref(r).isCustomMark(E),greyed:M.value&&!t.unref(r).isCustomMark(E)}]),onClick:_=>K(E,_)},t.toDisplayString(E),11,bt))),128)),z.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["mark-option add-mark",{greyed:M.value}]),onClick:y[1]||(y[1]=E=>!M.value&&R(E))}," + ",2)):t.createCommentVNode("",!0),p.value?(t.openBlock(),t.createElementBlock("div",{key:1,class:t.normalizeClass(["mark-option trash-icon",{active:M.value}]),onClick:y[2]||(y[2]=E=>q(E))},y[8]||(y[8]=[t.createElementVNode("svg",{viewBox:"0 -960 960 960",fill:"currentColor"},[t.createElementVNode("path",{transform:"rotate(135)",d:"M -831.95532 179.98077 L -751.96387 179.98077 L -751.96387 39.995727 L -611.97882 39.995727 L -611.97882 -39.995727 L -751.96387 -39.995727 L -751.96387 -179.98077 L -831.95532 -179.98077 L -831.95532 -39.995727 L -971.94037 -39.995727 L -971.94037 39.995727 L -831.95532 39.995727 L -831.95532 179.98077 z "}),t.createElementVNode("path",{d:"M 280 -840 L 280 -680 L 120 -680 L 120 -120 L 680 -120 L 680 -280 L 840 -280 L 840 -840 L 280 -840 z M 360 -760 L 760 -760 L 760 -360 L 360 -360 L 360 -760 z M 200 -600 L 280 -600 L 280 -280 L 600 -280 L 600 -200 L 200 -200 L 200 -600 z "})],-1)]),2)):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)],34))}},[["__scopeId","data-v-e542aa14"]]),vt={class:"frame"},yt={class:"title"},me=L({__name:"BaseNumericInput",props:t.mergeModels({title:{type:String,required:!0},color:{type:String,default:"#336"},focusColor:{type:String,default:"#558"},textColor:{type:String,default:"#aad"},backgroundColor:{type:String,default:"#111117"},sliderMax:{type:Number,default:1},sliderMin:{type:Number,default:0},thumbLength:{type:Number,default:2},formatValue:{type:Function,default:a=>a.toString()},parseValue:{type:Function,default:a=>parseFloat(a)},validateInput:{type:Function,default:a=>a.replace(/[^0-9.]/g,"")},transformSliderToDisplay:{type:Function,default:a=>a},transformDisplayToSlider:{type:Function,default:a=>a},maxChars:{type:Number,default:null}},{value:{default:.5},valueModifiers:{}}),emits:["update:value"],setup(a){t.useCssVars(g=>({"391e6684":a.textColor,"6eae8f5d":a.backgroundColor,"6ee151eb":a.color,"29a40ccc":v.value,"7366daab":h.value,"0f87383a":a.focusColor}));const e=a,s=t.useTemplateRef("el"),{width:n,height:i}=O(s),r=t.useModel(a,"value"),o=t.ref(e.formatValue(e.transformSliderToDisplay(r.value)));t.watch(r,()=>{const g=e.transformSliderToDisplay(r.value);o.value=e.formatValue(g)}),t.watch(o,()=>{o.value=e.validateInput(o.value),e.maxChars&&o.value.length>e.maxChars&&(o.value=o.value.slice(0,e.maxChars))});const h=t.computed(()=>Math.min(i.value/2.25,n.value/2.2)+"px"),v=t.computed(()=>Math.min(n.value/3,i.value/6.4)+"px");function c(){const g=e.parseValue(o.value),B=e.transformDisplayToSlider(g);r.value=Math.min(Math.max(B,e.sliderMin),e.sliderMax)}return(g,B)=>(t.openBlock(),t.createElementBlock("div",{class:"outer",ref_key:"el",ref:s},[t.createElementVNode("div",vt,[t.withDirectives(t.createElementVNode("input",{type:"text",class:"input","onUpdate:modelValue":B[0]||(B[0]=w=>o.value=w),inputmode:"decimal",pattern:"\\d*",onChange:c},null,544),[[t.vModelText,o.value]]),t.createElementVNode("div",yt,t.toDisplayString(a.title),1)]),t.createVNode(Y,{class:"slider",value:r.value,"onUpdate:value":B[1]||(B[1]=w=>r.value=w),"thumb-length":a.thumbLength,max:a.sliderMax,min:a.sliderMin,tabindex:"-1"},null,8,["value","thumb-length","max","min"])],512))}},[["__scopeId","data-v-3c97bdb4"]]),Ce={__name:"SpeedInput",setup(a){const e=F(),s=W(),n=t.computed({get:()=>Math.log2(e.playbackSpeed)*.5+.5,set:c=>{const g=Math.floor(Math.pow(2,c*2-1)*20+.5)*.05;s.setPlaybackSpeed(g)}}),i=c=>Math.floor(Math.pow(2,c*2-1)*20+.5)*5+"",r=c=>parseFloat(c),o=c=>c.replace(/\D/g,""),h=c=>c,v=c=>{const g=Math.log2(c/100)*.5+.5;return Math.min(Math.max(g,0),1)};return(c,g)=>(t.openBlock(),t.createBlock(me,{value:n.value,"onUpdate:value":g[0]||(g[0]=B=>n.value=B),title:"Speed",color:"#336","text-color":"#aad","format-value":i,"parse-value":r,"validate-input":o,"transform-slider-to-display":h,"transform-display-to-slider":v,"thumb-length":2,"max-chars":3},null,8,["value"]))}},xe={__name:"TimeInput",setup(a){const e=F(),s=U(),n=W(),i=c=>c.toFixed(1),r=c=>parseFloat(c),o=c=>c.replace(/[^0-9.]/g,""),h=c=>c,v=c=>c;return(c,g)=>(t.openBlock(),t.createBlock(me,{value:t.unref(e).currentTime,"onUpdate:value":[g[0]||(g[0]=B=>t.unref(e).currentTime=B),t.unref(n).setTime],title:"Time",color:"#344","focus-color":"#556868","text-color":"#acc","background-color":"#111117","slider-max":t.unref(s).totalDuration,"slider-min":0,"format-value":i,"parse-value":r,"validate-input":o,"transform-slider-to-display":h,"transform-display-to-slider":v,"thumb-length":2},null,8,["value","onUpdate:value","slider-max"]))}},kt=["title"],Mt={class:"inner"},G=L({__name:"AudioButton",props:{disabled:{type:Boolean,default:!1},title:{type:String,default:""}},setup(a){const e=a,s=t.ref(!1),n=()=>{e.disabled||(s.value=!0)},i=()=>s.value=!1;return(r,o)=>(t.openBlock(),t.createElementBlock("div",{title:a.title,class:t.normalizeClass(["button-outer",{down:s.value,disabled:a.disabled}]),onPointerdown:n,onPointerup:i,onPointerleave:i},[t.createElementVNode("div",Mt,[t.renderSlot(r.$slots,"default",{},void 0,!0)])],42,kt))}},[["__scopeId","data-v-77d8694a"]]),St={class:"outer"},Et={class:"title"},Bt={class:"buttons",role:"toolbar","aria-label":"Transport controls"},Pt={class:"icon",viewBox:"0 0 48 48"},wt=["d"],Te=L({__name:"MixerControls",props:{externalMenuControl:{type:Boolean,default:!1}},emits:["menu-click"],setup(a,{emit:e}){const s=a,n=e,i=U(),r=F(),o=se(),h=W();function v(){r.isPlayingOrLeadIn?h.stop():h.play()}function c(){const u=o.navigationPoints;if((o.lastNavigationAction==="pause"||o.lastNavigationAction==="ended")&&o.lastPlayStartTime!==null){h.setTime(o.lastPlayStartTime),o.setNavigationAction(null);return}const p=r.currentTime,b=u.filter(x=>x.time<p-.01).pop();b&&h.setTime(b.time)}function g(){const u=o.navigationPoints,p=r.currentTime,b=u.find(x=>x.time>p+.01);b&&h.setTime(b.time)}function B(){h.playStartingNotes()}const w=t.computed(()=>r.metronomeEnabled),N=t.computed(()=>r.leadInEnabled),f=t.ref(!1),S=t.ref(null);function M(){if(s.externalMenuControl){n("menu-click"),h.audioEngine.initializeAudioSystem().catch(u=>{console.warn("Audio system pre-initialization failed:",u)});return}f.value=!f.value,f.value&&(h.audioEngine.initializeAudioSystem().catch(u=>{console.warn("Audio system pre-initialization failed:",u)}),setTimeout(()=>{var p;const u=(p=S.value)==null?void 0:p.querySelector('button, a, [tabindex="0"]');u&&u.focus()},0))}function C(){f.value=!1}function T(u){S.value&&!S.value.contains(u.target)&&C()}t.onMounted(()=>{document.addEventListener("click",T),document.addEventListener("keydown",z)}),t.onUnmounted(()=>{document.removeEventListener("click",T),document.removeEventListener("keydown",z)});function V(){h.toggleMetronome()}function D(){h.toggleLeadIn()}const I=t.computed({get:()=>r.masterVolume,set:u=>r.setMasterVolume(u)}),A=t.computed({get:()=>r.metronomeVolume,set:u=>r.setMetronomeVolume(u)}),z=u=>{const p=u.target;if(!(p.matches('input[type="text"]')&&(p.closest(".time")||p.closest(".speed")))){if(u.key==="Escape")u.preventDefault(),M();else if(u.key==="B"&&u.shiftKey){u.preventDefault();const b=document.querySelector(".bar");b&&b.focus()}else if(u.key==="T"&&u.shiftKey){u.preventDefault();const b=document.querySelector(".time input");b&&b.focus()}else if(u.key==="S"&&u.shiftKey){u.preventDefault();const b=document.querySelector(".speed input");b&&b.focus()}else if(u.key===" ")u.preventDefault(),v();else if(u.key==="PageUp")u.preventDefault(),g();else if(u.key==="PageDown")u.preventDefault(),c();else if(u.key==="M"&&u.shiftKey)u.preventDefault(),V();else if(u.key==="L"&&u.shiftKey)u.preventDefault(),D();else if(u.key==="N"&&u.shiftKey)u.preventDefault(),r.isPlayingOrLeadIn||B();else if(/^[0-9]$/.test(u.key)&&!u.ctrlKey&&!u.metaKey&&!u.shiftKey){const b=document.querySelector(".bar .bar-input");if(document.activeElement===b)return;u.preventDefault(),b&&(b.value=u.key,b.focus(),b.setSelectionRange(1,1),b.dispatchEvent(new Event("input",{bubbles:!0})))}else if(/^[a-z]$/.test(u.key)&&!u.ctrlKey&&!u.metaKey&&!u.shiftKey){u.preventDefault();const b=document.querySelector(".bar");if(b){b.focus();const x=new KeyboardEvent("keydown",{key:u.key,code:u.code,bubbles:!0,cancelable:!0});b.dispatchEvent(x)}}else if(u.key==="+"){u.preventDefault();const b=document.querySelector(".bar");if(b){b.focus();const x=new KeyboardEvent("keydown",{key:"+",code:"Equal",shiftKey:!0,bubbles:!0,cancelable:!0});b.dispatchEvent(x)}}}};return(u,p)=>(t.openBlock(),t.createElementBlock("div",St,[t.createElementVNode("div",Et,[t.createVNode(de,{class:"text",align:"centre",overflow:"scroll"},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(t.unref(i).title),1)]),_:1}),t.createElementVNode("div",{class:"menu-container",ref_key:"menuRef",ref:S},[(t.openBlock(),t.createElementBlock("svg",{class:"menu",viewBox:"0 -960 960 960",onClick:M},p[2]||(p[2]=[t.createElementVNode("path",{d:"M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z"},null,-1)]))),!a.externalMenuControl&&f.value&&u.$slots.menu?(t.openBlock(),t.createElementBlock("div",{key:0,class:"dropdown-menu",onClick:C},[t.renderSlot(u.$slots,"menu",{},void 0,!0)])):t.createCommentVNode("",!0)],512)]),t.createVNode(Y,{class:"main",colour:"red",step:.01,keystep:.1,value:I.value,"onUpdate:value":p[0]||(p[0]=b=>I.value=b)},null,8,["value"]),p[8]||(p[8]=t.createElementVNode("div",{class:"main-t"},"Main",-1)),p[9]||(p[9]=t.createElementVNode("div",{class:"main-focus"},null,-1)),t.createVNode(Y,{class:"tick",colour:"blue",step:.01,keystep:.1,value:A.value,"onUpdate:value":p[1]||(p[1]=b=>A.value=b)},null,8,["value"]),p[10]||(p[10]=t.createElementVNode("div",{class:"tick-t"},"Tick",-1)),p[11]||(p[11]=t.createElementVNode("div",{class:"tick-focus"},null,-1)),t.createVNode(we,{class:"bar"}),t.createVNode(xe,{class:"time"}),t.createVNode(Ce,{class:"speed"}),t.createElementVNode("div",Bt,[t.createVNode(G,{title:"Previous Mark",class:"button",tabindex:"-1",onClick:c},{default:t.withCtx(()=>p[3]||(p[3]=[t.createElementVNode("svg",{class:"icon",viewBox:"0 0 48 48"},[t.createElementVNode("path",{d:"M11 36V12h3v24Zm26 0L19.7 24 37 12Z"})],-1)])),_:1,__:[3]}),t.createVNode(G,{title:t.unref(r).isPlayingOrLeadIn?"Pause":"Play",class:"button",tabindex:"-1",onClick:v},{default:t.withCtx(()=>[(t.openBlock(),t.createElementBlock("svg",Pt,[t.createElementVNode("path",{d:t.unref(r).isPlayingOrLeadIn?"M27.4 35.4V12.6h8v22.8Zm-14.8 0V12.6h8.05v22.8Z":"M16 37.85v-28l22 14Z"},null,8,wt)]))]),_:1},8,["title"]),t.createVNode(G,{title:"Next Mark",class:"button",tabindex:"-1",onClick:g},{default:t.withCtx(()=>p[4]||(p[4]=[t.createElementVNode("svg",{class:"icon",viewBox:"0 0 48 48"},[t.createElementVNode("path",{d:"M34 36V12h3v24Zm-23 0V12l17.3 12Z"})],-1)])),_:1,__:[4]}),t.createVNode(G,{title:"Toggle Metronome",class:"button",tabindex:"-1",onClick:V},{default:t.withCtx(()=>[(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["icon",w.value?"on":"off"]),viewBox:"-128 -128 768 768"},p[5]||(p[5]=[t.createElementVNode("path",{d:"m 463.84136,154.89339 c -6.42,-6.42 -16.83,-6.42 -23.251,0 -71.31197,70.35135 -136.61146,132.25426 -208.741,199.7 h -105.82 c 23.35495,-140.1063 67.13099,-217.59716 120.727,-318.357996 0.86,-0.803 2.209,-0.801 3.067,-10e-4 20.50653,37.383983 48.51152,88.812606 72.26194,147.190756 1.186,9.002 12.2214,17.4338 23.3242,11.71391 9.002,-1.186 11.1594,-12.2324 9.9724,-21.2344 -21.69905,-53.89113 -30.43965,-85.078342 -83.11454,-161.702266 -13.446,-12.55299965 -34.508,-12.55699965 -47.954,10e-4 C 126.80877,149.30021 96.099465,324.74626 77.091365,474.25139 c -2.829,21.473 13.907,40.535 35.543995,40.535 h 271.311 c 21.661,0 38.373,-19.087 35.544,-40.535 -8.26237,-52.34207 -14.88466,-100.7074 -24.7871,-157.02622 -6.40949,-11.78839 -8.3911,-14.9907 -17.4031,-13.8037 -9.002,1.186 -13.59751,8.0528 -12.41051,17.0548 l 5.66371,34.11712 h -83.159 c 64.35441,-63.86663 129.29308,-130.29894 176.448,-176.449 6.42,-6.42 6.42,-16.83 -10e-4,-23.251 z m -88.956,232.582 12.004,91.074 c 0.112,0.846 -0.148,1.701 -0.708,2.341 -0.566,0.645 -1.38,1.014 -2.235,1.014 h -271.311 c -0.855,0 -1.668,-0.369 -2.231,-1.011 -0.564,-0.643 -0.824,-1.499 -0.712,-2.347 l 12.003,-91.072 h 253.19 z"},null,-1)]),2))]),_:1}),t.createVNode(G,{title:"Toggle Lead-in",class:"button",tabindex:"-1",onClick:D},{default:t.withCtx(()=>[(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["icon",N.value?"on":"off"]),viewBox:"-2 -2 28 28"},p[6]||(p[6]=[t.createElementVNode("path",{d:"m 8.9838564,1.5166215 v 2 h 5.9999996 v -2 z m 2.9999996,3 c -4.9699996,0 -8.9999996,4.0299999 -8.9999996,8.9999995 0,4.97 4.02,9 8.9999996,9 4.98,0 9,-4.03 9,-9 0,-2.12 -0.740703,-4.0693745 -1.970703,-5.6093745 l 1.419922,-1.421875 c -0.43,-0.51 -0.900156,-0.9882031 -1.410156,-1.4082031 l -1.419922,1.4199219 c -1.55,-1.24 -3.499141,-1.9804688 -5.619141,-1.9804688 z m -1.789062,4.7480469 6,4.4999996 -6,4.5 z"},null,-1)]),2))]),_:1}),t.createVNode(G,{title:"Starting Notes",class:"button",tabindex:"-1",disabled:t.unref(r).isPlayingOrLeadIn,onClick:B},{default:t.withCtx(()=>p[7]||(p[7]=[t.createElementVNode("svg",{class:"icon",viewBox:"0 -960 960 960"},[t.createElementVNode("path",{d:"m 306.66667,-360 q -44,0 -75.33334,-31.33333 Q 200,-422.66667 200,-466.66667 q 0,-44 31.33333,-75.33333 31.33334,-31.33333 75.33334,-31.33333 15.33333,0 28.33333,3.66666 13,3.66667 25,11 V -840 h 160 v 106.66667 H 413.33333 v 266.66666 q 0,44 -31.33333,75.33334 Q 350.66667,-360 306.66667,-360 Z"}),t.createElementVNode("path",{d:"m 546.66667,-120 q -44,0 -75.33334,-31.33333 Q 440,-182.66667 440,-226.66667 q 0,-44 31.33333,-75.33333 31.33334,-31.33333 75.33334,-31.33333 15.33333,0 28.33333,3.66666 13,3.66667 25,11 V -600 h 160 v 106.66667 H 653.33333 v 266.66666 q 0,44 -31.33333,75.33334 Q 590.66667,-120 546.66667,-120 Z"})],-1)])),_:1,__:[7]},8,["disabled"])])]))}},[["__scopeId","data-v-9470408d"]]),Ct={class:"init-progress"},xt={key:0,class:"progress-track"},Tt={class:"message-container"},Ne=L({__name:"InitializationProgress",props:{stage:{type:String,default:null},message:{type:String,default:""},progress:{type:Number,default:null},hasError:{type:Boolean,default:!1},errorMessage:{type:String,default:null}},setup(a){const e=a,s=t.computed(()=>e.progress!==null),n=t.computed(()=>e.progress===null?0:Math.max(0,Math.min(100,e.progress*100))),i=t.computed(()=>e.hasError?e.errorMessage:e.message);return(r,o)=>(t.openBlock(),t.createElementBlock("div",Ct,[s.value?(t.openBlock(),t.createElementBlock("div",xt,[t.createElementVNode("div",{class:"progress-fill",style:t.normalizeStyle({width:`${n.value}%`})},null,4)])):t.createCommentVNode("",!0),t.createElementVNode("div",Tt,[t.createElementVNode("div",{class:t.normalizeClass(["message",{error:a.hasError}])},t.toDisplayString(i.value),3)])]))}},[["__scopeId","data-v-a9ed87f2"]]),Ve=X.defineStore("initialization",{state:()=>({currentStage:null,message:"",progress:null,isInitializing:!1,isReady:!1,hasError:!1,errorMessage:null}),actions:{updateProgress(a){this.currentStage=a.stage,this.message=a.message,this.progress=a.progress??null,a.stage==="ready"?(this.isInitializing=!1,this.isReady=!0):(this.isInitializing=!0,this.isReady=!1),this.hasError=!1,this.errorMessage=null},setError(a){this.hasError=!0,this.errorMessage=a,this.isInitializing=!1,this.isReady=!1},reset(){this.currentStage=null,this.message="",this.progress=null,this.isInitializing=!1,this.isReady=!1,this.hasError=!1,this.errorMessage=null},initializeListeners(){m.on("initProgress",a=>{this.updateProgress(a)})}},getters:{shouldShowProgress:a=>a.isInitializing||a.hasError,hasProgressBar:a=>a.progress!==null}}),Nt={class:"container"},Vt={class:"panel"},_t={key:0,class:"blur"},_e=40,Le=40,Ae=100,Lt=50,Ie=400,De=570,ze=570,At=350,It=330,Dt=360,zt=360,Rt=L({__name:"MixerLayout",props:{showInitProgress:{type:Boolean,default:!0},externalMenuControl:{type:Boolean,default:!1}},emits:["menu-click"],setup(a,{emit:e}){t.useCssVars(f=>({"3e3bf6e6":B.value,"3e499cb2":w.value,"3a701552":N.value}));const s=a,n=e,i=U(),r=F(),o=Ve();t.onMounted(()=>{o.initializeListeners()});const h=t.useTemplateRef("container"),{width:v}=O(h),c=t.computed(()=>r.isLoaded),g=t.computed(()=>{const f=v.value,S=i.parts.length;return f<640||f<_e*S+Ie?0:f<Le*S+De?1:f<Ae*S+ze?2:3}),B=t.computed(()=>{switch(g.value){case 0:return`${At}px `+`${Lt}px `.repeat(i.parts.length);case 1:return`${It}px`;case 2:return`${Dt}px`;default:return`${zt}px`}}),w=t.computed(()=>{switch(g.value){case 0:return"100vw";case 1:return`${_e}px `.repeat(i.parts.length)+`${Ie}px`;case 2:return`${Le}px `.repeat(i.parts.length)+`${De}px`;default:return`${Ae}px `.repeat(i.parts.length)+`${ze}px`}}),N=t.computed(()=>{const f=[...i.parts.keys()];return g.value>0?'"'+f.map(S=>"part"+S).join(" ")+' controls"':'"controls" '+f.map(S=>'"part'+S+'"').join(" ")});return(f,S)=>(t.openBlock(),t.createElementBlock("div",{class:"outer",ref_key:"container",ref:h},[t.createElementVNode("div",Nt,[t.createElementVNode("div",Vt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(i).parts,(M,C)=>(t.openBlock(),t.createBlock(Pe,{key:M.name,class:t.normalizeClass("part"+C),name:M.name,volume:M.volume,"onUpdate:volume":T=>M.volume=T,solo:M.solo,"onUpdate:solo":T=>M.solo=T,mute:M.mute,"onUpdate:mute":T=>M.mute=T,ref_for:!0,ref:"parts"},null,8,["class","name","volume","onUpdate:volume","solo","onUpdate:solo","mute","onUpdate:mute"]))),128)),t.createVNode(Te,{"external-menu-control":s.externalMenuControl,onMenuClick:S[0]||(S[0]=M=>n("menu-click")),class:"controls"},{menu:t.withCtx(()=>[t.renderSlot(f.$slots,"menu",{},void 0,!0)]),_:3},8,["external-menu-control"]),c.value?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("div",_t)),s.showInitProgress&&t.unref(o).shouldShowProgress?(t.openBlock(),t.createBlock(Ne,{key:1,stage:t.unref(o).currentStage,message:t.unref(o).message,progress:t.unref(o).progress,"has-error":t.unref(o).hasError,"error-message":t.unref(o).errorMessage},null,8,["stage","message","progress","has-error","error-message"])):t.createCommentVNode("",!0)])])],512))}},[["__scopeId","data-v-cf29d602"]]),$t={class:"outer"},Ot={class:"mid"},Ft={class:"inner"},Ut={key:0,class:"content"},Kt=L({__name:"Placeholder",props:{colour:{type:String,default:"red"},text:{type:String,default:""}},setup(a){return t.useCssVars(e=>({"66bea586":a.colour})),(e,s)=>(t.openBlock(),t.createElementBlock("div",$t,[t.createElementVNode("div",Ot,[t.createElementVNode("div",Ft,[a.text||e.$slots.default?(t.openBlock(),t.createElementBlock("div",Ut,[t.createTextVNode(t.toDisplayString(a.text)+" ",1),t.renderSlot(e.$slots,"default",{},void 0,!0)])):t.createCommentVNode("",!0)])])]))}},[["__scopeId","data-v-dff76c48"]]),Gt={class:"modal-footer"},qt={key:0,class:"dont-remind"},Ht=L({__name:"KeyboardShortcutsHelp",props:{visible:{type:Boolean,default:!1},showDontRemind:{type:Boolean,default:!1}},emits:["update:visible","dont-remind"],setup(a,{emit:e}){const s=a,n=e,i=t.ref(!1),r=t.ref(null),o=()=>{i.value&&n("dont-remind",!0),n("update:visible",!1)},h=v=>{v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),o())};return t.watch(()=>s.visible,async v=>{var c;v&&(await t.nextTick(),(c=r.value)==null||c.focus())}),(v,c)=>a.visible?(t.openBlock(),t.createElementBlock("div",{key:0,class:"modal-overlay",onClick:o,onKeydown:h},[t.createElementVNode("div",{class:"modal-content shortcuts-help",onClick:c[1]||(c[1]=t.withModifiers(()=>{},["stop"])),role:"dialog","aria-labelledby":"shortcuts-title","aria-modal":"true"},[c[3]||(c[3]=t.createStaticVNode('<h2 id="shortcuts-title" data-v-bfa878a3>Keyboard Shortcuts</h2><div class="shortcuts-container" data-v-bfa878a3><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Transport Controls</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>P</kbd></dt><dd data-v-bfa878a3>Play / Pause</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>S</kbd></dt><dd data-v-bfa878a3>Stop</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>B</kbd></dt><dd data-v-bfa878a3>Previous bar</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>F</kbd></dt><dd data-v-bfa878a3>Next bar</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Features</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>M</kbd></dt><dd data-v-bfa878a3>Toggle metronome</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>L</kbd></dt><dd data-v-bfa878a3>Toggle lead-in</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>N</kbd></dt><dd data-v-bfa878a3>Play starting notes</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Sliders &amp; Controls</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>↑</kbd> / <kbd data-v-bfa878a3>→</kbd></dt><dd data-v-bfa878a3>Increase value</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>↓</kbd> / <kbd data-v-bfa878a3>←</kbd></dt><dd data-v-bfa878a3>Decrease value</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Home</kbd></dt><dd data-v-bfa878a3>Set to minimum</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>End</kbd></dt><dd data-v-bfa878a3>Set to maximum</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Page Up</kbd> / <kbd data-v-bfa878a3>Page Down</kbd></dt><dd data-v-bfa878a3>Large adjustment</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Navigation</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Tab</kbd></dt><dd data-v-bfa878a3>Next control</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>Tab</kbd></dt><dd data-v-bfa878a3>Previous control</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Enter</kbd> / <kbd data-v-bfa878a3>Space</kbd></dt><dd data-v-bfa878a3>Activate button</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Escape</kbd></dt><dd data-v-bfa878a3>Close dialog / menu</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Help</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>?</kbd></dt><dd data-v-bfa878a3>Show this help</dd></div></dl></section></div>',2)),t.createElementVNode("div",Gt,[a.showDontRemind?(t.openBlock(),t.createElementBlock("label",qt,[t.withDirectives(t.createElementVNode("input",{type:"checkbox","onUpdate:modelValue":c[0]||(c[0]=g=>i.value=g)},null,512),[[t.vModelCheckbox,i.value]]),c[2]||(c[2]=t.createTextVNode(" Don't show this again "))])):t.createCommentVNode("",!0),t.createElementVNode("button",{onClick:o,class:"close-button",ref_key:"closeButton",ref:r},"Close",512)])])],32)):t.createCommentVNode("",!0)}},[["__scopeId","data-v-bfa878a3"]]);class Re{constructor(){this.eventBus=Se(),this.currentTime=0,this.isPlaying=!1,this.playbackSpeed=1,this.masterVolume=.75,this.parts=new Map,this.playbackTimer=null,this.lastTimestamp=0}initialize(e){if(this.musicData=e,this.beats=e.beats||[],this.practiceMarks=e.practiceMarks||{},this.beats.length>0){const s=this.beats[this.beats.length-1],n=s.tempo>0?60/s.tempo:.75;this.songDuration=s.time+n,this.maxBar=Math.max(...this.beats.map(i=>i.bar))}else this.songDuration=0,this.maxBar=0;e.parts&&e.parts.forEach(s=>{this.parts.set(s.name,{name:s.name,volume:s.volume||.75,muted:!1})}),this.eventBus.emit("initialized",{parts:Array.from(this.parts.values())})}play(){this.isPlaying||(this.isPlaying=!0,this.lastTimestamp=performance.now(),this.startPlaybackTimer(),this.eventBus.emit("playbackStateChanged",{isPlaying:!0,currentTime:this.currentTime}))}stop(){this.isPlaying&&(this.isPlaying=!1,this.stopPlaybackTimer(),this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime}))}pause(){this.stop()}setTime(e){this.currentTime=Math.max(0,e),this.eventBus.emit("timeChanged",{currentTime:this.currentTime});const s=this.getBarFromTime(this.currentTime);s&&this.eventBus.emit("barChanged",s)}getCurrentTime(){return this.currentTime}setBar(e,s=0){const n=this.getTimeFromBar(e,s);n!==null&&this.setTime(n)}goToPracticeMark(e){const s=this.practiceMarks[e];s!==void 0&&(this.setBar(s),this.eventBus.emit("practiceMarkChanged",{mark:e,bar:s}))}setPlaybackSpeed(e){this.playbackSpeed=Math.max(.25,Math.min(2,e)),this.eventBus.emit("speedChanged",{speed:this.playbackSpeed})}getPlaybackSpeed(){return this.playbackSpeed}setMasterVolume(e){this.masterVolume=Math.max(0,Math.min(1,e)),this.eventBus.emit("masterVolumeChanged",{volume:this.masterVolume})}getMasterVolume(){return this.masterVolume}setPartVolume(e,s){const n=this.parts.get(e);n&&(n.volume=Math.max(0,Math.min(1,s)),this.eventBus.emit("partVolumeChanged",{partName:e,volume:n.volume}))}setPartMuted(e,s){const n=this.parts.get(e);n&&(n.muted=s,this.eventBus.emit("partMutedChanged",{partName:e,muted:s}))}getParts(){return Array.from(this.parts.values())}playLeadIn(e=1){this.eventBus.emit("leadInStarted",{bars:e}),setTimeout(()=>{this.eventBus.emit("leadInCompleted")},1e3*e)}playStartingNotes(){this.eventBus.emit("startingNotesStarted"),setTimeout(()=>{this.eventBus.emit("startingNotesCompleted")},2e3)}on(e,s){this.eventBus.on(e,s)}off(e,s){this.eventBus.off(e,s)}startPlaybackTimer(){const e=()=>{if(!this.isPlaying)return;const s=performance.now(),n=(s-this.lastTimestamp)/1e3;if(this.lastTimestamp=s,this.currentTime+=n*this.playbackSpeed,this.songDuration>0&&this.currentTime>=this.songDuration){this.stop(),this.eventBus.emit("songEnded",{finalTime:this.currentTime});return}this.eventBus.emit("timeChanged",{currentTime:this.currentTime});const i=this.getBarFromTime(this.currentTime);if(i&&(this.eventBus.emit("barChanged",i),this.maxBar>0&&i.bar>this.maxBar)){this.stop(),this.eventBus.emit("songEnded",{finalTime:this.currentTime});return}this.playbackTimer=requestAnimationFrame(e)};this.playbackTimer=requestAnimationFrame(e)}stopPlaybackTimer(){this.playbackTimer&&(cancelAnimationFrame(this.playbackTimer),this.playbackTimer=null)}getBarFromTime(e){if(!this.beats||this.beats.length===0)return null;let s=null;for(let n=this.beats.length-1;n>=0;n--)if(this.beats[n].time<=e){s=this.beats[n];break}return s?{bar:s.bar,beat:s.beat,repeat:s.repeat,time:s.time}:null}getTimeFromBar(e,s=0){if(!this.beats||this.beats.length===0)return null;let n=this.beats.find(i=>i.bar===e&&i.beat===1&&i.repeat===s);return n||(n=this.beats.find(i=>i.bar===e&&i.beat===1)),n?n.time:null}destroy(){this.stop(),this.eventBus.all.clear(),this.parts.clear()}}new Re,P.AudioButton=G,P.AudioSlider=Y,P.BarInput=we,P.BaseNumericInput=me,P.DEV_MODE=ae,P.DummyAudioEngine=Re,P.InitializationProgress=Ne,P.KeyboardShortcutsHelp=Ht,P.MixerControls=Te,P.MixerLayout=Rt,P.PartControl=Pe,P.Placeholder=Kt,P.SpeedInput=Ce,P.TimeInput=xe,P.TitleText=de,P.TriState=Me,P.audioEngineConfig=Be,P.isDevFeature=ue,P.isDevMode=ot,P.useAudioStateStore=F,P.useElementSize=O,P.useInitializationState=Ve,P.useMasterAudioControl=W,P.useMusicDataStore=U,P.usePlaybackStateStore=se,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
1
+ (function(P,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("pinia"),require("audio-mixer-engine")):typeof define=="function"&&define.amd?define(["exports","vue","pinia","audio-mixer-engine"],t):(P=typeof globalThis<"u"?globalThis:P||self,t(P.AudioMixerUI={},P.Vue,P.Pinia,P.AudioMixerEngine))})(this,function(P,t,X,le){"use strict";var pe=function(){if(typeof Map<"u")return Map;function a(e,s){var n=-1;return e.some(function(i,r){return i[0]===s?(n=r,!0):!1}),n}return function(){function e(){this.__entries__=[]}return Object.defineProperty(e.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),e.prototype.get=function(s){var n=a(this.__entries__,s),i=this.__entries__[n];return i&&i[1]},e.prototype.set=function(s,n){var i=a(this.__entries__,s);~i?this.__entries__[i][1]=n:this.__entries__.push([s,n])},e.prototype.delete=function(s){var n=this.__entries__,i=a(n,s);~i&&n.splice(i,1)},e.prototype.has=function(s){return!!~a(this.__entries__,s)},e.prototype.clear=function(){this.__entries__.splice(0)},e.prototype.forEach=function(s,n){n===void 0&&(n=null);for(var i=0,r=this.__entries__;i<r.length;i++){var o=r[i];s.call(n,o[1],o[0])}},e}()}(),ce=typeof window<"u"&&typeof document<"u"&&window.document===document,J=function(){return typeof global<"u"&&global.Math===Math?global:typeof self<"u"&&self.Math===Math?self:typeof window<"u"&&window.Math===Math?window:Function("return this")()}(),$e=function(){return typeof requestAnimationFrame=="function"?requestAnimationFrame.bind(J):function(a){return setTimeout(function(){return a(Date.now())},1e3/60)}}(),Oe=2;function Fe(a,e){var s=!1,n=!1,i=0;function r(){s&&(s=!1,a()),n&&h()}function o(){$e(r)}function h(){var v=Date.now();if(s){if(v-i<Oe)return;n=!0}else s=!0,n=!1,setTimeout(o,e);i=v}return h}var Ue=20,Ke=["top","right","bottom","left","width","height","size","weight"],Ge=typeof MutationObserver<"u",qe=function(){function a(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=Fe(this.refresh.bind(this),Ue)}return a.prototype.addObserver=function(e){~this.observers_.indexOf(e)||this.observers_.push(e),this.connected_||this.connect_()},a.prototype.removeObserver=function(e){var s=this.observers_,n=s.indexOf(e);~n&&s.splice(n,1),!s.length&&this.connected_&&this.disconnect_()},a.prototype.refresh=function(){var e=this.updateObservers_();e&&this.refresh()},a.prototype.updateObservers_=function(){var e=this.observers_.filter(function(s){return s.gatherActive(),s.hasActive()});return e.forEach(function(s){return s.broadcastActive()}),e.length>0},a.prototype.connect_=function(){!ce||this.connected_||(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),Ge?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},a.prototype.disconnect_=function(){!ce||!this.connected_||(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},a.prototype.onTransitionEnd_=function(e){var s=e.propertyName,n=s===void 0?"":s,i=Ke.some(function(r){return!!~n.indexOf(r)});i&&this.refresh()},a.getInstance=function(){return this.instance_||(this.instance_=new a),this.instance_},a.instance_=null,a}(),ge=function(a,e){for(var s=0,n=Object.keys(e);s<n.length;s++){var i=n[s];Object.defineProperty(a,i,{value:e[i],enumerable:!1,writable:!1,configurable:!0})}return a},j=function(a){var e=a&&a.ownerDocument&&a.ownerDocument.defaultView;return e||J},be=te(0,0,0,0);function ee(a){return parseFloat(a)||0}function ve(a){for(var e=[],s=1;s<arguments.length;s++)e[s-1]=arguments[s];return e.reduce(function(n,i){var r=a["border-"+i+"-width"];return n+ee(r)},0)}function He(a){for(var e=["top","right","bottom","left"],s={},n=0,i=e;n<i.length;n++){var r=i[n],o=a["padding-"+r];s[r]=ee(o)}return s}function je(a){var e=a.getBBox();return te(0,0,e.width,e.height)}function We(a){var e=a.clientWidth,s=a.clientHeight;if(!e&&!s)return be;var n=j(a).getComputedStyle(a),i=He(n),r=i.left+i.right,o=i.top+i.bottom,h=ee(n.width),v=ee(n.height);if(n.boxSizing==="border-box"&&(Math.round(h+r)!==e&&(h-=ve(n,"left","right")+r),Math.round(v+o)!==s&&(v-=ve(n,"top","bottom")+o)),!Ye(a)){var c=Math.round(h+r)-e,g=Math.round(v+o)-s;Math.abs(c)!==1&&(h-=c),Math.abs(g)!==1&&(v-=g)}return te(i.left,i.top,h,v)}var Ze=function(){return typeof SVGGraphicsElement<"u"?function(a){return a instanceof j(a).SVGGraphicsElement}:function(a){return a instanceof j(a).SVGElement&&typeof a.getBBox=="function"}}();function Ye(a){return a===j(a).document.documentElement}function Qe(a){return ce?Ze(a)?je(a):We(a):be}function Xe(a){var e=a.x,s=a.y,n=a.width,i=a.height,r=typeof DOMRectReadOnly<"u"?DOMRectReadOnly:Object,o=Object.create(r.prototype);return ge(o,{x:e,y:s,width:n,height:i,top:s,right:e+n,bottom:i+s,left:e}),o}function te(a,e,s,n){return{x:a,y:e,width:s,height:n}}var Je=function(){function a(e){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=te(0,0,0,0),this.target=e}return a.prototype.isActive=function(){var e=Qe(this.target);return this.contentRect_=e,e.width!==this.broadcastWidth||e.height!==this.broadcastHeight},a.prototype.broadcastRect=function(){var e=this.contentRect_;return this.broadcastWidth=e.width,this.broadcastHeight=e.height,e},a}(),et=function(){function a(e,s){var n=Xe(s);ge(this,{target:e,contentRect:n})}return a}(),tt=function(){function a(e,s,n){if(this.activeObservations_=[],this.observations_=new pe,typeof e!="function")throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=e,this.controller_=s,this.callbackCtx_=n}return a.prototype.observe=function(e){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if(!(typeof Element>"u"||!(Element instanceof Object))){if(!(e instanceof j(e).Element))throw new TypeError('parameter 1 is not of type "Element".');var s=this.observations_;s.has(e)||(s.set(e,new Je(e)),this.controller_.addObserver(this),this.controller_.refresh())}},a.prototype.unobserve=function(e){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if(!(typeof Element>"u"||!(Element instanceof Object))){if(!(e instanceof j(e).Element))throw new TypeError('parameter 1 is not of type "Element".');var s=this.observations_;s.has(e)&&(s.delete(e),s.size||this.controller_.removeObserver(this))}},a.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},a.prototype.gatherActive=function(){var e=this;this.clearActive(),this.observations_.forEach(function(s){s.isActive()&&e.activeObservations_.push(s)})},a.prototype.broadcastActive=function(){if(this.hasActive()){var e=this.callbackCtx_,s=this.activeObservations_.map(function(n){return new et(n.target,n.broadcastRect())});this.callback_.call(e,s,e),this.clearActive()}},a.prototype.clearActive=function(){this.activeObservations_.splice(0)},a.prototype.hasActive=function(){return this.activeObservations_.length>0},a}(),ye=typeof WeakMap<"u"?new WeakMap:new pe,ke=function(){function a(e){if(!(this instanceof a))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var s=qe.getInstance(),n=new tt(e,s,this);ye.set(this,n)}return a}();["observe","unobserve","disconnect"].forEach(function(a){ke.prototype[a]=function(){var e;return(e=ye.get(this))[a].apply(e,arguments)}});var at=function(){return typeof J.ResizeObserver<"u"?J.ResizeObserver:ke}();function O(a){const e=t.ref(0),s=t.ref(0);let n=null;const i=()=>{n&&(n.disconnect(),n=null)},r=()=>{i();const o=t.unref(a);if(!o)return;n=new at(v=>{const c=v[0];c&&(e.value=c.contentRect.width,s.value=c.contentRect.height)}),n.observe(o);const h=o.getBoundingClientRect();e.value=h.width,s.value=h.height};return t.watch(()=>t.unref(a),r,{immediate:!0}),t.onScopeDispose(i),{width:t.readonly(e),height:t.readonly(s)}}const L=(a,e)=>{const s=a.__vccOpts||a;for(const[n,i]of e)s[n]=i;return s},st=["aria-valuemin","aria-valuemax","aria-valuenow","aria-label","aria-orientation","tabindex"],nt={key:0,class:"level"},Y=L({__name:"AudioSlider",props:t.mergeModels({min:{type:Number,default:0},max:{type:Number,default:1},step:{type:Number,default:.01},keystep:{type:Number,default:null},colour:{type:String,default:"grey"},style:{type:String,default:"volume"},thumbLength:{type:Number,default:1},showLevel:{type:Boolean,default:!1},level:{type:Number,default:.5},tabindex:{type:String,default:"0"}},{value:{default:.75},valueModifiers:{}}),emits:["update:value"],setup(a){t.useCssVars(p=>({"2096b4c3":N.value,"757f26aa":C.value,"744b71b7":M.value,d898db12:f.value,"3a8d2f7c":S.value}));const e=a,s=t.useTemplateRef("root"),{width:n,height:i}=O(s),r=t.computed(()=>Math.min(n.value,i.value)),o=t.computed(()=>Math.max(n.value,i.value)),h=t.computed(()=>n.value>i.value),v=t.computed(()=>h.value?"h-slide":"v-slide"),c=t.useModel(a,"value");t.computed(()=>Math.pow(1-c.value,.5)*180+20),t.computed(()=>Math.pow(c.value,.5)*180+20);const g=t.computed(()=>r.value*.8),B=t.computed(()=>r.value*e.thumbLength*.8),C=t.computed(()=>(h.value?B:g).value+"px"),N=t.computed(()=>(h.value?g:B).value+"px"),f=t.computed(()=>r.value*.1+"px"),S=t.computed(()=>(o.value-B.value)*(c.value-e.min)/(e.max-e.min)+"px"),M=t.computed(()=>h.value?"90deg":"0deg"),w=t.ref(!1),T=t.ref(0),V=p=>{if(!s.value)return c.value;const b=s.value.getBoundingClientRect(),x=p.clientX,Q=p.clientY;let K;if(h.value){const q=x-b.left-g.value/2,H=b.width-g.value;K=Math.max(0,Math.min(1,q/H))}else{const q=b.bottom-Q-g.value/2,H=b.height-g.value;K=Math.max(0,Math.min(1,q/H))}const R=e.min+K*(e.max-e.min);return e.step>0?Math.round(R/e.step)*e.step:R},D=p=>{p.preventDefault(),w.value=!0,T.value=c.value,s.value&&s.value.focus(),c.value=V(p),s.value&&s.value.setPointerCapture&&s.value.setPointerCapture(p.pointerId),document.addEventListener("pointermove",I),document.addEventListener("pointerup",A),document.addEventListener("pointercancel",A)},I=p=>{w.value&&(p.preventDefault(),c.value=V(p))},A=p=>{if(w.value){if(p.preventDefault(),w.value=!1,s.value&&s.value.releasePointerCapture)try{s.value.releasePointerCapture(p.pointerId)}catch{}document.removeEventListener("pointermove",I),document.removeEventListener("pointerup",A),document.removeEventListener("pointercancel",A)}},z=p=>{if(s.value&&s.value.getAttribute("tabindex")==="-1")return;const b=e.keystep!==null?e.keystep:e.step||.01;let x=c.value;switch(p.key){case"ArrowLeft":case"ArrowDown":p.preventDefault(),x=Math.max(e.min,c.value-b);break;case"ArrowRight":case"ArrowUp":p.preventDefault(),x=Math.min(e.max,c.value+b);break;default:return}c.value=x},u=p=>Math.min(1,Math.max(0,e.level*10-p+1));return(p,b)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(v.value),ref_key:"root",ref:s,role:"slider","aria-valuemin":a.min,"aria-valuemax":a.max,"aria-valuenow":c.value,"aria-label":`${a.style} control`,"aria-orientation":h.value?"horizontal":"vertical",tabindex:a.tabindex,onPointerdown:D,onKeydown:z,style:{userSelect:"none",touchAction:"none"}},[b[0]||(b[0]=t.createElementVNode("div",{class:"track"},null,-1)),a.showLevel?(t.openBlock(),t.createElementBlock("div",nt,[(t.openBlock(),t.createElementBlock(t.Fragment,null,t.renderList(10,x=>t.createElementVNode("div",{class:t.normalizeClass(["focus","led"+x])},[t.createElementVNode("div",{class:"on",style:t.normalizeStyle({opacity:u(x)})},null,4)],2)),64))])):t.createCommentVNode("",!0),t.createElementVNode("div",{class:t.normalizeClass(["thumb",{dragging:w.value,[a.colour]:!0,[a.style]:!0}])},null,2)],42,st))}},[["__scopeId","data-v-42160c3a"]]),de=L({__name:"TitleText",props:{align:{type:String,default:"left"},overflow:{type:String,default:"crop",validator:a=>["crop","scroll"].includes(a)}},setup(a){t.useCssVars(B=>({"9d94564a":v.value,"6241cf7e":c.value+"px"}));const e=a,s=t.useTemplateRef("el"),n=t.useTemplateRef("textEl"),{width:i,height:r}=O(s),o=t.computed(()=>Math.min(i.value,r.value)),h=t.computed(()=>i.value>r.value?"h-text":"v-text"),v=t.computed(()=>o.value*3/4+"px"),c=t.ref(0),g=t.ref(!1);return t.watchEffect(()=>{if(!n.value||!s.value||e.overflow!=="scroll"){g.value=!1,c.value=0;return}const B=h.value==="h-text"?i.value:r.value,C=h.value==="h-text"?n.value.scrollWidth:n.value.scrollHeight,N=B-20;C>N?(g.value=!0,c.value=C-N):(g.value=!1,c.value=0)}),(B,C)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"el",ref:s,class:"outer"},[t.createElementVNode("div",{ref_key:"textEl",ref:n,class:t.normalizeClass({[h.value]:!0,[a.align]:!0,scrolling:g.value})},[t.renderSlot(B.$slots,"default",{},void 0,!0)],2)],512))}},[["__scopeId","data-v-8efcf3aa"]]),it={class:"s-label"},rt={class:"m-label"},Me=L({__name:"TriState",props:{mute:{default:!1},muteModifiers:{},solo:{default:!1},soloModifiers:{}},emits:["update:mute","update:solo"],setup(a){const e=t.useModel(a,"mute"),s=t.useModel(a,"solo"),n=t.useTemplateRef("outer"),{width:i,height:r}=O(n),o=t.computed(()=>i.value>r.value*1.9);function h(){e.value=!e.value,s.value=!1}function v(){s.value=!s.value,e.value=!1}return(c,g)=>(t.openBlock(),t.createElementBlock("div",{class:"outer",ref_key:"outer",ref:n},[t.createElementVNode("div",{title:"Solo",class:t.normalizeClass(["solo",{on:s.value}]),onClick:v},null,2),t.createElementVNode("div",it,t.toDisplayString(o.value?"SOLO":"S"),1),t.createElementVNode("div",{title:"Mute",class:t.normalizeClass(["mute",{on:e.value}]),onClick:h},null,2),t.createElementVNode("div",rt,t.toDisplayString(o.value?"MUTE":"M"),1)],512))}},[["__scopeId","data-v-7e3c1495"]]),ae={enabled:!1,features:{beatAnimation:!0,randomLevelIndicators:!0,debugMode:!1}},ot=()=>ae.enabled,ue=a=>ae.enabled&&ae.features[a],F=X.defineStore("audioState",{state:()=>({isPlaying:!1,currentTime:0,playbackSpeed:1,currentBar:1,currentBeat:1,currentRepeat:0,masterVolume:.75,metronomeVolume:.7,partVolumes:{},partMuted:{},partSolo:{},isLeadInActive:!1,isStartingNotesActive:!1,leadInBars:1,metronomeEnabled:!1,leadInEnabled:!0,isLoaded:!1}),getters:{isPlayingOrLeadIn:a=>a.isPlaying||a.isLeadInActive,formattedTime:a=>{const e=Math.floor(a.currentTime/60),s=Math.floor(a.currentTime%60);return`${e}:${s.toString().padStart(2,"0")}`},getPartVolume:a=>e=>a.partVolumes[e]??.75,isPartMuted:a=>e=>a.partMuted[e]??!1,isPartSolo:a=>e=>a.partSolo[e]??!1,isAnySolo:a=>Object.values(a.partSolo).some(e=>e===!0),currentPosition:a=>{let e=`${a.currentBar}.${a.currentBeat}`;return a.currentRepeat>0&&(e+=` (R${a.currentRepeat})`),e}},actions:{setPlaybackState(a){this.isPlaying=a},setCurrentTime(a){this.currentTime=a},setPlaybackSpeed(a){this.playbackSpeed=a},setCurrentBar(a,e=1,s=0){typeof a=="number"&&(this.currentBar=a),typeof e=="number"&&(this.currentBeat=e),typeof s=="number"&&(this.currentRepeat=s)},setMasterVolume(a){this.masterVolume=Math.max(0,Math.min(1,a))},setMetronomeVolume(a){this.metronomeVolume=Math.max(0,Math.min(1,a))},setPartVolume(a,e){this.partVolumes[a]=Math.max(0,Math.min(1,e))},setPartMuted(a,e){this.partMuted[a]=e},setPartSolo(a,e){this.partSolo[a]=e},setLeadInActive(a,e=1){this.isLeadInActive=a,this.leadInBars=e},setStartingNotesActive(a){this.isStartingNotesActive=a},setMetronomeEnabled(a){this.metronomeEnabled=a},setLeadInEnabled(a){this.leadInEnabled=a},initializeParts(a){this.partVolumes={},this.partMuted={},this.partSolo={},a.forEach(e=>{this.partVolumes[e.name]=e.volume||.75,this.partMuted[e.name]=!1,this.partSolo[e.name]=!1})},setLoaded(a){this.isLoaded=a}}}),U=X.defineStore("musicData",{state:()=>({beats:[],practiceMarks:{},customPracticeMarks:{},parts:[],title:"",totalDuration:0,maxBar:0,timeSignature:4,baseTempo:80}),getters:{practiceMarkLetters:a=>Object.keys(a.practiceMarks).sort(),getBarForMark:a=>e=>a.practiceMarks[e],allBars:a=>{const e=new Set;return a.beats.forEach(s=>{s.beat===1&&e.add(s.bar)}),Array.from(e).sort((s,n)=>s-n)},hasRepeats:a=>e=>a.beats.some(s=>s.bar===e&&s.repeat>0),getRepeatCountForBar:a=>e=>{const s=new Set;return a.beats.forEach(n=>{n.bar===e&&s.add(n.repeat)}),s.size},allPracticeMarks:a=>({...a.practiceMarks,...a.customPracticeMarks}),allPracticeMarksSorted:a=>{const e={...a.practiceMarks,...a.customPracticeMarks};return Object.entries(e).sort(([,s],[,n])=>s-n).map(([s])=>s)},barHasMark:a=>e=>{const s={...a.practiceMarks,...a.customPracticeMarks};return Object.values(s).includes(e)},isCustomMark:a=>e=>e in a.customPracticeMarks,nextAvailableLetter:a=>{const e=new Set([...Object.keys(a.practiceMarks),...Object.keys(a.customPracticeMarks)]);for(let s=0;s<26;s++){const n=String.fromCharCode(65+s);if(!e.has(n))return n}return null}},actions:{loadMusicData(a){this.title=a.title||"Untitled",this.beats=a.beats||[],this.practiceMarks=a.practiceMarks||a.marks||{},this.parts=(a.parts||[]).map(e=>({...e,solo:e.solo||!1,mute:e.mute||!1})),this.calculateDuration(),this.calculateMaxBar(),this.extractTimeSignature(),this.loadCustomMarksFromStorage()},calculateDuration(){this.beats.length>0&&(this.totalDuration=Math.max(...this.beats.map(a=>a.time)))},calculateMaxBar(){this.beats.length>0&&(this.maxBar=Math.max(...this.beats.map(a=>a.bar)))},extractTimeSignature(){this.beats.length>0&&this.beats[0].timeSig&&(this.timeSignature=this.beats[0].timeSig),this.beats.length>0&&this.beats[0].tempo&&(this.baseTempo=this.beats[0].tempo)},setPracticeMark(a,e){this.practiceMarks[a]=e},removePracticeMark(a){delete this.practiceMarks[a]},addCustomMark(a){const e=this.nextAvailableLetter;return e&&!this.barHasMark(a)?(this.customPracticeMarks[e]=a,this.saveCustomMarksToStorage(),e):null},removeCustomMark(a){a in this.customPracticeMarks&&(delete this.customPracticeMarks[a],this.saveCustomMarksToStorage())},getStorageKey(){return`customPracticeMarks_${this.title}`},saveCustomMarksToStorage(){this.title&&localStorage.setItem(this.getStorageKey(),JSON.stringify(this.customPracticeMarks))},loadCustomMarksFromStorage(){if(this.title){const a=localStorage.getItem(this.getStorageKey());if(a)try{this.customPracticeMarks=JSON.parse(a)}catch{this.customPracticeMarks={}}else this.customPracticeMarks={}}},updateBeats(a){console.log("Updating beats in music data store"),this.beats=a,this.calculateDuration(),this.calculateMaxBar(),this.extractTimeSignature()},setTotalDuration(a){console.log("Setting total duration in music data store to:",a),this.totalDuration=a},isValidBar(a,e=0){return this.beats.some(s=>s.bar===a&&s.repeat===e)},setParts(a){this.parts=a.map(e=>({name:e.name,volume:e.volume||.75,solo:e.solo||!1,mute:e.mute||!1}))},clear(){this.beats=[],this.practiceMarks={},this.customPracticeMarks={},this.parts=[],this.title="",this.totalDuration=0,this.maxBar=0,this.timeSignature=4,this.baseTempo=80}}}),se=X.defineStore("playbackState",{state:()=>({transportState:"stopped",autoPlay:!1,loopEnabled:!1,loopStart:1,loopEnd:null,leadInEnabled:!0,leadInBars:1,startingNotesEnabled:!0,startingNotesSequential:!0,metronomeEnabled:!1,metronomeVolume:.5,showTransportControls:!0,showPartControls:!0,showNavigationControls:!0,lastBarPosition:1,lastPracticeMarkUsed:null,lastPlayStartBar:null,lastPlayStartRepeat:null,lastPlayStartTime:null,lastNavigationAction:null,fixedNavigationPoints:[],navigationPoints:[]}),getters:{isPlaying:a=>a.transportState==="playing",isPaused:a=>a.transportState==="paused",isStopped:a=>a.transportState==="stopped",isLoopConfigured:a=>a.loopEnabled&&a.loopStart&&a.loopEnd&&a.loopEnd>a.loopStart,loopRange:a=>!a.loopEnabled||!a.loopStart||!a.loopEnd?null:`${a.loopStart}-${a.loopEnd}`,getNavigationPoints:a=>a.navigationPoints},actions:{setTransportState(a){["stopped","playing","paused"].includes(a)&&(this.transportState=a)},play(){this.setTransportState("playing")},pause(){this.setTransportState("paused")},stop(){this.setTransportState("stopped")},setAutoPlay(a){this.autoPlay=a},setLoop(a,e=null,s=null){this.loopEnabled=a,e!==null&&(this.loopStart=e),s!==null&&(this.loopEnd=s)},setLoopStart(a){this.loopStart=a,this.loopEnd&&this.loopEnd<=a&&(this.loopEnd=a+4)},setLoopEnd(a){this.loopEnd=a,this.loopStart&&this.loopStart>=a&&(this.loopStart=Math.max(1,a-4))},setLeadInEnabled(a){this.leadInEnabled=a},setLeadInBars(a){this.leadInBars=Math.max(1,Math.min(4,a))},setStartingNotesEnabled(a){this.startingNotesEnabled=a},setStartingNotesSequential(a){this.startingNotesSequential=a},setMetronomeEnabled(a){this.metronomeEnabled=a},setMetronomeVolume(a){this.metronomeVolume=Math.max(0,Math.min(1,a))},setTransportControlsVisible(a){this.showTransportControls=a},setPartControlsVisible(a){this.showPartControls=a},setNavigationControlsVisible(a){this.showNavigationControls=a},updateLastBarPosition(a){this.lastBarPosition=a},updateLastPracticeMarkUsed(a){this.lastPracticeMarkUsed=a},buildFixedNavigationPoints(){const a=[],e=U();a.push({time:0,bar:1,repeat:1,label:"Start"});const s=e.beats.filter(n=>n.beat===1);for(const[n,i]of Object.entries(e.allPracticeMarks))s.filter(r=>r.bar===i).forEach(r=>{a.push({time:r.time,bar:r.bar,repeat:r.repeat,label:`Mark ${n}`})});if(e.beats.length>0){const n=Math.max(...e.beats.map(i=>i.time));a.push({time:n,label:"End"})}this.fixedNavigationPoints=a.sort((n,i)=>n.time-i.time),this.navigationPoints=[...this.fixedNavigationPoints]},rebuildNavigationPoints(){setTimeout(()=>{const a=U(),e=[...this.fixedNavigationPoints];this.lastPlayStartBar!==null&&a.beats.filter(i=>i.beat===1&&i.bar===this.lastPlayStartBar).forEach(i=>{e.push({time:i.time,bar:i.bar,repeat:i.repeat,label:"Last Play Start"})});const s=e.sort((n,i)=>n.time-i.time);this.navigationPoints=s.filter((n,i,r)=>i===0||n.time!==r[i-1].time)},50)},setLastPlayStart(a,e,s){this.lastPlayStartBar=a,this.lastPlayStartRepeat=e,this.lastPlayStartTime=s,this.rebuildNavigationPoints()},setNavigationAction(a){this.lastNavigationAction=a},resetToDefaults(){this.transportState="stopped",this.autoPlay=!1,this.loopEnabled=!1,this.loopStart=1,this.loopEnd=null,this.leadInEnabled=!0,this.leadInBars=1,this.startingNotesEnabled=!0,this.startingNotesSequential=!0,this.metronomeEnabled=!1,this.metronomeVolume=.5}}});function Se(a){return{all:a=a||new Map,on:function(e,s){var n=a.get(e);n?n.push(s):a.set(e,[s])},off:function(e,s){var n=a.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):a.set(e,[]))},emit:function(e,s){var n=a.get(e);n&&n.slice().map(function(i){i(s)}),(n=a.get("*"))&&n.slice().map(function(i){i(e,s)})}}}const Ee=["spessasynth","lightweight"];class lt{constructor(){this._engineType="spessasynth"}setEngineType(e){if(!Ee.includes(e))throw new Error(`Invalid audio engine type: "${e}". Must be one of: ${Ee.join(", ")}`);this._engineType=e}getEngineType(){return this._engineType}resetToDefault(){this._engineType="spessasynth"}}const Be=new lt;class ct{constructor(){this.eventBus=Se(),this.currentTime=0,this.isPlaying=!1,this.playbackSpeed=1,this.masterVolume=.75,this.metronomeVolume=.7,this.parts=new Map,this.playbackTimer=null,this.lastTimestamp=0,this.audioContext=null,this.audioEngine=null,this.playbackManager=null,this.musicData=null,this.beats=[],this.practiceMarks={},this.songDuration=0,this.maxBar=0,this.masterGain=null,this.metronomeGain=null,this.partGainNodes=new Map,this.partAnalyserNodes=new Map,this.isInitialized=!1}sanitizePartName(e){return!e||typeof e!="string"?"unknown":e.replace(/[\x00-\x1F\x7F-\x9F]/g,"").toLowerCase().trim()}async initializeAudioSystem(e={}){if(this.isInitialized)return;this.audioContext=new(window.AudioContext||window.webkitAudioContext),this.audioContext.state==="suspended"&&await this.audioContext.resume();const s=Be.getEngineType();if(s==="lightweight"?(this.audioEngine=new le.LightweightAudioEngine(this.audioContext),console.log("Using LightweightAudioEngine")):(this.audioEngine=new le.SpessaSynthAudioEngine(this.audioContext),console.log("Using SpessaSynthAudioEngine")),this.audioEngine.on("initProgress",n=>{this.eventBus.emit("initProgress",n)}),s==="spessasynth"){const n=e.soundfontUrl?[e.soundfontUrl]:["/FluidR3Mono_GM.sf3","/FluidR3_GM.sf2","/soundfont.sf2"];let i=!1,r=null;for(const o of n)try{await this.audioEngine.initialize(o),console.log(`Loaded soundfont: ${o}`),i=!0;break}catch(h){console.warn(`Failed to load soundfont ${o}:`,h.message),r=h}if(!i){const o="No soundfont could be loaded";throw this.eventBus.emit("initProgress",{stage:"error",message:o,error:r}),new Error(o)}}else try{await this.audioEngine.initialize(),console.log("LightweightAudioEngine initialized")}catch(n){const i="Failed to initialize LightweightAudioEngine";throw this.eventBus.emit("initProgress",{stage:"error",message:i,error:n}),new Error(i)}this.setupMasterAudioGraph(),this.isInitialized=!0,console.log("AudioEngineService initialized successfully")}setupMasterAudioGraph(){this.masterGain=this.audioContext.createGain(),this.masterGain.gain.value=this.masterVolume,this.masterGain.connect(this.audioContext.destination),this.metronomeGain=this.audioContext.createGain(),this.metronomeGain.gain.value=.7,this.metronomeGain.connect(this.audioContext.destination)}async initialize(e,s={}){if(this.isInitialized||await this.initializeAudioSystem(s),this.cleanup(),this.musicData=e,e.midiData)console.log(e),await this.setupMidiPlayback(e.midiData,e.metadata);else{if(this.beats=e.beats||[],this.practiceMarks=e.marks||e.practiceMarks||{},this.beats.length>0){const n=this.beats[this.beats.length-1],i=n.tempo>0?60/n.tempo:.75;this.songDuration=n.time+i,this.maxBar=Math.max(...this.beats.map(r=>r.bar))}else this.songDuration=0,this.maxBar=0;this.setupLegacyParts(e.parts||[]),this.eventBus.emit("initialized",{parts:Array.from(this.parts.values())})}}async setupMidiPlayback(e,s){try{this.playbackManager=new le.PlaybackManager(this.audioEngine,{metronome:{enabled:!0,tickInstrument:115,accentInstrument:116,volume:.7},leadIn:{enabled:!0,bars:1},startup:{delayMs:25}});const n=await this.playbackManager.calibrateAudioLatency({measurements:1,sampleIntervalMs:10,threshold:.01,timeout:3e3,silent:!0});console.log(`Measured audio latency: ${n} ms`),this.setupPlaybackManagerEventDelegation(),await this.playbackManager.load(e,s);const i=this.playbackManager.getPartNames();this.setupMidiParts(i),this.eventBus.emit("initialized",{parts:Array.from(this.parts.values())}),await this.setupPartAudioRouting(i),this.setupMetronomeAudioRouting(),this.extractMusicDataFromPlayer(),this.updateSongDurationFromPlayer(),console.log("MIDI playback with PlaybackManager setup complete")}catch(n){throw console.error("Failed to setup MIDI playback:",n),n}}setupMidiParts(e){e.forEach(s=>{const n=this.sanitizePartName(s);this.parts.set(n,{name:s,sanitizedName:n,volume:.75,muted:!1,solo:!1})})}async setupPartAudioRouting(){for(const[e,s]of this.playbackManager.getPartOutputs()){const n=this.audioContext.createGain();n.gain.value=1;const i=this.audioContext.createAnalyser();i.fftSize=256,i.smoothingTimeConstant=.3,s.connect(n),n.connect(i),i.connect(this.masterGain);const r=this.sanitizePartName(e);this.partGainNodes.set(r,n),this.partAnalyserNodes.set(r,i),console.log(`Audio routing established for part: ${e}`)}}setupMetronomeAudioRouting(){this.playbackManager.getMetronomeOutput().connect(this.metronomeGain),console.log("Metronome audio routing established")}extractMusicDataFromPlayer(){try{this.beats=this.playbackManager.getBeats(),this.practiceMarks=this.playbackManager.getPracticeMarks(),this.beats.length>0?this.maxBar=Math.max(...this.beats.map(e=>e.bar)):this.maxBar=0,console.log(`Extracted ${this.beats.length} beats and ${Object.keys(this.practiceMarks).length} practice marks from player`),this.eventBus.emit("musicDataExtracted",{beats:this.beats,practiceMarks:this.practiceMarks,maxBar:this.maxBar})}catch(e){console.warn("Could not extract music data from player:",e),this.beats=[],this.practiceMarks={},this.maxBar=0}}updateSongDurationFromPlayer(){let e=this.playbackManager.getTotalDuration();e&&e>0?(this.songDuration=e,this.musicData&&(this.musicData.duration=e),this.eventBus.emit("durationUpdated",{duration:e})):console.warn("Could not get duration from player")}snapTimeToBarStart(e){try{const s=this.getBarFromTime(e);if(s){const n=this.getTimeFromBar(s.bar,s.repeat);if(n!==null)return n}}catch(s){console.warn("Failed to snap time to bar start:",s)}return e}emitTimeAndBarUpdates(e){this.eventBus.emit("timeChanged",{currentTime:e});const s=this.getBarFromTime(e);s&&this.eventBus.emit("barChanged",s)}setupPlaybackManagerEventDelegation(){this.playbackManager.on("timeupdate",({audioTime:e,leadInProgress:s})=>{this.currentTime=e,this.eventBus.emit("timeChanged",{currentTime:e,leadInProgress:s})}),this.playbackManager.on("beatAudible",({bar:e,beat:s,isLeadIn:n,repeat:i,time:r})=>{this.eventBus.emit("barChanged",{bar:e,beat:s,repeat:i,time:r,isLeadIn:n})}),this.playbackManager.on("leadInStarted",({totalBeats:e,duration:s,bars:n})=>{this.eventBus.emit("leadInStarted",{bars:n,totalBeats:e,duration:s})}),this.playbackManager.on("leadInEnded",()=>{this.eventBus.emit("leadInCompleted")}),this.playbackManager.on("playbackStarted",()=>{this.isPlaying=!0,this.eventBus.emit("playbackStateChanged",{isPlaying:!0,currentTime:this.currentTime})}),this.playbackManager.on("playbackPaused",()=>{this.isPlaying=!1,this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime})}),this.playbackManager.on("playbackStopped",()=>{this.isPlaying=!1,this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime})}),this.playbackManager.on("playbackEnded",()=>{this.isPlaying=!1,this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime}),this.eventBus.emit("songEnded",{finalTime:this.currentTime})})}setupLegacyParts(e){e&&e.forEach(s=>{const n=this.sanitizePartName(s.name);this.parts.set(n,{name:s.name,sanitizedName:n,volume:s.volume||.75,muted:!1,solo:!1})})}getCurrentToggleStates(){const e=this.getLeadInSettings();return{metronome:this.metronomeEnabled||!1,leadIn:this.leadInEnabled!==!1,leadInBars:e.bars}}updateToggleStates(e,s){this.setMetronomeEnabled(e),this.leadInEnabled=s}setMetronomeEnabled(e){this.metronomeEnabled=e,this.playbackManager.setMetronomeEnabled(e)}setLeadInBars(e){this.playbackManager.setLeadInBars(e)}setLeadInEnabled(e){this.leadInEnabled=e,this.playbackManager.setLeadInEnabled(e)}getLeadInSettings(){return this.playbackManager.getLeadInSettings()}async play(e={}){if(this.audioContext&&this.audioContext.state==="suspended")try{await this.audioContext.resume()}catch(n){console.warn("Failed to resume AudioContext before play:",n)}const s=this.getCurrentToggleStates();e.leadInBars!==void 0&&this.setLeadInBars(e.leadInBars),this.playbackManager.play({leadIn:e.leadIn!==void 0?e.leadIn:s.leadIn,metronome:e.metronome!==void 0?e.metronome:s.metronome})}stop(){this.playbackManager.pause()}pause(){this.stop()}setTime(e){const s=this.snapTimeToBarStart(e);this.currentTime=Math.max(0,s),this.playbackManager.skipToTime(this.currentTime),this.emitTimeAndBarUpdates(this.currentTime)}getCurrentTime(){return this.playbackManager.getCurrentTime()}setBar(e,s=0){const n=Math.max(0,Math.min(this.maxBar,e));this.playbackManager.setBar(n,s);const i=this.getCurrentTime();this.currentTime=i,this.emitTimeAndBarUpdates(i)}goToPracticeMark(e){const s=this.practiceMarks[e];s!==void 0&&(this.setBar(s),this.eventBus.emit("practiceMarkChanged",{mark:e,bar:s}))}setPlaybackSpeed(e){this.playbackSpeed=Math.max(.25,Math.min(2,e)),this.playbackManager.setPlaybackSpeed(e,!1),this.eventBus.emit("speedChanged",{speed:this.playbackSpeed})}setMasterVolume(e){this.masterVolume=Math.max(0,Math.min(1,e)),this.masterGain&&(this.masterGain.gain.value=this.masterVolume),this.eventBus.emit("masterVolumeChanged",{volume:this.masterVolume})}getMasterVolume(){return this.masterVolume}setMetronomeVolume(e){const s=Math.max(0,Math.min(1,e));this.metronomeGain&&(this.metronomeGain.gain.value=s),this.metronomeVolume=s}getMetronomeVolume(){return this.metronomeVolume||.7}setPartVolume(e,s){const n=this.sanitizePartName(e),i=this.parts.get(n);i?(i.volume=Math.max(0,Math.min(1,s)),this.updatePartAudioState(n),this.eventBus.emit("partVolumeChanged",{partName:e,volume:s})):(console.log(`Part not found: "${e}" (sanitized: "${n}")`),console.log("Available parts:",[...this.parts.keys()]))}setPartMuted(e,s){const n=this.sanitizePartName(e),i=this.parts.get(n);i&&(i.muted=s,this.updatePartAudioState(n),this.eventBus.emit("partMutedChanged",{partName:e,muted:s}))}setPartSolo(e,s){const n=this.sanitizePartName(e),i=this.parts.get(n);i&&(i.solo=s,this.updateAllPartsAudioState(),this.eventBus.emit("partSoloChanged",{partName:e,solo:s}))}isPartEffectivelyMuted(e){const s=this.sanitizePartName(e),n=this.parts.get(s);return!n||n.muted?!0:Array.from(this.parts.values()).some(r=>r.solo)&&!n.solo}updatePartAudioState(e){const s=this.parts.get(e),n=this.partGainNodes.get(e);if(s&&n){const i=this.isPartEffectivelyMuted(s.name);n.gain.value=i?0:s.volume}}updateAllPartsAudioState(){for(const[e]of this.parts)this.updatePartAudioState(e)}getParts(){return Array.from(this.parts.values())}getPartLevel(e){const s=this.sanitizePartName(e),n=this.partAnalyserNodes.get(s);if(!n)return 0;try{const i=n.frequencyBinCount,r=new Uint8Array(i);n.getByteFrequencyData(r);let o=0;for(let v=0;v<i;v++){const c=r[v]/255;o+=c*c}const h=Math.sqrt(o/i);return Math.min(1,Math.pow(h*2,.7))}catch(i){return console.warn(`Failed to get level for part ${e}:`,i),0}}playLeadIn(e=1){this.setLeadInBars(e),this.playbackManager.play({leadIn:!0,metronome:!0})}playStartingNotes(){console.log(this.parts);const e=[...this.parts.values()],s=e.some(i=>i.solo),n=e.filter(i=>s?i.solo:!i.muted).map(i=>i.name);console.log(e,s,n),this.playbackManager.previewNextNotes({instrument:"piano",delayBetweenParts:.4,duration:.6,velocity:110,partOrder:n})}on(e,s){this.eventBus.on(e,s)}off(e,s){this.eventBus.off(e,s)}getBarFromTime(e){const s=this.playbackManager.midiPlayer.getBeatFromTime(e);return s?{bar:s.bar,beat:s.beat,repeat:s.repeat||0,time:s.time||e}:null}getTimeFromBar(e,s=0){return this.playbackManager.midiPlayer.getTimeFromBar(e,s)}allSoundsOff(){this.playbackManager&&this.playbackManager.allSoundsOff()}cleanup(){if(this.playbackManager)try{this.playbackManager.pause()}catch{}if(this.playbackManager&&this.metronomeGain)try{const e=this.playbackManager.getMetronomeOutput();e&&e.disconnect(this.metronomeGain)}catch{}if(this.partGainNodes.forEach(e=>{try{e.disconnect()}catch{}}),this.partAnalyserNodes.forEach(e=>{try{e.disconnect()}catch{}}),this.playbackManager){try{this.playbackManager.destroy()}catch{}this.playbackManager=null}this.parts.clear(),this.partGainNodes.clear(),this.partAnalyserNodes.clear(),this.beats=[],this.practiceMarks={},this.songDuration=0,this.maxBar=0}destroy(){this.cleanup(),this.audioEngine&&this.audioEngine.destroy(),this.audioContext&&this.audioContext.state!=="closed"&&this.audioContext.close(),this.eventBus.all.clear()}}const m=new ct;function W(a={}){const e=F(),s=U(),n=se(),i={soundfontUrl:a.soundfontUrl},r=({currentTime:l})=>{e.setCurrentTime(l)},o=({isPlaying:l})=>{e.setPlaybackState(l),n.setTransportState(l?"playing":"stopped"),!l&&e.isLeadInActive&&(e.setLeadInActive(!1),m.emitTimeAndBarUpdates(e.currentTime))},h=l=>{l&&(e.isLeadInActive?l.isLeadIn&&l.beat!==void 0&&e.setCurrentBar(null,l.beat,null):(e.setCurrentBar(l.bar,l.beat,l.repeat),n.updateLastBarPosition(l.bar)))},v=({speed:l})=>{e.setPlaybackSpeed(l)},c=({volume:l})=>{e.setMasterVolume(l)},g=({partName:l,volume:k})=>{e.setPartVolume(l,k)},B=({partName:l,muted:k})=>{e.setPartMuted(l,k)},C=({partName:l,solo:k})=>{e.setPartSolo(l,k)},N=({bars:l})=>{e.setLeadInActive(!0,l)},f=()=>{e.setLeadInActive(!1)},S=()=>{e.setStartingNotesActive(!0)},M=()=>{e.setStartingNotesActive(!1)},w=({mark:l})=>{n.updateLastPracticeMarkUsed(l)},T=({parts:l})=>{e.initializeParts(l),s.setParts(l)},V=({finalTime:l})=>{e.setPlaybackState(!1),n.setTransportState("stopped"),n.setNavigationAction("ended"),console.log(`Song ended at time: ${l}`)},D=({duration:l})=>{console.log("Updating total duration in store to:",l),s.setTotalDuration(l)},I=({beats:l,practiceMarks:k,maxBar:$})=>{console.log(`Updating music data store with ${l.length} beats and ${Object.keys(k).length} practice marks`),s.updateBeats(l),s.practiceMarks=k,s.maxBar=$},A=()=>{m.on("timeChanged",r),m.on("playbackStateChanged",o),m.on("barChanged",h),m.on("speedChanged",v),m.on("masterVolumeChanged",c),m.on("partVolumeChanged",g),m.on("partMutedChanged",B),m.on("partSoloChanged",C),m.on("leadInStarted",N),m.on("leadInCompleted",f),m.on("startingNotesStarted",S),m.on("startingNotesCompleted",M),m.on("practiceMarkChanged",w),m.on("initialized",T),m.on("songEnded",V),m.on("durationUpdated",D),m.on("musicDataExtracted",I)},z=()=>{m.off("timeChanged",r),m.off("playbackStateChanged",o),m.off("barChanged",h),m.off("speedChanged",v),m.off("masterVolumeChanged",c),m.off("partVolumeChanged",g),m.off("partMutedChanged",B),m.off("partSoloChanged",C),m.off("leadInStarted",N),m.off("leadInCompleted",f),m.off("startingNotesStarted",S),m.off("startingNotesCompleted",M),m.off("practiceMarkChanged",w),m.off("initialized",T),m.off("songEnded",V),m.off("durationUpdated",D),m.off("musicDataExtracted",I)};(()=>{t.watchEffect(()=>{const l=e.masterVolume;try{m.getMasterVolume()!==l&&m.setMasterVolume(l)}catch(k){console.warn("Master volume sync skipped during initialization:",k.message)}}),t.watchEffect(()=>{const l=e.metronomeVolume;try{m.getMetronomeVolume()!==l&&m.setMetronomeVolume(l)}catch(k){console.warn("Metronome volume sync skipped during initialization:",k.message)}})})();const p=async l=>{try{if(e.setLoaded(!1),A(),s.loadMusicData(l),await m.initialize(l,i),n.buildFixedNavigationPoints(),!l.midiData&&l.beats&&l.beats.length>0){const k=l.beats[0];e.setCurrentBar(k.bar,k.beat,k.repeat),m.setTime(k.time)}m.updateToggleStates(e.metronomeEnabled,e.leadInEnabled),e.setLoaded(!0)}catch(k){throw console.error("Failed to initialize audio engine:",k),e.setLoaded(!1),k}},b=()=>{const l=e.currentBar,k=e.currentRepeat,$=e.currentTime;n.setLastPlayStart(l,k,$),n.setNavigationAction("play"),m.play()},x=()=>{n.setNavigationAction("pause"),m.stop()},Q=()=>{n.setNavigationAction("pause"),m.pause()},K=l=>{n.setNavigationAction("manual"),m.setTime(l)},R=(l,k=0)=>{n.setNavigationAction("manual"),m.setBar(l,k)},q=l=>{if(s.isCustomMark(l)){const k=s.customPracticeMarks[l];k!==void 0&&m.setBar(k)}else m.goToPracticeMark(l)},H=l=>{m.setPlaybackSpeed(l)},ne=l=>{m.setMasterVolume(l)},ie=(l,k)=>{m.setPartVolume(l,k)},he=(l,k)=>{m.setPartMuted(l,k)},re=(l,k)=>{m.setPartSolo(l,k)},oe=(l=1)=>{m.playLeadIn(l)},fe=()=>{m.playStartingNotes()},d=(l,k=!0,$=0)=>{k&&n.leadInEnabled?(R(l,$),oe(n.leadInBars)):(R(l,$),b())},y=(l,k=!0)=>{const $=s.getBarForMark(l);$&&d($,k)},E=()=>{const l=!e.metronomeEnabled;return e.setMetronomeEnabled(l),m.setMetronomeEnabled(l),l},_=()=>{const l=!e.leadInEnabled;return e.setLeadInEnabled(l),m.updateToggleStates(e.metronomeEnabled,l),l},Z=()=>{m.stop(),e.setLoaded(!1),s.clear(),console.log("Audio mixer reset - ready for new score")};return t.onUnmounted(()=>{z()}),{initialize:p,reset:Z,play:b,stop:x,pause:Q,setTime:K,setBar:R,goToPracticeMark:q,setPlaybackSpeed:H,setMasterVolume:ne,setPartVolume:ie,setPartMuted:he,setPartSolo:re,getPartLevel:l=>m.getPartLevel(l),playLeadIn:oe,playStartingNotes:fe,toggleMetronome:E,toggleLeadIn:_,setMetronomeEnabled:l=>{e.setMetronomeEnabled(l),m.setMetronomeEnabled(l)},playFromBar:d,playFromMark:y,audioState:e,musicData:s,playbackState:n,audioEngine:m}}const dt=["aria-label"],Pe=L({__name:"PartControl",props:t.mergeModels({name:{type:String,required:!0},level:{type:Number,default:0,validator:a=>a>=0&&a<=1}},{volume:{default:.75},volumeModifiers:{},mute:{default:!1},muteModifiers:{},solo:{default:!1},soloModifiers:{}}),emits:["update:volume","update:mute","update:solo"],setup(a){t.useCssVars(f=>({"03f87250":c.value}));const e=a;F();const s=W(),n=t.useModel(a,"volume"),i=t.useModel(a,"mute"),r=t.useModel(a,"solo");t.watch(n,f=>{s.setPartVolume(e.name,f)}),t.watch(i,f=>{s.setPartMuted(e.name,f),f&&(r.value=!1)}),t.watch(r,f=>{s.setPartSolo(e.name,f),f&&(i.value=!1)});const o=t.useTemplateRef("el"),{width:h,height:v}=O(o),c=t.computed(()=>Math.min(h.value,v.value)+"px"),g=t.computed(()=>h.value>v.value?"mobile":h.value<60?"tablet":"desktop");let B=null;const C=t.ref(0);t.onMounted(()=>{B=setInterval(()=>{if(i.value)C.value=0;else try{C.value=s.getPartLevel(e.name)}catch{ue("randomLevelIndicators")?C.value=Math.random()*n.value:C.value=0}},16)}),t.onUnmounted(()=>{B&&(clearInterval(B),B=null)});const N=f=>{if(["ArrowUp","ArrowRight","ArrowDown","ArrowLeft"].includes(f.key)){f.preventDefault(),f.stopPropagation();const S=f.key==="ArrowUp"||f.key==="ArrowRight"?.1:-.1;n.value=Math.max(0,Math.min(1,n.value+S))}else f.key==="m"&&!f.shiftKey?(f.preventDefault(),f.stopPropagation(),i.value=!i.value):f.key==="s"&&!f.shiftKey&&(f.preventDefault(),f.stopPropagation(),r.value=!r.value)};return(f,S)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"el",ref:o,class:t.normalizeClass([g.value,"part"]),tabindex:"0",role:"group","aria-label":`${a.name} part controls`,onKeydown:N},[S[3]||(S[3]=t.createElementVNode("div",{class:"focus"},null,-1)),t.createVNode(Me,{class:"tri",mute:i.value,"onUpdate:mute":S[0]||(S[0]=M=>i.value=M),solo:r.value,"onUpdate:solo":S[1]||(S[1]=M=>r.value=M),tabindex:"-1"},null,8,["mute","solo"]),t.createVNode(de,{align:"left",class:"name"},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(a.name),1)]),_:1}),t.createVNode(Y,{level:C.value,"show-level":!0,class:"vol",value:n.value,"onUpdate:value":S[2]||(S[2]=M=>n.value=M),step:.01,tabindex:"-1"},null,8,["level","value"])],42,dt))}},[["__scopeId","data-v-67bb489c"]]),ut={class:"mark"},mt={class:"rpt"},ht={class:"beat-ind"},ft={class:"beat"},pt={key:1,class:"mark-grid-container"},gt={class:"mark-grid"},bt=["onClick"],Ce=L({__name:"BarInput",setup(a){t.useCssVars(d=>({aa78c0c8:D.value,"286643ea":I.value}));const e=t.useTemplateRef("el"),s=t.useTemplateRef("rpt"),{width:n,height:i}=O(e),r=U(),o=F(),h=se(),v=W(),c=t.ref("1"),g=t.ref("A"),B=t.ref(0),C=t.ref(2),N=t.ref(!1),f=t.ref(!1),S=t.ref(!1),M=t.ref(!1),w=t.ref(new Set),T=t.ref(!0);let V=null;t.watch(()=>{var d;return((d=r.beats)==null?void 0:d.length)>0},d=>{console.log(d),d&&!N.value&&(c.value=o.currentBar.toString(),B.value=o.currentRepeat,C.value=r.getRepeatCountForBar(o.currentBar),b(o.currentBar),N.value=!0)}),t.watch(()=>o.currentBar,d=>{C.value=r.getRepeatCountForBar(d)}),t.watch(c,()=>{c.value=c.value.replace(/\D/g,""),c.value.length>3&&(c.value=c.value.slice(0,3))}),t.watch(()=>o.currentBar,d=>{c.value=d.toString(),b(d)}),t.watch(()=>o.currentBeat,()=>{T.value=!0,setTimeout(()=>{T.value=!1},50)}),t.watch(f,()=>{f.value&&oe()});const D=t.computed(()=>Math.min(i.value/2.25,n.value/4.5)+"px"),I=t.computed(()=>Math.min(n.value/15,i.value/6.4)+"px"),A=t.computed(()=>r.allPracticeMarksSorted),z=t.computed(()=>!r.barHasMark(o.currentBar)&&r.nextAvailableLetter!==null),u=t.computed(()=>!0),p=t.computed(()=>Object.keys(r.customPracticeMarks).length>0);function b(d){const y=r.allPracticeMarks,E=Object.keys(y).filter(_=>y[_]<=d).sort((_,Z)=>y[Z]-y[_]);E.length>0?g.value=E[0]:g.value=""}function x(){var y;const d=parseInt(c.value);if(~isNaN(d)){Q(d);const E=(y=e.value)==null?void 0:y.querySelector(".bar-input");E&&E.blur(),e.value&&e.value.focus()}}function Q(d){v.setBar(d,0)}function K(d,y){if(y&&y.stopPropagation(),M.value){r.isCustomMark(d)&&H(d);return}g.value=d,f.value=!1,v.goToPracticeMark(d),e.value&&e.value.blur()}function R(d){d&&d.stopPropagation();const y=r.addCustomMark(o.currentBar);y&&(g.value=y,f.value=!1,h.buildFixedNavigationPoints())}function q(d){if(d&&d.stopPropagation(),M.value){const y=w.value.size>0;w.value.forEach(E=>{r.removeCustomMark(E)}),w.value=new Set,M.value=!1,b(o.currentBar),y&&h.buildFixedNavigationPoints()}else M.value=!0,w.value=new Set}function H(d,y){const E=new Set(w.value);E.has(d)?E.delete(d):E.add(d),w.value=E}function ne(){C.value>1&&(S.value=!0),o.currentRepeat<C.value&&v.setBar(o.currentBar,o.currentRepeat+1)}function ie(){C.value>1&&(S.value=!0),o.currentRepeat>1&&v.setBar(o.currentBar,o.currentRepeat-1)}function he(d){d.stopPropagation(),S.value=!1,f.value=!f.value,!f.value&&M.value&&(M.value=!1,w.value=new Set)}function re(d){var y,E;(y=e.value)!=null&&y.contains(d.target)||(f.value=!1,M.value&&(M.value=!1,w.value=new Set)),(E=s.value)!=null&&E.contains(d.target)||(S.value=!1)}function oe(){f.value&&setTimeout(()=>{var E,_;const d=(E=e.value)==null?void 0:E.querySelector(".mark-grid"),y=(_=e.value)==null?void 0:_.querySelector(".mark-option.selected");if(y&&d){const Z=d.getBoundingClientRect(),l=y.getBoundingClientRect(),k=l.left-Z.left-Z.width/2+l.width/2;d.scrollLeft=Math.max(0,d.scrollLeft+k)}},50)}t.onMounted(()=>{document.addEventListener("click",re),ue("beatAnimation")&&(V=setInterval(()=>{const d=o.currentBeat%r.timeSignature+1;o.setCurrentBar(o.currentBar,d,o.currentRepeat)},800))}),t.onUnmounted(()=>{document.removeEventListener("click",re),V&&(clearInterval(V),V=null)});const fe=d=>{var E;const y=(E=e.value)==null?void 0:E.querySelector(".bar-input");if(document.activeElement!==y)if(/^[a-z]$/.test(d.key)&&!d.ctrlKey&&!d.metaKey&&!d.shiftKey){d.preventDefault(),d.stopPropagation();const _=d.key.toUpperCase();A.value.includes(_)&&K(_,null)}else d.key==="ArrowUp"?(d.preventDefault(),d.stopPropagation(),ne()):d.key==="ArrowDown"?(d.preventDefault(),d.stopPropagation(),ie()):d.key==="Enter"?(d.preventDefault(),d.stopPropagation(),x()):d.key==="+"&&(d.preventDefault(),d.stopPropagation(),z.value&&R(null))};return(d,y)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"el",ref:e,class:t.normalizeClass(["outer",{pulse:T.value,"mark-selecting":f.value}]),tabindex:"0",role:"group","aria-label":"Musical navigation",onKeydown:fe},[y[9]||(y[9]=t.createElementVNode("div",{class:"frame"},null,-1)),t.createElementVNode("div",{class:t.normalizeClass(["mark-input",{empty:!g.value,edit:f.value,disabled:!u.value}]),tabindex:"-1",onClick:he},[t.createElementVNode("div",ut,t.toDisplayString(g.value||"-"),1)],2),y[10]||(y[10]=t.createElementVNode("div",{class:"mark-title"},"Mark",-1)),f.value?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.withDirectives(t.createElementVNode("input",{type:"text",class:"bar-input","onUpdate:modelValue":y[0]||(y[0]=E=>c.value=E),inputmode:"decimal",pattern:"\\d*",tabindex:"-1",onChange:x,onKeyup:t.withKeys(x,["enter"])},null,544),[[t.vModelText,c.value]]),y[5]||(y[5]=t.createElementVNode("div",{class:"bar-title"},"Bar",-1)),t.createElementVNode("div",{ref_key:"rpt",ref:s,class:t.normalizeClass(["rpt-input",{edit:S.value,available:C.value>1}])},[t.createElementVNode("div",mt,t.toDisplayString(t.unref(o).currentRepeat||"-"),1),(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["inc",{disabled:t.unref(o).currentRepeat>=C.value}]),viewBox:"0 -100 100 100",onClick:t.withModifiers(ne,["prevent"])},y[3]||(y[3]=[t.createElementVNode("path",{d:"m10-20 40-60 40 60H10Z"},null,-1)]),2)),(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["dec",{disabled:t.unref(o).currentRepeat<=1}]),viewBox:"0 -100 100 100",onClick:t.withModifiers(ie,["prevent"])},y[4]||(y[4]=[t.createElementVNode("path",{d:"m10-80 40 60 40-60H10Z"},null,-1)]),2))],2),y[6]||(y[6]=t.createElementVNode("div",{class:"rpt-title"},"Rpt",-1)),t.createElementVNode("div",ht,[t.createElementVNode("div",ft,t.toDisplayString(t.unref(o).currentBeat),1)]),y[7]||(y[7]=t.createElementVNode("div",{class:"beat-title"},"Beat",-1))],64)),f.value?(t.openBlock(),t.createElementBlock("div",pt,[t.createElementVNode("div",gt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(A.value,E=>(t.openBlock(),t.createElementBlock("div",{key:E,class:t.normalizeClass(["mark-option",{selected:!M.value&&E===g.value,deleting:M.value&&w.value.has(E),custom:t.unref(r).isCustomMark(E),greyed:M.value&&!t.unref(r).isCustomMark(E)}]),onClick:_=>K(E,_)},t.toDisplayString(E),11,bt))),128)),z.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["mark-option add-mark",{greyed:M.value}]),onClick:y[1]||(y[1]=E=>!M.value&&R(E))}," + ",2)):t.createCommentVNode("",!0),p.value?(t.openBlock(),t.createElementBlock("div",{key:1,class:t.normalizeClass(["mark-option trash-icon",{active:M.value}]),onClick:y[2]||(y[2]=E=>q(E))},y[8]||(y[8]=[t.createElementVNode("svg",{viewBox:"0 -960 960 960",fill:"currentColor"},[t.createElementVNode("path",{transform:"rotate(135)",d:"M -831.95532 179.98077 L -751.96387 179.98077 L -751.96387 39.995727 L -611.97882 39.995727 L -611.97882 -39.995727 L -751.96387 -39.995727 L -751.96387 -179.98077 L -831.95532 -179.98077 L -831.95532 -39.995727 L -971.94037 -39.995727 L -971.94037 39.995727 L -831.95532 39.995727 L -831.95532 179.98077 z "}),t.createElementVNode("path",{d:"M 280 -840 L 280 -680 L 120 -680 L 120 -120 L 680 -120 L 680 -280 L 840 -280 L 840 -840 L 280 -840 z M 360 -760 L 760 -760 L 760 -360 L 360 -360 L 360 -760 z M 200 -600 L 280 -600 L 280 -280 L 600 -280 L 600 -200 L 200 -200 L 200 -600 z "})],-1)]),2)):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)],34))}},[["__scopeId","data-v-e542aa14"]]),vt={class:"frame"},yt={class:"title"},me=L({__name:"BaseNumericInput",props:t.mergeModels({title:{type:String,required:!0},color:{type:String,default:"#336"},focusColor:{type:String,default:"#558"},textColor:{type:String,default:"#aad"},backgroundColor:{type:String,default:"#111117"},sliderMax:{type:Number,default:1},sliderMin:{type:Number,default:0},thumbLength:{type:Number,default:2},formatValue:{type:Function,default:a=>a.toString()},parseValue:{type:Function,default:a=>parseFloat(a)},validateInput:{type:Function,default:a=>a.replace(/[^0-9.]/g,"")},transformSliderToDisplay:{type:Function,default:a=>a},transformDisplayToSlider:{type:Function,default:a=>a},maxChars:{type:Number,default:null}},{value:{default:.5},valueModifiers:{}}),emits:["update:value"],setup(a){t.useCssVars(g=>({"391e6684":a.textColor,"6eae8f5d":a.backgroundColor,"6ee151eb":a.color,"29a40ccc":v.value,"7366daab":h.value,"0f87383a":a.focusColor}));const e=a,s=t.useTemplateRef("el"),{width:n,height:i}=O(s),r=t.useModel(a,"value"),o=t.ref(e.formatValue(e.transformSliderToDisplay(r.value)));t.watch(r,()=>{const g=e.transformSliderToDisplay(r.value);o.value=e.formatValue(g)}),t.watch(o,()=>{o.value=e.validateInput(o.value),e.maxChars&&o.value.length>e.maxChars&&(o.value=o.value.slice(0,e.maxChars))});const h=t.computed(()=>Math.min(i.value/2.25,n.value/2.2)+"px"),v=t.computed(()=>Math.min(n.value/3,i.value/6.4)+"px");function c(){const g=e.parseValue(o.value),B=e.transformDisplayToSlider(g);r.value=Math.min(Math.max(B,e.sliderMin),e.sliderMax)}return(g,B)=>(t.openBlock(),t.createElementBlock("div",{class:"outer",ref_key:"el",ref:s},[t.createElementVNode("div",vt,[t.withDirectives(t.createElementVNode("input",{type:"text",class:"input","onUpdate:modelValue":B[0]||(B[0]=C=>o.value=C),inputmode:"decimal",pattern:"\\d*",onChange:c},null,544),[[t.vModelText,o.value]]),t.createElementVNode("div",yt,t.toDisplayString(a.title),1)]),t.createVNode(Y,{class:"slider",value:r.value,"onUpdate:value":B[1]||(B[1]=C=>r.value=C),"thumb-length":a.thumbLength,max:a.sliderMax,min:a.sliderMin,tabindex:"-1"},null,8,["value","thumb-length","max","min"])],512))}},[["__scopeId","data-v-3c97bdb4"]]),we={__name:"SpeedInput",setup(a){const e=F(),s=W(),n=t.computed({get:()=>Math.log2(e.playbackSpeed)*.5+.5,set:c=>{const g=Math.floor(Math.pow(2,c*2-1)*20+.5)*.05;s.setPlaybackSpeed(g)}}),i=c=>Math.floor(Math.pow(2,c*2-1)*20+.5)*5+"",r=c=>parseFloat(c),o=c=>c.replace(/\D/g,""),h=c=>c,v=c=>{const g=Math.log2(c/100)*.5+.5;return Math.min(Math.max(g,0),1)};return(c,g)=>(t.openBlock(),t.createBlock(me,{value:n.value,"onUpdate:value":g[0]||(g[0]=B=>n.value=B),title:"Speed",color:"#336","text-color":"#aad","format-value":i,"parse-value":r,"validate-input":o,"transform-slider-to-display":h,"transform-display-to-slider":v,"thumb-length":2,"max-chars":3},null,8,["value"]))}},xe={__name:"TimeInput",setup(a){const e=F(),s=U(),n=W(),i=c=>c.toFixed(1),r=c=>parseFloat(c),o=c=>c.replace(/[^0-9.]/g,""),h=c=>c,v=c=>c;return(c,g)=>(t.openBlock(),t.createBlock(me,{value:t.unref(e).currentTime,"onUpdate:value":[g[0]||(g[0]=B=>t.unref(e).currentTime=B),t.unref(n).setTime],title:"Time",color:"#344","focus-color":"#556868","text-color":"#acc","background-color":"#111117","slider-max":t.unref(s).totalDuration,"slider-min":0,"format-value":i,"parse-value":r,"validate-input":o,"transform-slider-to-display":h,"transform-display-to-slider":v,"thumb-length":2},null,8,["value","onUpdate:value","slider-max"]))}},kt=["title"],Mt={class:"inner"},G=L({__name:"AudioButton",props:{disabled:{type:Boolean,default:!1},title:{type:String,default:""}},setup(a){const e=a,s=t.ref(!1),n=()=>{e.disabled||(s.value=!0)},i=()=>s.value=!1;return(r,o)=>(t.openBlock(),t.createElementBlock("div",{title:a.title,class:t.normalizeClass(["button-outer",{down:s.value,disabled:a.disabled}]),onPointerdown:n,onPointerup:i,onPointerleave:i},[t.createElementVNode("div",Mt,[t.renderSlot(r.$slots,"default",{},void 0,!0)])],42,kt))}},[["__scopeId","data-v-77d8694a"]]),St={class:"outer"},Et={class:"title"},Bt={class:"buttons",role:"toolbar","aria-label":"Transport controls"},Pt={class:"icon",viewBox:"0 0 48 48"},Ct=["d"],Te=L({__name:"MixerControls",props:{externalMenuControl:{type:Boolean,default:!1}},emits:["menu-click"],setup(a,{emit:e}){const s=a,n=e,i=U(),r=F(),o=se(),h=W();function v(){r.isPlayingOrLeadIn?h.stop():h.play()}function c(){const u=o.navigationPoints;if((o.lastNavigationAction==="pause"||o.lastNavigationAction==="ended")&&o.lastPlayStartTime!==null){h.setTime(o.lastPlayStartTime),o.setNavigationAction(null);return}const p=r.currentTime,b=u.filter(x=>x.time<p-.01).pop();b&&h.setTime(b.time)}function g(){const u=o.navigationPoints,p=r.currentTime,b=u.find(x=>x.time>p+.01);b&&h.setTime(b.time)}function B(){h.playStartingNotes()}const C=t.computed(()=>r.metronomeEnabled),N=t.computed(()=>r.leadInEnabled),f=t.ref(!1),S=t.ref(null);function M(){if(s.externalMenuControl){n("menu-click"),h.audioEngine.initializeAudioSystem().catch(u=>{console.warn("Audio system pre-initialization failed:",u)});return}f.value=!f.value,f.value&&(h.audioEngine.initializeAudioSystem().catch(u=>{console.warn("Audio system pre-initialization failed:",u)}),setTimeout(()=>{var p;const u=(p=S.value)==null?void 0:p.querySelector('button, a, [tabindex="0"]');u&&u.focus()},0))}function w(){f.value=!1}function T(u){S.value&&!S.value.contains(u.target)&&w()}t.onMounted(()=>{document.addEventListener("click",T),document.addEventListener("keydown",z)}),t.onUnmounted(()=>{document.removeEventListener("click",T),document.removeEventListener("keydown",z)});function V(){h.toggleMetronome()}function D(){h.toggleLeadIn()}const I=t.computed({get:()=>r.masterVolume,set:u=>r.setMasterVolume(u)}),A=t.computed({get:()=>r.metronomeVolume,set:u=>r.setMetronomeVolume(u)}),z=u=>{const p=u.target;if(!(p.matches('input[type="text"]')&&(p.closest(".time")||p.closest(".speed")))){if(u.key==="Escape")u.preventDefault(),M();else if(u.key==="B"&&u.shiftKey){u.preventDefault();const b=document.querySelector(".bar");b&&b.focus()}else if(u.key==="T"&&u.shiftKey){u.preventDefault();const b=document.querySelector(".time input");b&&b.focus()}else if(u.key==="S"&&u.shiftKey){u.preventDefault();const b=document.querySelector(".speed input");b&&b.focus()}else if(u.key===" ")u.preventDefault(),v();else if(u.key==="PageUp")u.preventDefault(),g();else if(u.key==="PageDown")u.preventDefault(),c();else if(u.key==="M"&&u.shiftKey)u.preventDefault(),V();else if(u.key==="L"&&u.shiftKey)u.preventDefault(),D();else if(u.key==="N"&&u.shiftKey)u.preventDefault(),r.isPlayingOrLeadIn||B();else if(/^[0-9]$/.test(u.key)&&!u.ctrlKey&&!u.metaKey&&!u.shiftKey){const b=document.querySelector(".bar .bar-input");if(document.activeElement===b)return;u.preventDefault(),b&&(b.value=u.key,b.focus(),b.setSelectionRange(1,1),b.dispatchEvent(new Event("input",{bubbles:!0})))}else if(/^[a-z]$/.test(u.key)&&!u.ctrlKey&&!u.metaKey&&!u.shiftKey){u.preventDefault();const b=document.querySelector(".bar");if(b){b.focus();const x=new KeyboardEvent("keydown",{key:u.key,code:u.code,bubbles:!0,cancelable:!0});b.dispatchEvent(x)}}else if(u.key==="+"){u.preventDefault();const b=document.querySelector(".bar");if(b){b.focus();const x=new KeyboardEvent("keydown",{key:"+",code:"Equal",shiftKey:!0,bubbles:!0,cancelable:!0});b.dispatchEvent(x)}}}};return(u,p)=>(t.openBlock(),t.createElementBlock("div",St,[t.createElementVNode("div",Et,[t.createVNode(de,{class:"text",align:"centre",overflow:"scroll"},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(t.unref(i).title),1)]),_:1}),t.createElementVNode("div",{class:"menu-container",ref_key:"menuRef",ref:S},[(t.openBlock(),t.createElementBlock("svg",{class:"menu",viewBox:"0 -960 960 960",onClick:M},p[2]||(p[2]=[t.createElementVNode("path",{d:"M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z"},null,-1)]))),!a.externalMenuControl&&f.value&&u.$slots.menu?(t.openBlock(),t.createElementBlock("div",{key:0,class:"dropdown-menu",onClick:w},[t.renderSlot(u.$slots,"menu",{},void 0,!0)])):t.createCommentVNode("",!0)],512)]),t.createVNode(Y,{class:"main",colour:"red",step:.01,keystep:.1,value:I.value,"onUpdate:value":p[0]||(p[0]=b=>I.value=b)},null,8,["value"]),p[8]||(p[8]=t.createElementVNode("div",{class:"main-t"},"Main",-1)),p[9]||(p[9]=t.createElementVNode("div",{class:"main-focus"},null,-1)),t.createVNode(Y,{class:"tick",colour:"blue",step:.01,keystep:.1,value:A.value,"onUpdate:value":p[1]||(p[1]=b=>A.value=b)},null,8,["value"]),p[10]||(p[10]=t.createElementVNode("div",{class:"tick-t"},"Tick",-1)),p[11]||(p[11]=t.createElementVNode("div",{class:"tick-focus"},null,-1)),t.createVNode(Ce,{class:"bar"}),t.createVNode(xe,{class:"time"}),t.createVNode(we,{class:"speed"}),t.createElementVNode("div",Bt,[t.createVNode(G,{title:"Previous Mark",class:"button",tabindex:"-1",onClick:c},{default:t.withCtx(()=>p[3]||(p[3]=[t.createElementVNode("svg",{class:"icon",viewBox:"0 0 48 48"},[t.createElementVNode("path",{d:"M11 36V12h3v24Zm26 0L19.7 24 37 12Z"})],-1)])),_:1,__:[3]}),t.createVNode(G,{title:t.unref(r).isPlayingOrLeadIn?"Pause":"Play",class:"button",tabindex:"-1",onClick:v},{default:t.withCtx(()=>[(t.openBlock(),t.createElementBlock("svg",Pt,[t.createElementVNode("path",{d:t.unref(r).isPlayingOrLeadIn?"M27.4 35.4V12.6h8v22.8Zm-14.8 0V12.6h8.05v22.8Z":"M16 37.85v-28l22 14Z"},null,8,Ct)]))]),_:1},8,["title"]),t.createVNode(G,{title:"Next Mark",class:"button",tabindex:"-1",onClick:g},{default:t.withCtx(()=>p[4]||(p[4]=[t.createElementVNode("svg",{class:"icon",viewBox:"0 0 48 48"},[t.createElementVNode("path",{d:"M34 36V12h3v24Zm-23 0V12l17.3 12Z"})],-1)])),_:1,__:[4]}),t.createVNode(G,{title:"Toggle Metronome",class:"button",tabindex:"-1",onClick:V},{default:t.withCtx(()=>[(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["icon",C.value?"on":"off"]),viewBox:"-128 -128 768 768"},p[5]||(p[5]=[t.createElementVNode("path",{d:"m 463.84136,154.89339 c -6.42,-6.42 -16.83,-6.42 -23.251,0 -71.31197,70.35135 -136.61146,132.25426 -208.741,199.7 h -105.82 c 23.35495,-140.1063 67.13099,-217.59716 120.727,-318.357996 0.86,-0.803 2.209,-0.801 3.067,-10e-4 20.50653,37.383983 48.51152,88.812606 72.26194,147.190756 1.186,9.002 12.2214,17.4338 23.3242,11.71391 9.002,-1.186 11.1594,-12.2324 9.9724,-21.2344 -21.69905,-53.89113 -30.43965,-85.078342 -83.11454,-161.702266 -13.446,-12.55299965 -34.508,-12.55699965 -47.954,10e-4 C 126.80877,149.30021 96.099465,324.74626 77.091365,474.25139 c -2.829,21.473 13.907,40.535 35.543995,40.535 h 271.311 c 21.661,0 38.373,-19.087 35.544,-40.535 -8.26237,-52.34207 -14.88466,-100.7074 -24.7871,-157.02622 -6.40949,-11.78839 -8.3911,-14.9907 -17.4031,-13.8037 -9.002,1.186 -13.59751,8.0528 -12.41051,17.0548 l 5.66371,34.11712 h -83.159 c 64.35441,-63.86663 129.29308,-130.29894 176.448,-176.449 6.42,-6.42 6.42,-16.83 -10e-4,-23.251 z m -88.956,232.582 12.004,91.074 c 0.112,0.846 -0.148,1.701 -0.708,2.341 -0.566,0.645 -1.38,1.014 -2.235,1.014 h -271.311 c -0.855,0 -1.668,-0.369 -2.231,-1.011 -0.564,-0.643 -0.824,-1.499 -0.712,-2.347 l 12.003,-91.072 h 253.19 z"},null,-1)]),2))]),_:1}),t.createVNode(G,{title:"Toggle Lead-in",class:"button",tabindex:"-1",onClick:D},{default:t.withCtx(()=>[(t.openBlock(),t.createElementBlock("svg",{class:t.normalizeClass(["icon",N.value?"on":"off"]),viewBox:"-2 -2 28 28"},p[6]||(p[6]=[t.createElementVNode("path",{d:"m 8.9838564,1.5166215 v 2 h 5.9999996 v -2 z m 2.9999996,3 c -4.9699996,0 -8.9999996,4.0299999 -8.9999996,8.9999995 0,4.97 4.02,9 8.9999996,9 4.98,0 9,-4.03 9,-9 0,-2.12 -0.740703,-4.0693745 -1.970703,-5.6093745 l 1.419922,-1.421875 c -0.43,-0.51 -0.900156,-0.9882031 -1.410156,-1.4082031 l -1.419922,1.4199219 c -1.55,-1.24 -3.499141,-1.9804688 -5.619141,-1.9804688 z m -1.789062,4.7480469 6,4.4999996 -6,4.5 z"},null,-1)]),2))]),_:1}),t.createVNode(G,{title:"Starting Notes",class:"button",tabindex:"-1",disabled:t.unref(r).isPlayingOrLeadIn,onClick:B},{default:t.withCtx(()=>p[7]||(p[7]=[t.createElementVNode("svg",{class:"icon",viewBox:"0 -960 960 960"},[t.createElementVNode("path",{d:"m 306.66667,-360 q -44,0 -75.33334,-31.33333 Q 200,-422.66667 200,-466.66667 q 0,-44 31.33333,-75.33333 31.33334,-31.33333 75.33334,-31.33333 15.33333,0 28.33333,3.66666 13,3.66667 25,11 V -840 h 160 v 106.66667 H 413.33333 v 266.66666 q 0,44 -31.33333,75.33334 Q 350.66667,-360 306.66667,-360 Z"}),t.createElementVNode("path",{d:"m 546.66667,-120 q -44,0 -75.33334,-31.33333 Q 440,-182.66667 440,-226.66667 q 0,-44 31.33333,-75.33333 31.33334,-31.33333 75.33334,-31.33333 15.33333,0 28.33333,3.66666 13,3.66667 25,11 V -600 h 160 v 106.66667 H 653.33333 v 266.66666 q 0,44 -31.33333,75.33334 Q 590.66667,-120 546.66667,-120 Z"})],-1)])),_:1,__:[7]},8,["disabled"])])]))}},[["__scopeId","data-v-9470408d"]]),wt={class:"init-progress"},xt={key:0,class:"progress-track"},Tt={class:"message-container"},Ne=L({__name:"InitializationProgress",props:{stage:{type:String,default:null},message:{type:String,default:""},progress:{type:Number,default:null},hasError:{type:Boolean,default:!1},errorMessage:{type:String,default:null}},setup(a){const e=a,s=t.computed(()=>e.progress!==null),n=t.computed(()=>e.progress===null?0:Math.max(0,Math.min(100,e.progress*100))),i=t.computed(()=>e.hasError?e.errorMessage:e.message);return(r,o)=>(t.openBlock(),t.createElementBlock("div",wt,[s.value?(t.openBlock(),t.createElementBlock("div",xt,[t.createElementVNode("div",{class:"progress-fill",style:t.normalizeStyle({width:`${n.value}%`})},null,4)])):t.createCommentVNode("",!0),t.createElementVNode("div",Tt,[t.createElementVNode("div",{class:t.normalizeClass(["message",{error:a.hasError}])},t.toDisplayString(i.value),3)])]))}},[["__scopeId","data-v-a9ed87f2"]]),Ve=X.defineStore("initialization",{state:()=>({currentStage:null,message:"",progress:null,isInitializing:!1,isReady:!1,hasError:!1,errorMessage:null}),actions:{updateProgress(a){this.currentStage=a.stage,this.message=a.message,this.progress=a.progress??null,a.stage==="ready"?(this.isInitializing=!1,this.isReady=!0):(this.isInitializing=!0,this.isReady=!1),this.hasError=!1,this.errorMessage=null},setError(a){this.hasError=!0,this.errorMessage=a,this.isInitializing=!1,this.isReady=!1},reset(){this.currentStage=null,this.message="",this.progress=null,this.isInitializing=!1,this.isReady=!1,this.hasError=!1,this.errorMessage=null},initializeListeners(){m.on("initProgress",a=>{this.updateProgress(a)})}},getters:{shouldShowProgress:a=>a.isInitializing||a.hasError,hasProgressBar:a=>a.progress!==null}}),Nt={class:"container"},Vt={class:"panel"},_t={key:0,class:"blur"},_e=40,Le=40,Ae=100,Lt=50,Ie=400,De=570,ze=570,At=350,It=330,Dt=360,zt=360,Rt=L({__name:"MixerLayout",props:{showInitProgress:{type:Boolean,default:!0},externalMenuControl:{type:Boolean,default:!1}},emits:["menu-click"],setup(a,{emit:e}){t.useCssVars(f=>({"3e3bf6e6":B.value,"3e499cb2":C.value,"3a701552":N.value}));const s=a,n=e,i=U(),r=F(),o=Ve();t.onMounted(()=>{o.initializeListeners()});const h=t.useTemplateRef("container"),{width:v}=O(h),c=t.computed(()=>r.isLoaded),g=t.computed(()=>{const f=v.value,S=i.parts.length;return f<640||f<_e*S+Ie?0:f<Le*S+De?1:f<Ae*S+ze?2:3}),B=t.computed(()=>{switch(g.value){case 0:return`${At}px `+`${Lt}px `.repeat(i.parts.length);case 1:return`${It}px`;case 2:return`${Dt}px`;default:return`${zt}px`}}),C=t.computed(()=>{switch(g.value){case 0:return"100vw";case 1:return`${_e}px `.repeat(i.parts.length)+`${Ie}px`;case 2:return`${Le}px `.repeat(i.parts.length)+`${De}px`;default:return`${Ae}px `.repeat(i.parts.length)+`${ze}px`}}),N=t.computed(()=>{const f=[...i.parts.keys()];return g.value>0?'"'+f.map(S=>"part"+S).join(" ")+' controls"':'"controls" '+f.map(S=>'"part'+S+'"').join(" ")});return(f,S)=>(t.openBlock(),t.createElementBlock("div",{class:"outer",ref_key:"container",ref:h},[t.createElementVNode("div",Nt,[t.createElementVNode("div",Vt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(i).parts,(M,w)=>(t.openBlock(),t.createBlock(Pe,{key:M.name,class:t.normalizeClass("part"+w),name:M.name,volume:M.volume,"onUpdate:volume":T=>M.volume=T,solo:M.solo,"onUpdate:solo":T=>M.solo=T,mute:M.mute,"onUpdate:mute":T=>M.mute=T,ref_for:!0,ref:"parts"},null,8,["class","name","volume","onUpdate:volume","solo","onUpdate:solo","mute","onUpdate:mute"]))),128)),t.createVNode(Te,{"external-menu-control":s.externalMenuControl,onMenuClick:S[0]||(S[0]=M=>n("menu-click")),class:"controls"},{menu:t.withCtx(()=>[t.renderSlot(f.$slots,"menu",{},void 0,!0)]),_:3},8,["external-menu-control"]),c.value?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("div",_t)),s.showInitProgress&&t.unref(o).shouldShowProgress?(t.openBlock(),t.createBlock(Ne,{key:1,stage:t.unref(o).currentStage,message:t.unref(o).message,progress:t.unref(o).progress,"has-error":t.unref(o).hasError,"error-message":t.unref(o).errorMessage},null,8,["stage","message","progress","has-error","error-message"])):t.createCommentVNode("",!0)])])],512))}},[["__scopeId","data-v-cf29d602"]]),$t={class:"outer"},Ot={class:"mid"},Ft={class:"inner"},Ut={key:0,class:"content"},Kt=L({__name:"Placeholder",props:{colour:{type:String,default:"red"},text:{type:String,default:""}},setup(a){return t.useCssVars(e=>({"66bea586":a.colour})),(e,s)=>(t.openBlock(),t.createElementBlock("div",$t,[t.createElementVNode("div",Ot,[t.createElementVNode("div",Ft,[a.text||e.$slots.default?(t.openBlock(),t.createElementBlock("div",Ut,[t.createTextVNode(t.toDisplayString(a.text)+" ",1),t.renderSlot(e.$slots,"default",{},void 0,!0)])):t.createCommentVNode("",!0)])])]))}},[["__scopeId","data-v-dff76c48"]]),Gt={class:"modal-footer"},qt={key:0,class:"dont-remind"},Ht=L({__name:"KeyboardShortcutsHelp",props:{visible:{type:Boolean,default:!1},showDontRemind:{type:Boolean,default:!1}},emits:["update:visible","dont-remind"],setup(a,{emit:e}){const s=a,n=e,i=t.ref(!1),r=t.ref(null),o=()=>{i.value&&n("dont-remind",!0),n("update:visible",!1)},h=v=>{v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),o())};return t.watch(()=>s.visible,async v=>{var c;v&&(await t.nextTick(),(c=r.value)==null||c.focus())}),(v,c)=>a.visible?(t.openBlock(),t.createElementBlock("div",{key:0,class:"modal-overlay",onClick:o,onKeydown:h},[t.createElementVNode("div",{class:"modal-content shortcuts-help",onClick:c[1]||(c[1]=t.withModifiers(()=>{},["stop"])),role:"dialog","aria-labelledby":"shortcuts-title","aria-modal":"true"},[c[3]||(c[3]=t.createStaticVNode('<h2 id="shortcuts-title" data-v-bfa878a3>Keyboard Shortcuts</h2><div class="shortcuts-container" data-v-bfa878a3><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Transport Controls</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>P</kbd></dt><dd data-v-bfa878a3>Play / Pause</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>S</kbd></dt><dd data-v-bfa878a3>Stop</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>B</kbd></dt><dd data-v-bfa878a3>Previous bar</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>F</kbd></dt><dd data-v-bfa878a3>Next bar</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Features</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>M</kbd></dt><dd data-v-bfa878a3>Toggle metronome</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>L</kbd></dt><dd data-v-bfa878a3>Toggle lead-in</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>N</kbd></dt><dd data-v-bfa878a3>Play starting notes</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Sliders &amp; Controls</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>↑</kbd> / <kbd data-v-bfa878a3>→</kbd></dt><dd data-v-bfa878a3>Increase value</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>↓</kbd> / <kbd data-v-bfa878a3>←</kbd></dt><dd data-v-bfa878a3>Decrease value</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Home</kbd></dt><dd data-v-bfa878a3>Set to minimum</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>End</kbd></dt><dd data-v-bfa878a3>Set to maximum</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Page Up</kbd> / <kbd data-v-bfa878a3>Page Down</kbd></dt><dd data-v-bfa878a3>Large adjustment</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Navigation</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Tab</kbd></dt><dd data-v-bfa878a3>Next control</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Shift</kbd> + <kbd data-v-bfa878a3>Tab</kbd></dt><dd data-v-bfa878a3>Previous control</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Enter</kbd> / <kbd data-v-bfa878a3>Space</kbd></dt><dd data-v-bfa878a3>Activate button</dd></div><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>Escape</kbd></dt><dd data-v-bfa878a3>Close dialog / menu</dd></div></dl></section><section class="shortcut-group" data-v-bfa878a3><h3 data-v-bfa878a3>Help</h3><dl data-v-bfa878a3><div class="shortcut-item" data-v-bfa878a3><dt data-v-bfa878a3><kbd data-v-bfa878a3>?</kbd></dt><dd data-v-bfa878a3>Show this help</dd></div></dl></section></div>',2)),t.createElementVNode("div",Gt,[a.showDontRemind?(t.openBlock(),t.createElementBlock("label",qt,[t.withDirectives(t.createElementVNode("input",{type:"checkbox","onUpdate:modelValue":c[0]||(c[0]=g=>i.value=g)},null,512),[[t.vModelCheckbox,i.value]]),c[2]||(c[2]=t.createTextVNode(" Don't show this again "))])):t.createCommentVNode("",!0),t.createElementVNode("button",{onClick:o,class:"close-button",ref_key:"closeButton",ref:r},"Close",512)])])],32)):t.createCommentVNode("",!0)}},[["__scopeId","data-v-bfa878a3"]]);class Re{constructor(){this.eventBus=Se(),this.currentTime=0,this.isPlaying=!1,this.playbackSpeed=1,this.masterVolume=.75,this.parts=new Map,this.playbackTimer=null,this.lastTimestamp=0}initialize(e){if(this.musicData=e,this.beats=e.beats||[],this.practiceMarks=e.practiceMarks||{},this.beats.length>0){const s=this.beats[this.beats.length-1],n=s.tempo>0?60/s.tempo:.75;this.songDuration=s.time+n,this.maxBar=Math.max(...this.beats.map(i=>i.bar))}else this.songDuration=0,this.maxBar=0;e.parts&&e.parts.forEach(s=>{this.parts.set(s.name,{name:s.name,volume:s.volume||.75,muted:!1})}),this.eventBus.emit("initialized",{parts:Array.from(this.parts.values())})}play(){this.isPlaying||(this.isPlaying=!0,this.lastTimestamp=performance.now(),this.startPlaybackTimer(),this.eventBus.emit("playbackStateChanged",{isPlaying:!0,currentTime:this.currentTime}))}stop(){this.isPlaying&&(this.isPlaying=!1,this.stopPlaybackTimer(),this.eventBus.emit("playbackStateChanged",{isPlaying:!1,currentTime:this.currentTime}))}pause(){this.stop()}setTime(e){this.currentTime=Math.max(0,e),this.eventBus.emit("timeChanged",{currentTime:this.currentTime});const s=this.getBarFromTime(this.currentTime);s&&this.eventBus.emit("barChanged",s)}getCurrentTime(){return this.currentTime}setBar(e,s=0){const n=this.getTimeFromBar(e,s);n!==null&&this.setTime(n)}goToPracticeMark(e){const s=this.practiceMarks[e];s!==void 0&&(this.setBar(s),this.eventBus.emit("practiceMarkChanged",{mark:e,bar:s}))}setPlaybackSpeed(e){this.playbackSpeed=Math.max(.25,Math.min(2,e)),this.eventBus.emit("speedChanged",{speed:this.playbackSpeed})}getPlaybackSpeed(){return this.playbackSpeed}setMasterVolume(e){this.masterVolume=Math.max(0,Math.min(1,e)),this.eventBus.emit("masterVolumeChanged",{volume:this.masterVolume})}getMasterVolume(){return this.masterVolume}setPartVolume(e,s){const n=this.parts.get(e);n&&(n.volume=Math.max(0,Math.min(1,s)),this.eventBus.emit("partVolumeChanged",{partName:e,volume:n.volume}))}setPartMuted(e,s){const n=this.parts.get(e);n&&(n.muted=s,this.eventBus.emit("partMutedChanged",{partName:e,muted:s}))}getParts(){return Array.from(this.parts.values())}playLeadIn(e=1){this.eventBus.emit("leadInStarted",{bars:e}),setTimeout(()=>{this.eventBus.emit("leadInCompleted")},1e3*e)}playStartingNotes(){this.eventBus.emit("startingNotesStarted"),setTimeout(()=>{this.eventBus.emit("startingNotesCompleted")},2e3)}on(e,s){this.eventBus.on(e,s)}off(e,s){this.eventBus.off(e,s)}startPlaybackTimer(){const e=()=>{if(!this.isPlaying)return;const s=performance.now(),n=(s-this.lastTimestamp)/1e3;if(this.lastTimestamp=s,this.currentTime+=n*this.playbackSpeed,this.songDuration>0&&this.currentTime>=this.songDuration){this.stop(),this.eventBus.emit("songEnded",{finalTime:this.currentTime});return}this.eventBus.emit("timeChanged",{currentTime:this.currentTime});const i=this.getBarFromTime(this.currentTime);if(i&&(this.eventBus.emit("barChanged",i),this.maxBar>0&&i.bar>this.maxBar)){this.stop(),this.eventBus.emit("songEnded",{finalTime:this.currentTime});return}this.playbackTimer=requestAnimationFrame(e)};this.playbackTimer=requestAnimationFrame(e)}stopPlaybackTimer(){this.playbackTimer&&(cancelAnimationFrame(this.playbackTimer),this.playbackTimer=null)}getBarFromTime(e){if(!this.beats||this.beats.length===0)return null;let s=null;for(let n=this.beats.length-1;n>=0;n--)if(this.beats[n].time<=e){s=this.beats[n];break}return s?{bar:s.bar,beat:s.beat,repeat:s.repeat,time:s.time}:null}getTimeFromBar(e,s=0){if(!this.beats||this.beats.length===0)return null;let n=this.beats.find(i=>i.bar===e&&i.beat===1&&i.repeat===s);return n||(n=this.beats.find(i=>i.bar===e&&i.beat===1)),n?n.time:null}destroy(){this.stop(),this.eventBus.all.clear(),this.parts.clear()}}new Re,P.AudioButton=G,P.AudioSlider=Y,P.BarInput=Ce,P.BaseNumericInput=me,P.DEV_MODE=ae,P.DummyAudioEngine=Re,P.InitializationProgress=Ne,P.KeyboardShortcutsHelp=Ht,P.MixerControls=Te,P.MixerLayout=Rt,P.PartControl=Pe,P.Placeholder=Kt,P.SpeedInput=we,P.TimeInput=xe,P.TitleText=de,P.TriState=Me,P.audioEngineConfig=Be,P.isDevFeature=ue,P.isDevMode=ot,P.useAudioStateStore=F,P.useElementSize=O,P.useInitializationState=Ve,P.useMasterAudioControl=W,P.useMusicDataStore=U,P.usePlaybackStateStore=se,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "audio-mixer-ui",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Vue 3 component library for audio mixer interfaces with musical navigation",
5
5
  "type": "module",
6
6
  "main": "./dist/audio-mixer-ui.umd.cjs",