-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-bookmarklet.js
More file actions
1 lines (1 loc) · 1.46 KB
/
sync-bookmarklet.js
File metadata and controls
1 lines (1 loc) · 1.46 KB
1
javascript:(()=>{const t={READY:!1,LAST_MEASURE:null,MEASURES:[],POINTS:[],sum:t=>t.reduce((t,e)=>t+e,0),nextUntilTheEnd:async e=>{let i=await flatExecutePublicAction("getMeasureDetails");if(t.MEASURES.push({idx:e.measureIdx,measureUuid:e.measureUuid,beats:i.time.beats,tempo:i.tempo.bpm,duration:(60/i.tempo.bpm)*(i.time.beats/(i.time['beat-type']/4))}),e.measureUuid===t.LAST_MEASURE.measureUuid||t.QUIT)return!1;await flatExecutePublicAction("goNextMeasure",{partIdx:0}),await t.nextUntilTheEnd(await flatExecutePublicAction("getCursorPosition"))},getPoints:()=>(t.POINTS=t.MEASURES.map((e,i)=>({measureUuid:e.measureUuid,type:"measure",time:Number(t.sum(t.MEASURES.slice(0,e.idx).map(t=>t.duration)).toFixed(4))})),t.POINTS.push({type:"end",time:Math.ceil(1+Number((t.POINTS.slice(-1)[0].time+t.MEASURES.slice(-1)[0].duration).toFixed(4)))}),JSON.stringify({synchronizationPoints:t.POINTS},null,2)),start:async e=>{t.READY||await t.init(),t.MEASURES=[],await flatExecutePublicAction("setCursorPosition",{partIdx:0}),await t.nextUntilTheEnd(await flatExecutePublicAction("getCursorPosition")),e&&(await navigator.clipboard.writeText(t.getPoints()),alert("Your sync points have been copied to your clipboard!"))},init:async()=>{await flatExecutePublicAction("setCursorPosition",{partIdx:0}),await flatExecutePublicAction("goPartEnd"),t.LAST_MEASURE=await flatExecutePublicAction("getCursorPosition"),await flatExecutePublicAction("setCursorPosition",{partIdx:0}),t.READY=!0}};t.start(!0)})();