starry / dist /assets /scheduler-a7fa9c3c.js
k-l-lambda's picture
Initial deployment: frontend + omr-service + cluster-server + nginx proxy
6f1c297
class l{tickTable;static createFromNotation(e,c){const n={},s=new Set;let i=0;return e.notes.filter(t=>!t.chordPosition||t.chordPosition.index===0).forEach(t=>{if(t.ids){if(t.measure!==i)s.clear(),i=t.measure;else if(t.ids.some(r=>s.has(r)))return;t.ids.forEach(s.add.bind(s)),n[t.startTick]=n[t.startTick]||[];const a=t.ids.map(r=>c.get(r)).filter(r=>r);n[t.startTick].push(...a)}}),l.createFromTokenTable(n,e.endTick)}static createFromTokenTable(e,c){const n=Object.entries(e).map(([s,i])=>{if(!i.length)return null;i.sort((a,r)=>a.system===r.system?a.x-r.x:a.system-r.system);const t=i[0];return console.assert(Number.isFinite(t.x),"invalid token.x:",t),{tick:Number(s),system:t.system,measure:t.measure,x:t.x,endX:t.endX}}).filter(Boolean).sort((s,i)=>s.tick-i.tick);return n.forEach((s,i)=>{const t=n[i+1];s.endTick=t?t.tick:c,console.assert(s.endTick>s.tick,"invalid tick item, tick span is non-positive:",s,e[s.tick]),t&&s.system===t.system&&[0,1].includes(t.measure-s.measure)&&(s.endX=t.x)}),new l({tickTable:n})}constructor({tickTable:e}){console.assert(e.length>0,"invalid tick table:",e),this.tickTable=e}get startTick(){return this.tickTable[0]?this.tickTable[0].tick:null}get endTick(){return this.tickTable[0]?this.tickTable[this.tickTable.length-1].endTick:null}lookupPosition(e){e=Math.max(Math.min(e,this.endTick),this.startTick);const c=this.tickTable.find(s=>s.tick<=e&&s.endTick>e)||this.tickTable[this.tickTable.length-1];if(!c)return console.warn("cannot find tick item:",e,this.tickTable),null;const n=c.x+(e-c.tick)*(c.endX-c.x)/(c.endTick-c.tick);return{system:c.system,x:n}}lookupTick(e){const c=this.tickTable.filter(i=>i.system===e.system).sort((i,t)=>i.x-t.x);let n=c.find(i=>i.x<=e.x&&i.endX>=e.x);if(!n){const i=c[0];if(i&&e.x<i.endX)n=i;else return null}return n.tick+Math.max(e.x-n.x,0)*(n.endTick-n.tick)/(n.endX-n.x)}}export{l as S};