@fretfall/player 0.3.0 → 0.4.1
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.
- package/README.md +37 -10
- package/highway.js +1 -1
- package/index.html +170 -120
- package/mount.d.ts +50 -0
- package/mount.js +170 -120
- package/music.js +1 -1
- package/package.json +1 -1
- package/player.js +1 -1
- package/sync.js +1 -1
- package/themes.js +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Fretfall Player
|
|
2
2
|
|
|
3
|
-
An arcade-style note highway for Guitar Pro and MusicXML tabs, in the browser.
|
|
3
|
+
An arcade-style note highway for Guitar Pro and MusicXML tabs, in the browser — with a tablature and a notation page beside it.
|
|
4
4
|
|
|
5
5
|
[](https://github.com/fretfall/player/actions/workflows/ci.yml)
|
|
6
6
|
[](https://github.com/fretfall/player/actions/workflows/perf.yml)
|
|
@@ -15,9 +15,10 @@ Open a tab and play along: the notes fall down a 3D fretboard, with hand positio
|
|
|
15
15
|
band's recording and the player lines the tab up with it on its own.
|
|
16
16
|
|
|
17
17
|
- **Formats**: `.gp`, `.gp3`–`.gp5`, `.gpx`, `.musicxml`, `.mxl`, plus `.mp3`, `.m4a`, `.ogg`, `.wav`, `.flac` recordings
|
|
18
|
-
- **
|
|
18
|
+
- **Views**: the 3D highway; a tablature, scrolling or a page at a time, with the rhythm written over it; and a notation page — the tab as systems of whole bars with the rhythm, the technique marks, chord names and lyrics, on the theme's card or on paper, with a staff over each system if you like
|
|
19
|
+
- **Practice**: phrase loops, speed control with a speed trainer, metronome
|
|
19
20
|
- **Band**: every part in a window of its own, all in time
|
|
20
|
-
- **Lean**: plain HTML and ES modules, no framework, no runtime dependencies, about
|
|
21
|
+
- **Lean**: plain HTML and ES modules, no framework, no runtime dependencies, about 70 kB gzipped
|
|
21
22
|
|
|
22
23
|
## Quick start
|
|
23
24
|
|
|
@@ -26,7 +27,7 @@ npm install @fretfall/player
|
|
|
26
27
|
npx serve node_modules/@fretfall/player
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
Any static file server works. Tabs are read and played by [alphaTab](https://www.alphatab.net), loaded from jsDelivr.
|
|
30
|
+
Any static file server works. Tabs are read and played by [alphaTab](https://www.alphatab.net), loaded from jsDelivr; the fonts, the notation's music face among them, come from Google Fonts.
|
|
30
31
|
|
|
31
32
|
## Build on it
|
|
32
33
|
|
|
@@ -48,13 +49,21 @@ fretfall.part = 1;
|
|
|
48
49
|
| `playing`, `time`, `length` | Where playback is, in seconds. `playing` is settable: it waits for the synth's instruments. So is `time`: a jump to there, kept within the song |
|
|
49
50
|
| `parts`, `part` | The song's parts, and the one shown (settable) |
|
|
50
51
|
| `notes` | What the part shown asks for: the open strings, and each note's time, string, fret and midi note. A copy each read |
|
|
52
|
+
| `offset`, `snap()` | The open song's own nudge in ms, on top of how the player lined its recording up and of Audio delay (the device's): positive makes the notes later. Settable once the song is open; a new song starts at 0. It moves the song's clock: `time`, seeks and the loop go by it. `snap()` sets it so the tab's first note lands on its attack in the recording and returns it (`null` without a recording lined up here): near where the player's fit puts that note when the fit is sure, else the recording's first loud sound, which a count-in can be |
|
|
51
53
|
| `speed` | How fast it plays, 1 being the song's own tempo. Settable, in the player's steps of a tenth from 0.1 to 1.5 |
|
|
52
54
|
| `style` | The look: note shape, colour set, fonts, string colours, headstock. Settable whole or in part |
|
|
55
|
+
| `volume`, `muted` | 0 to 1, and the mute. Settable; a volume of 0 is muted, and setting one asks for sound again |
|
|
56
|
+
| `loop` | `{ start, end }` in seconds, or `null`. Settable: kept inside the song, and anything else clears it |
|
|
57
|
+
| `metronome` | The click, on the chart's beats. Settable |
|
|
58
|
+
| `view`, `minimal`, `band()` | What the notes are drawn as — `'highway'`, `'tablature'` or `'notation'` — and the view alone with the lyrics; both settable. `band()` opens every other part in a window of its own |
|
|
59
|
+
| `sheet` | Which sheet is open: `'settings'`, `'legend'` or `null`. Settable |
|
|
60
|
+
| `fullscreen` | Settable — set it from your own button's click, as browsers want a gesture behind it |
|
|
61
|
+
| `controls` | Everything above that a control toggles, in one object, for a bar of your own to draw itself from |
|
|
53
62
|
| `addFormat({ name, extensions, open })` | Read another file type: `open(file)` resolves to `{ song, audio }` |
|
|
54
63
|
| `closeSheets()` | Close Settings and the notation sheet |
|
|
55
64
|
| `dock(element, more?)` | Mounted in a page: the header's controls in an element of the page's own, see below |
|
|
56
65
|
|
|
57
|
-
Events on `window`: `fretfall:ready`, `fretfall:song`, `fretfall:playing`, `fretfall:sheet`. The modules import on their own
|
|
66
|
+
Events on `window`: `fretfall:ready`, `fretfall:song`, `fretfall:playing`, `fretfall:sheet`, `fretfall:controls`. The modules import on their own
|
|
58
67
|
too, for example `music.js` for tunings and note names.
|
|
59
68
|
|
|
60
69
|
### In a page of your own
|
|
@@ -83,19 +92,37 @@ const fretfall = await mount(element); // window.fretfall, once fretfall:ready h
|
|
|
83
92
|
#### One bar: the player's controls in the page's own
|
|
84
93
|
|
|
85
94
|
A page with a bar of its own has two once the player is in it. `fretfall.dock(element)` moves the header's controls — the
|
|
86
|
-
part picker, time, speed, volume, loop, play, open, help, settings and full screen — into `element`, and hides the player's
|
|
95
|
+
part picker, the view switch, time, speed, volume, loop, play, open, metronome, band, minimal, help, settings and full screen — into `element`, and hides the player's
|
|
87
96
|
header while they are there, so the highway starts at the top of its element. They are the player's own buttons, styled
|
|
88
97
|
by its stylesheet: `element` is marked `data-fretfall` (and `data-fretfall-dock`) so that reaches it, in its own colours
|
|
89
98
|
and fonts rather than the theme's — set the variables it draws with (`--chip`, `--chip-border`, `--ink`, `--text`,
|
|
90
99
|
`--muted`, `--accent`, `--ui`, `--num`) on the element for your bar's, and hide or restyle what your bar does differently
|
|
91
100
|
under that attribute. `fretfall.dock(element, more)` puts help, settings and full screen into `more` instead, for a bar
|
|
92
|
-
with a right side of its own. The tooltips and the volume slider open under the buttons, where they stand now
|
|
93
|
-
|
|
101
|
+
with a right side of its own. The tooltips and the volume slider open under the buttons, where they stand now; under
|
|
102
|
+
900 px wide the slider opens at the right edge of the volume button's nearest positioned ancestor, so give your bar
|
|
103
|
+
`position: relative`. Keep `element` (and `more`) for the tools alone: the stylesheet reaches every child of an element
|
|
104
|
+
marked `data-fretfall`, so anything else of yours in there picks up the player's rules. Keys pressed on the tools are the
|
|
105
|
+
player's, on the rest of the page the page's. Full screen shows the player alone, so the tools come home meanwhile and go
|
|
106
|
+
back when it ends. `fretfall.dock(null)` brings everything home, and a page removing its bar has to call it first, or the controls go with
|
|
94
107
|
it (`demo/mount.html` shows a dock).
|
|
95
108
|
|
|
109
|
+
#### Controls of your own
|
|
110
|
+
|
|
111
|
+
`dock()` moves the player's controls into your bar. To build your own instead, everything they do is on the hook —
|
|
112
|
+
`playing`, `time`, `speed`, `volume`, `muted`, `loop`, `metronome`, `part`, `sheet`, `fullscreen`, `view`, `minimal`, `band()`, `pick()` — so your
|
|
113
|
+
buttons drive the player without reaching into its markup. `fretfall.controls` is the lot in one object, and
|
|
114
|
+
`fretfall:controls` fires whenever any of them changes, whoever changed it: one listener, one re-render, rather than an
|
|
115
|
+
event per knob. The player's own controls stay in step, so you can dock some and build others.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const bar = () => { const c = fretfall.controls; play.textContent = c.playing ? 'Pause' : 'Play'; /* … */ };
|
|
119
|
+
addEventListener('fretfall:controls', bar);
|
|
120
|
+
play.onclick = () => (fretfall.playing = !fretfall.playing);
|
|
121
|
+
```
|
|
122
|
+
|
|
96
123
|
Types come with it (`mount.d.ts`): `mount()`, the `fretfall` hook and its events.
|
|
97
124
|
|
|
98
|
-
Keys: <kbd>Space</kbd> play · <kbd>L</kbd> loop · <kbd>O</kbd> open · <kbd>D</kbd>
|
|
125
|
+
Keys: <kbd>Space</kbd> play · <kbd>L</kbd> loop · <kbd>O</kbd> open · <kbd>D</kbd> tablature · <kbd>N</kbd> notation · <kbd>H</kbd> minimal · <kbd>K</kbd> metronome ·
|
|
99
126
|
<kbd>F</kbd> full screen · <kbd>S</kbd> settings · <kbd>?</kbd> everything else. Add `?perf` to the URL for a frame profiler.
|
|
100
127
|
|
|
101
128
|
## Develop
|
|
@@ -106,7 +133,7 @@ npm start # the demo on http://localhost:4410, rebuilt from src/ on ever
|
|
|
106
133
|
npm test # node --test
|
|
107
134
|
npm run lint # oxlint: correctness and performance rules
|
|
108
135
|
npm run build # dist/, the published package (DEMO=1: with the demo's front door, as github.io serves it)
|
|
109
|
-
npm run bench # frame time
|
|
136
|
+
npm run bench # frame time and draw calls of the highway, the tablature and the notation page, sync, fingering and size of dist/
|
|
110
137
|
```
|
|
111
138
|
|
|
112
139
|
`src/` is the player's modules, `demo/` the page they ship with, and the demo's front door and tab. The build flattens both
|
package/highway.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lap as ue}from"./perf.js";import{noteName as $i}from"./music.js";const Ot=900,Li=84,Jn=28,Vn=2.2,Di=.9,Ci=2.4,Ri=a=>Li*(a.drawDistance??1)/(Jn*(a.noteSpeed??1)),_i=.34,$t=24,fn=1.2,Ei=1.25,Oi=1.25,Re=5,cn=1,Bi=1.6,Hi=2,dn=.19,Zn=.12,Qn=3,Ni=11,Fi=[{time:-1/0,endTime:1/0,fret:1,width:4}],Cn=[3,5,7,9,12,15,17,19,21,24],Rn=.15,ti=.31,ei=1.7,ni=1.4,ii=1,oi=1.2,zi=.75,ai=(a,l,f,o,e)=>{const[M,m,d,t]=[Math.min(a,l),Math.max(a,l),Math.min(f,o),Math.max(f,o)],L=Math.min(e,(m-M)/2,(t-d)/2),R=(kt,U,wt)=>{const _=Array.from({length:5},(xt,st)=>[kt+Math.cos(wt+st*Math.PI/8)*L,U+Math.sin(wt+st*Math.PI/8)*L]);return[_[0],..._,_[4]]};return[...R(m-L,t-L,0),...R(M+L,t-L,Math.PI/2),...R(M+L,d+L,Math.PI),...R(m-L,d+L,1.5*Math.PI)]},Gi=a=>[...a,a.at(-1),...a.slice(0,-1).reverse().map(([l,f])=>[l,-f])],Ui={inline:{label:"6 in line",outline:[[0,1],[.42,1.05],[.73,1.3],[1.01,1.53],[1.46,1.45],[2.73,1.08],[4.38,.62],[5.79,.17],[6.54,-.13],[6.88,-.35],[7.03,-.88],[6.98,-1.56],[6.64,-2.11],[6.14,-2.38],[5.59,-2.34],[5.21,-2.05],[4.99,-1.66],[4.75,-1.39],[4.25,-1.3],[3.5,-1.39],[2.6,-1.6],[1.85,-1.81],[1.18,-1.75],[.83,-1.36],[.47,-1.06],[0,-1]],posts:{from:[1.56,.95],to:[6.01,-.58]},keys:"machine",tree:2.47},fourTwo:{label:"4 + 2",outline:[[0,1],[.48,1.03],[.94,1.35],[1.21,1.72],[1.52,1.72],[2.99,1.31],[4.23,.95],[5.53,.57],[5.92,.28],[6.07,-.36],[6.05,-1.03],[5.79,-1.53],[5.36,-1.67],[4.95,-1.53],[4.68,-1.29],[4.36,-1.19],[4.02,-1.32],[3.67,-1.56],[2.99,-1.67],[2.08,-1.6],[1.4,-1.43],[.94,-1.16],[.48,-1.03],[0,-1]],posts:{from:[1.81,1.08],to:[4.94,-.03],treble:{share:1/3,from:[2.33,-1.03],to:[3.38,-.69]}},keys:"machine"},openBook:{label:"3 + 3 open book",outline:Gi([[0,1],[.48,1.07],[.96,1.33],[1.47,1.53],[3.16,1.67],[4.98,1.76],[6.25,1.8],[6.25,1.8],[6.42,.93],[6.3,0]]),posts:{from:[2.5,1.07],to:[5.1,1.07],treble:{share:1/2}},keys:"tulip",cover:[[.22,0],[.22,.4],[.36,.5],[.78,.4],[1.3,.25],[1.82,.16],[2.13,.1],[2.24,0],[2.13,-.1],[1.82,-.16],[1.3,-.25],[.78,-.4],[.36,-.5],[.22,-.4],[.22,0]],screws:[[.43,0],[1.98,0]]},pointed:{label:"3 + 3 pointed",outline:[[0,1],[.36,1.12],[.75,1.47],[1.07,1.84],[1.38,1.93],[2.29,1.73],[3.26,1.55],[4.36,1.35],[5.45,1.12],[5.75,.95],[5.86,.43],[5.98,-.22],[6.29,-.75],[6.75,-1.22],[6.75,-1.22],[6.17,-1.24],[5.33,-1.3],[4.36,-1.37],[3.26,-1.55],[2.29,-1.73],[1.38,-1.93],[1.07,-1.84],[.75,-1.47],[.36,-1.12],[0,-1]],posts:{from:[2.07,1],to:[4.65,.46],treble:{share:1/2}},keys:"machine",cover:[[.1,.44],[.1,.44],[.59,.4],[1.1,.28],[1.69,0],[1.69,0],[1.1,-.28],[.59,-.4],[.1,-.44],[.1,-.44],[.1,.44]],screws:[]},headless:{label:"Headless",outline:ai(.2,.95,-1.06,1.06,.2),clamps:.58}};function Yi(a,l){const f=l.length,o=ri(a.outline,10);let e=l.map(t=>[a.clamps,t]),M=l.map(()=>1);if(a.posts){const{from:t,to:L,treble:R}=a.posts,kt=R?Math.floor(f*R.share+1e-9):0,U=f-kt,wt=(Ht,dt,E)=>j=>Ht.map(($,P)=>$+(dt[P]-$)*j/Math.max(1,E-1)),_=([Ht,dt])=>[Ht,-dt],xt=wt(t,L,U),st=wt(R?.from??_(t),R?.to??_(L),kt);e=l.map((Ht,dt)=>dt<U?xt(dt):st(f-1-dt)),M=l.map((Ht,dt)=>dt<U?1:-1)}const m=(t,L)=>{let R=null;for(let kt=1;kt<o.length;kt++){const[U,wt]=o[kt-1],[_,xt]=o[kt];if((U-t)*(_-t)>0||U===_)continue;const st=wt+(xt-wt)*(t-U)/(_-U);(R===null||st*L>R*L)&&(R=st)}return R??L},d=a.keys?e.map(([t],L)=>({u:t,side:M[L],edge:m(t,M[L])})):[];return{outline:o,ends:e,keys:d}}const si=new WeakMap,Ye=new Map,qi=(a,l)=>{const f=l.join(),o=si.get(a);if(o?.key===f)return o.parts;const e=Yi(a,l);return si.set(a,{key:f,parts:e}),e},li=(a,l)=>(Ye.has(a)||(Ye.size>500&&Ye.clear(),Ye.set(a,l())),Ye.get(a)),ri=(a,l=8)=>[...a.slice(0,-1).flatMap((f,o)=>{const e=a[Math.max(0,o-1)],M=a[o+1],m=a[Math.min(a.length-1,o+2)];return f[0]===M[0]&&f[1]===M[1]?[f]:Array.from({length:l},(d,t)=>{const L=t/l;return[0,1].map(R=>.5*(2*f[R]+(M[R]-e[R])*L+(2*e[R]-5*f[R]+4*M[R]-m[R])*L*L+(3*f[R]-e[R]-3*M[R]+m[R])*L**3))})}),a.at(-1)],_n=(a,l)=>{if(!a.startsWith("#"))return a;const f=o=>{const e=parseInt(a.slice(o,o+2),16);return Math.round(l>0?e+(255-e)*l:e*(1+l)).toString(16).padStart(2,"0")};return`#${f(1)}${f(3)}${f(5)}`},mn=new Map,I=(a,l)=>{if(!a.startsWith("#"))return a;const f=a+l;let o=mn.get(f);return o||(mn.size>1e3&&mn.clear(),mn.set(f,o=`rgba(${parseInt(a.slice(1,3),16)}, ${parseInt(a.slice(3,5),16)}, ${parseInt(a.slice(5,7),16)}, ${l})`)),o},_e=(a,l)=>{let f=0,o=a.length;for(;f<o;){const e=f+o>>1;a[e].time<l?f=e+1:o=e}return f};function hi(a){if(a.links?.next.length===a.notes.length)return a.links;const l=a.notes.length,f=new Array(l).fill(-1),o=new Array(l).fill(-1),e={};let M=0;for(let m=0;m<l;m++){const{string:d,sustain:t}=a.notes[m];e[d]!==void 0&&([o[m],f[e[d]]]=[e[d],m]),e[d]=m,M=Math.max(M,t)}return a.links={next:f,prev:o,held:M}}const Me=a=>Math.round(a*4)/4,Bt=32,gn=new Map;let fi=0;const Jt=(a,l,f)=>{let o=gn.get(l);o||gn.set(l,o=new Map);let e=o.get(f);if(!e){++fi>5e3&&([fi,o]=[0,new Map],gn.clear(),gn.set(l,o)),a.font=l;const M=a.measureText(f);o.set(f,e={width:M.width,middle:(M.actualBoundingBoxAscent-M.actualBoundingBoxDescent)/2,top:M.actualBoundingBoxAscent})}return e},pn=128,En=new WeakMap,Xi=a=>{if(!En.has(a)){const l=new OffscreenCanvas(1,pn),f=l.getContext("2d"),[o,e]=[a.floor0,a.floor1].map(m=>[1,3,5].map(d=>parseInt(m.slice(d,d+2),16))),M=Array.from({length:pn},(m,d)=>{const t=(d+.5)/pn;return`rgba(${o.map((L,R)=>Math.round(L+(e[R]-L)*t))}, ${1-t})`});M.forEach((m,d)=>{f.fillStyle=m,f.fillRect(0,pn-1-d,1,1)}),En.set(a,{strip:l,near:M[0]})}return En.get(a)},Ee=new Map,ci=new WeakMap,di=(a,l,f)=>{let o=ci.get(a);o||ci.set(a,o=new Map);let e=o.get(l);if(!e){e=a.createLinearGradient(0,0,0,1);for(const[M,m]of f)e.addColorStop(M,m);o.set(l,e)}return e},un=new Map,mi=(a,l,f,o,e)=>{const M=`${l}|${f}|${o}|${e}`;let m=un.get(M);return m||(un.size>20&&un.clear(),m=a.createLinearGradient(0,l,0,f),m.addColorStop(0,o),m.addColorStop(1,e),un.set(M,m)),m},Mn=(a,l)=>[a[0]-l[0],a[1]-l[1],a[2]-l[2]],xn=(a,l)=>a[0]*l[0]+a[1]*l[1]+a[2]*l[2],ji=(a,l)=>[a[1]*l[2]-a[2]*l[1],a[2]*l[0]-a[0]*l[2],a[0]*l[1]-a[1]*l[0]],Ki=a=>a.map(l=>l/Math.hypot(...a)),Ji=(a,l)=>{let f=0;for(const o of a??[]){if(o.time>l)break;f=o.fret}return f},qe=(a,l)=>{let f=0,o=a.length;for(;f<o;){const e=f+o>>1;a[e].time<=l?f=e+1:o=e}return a[Math.max(0,f-1)]},gi=a=>a*a*(3-2*a),Vi=.3,pi=new WeakMap;function ui(a,l){let f=pi.get(a);if(f||pi.set(a,f={}),!(l in f)){const o=Math.max(a.sustain,.05),M=(a[l]??(l==="bendCurve"&&a.bend?[[0,0],[.25,a.bend]]:null))?.map(([m,d])=>[m*o,d,!1])??[];M.length&&M[0][0]>.001&&(M[0][2]=!0,M.unshift([0,0,!1])),f[l]=M.length?M:null}return f[l]}function Mi(a,l){if(!a)return 0;let f=a[0][1];for(let o=1;o<a.length&&l>a[o-1][0];o++){const[[e,M],[m,d,t]]=[a[o-1],a[o]],L=Math.min(m-e,Vi)||1e-6;f=M+(d-M)*gi(Math.min(1,Math.max(0,(l-(t?m-L:e))/L)))}return f}const Zi=(a,l)=>Mi(ui(a,"bendCurve"),l),Qi=(a,l)=>Mi(ui(a,"whammy"),l),xi=new WeakMap,Oe=a=>{let l=xi.get(a);return l===void 0&&xi.set(a,l=Math.max(a.bend||0,...(a.bendCurve??[]).map(([,f])=>f))),l};function to(a){if(a.chordSpans)return a.chordSpans;const l=[];for(const f of a.chords){const o=Math.max(f.time+.25,...f.notes.map(M=>a.notes[M].time+a.notes[M].sustain)),e=l.at(-1);e&&f.time-e.end<1&&(f.name?f.name===e.name:f.highDensity)?e.end=Math.max(e.end,o):f.name&&l.push({name:f.name,time:f.time,end:o})}for(const f of a.handShapes??[])f.arpeggio&&f.name&&l.push({name:f.name,time:f.startTime,end:f.endTime});return a.chordSpans=l.sort((f,o)=>f.time-o.time)}function eo(a){if(a.chordRails)return a.chordRails;const l=[],f=o=>Math.max(o.time+.15,...o.notes.map(e=>a.notes[e].time+a.notes[e].sustain));for(let o=0;o<a.chords.length;o++){const e=a.chords[o];if(e.highDensity)continue;let M=f(e),m=o+1;for(;a.chords[m]?.highDensity&&a.chords[m].time-M<1;m++)M=Math.max(M,f(a.chords[m]));M=Math.min(M,a.chords[m]?.time??1/0),M-e.time>.2&&l.push({time:e.time,end:M,frets:e.notes.map(d=>a.notes[d].fret)})}for(const o of a.handShapes??[])o.arpeggio&&l.push({time:o.startTime,end:o.endTime,frets:o.frets,arpeggio:o});return a.chordRails=l}const bi={artificial:"AH",pinch:"PH",tap:"TH",semi:"SH",feedback:"FH"},yi=a=>a<.5?"¼":a===.5?"½":a===1?"full":a%1?`${Math.floor(a)}½`:String(a),Si=(a,l,f,o)=>{if(a===void 0)return l;const e=a+(l-a)*(1-Math.exp(-f/o));return Math.abs(l-e)<1e-6?l:e};function ki(a,l,f,o,e){a[l]===void 0&&([a[l],a[l+"Speed"]]=[f,0]);const M=2/o,m=M*e,d=1/(1+m+.48*m*m+.235*m*m*m),t=a[l]-f,L=(a[l+"Speed"]+M*t)*e;a[l+"Speed"]=(a[l+"Speed"]-M*L)*d,a[l]=f+(t+L)*d,Math.abs(a[l]-f)<1e-6&&Math.abs(a[l+"Speed"])<1e-6&&([a[l],a[l+"Speed"]]=[f,0])}function Ti(a,l,f=0){let o=1/0,e=-1/0;for(const m of a)m.endTime<=l||m.time>=l+Qn||(o=Math.min(o,m.fret-1),e=Math.max(e,m.fret-1+m.width));if(o===1/0){const m=qe(a,l);[o,e]=[m.fret-1,m.fret-1+m.width]}f&&(o=Math.min(o,f-1));const M=Math.max(Ni,e-o+2)+1;return{lo:o,hi:e,span:M,center:Math.min(25-M/2,Math.max(M/2-1,(o+e)/2))}}function no(a,l,f,o,e=0){const M=Ti(l,f,e),m=a.target,d=!m||M.lo<m.center-m.span/2||M.hi>m.center+m.span/2,t=m&&m.span-Math.max(M.span,Ti(l,f+Qn,e).span)>2;(d||t)&&(a.target=M);const L=Math.min(o-(a.at??o),100);a.at=o,ki(a,"span",a.target.span,a.target.span>a.span?.8:1.4,L/1e3),ki(a,"center",a.target.center,1,L/1e3);const R=qe(l,f);return a.left=Si(a.left,R.fret-1,L,90),a.right=Si(a.right,R.fret-1+R.width,L,90),R}function Ai(a,l,f,o,e,M,m,d){a.beginPath(),a.moveTo(l-o,f-M*e),a.lineTo(l,f),a.lineTo(l+o,f-M*e),a.lineWidth=Math.max(3,e*1.15),a.strokeStyle=d,a.stroke(),a.lineWidth=Math.max(1.5,e*.65),a.strokeStyle=m,a.stroke(),a.lineWidth=Math.max(.6,e*.2),a.strokeStyle="rgba(255, 255, 255, 0.5)",a.stroke()}function Xe(a,l,f,o,e){a.beginPath(),a.moveTo(l,f),a.lineTo(o,e),a.stroke()}function Pi(a){const l=devicePixelRatio||1,f=a.clientWidth,o=a.clientHeight;(a.width!==Math.round(f*l)||a.height!==Math.round(o*l))&&(a.width=Math.round(f*l),a.height=Math.round(o*l));const e=a.getContext("2d"),M=o/Ot,m=f/M,d=l*M;return e.setTransform(d,0,0,d,0,0),e.clearRect(0,0,m,Ot),{g:e,W:m,B:d}}function ho(a,l,f,o,e){const{g:M,W:m,B:d}=Pi(a);let t=M;if(!l)return;const L=l.anchors.length?l.anchors:Fi,R=Ji(l.capos,f),kt=no(e,L,f,performance.now(),R),U=l.strings,wt=Math.min(.5,5*_i/Math.max(1,U-1)),_=wt*Oi*(o.boardHeight??1),xt=_*(U-1),st=n=>(o.stringOrder==="high"?n:U-1-n)*_,Ht=n=>(n>=U/2?1:-1)*(o.stringOrder==="high"?-1:1),dt=Jn*(o.noteSpeed??1),E=Ri(o),j=-.22,$=xt+.22,P=j-.06,Nt=E*dt,ct=n=>Math.max(0,n)*dt,Ft=n=>o.str[n%o.str.length],Lt=o.noteLines===0?null:`rgba(255, 255, 255, ${o.noteLines??.5})`,he=+o.fretNumbers||0,Vt=e.span,vt=[e.center,wt*(U-1)/2,0],we=(o.viewAngle??30)*Math.PI/180,He=.6*Math.SQRT2*Vt,je=[vt[0],xt+He*Math.sin(we),-He*Math.cos(we)],w=Ki(Mn([vt[0],0,2.2*Vt],je)),Q=ji(w,[1,0,0]),V=(o.sideAngle??0)*Math.PI/180,[bt,Ct]=[Math.sin(V),Math.cos(V)],te=Mn(je,vt),zt=xn(te,w),ve=xn(te,Q),Rt=[-bt,w[1]*Ct,w[2]*Ct],be=[Ct,w[1]*bt,w[2]*bt],Gt=[vt[0]+ve*Q[0]+zt*Rt[0],vt[1]+ve*Q[1]+zt*Rt[1],ve*Q[2]+zt*Rt[2]],Ke=Math.min(m*.88,Ot*(o.fill?1.3:1.05)),Je=Ke*xn(Mn(vt,Gt),Rt)/Vt,mt=Math.min(Ei*(o.fretWidth??1),m*Vt/(Ke*Math.max(1,Vt-2.5)));let Ve=0,Ne=0;const[bn,yn,Ze]=Gt,[Fe,ye,Sn]=Rt,[Se,kn,Qe]=be,[Tn,tn,en]=Q,v=(n,i,h)=>{const s=n-bn,r=i-yn,g=h-Ze,u=Je/Math.max(.05,s*Fe+r*ye+g*Sn);return[m/2+(s*Se+r*kn+g*Qe)*mt*u+Ve,Ot/2-(s*Tn+r*tn+g*en)*u+Ne,u]},[nn,on,p]=v(...vt);[Ve,Ne]=[m/2-nn,Ot*(o.fill?.83:.81)-on];const[,c]=v(e.center-Vt/2,P,0),[,D]=v(e.center+Vt/2,P,0),[,gt]=v(e.center,P,0);Ne-=Math.min(Ot*.08,Math.max(0,c-gt,D-gt)),ue("setup");const A=(n,i=!0)=>{t.beginPath();for(let h=0;h<n.length;h++){const[s,r]=v(n[h][0],n[h][1],n[h][2]);h?t.lineTo(s,r):t.moveTo(s,r)}i&&t.closePath()},H=(n,i)=>{A([n,i],!1),N()},Tt=(n,i,h,s,r)=>{if(o.gem!=="pill")return A([[n-s,i-r,h],[n+s,i-r,h],[n+s,i+r,h],[n-s,i+r,h]]);const[g,u]=v(n-s,i,h),[S,x]=v(n+s,i,h),[,k]=v(n,i+r,h),[,J]=v(n,i-r,h),F=Math.atan2(x-u,S-g),z=Math.min(Math.abs(J-k),Math.hypot(S-g,x-u))/2,[W,O]=[z*Math.cos(F),z*Math.sin(F)];t.beginPath(),t.arc(g+W,u+O,z,F+Math.PI/2,F+Math.PI*1.5),t.arc(S-W,x-O,z,F-Math.PI/2,F+Math.PI/2),t.closePath()},rt=(n,i)=>{const h=qe(L,i),s=n.filter(r=>r>0);return[Math.min(h.fret-1,...s.map(r=>r-1))+.05,Math.max(h.fret-1+Math.max(4,h.width),...s)-.05]},fe=(n,i,h,s,r)=>{H([n-s,i-r,h],[n+s,i+r,h]),H([n-s,i+r,h],[n+s,i-r,h])},We=o.markings==="white",Zt=We?"#ffffff":o.ink,Ie=(n,i,h,s,r,g,u,S=null)=>{const[x,k]=u?[r*.85,g*.8]:[Math.min(r,.34)*.4,g*.55],J=u&&!We&&!S;S||(t.strokeStyle=I(o.ink,J?.85:.7),t.lineWidth=J?Math.max(2,.06*s):Math.max(3.5,.1*s),fe(n,i,h,x,k)),!J&&(t.strokeStyle=S??"#ffffff",t.lineWidth=Math.max(S?2:1.8,.05*s),fe(n,i,h,x,k))};let Qt=null,_t=0;const ke=n=>{n!==Qt&&(t.font=Qt=n)},ce={},oe=(n,i,h,s,r,g)=>{const u=ce[r]??=`${r} ${Bt}px ${o.num}`,S=s/Bt;return Jt(t,u,n),ke(u),t.textAlign=g,t.setTransform(d*S,0,0,d*S,d*i,d*(h-_t)),Jt(t,u,n).middle},Ut=()=>t.setTransform(d,0,0,d,0,-d*_t),ze=(n,i,h)=>{t.fillStyle=n,t.setTransform(d,0,0,d*(h-i),0,d*(i-_t)),t.fill(),Ut()},At=(n,i,h,s,r,g,u=700,S="center",x=!0,k=!1)=>{const[J,F,z]=v(i,h,s),W=r*(k?z:Math.sqrt(z*p));if(W<(k?1:8)||J<-60||J>m+60)return;t.textBaseline="alphabetic";const O=oe(n,J,F,W,u,S);x&&(t.lineWidth=Bt*.2,t.strokeStyle=I(o.ink,.9),t.strokeText(n,0,O)),t.fillStyle=g,t.fillText(n,0,O),Ut(),t.textBaseline="middle"},ee=(n,i,h,s,r,g,u=700)=>{const[S,x,k]=v(i,P,h),J=(p/k)**zi,[F,z]=v(i+s*J,P,h),W=Math.hypot(F-S,z-x);let O=r*J,[lt,nt]=v(i,P,h+O),X=Math.hypot(lt-S,nt-x);for(let et=0;et<3&&X>W*oi;et++)O*=W*oi/X,[lt,nt]=v(i,P,h+O),X=Math.hypot(lt-S,nt-x);const at=Math.abs(Math.atan2(lt-S,x-nt));if(S<-60||S>m+60||X<ii||at>ni)return;const b=t.globalAlpha;t.globalAlpha=b*Math.min(1,(ni-at)/.2,(X-ii)/3);const St=ce[u]??=`${u} ${Bt}px ${o.num}`;ke(St),t.textAlign="center",t.textBaseline="alphabetic";const{top:It}=Jt(t,St,n);t.setTransform(d*(F-S)/Bt,d*(z-x)/Bt,-d*(lt-S)/Bt,-d*(nt-x)/Bt,d*S,d*(x-_t)),t.fillStyle=g,t.fillText(n,0,It),Ut(),t.globalAlpha=b,t.textBaseline="middle"},[,pt]=v(vt[0],P,0),[,$e]=v(vt[0],P,Nt),Wt=(n,i,h)=>{const s=`${pt}|${$e}`;(Ee.span!==s||Ee.size>300)&&(Ee.clear(),Ee.span=s);const r=`${n}|${i}|${h}`;let g=Ee.get(r);return g||(g=t.createLinearGradient(0,pt,0,$e),g.addColorStop(0,I(n,i)),g.addColorStop(1,I(n,h)),Ee.set(r,g)),g};let Yt=null;const tt=(n,i,h=10,s=!1)=>Yt=n?{color:i,blur:h,faded:s}:null,An=[[.6,.05],[.35,.13],[.15,.27]],de=[[.4,.3]],ae=n=>{if(!Yt)return;const{lineWidth:i,globalAlpha:h}=t,s=n?1:Math.min(1,2*i/Yt.blur);t.save(),t.strokeStyle=Yt.faded?Wt(Yt.color,1,.1):Yt.color;for(const[r,g]of Yt.blur>4?An:de)t.lineWidth=(n?0:i)+2*Yt.blur*r,t.globalAlpha=h*g*s,t.stroke();t.restore()},N=()=>{ae(!1),t.stroke()},Y=()=>{ae(!0),t.fill()};t.textBaseline="middle",t.lineCap="round",t.lineJoin="round";const{strip:se,near:B}=Xi(o);let[ot,ft]=[-60,$t+60];if(V){const n=vt[0]+(1-xn(Mn([vt[0],P,0],Gt),Rt))/Rt[0];[ot,ft]=Rt[0]>0?[Math.max(-60,n),$t+60]:[-60,Math.min($t+60,n)]}t.save(),A([[ot,P,0],[ft,P,0],[ft,P,Nt],[ot,P,Nt]]),t.clip(),V&&(t.fillStyle=B,t.fillRect(0,pt,m,Ot-pt)),t.imageSmoothingEnabled=!1,t.drawImage(se,0,$e,m,pt-$e),t.restore();const ut=(n,i)=>{const[h,s]=v(...n),[r,g]=v(...i);t.moveTo(h,s),t.lineTo(r,g)};t.strokeStyle=Wt(o.lane,.5,.04),t.lineWidth=Di,t.beginPath();for(let n=0;n<=$t;n++)ut([n,P,0],[n,P,Nt]);N();for(const n of[!1,!0]){t.strokeStyle=n?o.measure:o.beat,t.lineWidth=n?1.6:1,t.beginPath();const i=[];for(let h=_e(l.beats,f);h<l.beats.length;h++){const s=l.beats[h],r=s.time-f;if(r>E)break;s.measure>=0===n&&(r>E-.4?i.push(r):ut([0,P,ct(r)],[$t,P,ct(r)]))}N();for(const h of i)t.globalAlpha=(E-h)/.4,t.beginPath(),ut([0,P,ct(h)],[$t,P,ct(h)]),N();t.globalAlpha=1}if(he)for(let n=_e(l.beats,f);n<l.beats.length;n++){const i=l.beats[n],h=i.time-f;if(h>E)break;if(i.measure<0)continue;const s=qe(L,i.time),r=ct(h);t.globalAlpha=Math.min(1,(E-h)/.4);for(const g of Cn)(g<s.fret||g>=s.fret+s.width)&&ee(String(g),g-.5,r,ti,ei,I(o.inlay,he))}t.globalAlpha=1,(o.guides===!1?[]:L.filter(n=>n.endTime>f&&n.time<f+E)).forEach((n,i)=>{const h=ct(Math.max(0,n.time-f)),s=ct(Math.min(E,n.endTime-f)),r=n.fret-1,g=r+n.width;t.fillStyle=Wt(o.anchorFill,o.anchorOpacity,.02),A([[r,P,h],[g,P,h],[g,P,s],[r,P,s]]),Y(),t.strokeStyle=Wt(o.anchorLane,.55,.04),t.lineWidth=Ci*.6;for(const u of[r,g])H([u,P,h],[u,P,s]);i&&n.time>f&&H([r,P,h],[g,P,h])});const Te=new Map,ie=n=>{const i=Math.round(n*100);return Te.has(i)||Te.set(i,{dt:n-f,texts:[],pins:[]}),Te.get(i)};for(const n of l.markers??[])n.time>=f&&n.time<=f+E&&!ie(n.time).texts.includes(n.text)&&ie(n.time).texts.push(n.text);for(const n of l.hairpins??[])n.time>=f&&n.time<=f+E&&ie(n.time).pins.push(n.kind);const vi=Math.min(e.center-(e.span/2+.5)/mt,-.5);for(const{dt:n,texts:i,pins:h}of Te.values()){const[s,r,g]=v(vi,P,ct(n)),u=Math.sqrt(g*p),S=i.join(" · "),x=.25*u,k=`700 ${Bt}px ${o.num}`,J=.3*u/Bt,F=S?Jt(t,k,S).width*J:0,z=F+h.length*(.9*u+x);ke(k);let W=Math.max(s-.3*u,16+z);t.globalAlpha=Math.min(1,(E-n)/.4),S&&(t.save(),t.translate(W,r),t.scale(J,J),t.textAlign="right",t.lineWidth=Bt*.2,t.strokeStyle=I(o.ink,.9),t.strokeText(S,0,0),t.fillStyle=o.accent,t.fillText(S,0,0),t.restore(),W-=F+x);for(const O of h){const lt=W-.9*u,nt=.14*u,[X,at]=O==="cresc"?[lt,W]:[W,lt];for(const[b,St]of[[I(o.ink,.9),Math.max(3.5,.12*u)],[o.text,Math.max(1.5,.05*u)]])t.strokeStyle=b,t.lineWidth=St,t.beginPath(),t.moveTo(at,r-nt),t.lineTo(X,r),t.lineTo(at,r+nt),N();W=lt-x}}t.globalAlpha=1,ue("floor");const qt=[];for(let n=_e(l.notes,f-hi(l).held-.3);n<l.notes.length;n++){const i=l.notes[n];if(i.time>f+E)break;const h=Math.max(i.sustain,(i.slideTo??i.slideUnpitchTo??null)===null?0:.25,.15);i.time+h>=f-.05&&qt.push(i)}const me=n=>n.chord===null||n.chord===void 0?null:l.chords[n.chord],Pn=n=>o.repeatMarks==="frame"&&(n.repeat||me(n)?.highDensity),ge=n=>{const i=qe(L,n.time),h=n.fret===0;return{a:i,open:h,x:h?i.fret-1+i.width/2:n.fret-.5,y:st(n.string)}},an=(n,i,h)=>{const s=n.slideTo??n.slideUnpitchTo??null,r=Math.min(1,Math.max(0,h/Math.max(n.sustain,.25)));return s===null||n.fret===0?i:i+(s-.5-i)*r*r*(3-2*r)},On=(n,i)=>(Zi(n,i)*Ht(n.string)+Qi(n,i))*_*cn,Bn=n=>{const i=f-n.time;return i<0||n.fret===0||!(Oe(n)>0)?0:On(n,Math.min(i,Math.max(n.sustain,.15)))},sn=new Map;for(const n of qt){const i=n.time-f,h=Math.max(n.sustain,.15);i>0||-i>h||n.fret===0||!(Oe(n)>0)||sn.set(n.string,{note:n,x:n.fret-.5,dy:Bn(n)})}const wn=(n,i=0,h=!1)=>{const s=sn.get(n),r=st(n)+i,g=h?[[0,r,0]]:[rn?[rn[n][0],rn[n][1]+i,0]:[-.6,r,0],[0,r,0]];if(!s)return A([...g,[$t+.6,r,0]],!1);A([...g,[s.x,r+s.dy,0],[$t+.6,r,0]],!1)},ln=n=>st(n.string)+Bn(n),Xt=Ui[o.headstock],Ae=($-j)/2,vn=o.stringOrder==="high"?-1:1,le=([n,i])=>[-n*Ae/mt,xt/2+i*Ae*vn,0],Wn=n=>(st(n)-xt/2)*vn/Ae,jt=Xt&&qi(Xt,Array.from({length:U},(n,i)=>Wn(i))),rn=jt?.ends.map(le),yt=(n,i,h=1)=>{n&&(t.fillStyle=n,Y()),i&&(t.strokeStyle=i,t.lineWidth=h,N())},Pe=(n,i,h)=>{const[s,r]=le(n),[g,u]=v(s,r,0),[S]=v(s+i*Ae/mt,r,0),[,x]=v(s,r+h*Ae,0);t.beginPath(),t.ellipse(g,u,Math.abs(S-g),Math.abs(x-u),0,0,Math.PI*2)},Le=(n,i,h,s,r)=>A(li(`${n},${i},${h},${s},${r}`,()=>ai(n,i,h,s,r)).map(le)),Hn=()=>{for(const{u:h,side:s,edge:r}of jt.keys){const g=(u,S)=>[r+s*u,r+s*S];Xt.keys==="machine"?(Le(h-.15,h+.15,...g(-.12,.08),.03),yt(I(o.text,.12),I(o.anchorLane,.35)),Le(h-.03,h+.03,...g(.06,.22),0),yt(I(o.text,.28)),Le(h-.11,h+.11,...g(.2,.68),.1),yt(I(o.text,.18),I(o.anchorLane,.55))):(Le(h-.035,h+.035,...g(-.05,.22),0),yt(I(o.text,.28)),Pe([h,r+s*.18],.08,.04),yt(I(o.text,.3)),Pe([h,r+s*.4],.14,.2),yt(I(o.text,.18),I(o.anchorLane,.55)))}A(jt.outline.map(le));const[,n]=v(...le([0,1.6])),[,i]=v(...le([0,-1.2]));if(yt(mi(t,n,i,o.floor0,o.ink)),t.save(),t.clip(),yt(null,I(o.text,.07),.3*Ae*p),t.restore(),tt(!0,o.anchorLane,8),yt(null,I(o.anchorLane,.6),Math.max(1.5,.03*p)),tt(!1),Xt.cover){A(li(Xt.cover,()=>ri(Xt.cover)).map(le)),yt(I(o.text,.09),I(o.text,.4));for(const h of Xt.screws)Pe(h,.04,.04),yt(I(o.nut,.85))}},Nn=n=>Vn*(.7+.14*(U-1-n)),Wi=()=>{if(e.plate?.key!==In||e.plate.t!==o)return e.plate={key:In,t:o},Hn();const n=e.plate;if(!n.image){const[i,h]=[[],[]];for(const J of[...jt.outline,...jt.keys.map(({u:F,side:z,edge:W})=>[F,W+z*.8])]){const[F,z]=v(...le(J));i.push(F),h.push(z)}const s=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,r=Math.min(m,Math.max(...i)+24),g=Math.floor(Math.max(0,Math.min(...h)-24)*d)/d,u=Math.min(Ot,Math.max(...h)+24);n.image=new OffscreenCanvas(Math.max(1,Math.ceil((r-s)*d)),Math.max(1,Math.ceil((u-g)*d)));const[S,x,k]=[t,_t,Qt];[t,_t,Qt,n.x,n.y]=[n.image.getContext("2d"),0,null,s,g],t.setTransform(d,0,0,d,-s*d,-g*d),t.lineCap=t.lineJoin="round",Hn(),[t,_t,Qt]=[S,x,k]}t.drawImage(n.image,n.x,n.y,n.image.width/d,n.image.height/d)},Fn=()=>{t.fillStyle=o.board,A([[0,j,0],[$t+.6,j,0],[$t+.6,$,0],[0,$,0]]),Y(),t.fillStyle=I(o.anchorFill,.16),A([[e.left,j,0],[e.right,j,0],[e.right,$,0],[e.left,$,0]]),Y(),t.fillStyle=o.inlayDot;const n=s=>(Math.max(0,Math.ceil(s)-1)+.5)*_;t.beginPath();for(const s of Cn)for(const r of s%12?[n((U-1)/2)]:[n((U-1)/4),xt-n((U-1)/4)]){const[g,u,S]=v(s-.5,r,0);t.moveTo(g+.1*S,u),t.ellipse(g,u,.1*S,.08*S,0,0,Math.PI*2)}Y(),R>0&&(t.fillStyle=I(o.ink,.5),A([[0,j,0],[R-Rn,j,0],[R-Rn,$,0],[0,$,0]]),Y()),jt&&Wi();const[,i]=v(vt[0],$,0),[,h]=v(vt[0],j,0);t.strokeStyle=mi(t,i,h,I(o.anchorPost,.75),o.post),t.lineWidth=Math.max(1.5,.05*p),t.beginPath();for(let s=1;s<=$t;s++)ut([s,j-.04,0],[s,$+.04,0]);N(),t.strokeStyle=o.nut,t.lineWidth=Math.max(3,.12*p),H([0,j-.06,0],[0,$+.06,0]),tt(!0,o.anchorPost,12),t.strokeStyle=o.anchorPost,t.lineWidth=Math.max(3,.07*p);for(const s of[e.left,e.right])H([s,j-.14,0],[s,$+.14,0]);tt(!1);for(let s=0;s<U;s++){const r=Nn(s);tt(!0,Ft(s),3),t.strokeStyle=I(Ft(s),.9),t.lineWidth=r,wn(s),N(),tt(!1),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=Math.max(.6,r*.3),wn(s,.012),N()}if(jt&&(jt.ends.forEach(([s,r],g)=>{if(Xt.clamps)Le(s-.1,s+.1,r-.1,r+.1,.04),yt(I(o.text,.22),I(o.text,.45)),Pe([s,r],.05,.05),yt(o.nut);else{Pe([s,r],.17,.17),yt(I(o.ink,.5),I(o.nut,.4)),Pe([s,r],.085,.085),yt(o.nut),Pe([s,r],.03,.03),yt(I(o.ink,.85));const[u,S,x]=v(...rn[g]),[k,J]=v(0,st(g),0),F=Math.atan2(J-S,k-u);t.beginPath(),t.arc(u,S,.1*Ae*x,F-1.3,F+1.3),yt(null,Ft(g),Nn(g))}}),Xt.tree)){const s=[U-2,U-1].map(r=>{const[g,u]=jt.ends[r];return Wn(r)+(u-Wn(r))*Xt.tree/g});Le(Xt.tree-.05,Xt.tree+.05,Math.min(...s)-.08,Math.max(...s)+.08,.04),yt(I(o.nut,.7),I(o.ink,.6))}for(const s of[!1,!0])for(let r=1;r<=$t;r++){const g=r>=kt.fret&&r<kt.fret+kt.width,u=Cn.includes(r);(g||u)===s&&At(String(r),r-.5,j-.3,0,g?.3:u?.26:.2,g?o.accent:u?o.inlay:o.numOff,s?800:500,"center",!1)}},Ge=(n,i)=>v(n,i,0).slice(0,2).map(h=>Math.round(h*d*10)).join(":"),In=[o.headstock,U,_,vn,m,d,Math.round(mt*1e4),Ge(0,j),Ge($t,j),Ge(0,$),Ge($t,$),Ge(-4,xt/2)].join(),hn=!sn.size&&[In,kt.fret,kt.width,R,Math.round(e.left*1e3),Math.round(e.right*1e3)].join();if(!hn||e.board?.key!==hn||e.board.t!==o)e.board=hn&&{key:hn,t:o},Fn();else{const n=e.board;if(!n.drawn){const i=[[0,$+.2],[$t,$+.2],[0,j-.9],[$t,j-.9]].map(([u,S])=>v(u,S,0)[1]);jt&&i.push(...[...jt.outline,...jt.keys.map(({u,side:S,edge:x})=>[u,x+S*.8])].map(u=>v(...le(u))[1]));const h=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,s=Math.min(Ot,Math.max(...i)+24),[r,g]=[Math.ceil(m*d),Math.max(1,Math.ceil((s-h)*d))];(e.boardImage?.width!==r||e.boardImage.height!==g)&&(e.boardImage=new OffscreenCanvas(r,g)),[t,_t,Qt,n.y,n.drawn]=[e.boardImage.getContext("2d"),h,null,h,!0],t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,r,g),Ut(),t.lineCap=t.lineJoin="round",t.textBaseline="middle",Fn(),[t,_t,Qt]=[M,0,null]}t.drawImage(e.boardImage,0,n.y,e.boardImage.width/d,e.boardImage.height/d)}ue("board");const zn=(n,i)=>n.letRing&&-i>.25;for(const n of qt){const i=n.time-f;if(i>0||-i>Math.max(n.sustain,.15)||n.mute)continue;const h=Ft(n.string),s=ln(n);if(tt(!zn(n,i),h,10),t.strokeStyle=h,t.lineWidth=Vn+3,wn(n.string,0,!0),N(),tt(!1),-i<.2){const[r,g,u]=v(ge(n).x,s,0);t.save(),t.translate(r,g),t.scale(1,.4);const S=t.createRadialGradient(0,0,0,0,0,.5*u);S.addColorStop(0,I(o.flash,.8*(1+i/.2))),S.addColorStop(1,I(o.flash,0)),t.fillStyle=S,t.beginPath(),t.arc(0,0,.5*u,0,Math.PI*2),Y(),t.restore()}}t.strokeStyle=o.anchorLane,t.lineWidth=2.5,tt(!0,o.anchorLane,10);for(const n of l.handShapes??[]){if(n.startTime>f||n.endTime<=f||n.endTime-n.startTime<.3||!n.frets.some((s,r)=>s>=0&&r<U))continue;const[i,h]=rt(n.frets.filter((s,r)=>r<U),n.startTime);A([[i,j,0],[h,j,0],[h,$,0],[i,$,0]]),N()}if(tt(!1),R>0){const n=R-Rn;t.strokeStyle=o.nut,t.lineWidth=Math.max(4,.17*p),H([n,j-.16,0],[n,$+.16,0]),t.strokeStyle=I(o.ink,.45),t.lineWidth=Math.max(1,.05*p),H([n,j-.13,0],[n,$+.13,0])}ue("strings");for(const n of qt){const i=n.time-f,h=ct(i),s=me(n),{a:r,open:g,x:u,y:S}=ge(n),x=an(n,u,-i);if(i<-.15||Math.abs(v(x,S,h)[0]-m/2)>m/2+200)continue;const k=g?(r.width-.2)/2:.34;t.globalAlpha=i<0?Math.max(0,1+i/.15):Math.min(1,(E-i)/.4),!s&&Lt&&(t.strokeStyle=Lt,t.lineWidth=2,H([x-k,P,h],[x+k,P,h])),!(g||Pn(n))&&(t.strokeStyle=I(Ft(n.string),n.repeat||s?.highDensity?.35:.75),t.lineWidth=1.5,H([x,Math.min(S,ln(n))-.42*_,h],[x,P,h]))}t.globalAlpha=1;const Gn=(n,i,h)=>{const s=Array.from({length:13},(r,g)=>{const u=g/12;return[n[0]+(i[0]-n[0])*u,n[1]+(i[1]-n[1])*u+Math.sin(Math.PI*u)*h,n[2]+(i[2]-n[2])*u]});A(s,!1),N()};for(const n of eo(l)){if(n.end<=f||n.time>=f+E)continue;const[i,h]=rt(n.frets,n.time),s=n.time-f,r=ct(Math.max(s,0)),g=ct(Math.min(n.end-f,E));t.globalAlpha=Math.min(1,(E-Math.max(s,0))/.4),tt(!n.arpeggio,o.anchorLane,10,!0),t.strokeStyle=Wt(o.anchorLane,1,.2),t.lineWidth=3.5;for(const u of[i,h])H([u,P,r],[u,P,g]);tt(!1),n.arpeggio&&s>0&&(t.strokeStyle=I(o.anchorLane,.7),t.lineWidth=1.5,A([[i,P,r],[i,$,r],[h,$,r],[h,P,r]],!1),N(),n.arpeggio.name&&r>Re&&At(n.arpeggio.name,i-.12,$/2,r,.34,o.text,600,"right"))}t.globalAlpha=1;const $n=(n,i)=>{const h=ge(n);return Math.abs(h.x-i)<(h.open?(h.a.width-.2)/2+.1:.45)};for(const[n,i]of qt.entries()){const h=i.time-f,s=me(i),r=i.slideTo??i.slideUnpitchTo??null,{a:g,open:u,x:S,y:x}=ge(i),k=Ft(i.string),J=ct(h),F=(u?(g.width-.2)/2:.34)*(i.grace?.6:1),z=(u?.12:.42)*_*(i.grace?.6:1);if(h>-.15&&!s?.highDensity&&!i.repeat){if(t.globalAlpha=Math.min(1,(E-h)/.4),t.strokeStyle=k,t.lineWidth=2,t.setLineDash([4,4]),i.slideIn&&H([S+(i.slideIn==="below"?-1.4:1.4),x-z,Math.max(0,J-1)],[S+(i.slideIn==="below"?-F:F),x,J]),i.slideOut&&H([S+(i.slideOut==="up"?F:-F),x,J],[S+(i.slideOut==="up"?1.4:-1.4),x-z,J+1]),t.setLineDash([]),typeof i.tieTo=="number"){const G=l.notes[i.tieTo],q=ge(G);t.setLineDash([5,4]),Gn([S,x+z,J],[q.x,q.y+z,ct(G.time-f)],_*.9),t.setLineDash([])}t.globalAlpha=1}const W=r===null?i.sustain:Math.max(i.sustain,.25),O=r!==null||i.bend||i.bendCurve||i.whammy;if(W<=.2||h+W<=0||s&&!O||Pn(i))continue;u&&r&&(t.strokeStyle=k,t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]),Gn([S,x,ct(Math.max(h,0))],[r-.5,x,ct(Math.min(h+W,E))],_*1.5),t.setLineDash([]));let lt=null;for(let G=n+1;G<qt.length&&qt[G].time<=i.time+W+.02;G++){const q=qt[G];if(!(q.time<=i.time+.005)&&(me(q)||q.string===i.string||$n(q,S))){lt=q;break}}const nt=Math.max(h,0),X=i.bend||i.bendCurve||i.whammy;let at=Math.min(h+W,E,lt?lt.time-f:1/0);if(at<=nt)continue;const b=G=>{const q=G-h,it=ct(G),y=i.bend||i.bendCurve||i.whammy,T=i.vibrato&&!y?Math.sin(it/1.6*Math.PI*2)*_*(i.vibratoWide?.45:.25):0,C=i.tremolo?Math.floor(it/.3)%2?.05:-.05:0,Z=cn+(Bi-cn)*gi(Math.min(1,it/Hi));return[an(i,S,q)+C,x+T+On(i,q)*Z/cn,it]},St=lt&&b(at)[0],It=lt&&me(lt)?.notes.find(G=>$n(l.notes[G],St)),et=typeof It=="number"?l.notes[It]:lt;if(lt&&(X||$n(et,St))){const G=ge(et),q=ct(et.time-f),it=G.open?(G.a.width-.2)/2:.34,y=v(G.x,G.y-(G.open?.12:.42)*_,q)[1]+3,[T]=v(G.x-it,G.y,q),[C]=v(G.x+it,G.y,q),Z=K=>{const[Pt,pe]=v(...b(K));return pe<y&&Pt>Math.min(T,C)-2&&Pt<Math.max(T,C)+2};if(Z(at)&&!Z(nt)){let K=nt,Pt=at;for(let pe=0;pe<24;pe++)[K,Pt]=Z((K+Pt)/2)?[K,(K+Pt)/2]:[(K+Pt)/2,Pt];at=K}if(at<=nt+.001)continue}const De=r===null&&!X&&!i.vibrato&&!i.tremolo?1:Math.min(400,Math.max(12,Math.ceil((at-nt)*dt*8))),Mt=Array.from({length:De+1},(G,q)=>b(nt+(at-nt)*q/De));if(u&&!s){t.fillStyle=Wt(k,i.letRing?.14:.26,.03),A([...Mt.map(([G,q,it])=>[G-F,q,it]),...Mt.slice().reverse().map(([G,q,it])=>[G+F,q,it])]),Y(),tt(!i.letRing,k,6,!0),t.strokeStyle=Wt(k,.95,.3),t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]);for(const G of[-F,F])A(Mt.map(([q,it,y])=>[q+G,it,y]),!1),N();t.setLineDash([]),tt(!1)}else if(i.bend||i.bendCurve||i.whammy){const G=q=>A([...Mt.map(([it,y,T])=>[it-q,y,T]),...Mt.slice().reverse().map(([it,y,T])=>[it+q,y,T])]);G(dn),t.fillStyle=Wt(k,1,.6),Y(),G(dn*.35),t.fillStyle=Wt(_n(k,-.22),1,.55),Y(),tt(!0,k,8,!0),t.strokeStyle=Wt(_n(k,.6),1,.5),t.lineWidth=2;for(const q of[-dn,dn])A(Mt.map(([it,y,T])=>[it+q,y,T]),!1),N();tt(!1)}else tt(!i.letRing,k,6,!0),t.fillStyle=Wt(k,i.letRing?.4:.75,i.letRing?.15:.3),A([...Mt.map(([G,q,it])=>[G-.09,q,it]),...Mt.slice().reverse().map(([G,q,it])=>[G+.09,q,it])]),Y(),tt(!1);if((i.letRing||r!==null||!X&&(i.vibrato||i.tremolo))&&(t.strokeStyle=Wt(i.letRing?k:"#ffffff",.75,.3),t.lineWidth=i.letRing?2:1.5,t.setLineDash(i.letRing?[7,6]:[]),A(Mt,!1),N(),t.setLineDash([])),r!==null&&at>=Math.min(h+W,E)-.001){const[G,q,it]=b(h+W);t.strokeStyle=k,t.lineWidth=2,t.setLineDash(i.slideTo===null?[5,4]:[]),u?Tt(r-.5,q,it,.34,.42*_):Tt(G,q,it,F,z),N(),t.setLineDash([])}}ue("trails");const Un=new Set;for(let n=qt.length-1;n>=0;n--){const i=qt[n],h=i.time-f,s=ct(h),r=me(i),{a:g,open:u,x:S}=ge(i),x=an(i,S,-h),k=ln(i),J=i.mute||r?.fretHandMute,F=i.palmMute||r?.palmMute,z=Ft(i.string),W=(u?(g.width-.2)/2:.34)*(i.grace?.6:1),O=(u?.12:.42)*_*(i.grace?.6:1),lt=i.slideTo??i.slideUnpitchTo??null;if(h<-.15)continue;const nt=h<0?Math.max(0,1+h/.15):Math.min(1,(E-h)/.4);if(t.globalAlpha=nt,r&&!Un.has(i.chord)){Un.add(i.chord);const[y,T]=rt(r.notes.map(ht=>l.notes[ht].fret),i.time),C=t.globalAlpha,Z=s<Re,K=Z?.65:r.highDensity&&o.repeatMarks!=="frame"?.18:.5;if(A([[y,P,s],[T,P,s],[T,$,s],[y,$,s]]),o.frames==="gradient"){const[,ht]=v(y,P,s),[,Et]=v(y,$,s),Dt=Z?o.anchorLane:o.anchorFill;ze(di(t,`${Dt}|${K}`,[[0,I(Dt,K*.6)],[1,I(Dt,0)]]),ht,Et)}else t.globalAlpha=C*K,r.highDensity||(t.fillStyle=o.chordFill,Y()),t.strokeStyle=Z?o.anchorLane:o.chordBox,t.lineWidth=Z||!r.highDensity?1.5:1.2,tt(Z,o.anchorLane,8),N(),tt(!1);if(t.globalAlpha=C,t.strokeStyle=Lt,t.lineWidth=2,Lt&&H([y,P,s],[T,P,s]),r.highDensity&&(r.palmMute||r.fretHandMute)&&(t.strokeStyle=r.palmMute?o.muted:"#ffffff",fe((y+T)/2,P+_*.4,s,r.palmMute?.22:.12,_*(r.palmMute?.35:.22))),r.accent){const ht=Math.min(.6,(T-y)*.22),Et=($-P)*.35,Dt=Math.min(1,v(y,$,s)[2]/v(y,$,Re)[2]);t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,3.5*Dt*(r.accent==="heavy"?1.4:1)),t.lineCap="square",tt(!0,"#ffffff",Math.max(2,12*Dt)),A([[y,$-Et,s],[y,$,s],[y+ht,$,s]],!1),N(),A([[T-ht,$,s],[T,$,s],[T,$-Et,s]],!1),N(),tt(!1),t.lineCap="round"}if(r.barre&&(!r.highDensity||o.repeatMarks==="grey")){const ht=r.barre.fret-.5;t.strokeStyle=r.highDensity?o.muted:"rgba(255, 255, 255, 0.7)",t.lineWidth=Math.max(3,.1*v(ht,xt/2,s)[2]);const[Et,Dt]=[st(r.barre.from),st(r.barre.to)].sort((re,Kt)=>re-Kt);H([ht,Et-_*.4,s],[ht,Dt+_*.4,s]),At(r.barre.half?"½B":"B",ht,$+.12,s,.22,r.highDensity?o.muted:o.text)}if(r.strum||r.roll){const ht=y-.25,Et=st(0)>st(U-1)?$-.1:P+.15,Dt=Et>xt/2?P+.15:$-.1,[re,Kt]=(r.strum??r.roll)==="down"?[Et,Dt]:[Dt,Et];t.strokeStyle=o.text,t.lineWidth=2,r.roll?A(Array.from({length:17},(so,Kn)=>[ht+Math.sin(Kn/16*Math.PI*6)*.06,re+(Kt-re)*Kn/16,s]),!1):A([[ht,re,s],[ht,Kt,s]],!1),N();const Ce=Kt<re?.14:-.14;H([ht-.08,Kt+Ce,s],[ht,Kt,s]),H([ht+.08,Kt+Ce,s],[ht,Kt,s])}const Pt=l.chords[i.chord-1],pe=!Pt||i.time-Pt.time>1||Pt.name!==r.name;s>Re&&r.name&&!r.highDensity&&pe&&At(r.name,y-.12,$/2,s,.34,o.text,600,"right")}const[X,at,b]=v(x,k,s);if(X<-200||X>m+200||Pn(i)){t.globalAlpha=1;continue}const St=i.repeat||r?.highDensity;if(St){const y=s<Re;t.globalAlpha*=y?.9:.4,t.strokeStyle=z,t.lineWidth=y?2:1.5,tt(y,z,8),Tt(x,k,s,W,O),N(),tt(!1),(J||F)&&o.repeatMarks!=="hide"&&Ie(x,k,s,b,u?.34:W,u?_*.3:O,F,o.muted),t.globalAlpha=nt}else{if(!u&&he){const y=i.harmonic||i.harmonicPinch?`<${i.fret}>`:i.ghost?`(${i.fret})`:String(i.fret),T=i.grace?.7:1;ee(y,x,s,ti*T,ei*T,I(z,he))}if(i.dynamicLabel&&At(i.dynamicLabel,x-.6,P,s,.3,o.text,"italic 700","right"),i.ghost&&(t.globalAlpha=nt*.5),o.gem==="pill")o.notes3d!==!1&&(Tt(x,k,s+Zn,W,O),t.fillStyle=z,Y(),t.fillStyle="rgba(255, 255, 255, 0.35)",Y()),Tt(x,k,s,W,O),t.fillStyle=z,Y();else{const y=i.harmonic||i.harmonicPinch,T=Zn;if(!y&&o.notes3d!==!1)for(const[K,Pt]of[[[[x-W,k+O,s],[x+W,k+O,s],[x+W,k+O,s+T],[x-W,k+O,s+T]],"rgba(255, 255, 255, 0.35)"],[[[x-W,k-O,s],[x-W,k+O,s],[x-W,k+O,s+T],[x-W,k-O,s+T]],"rgba(0, 0, 0, 0.4)"],[[[x+W,k-O,s],[x+W,k+O,s],[x+W,k+O,s+T],[x+W,k-O,s+T]],"rgba(0, 0, 0, 0.4)"]])A(K),t.fillStyle=z,Y(),t.fillStyle=Pt,Y();tt(s<Re,z,8),t.fillStyle=z,y?A([[x,k+O*1.3,s],[x+W*.8,k,s],[x,k-O*1.3,s],[x-W*.8,k,s]]):Tt(x,k,s,W,O),Y(),tt(!1);const[,C]=v(x,k+O,s),[,Z]=v(x,k-O,s);ze(di(t,"shine",[[0,"rgba(255, 255, 255, 0.45)"],[.5,"rgba(255, 255, 255, 0)"],[1,"rgba(0, 0, 0, 0.25)"]]),C,Z),t.strokeStyle="rgba(255, 255, 255, 0.6)",t.lineWidth=1,N()}if((J||F)&&Ie(x,k,s,b,u?.34:W,u?_*.3:O,F,u&&F?z:null),!u&&!J&&!F){const y=i.finger??(r?.fingers?.[i.string]>=0?r.fingers[i.string]:null),T=y!==null?y===0?"T":String(y):"";if(T){const C=t.globalAlpha;t.globalAlpha=C*Math.min(1,Math.max(0,(1-h/E)/.4)),At(T,x,k,s-.01,_*.62,Zt,700,"center",We,!0),t.globalAlpha=C}}}if(St&&o.repeatMarks==="hide"){t.globalAlpha=1;continue}const It=St?o.muted:o.text;if(t.globalAlpha=nt*(St?.8:1)*Math.min(1,Math.max(0,(1-h/E)/.15)),i.ghost){const[y]=v(x-W,k,s),[T]=v(x+W,k,s),C=O*b*1.5;t.strokeStyle=St?It:z,t.lineWidth=Math.max(1.2,.035*b),t.beginPath(),t.arc(y+C*.35,at,C,Math.PI*.7,Math.PI*1.3),N(),t.beginPath(),t.arc(T-C*.35,at,C,-Math.PI*.3,Math.PI*.3),N()}if(i.grace&&(t.strokeStyle=It,t.lineWidth=Math.max(1,.03*b),Xe(t,X-W*b*mt*1.2,at+O*b*1.4,X+W*b*mt*1.2,at-O*b*1.4)),i.showString){const[y]=v(x-W,k,s),T=.12*b,C=y-T-.06*b;t.strokeStyle=t.fillStyle=St?It:z,t.lineWidth=Math.max(1,.025*b),t.beginPath(),t.arc(C,at,T,0,Math.PI*2),N(),oe(String(U-i.string),C,at,.15*b,700,"center"),t.fillText(String(U-i.string),0,0),Ut()}let et=at-O*b-.18*b;t.strokeStyle=t.fillStyle=It,t.lineWidth=Math.max(1.2,.04*b),t.textAlign="center";const Dn=(y,T,C)=>{t.beginPath();for(let Z=0;Z<=20;Z++)t[Z?"lineTo":"moveTo"](X-y+2*y*Z/20,et+Math.sin(Z/20*Math.PI*2*C)*T);N()},De=(y,T,C="700")=>{T*b<2||(oe(y,X,et,T*b,C,"center"),t.fillText(y,0,0),Ut(),et-=(T+.04)*b)};let Mt=at-O*b;const G=i.tap&&!i.tapLeft;if((i.hammerOn||i.pullOff)&&!G){const y=i.grace?.6:1,T=.2*b*mt*y,C=.38*_*b*y,[Z,K]=i.hammerOn?[Mt+.4*C,Mt-.6*C]:[Mt-.6*C,Mt+.4*C];t.beginPath(),t.moveTo(X-T,K),t.lineTo(X+T,K),t.lineTo(X,Z),t.closePath(),t.fillStyle=St?It:"#ffffff",t.strokeStyle=I(o.ink,.9),t.lineWidth=Math.max(1.5,.03*b),N(),Y(),Mt-=.6*C,et=Math.min(et,Mt-.14*b),t.strokeStyle=t.fillStyle=It,t.lineWidth=Math.max(1.2,.04*b)}if(G){const y=i.grace?.6:1,T=.28*b*mt*y,C=.62*_*b*y,Z=Mt+.15*C,K=Z-C;t.beginPath(),t.moveTo(X,Z),t.lineTo(X+T,K),t.lineTo(X,K+.38*C),t.lineTo(X-T,K),t.closePath(),t.strokeStyle=I(o.ink,.9),t.lineWidth=Math.max(3.5,.1*b),N(),t.fillStyle=St?I(It,.4):I(_n(z,.55),.85),Y(),t.strokeStyle=St?It:z,t.lineWidth=Math.max(1.8,.05*b),N(),Mt=K,et=Math.min(et,Mt-.14*b),t.strokeStyle=t.fillStyle=It,t.lineWidth=Math.max(1.2,.04*b)}const q=Oe(i);if(q>0){const y=i.bendCurve?.[0]?.[1]>0,T=(i.bendCurve?.length??0)>1&&i.bendCurve.at(-1)[1]<q,C=Math.min(3,Math.max(1,Math.round(q*2))),Z=W*b*mt*.6,K=W*b*.3,Pt=K*1.25,pe=I(o.ink,.9);let ht=Mt-.04*b;const Et=Kt=>{for(let Ce=0;Ce<C;Ce++)Ai(t,X,ht-Ce*Pt-(Kt>0?0:K),Z,K,Kt,St?It:z,pe);ht-=C*Pt+.08*b},Dt=Ht(i.string);(!y||!T)&&Et(-Dt),T&&Et(Dt);const re=`${y?"pre ":""}${yi(q)}`;t.fillStyle=It,oe(re,X+Z+.08*b,(at-O*b+ht)/2,.22*b,700,"left"),t.fillText(re,0,0),Ut(),t.textAlign="center",et=Math.min(et,ht-.1*b)}i.staccato&&(t.beginPath(),t.arc(X,et+.04*b,Math.max(1.5,.045*b),0,Math.PI*2),Y(),et-=.16*b),i.accent&&(i.accent==="tenuto"||!r?.accent)&&De({heavy:"^",tenuto:"–"}[i.accent]??">",.3);const it=[i.tapLeft?"m.g.":"",bi[i.harmonicType]??(i.harmonicPinch?"PH":""),i.slap?"slap":i.pop?"pop":"",i.golpe?`golpe (${i.golpe})`:"",i.rasgueado?`rasg. ${i.rasgueado}`:"",typeof i.trill=="number"?`tr ${i.trill}`:"",i.ornament??"",i.fade??"",i.whammy?"w/bar":"",i.wah==="open"?"o":i.wah==="closed"?"+":""];for(const y of it)y&&De(y,y.length>2?.22:.28);if(i.rightFinger&&De(i.rightFinger,.26,"italic 700"),i.vibrato&&(Dn(.24*b,(i.vibratoWide?.07:.035)*b,2),et-=(.16+(i.vibratoWide?.06:0))*b),i.pick){const y=.09*b,T=.13*b;t.beginPath(),i.pick==="down"?[[-y,T/2],[-y,-T/2],[y,-T/2],[y,T/2]].forEach(([C,Z],K)=>t[K?"lineTo":"moveTo"](X+C,et+Z)):[[-y,-T/2],[0,T/2],[y,-T/2]].forEach(([C,Z],K)=>t[K?"lineTo":"moveTo"](X+C,et+Z)),N(),et-=.22*b}if(i.fermata&&(t.beginPath(),t.arc(X,et+.06*b,.14*b,Math.PI,0),N(),t.beginPath(),t.arc(X,et+.02*b,Math.max(1.5,.03*b),0,Math.PI*2),Y(),et-=.24*b),i.tremolo){for(let y=-1;y<=1;y++)Xe(t,X-.12*b,et+(y*.08+.05)*b,X+.12*b,et+(y*.08-.05)*b);et-=.3*b,Dn(.14*b,.04*b,1.5),et-=.14*b}if(lt!==null&&!u){const y=Math.sign(lt-i.fret)||1,T=X-y*.16*b,C=X+y*.16*b,Z=et+.07*b,K=et-.09*b;Xe(t,T,Z,C,K),Xe(t,C,K,C-y*.1*b,K),Xe(t,C,K,C,K+.1*b),et-=.3*b}t.globalAlpha=1}ue("notes");const Yn=new Set;for(const n of qt){const i=n.time-f,h=me(n);if(!h?.barre||Yn.has(h)||i>.06||i<-Math.max(n.sustain,.12))continue;Yn.add(h),t.strokeStyle="rgba(255, 255, 255, 0.85)",t.lineWidth=Math.max(4,.12*p);const[s,r]=[st(h.barre.from),st(h.barre.to)].sort((g,u)=>g-u);H([h.barre.fret-.5,s-_*.45,0],[h.barre.fret-.5,r+_*.45,0])}const qn=new Set,Xn=new Set;for(const n of qt){const i=n.time-f,h=me(n),s=sn.get(n.string),r=n.heldFrom??null,g=i<=.06||r!==null&&f>=r-.06,u=(n.slideTo??n.slideUnpitchTo??null)!==null;if(n.mute||i>fn||i<-Math.max(n.sustain,u?.25:.12)||(h?.highDensity||r!==null)&&!g||s&&s.note!==n&&!g||g&&qn.has(`${n.string}:${n.fret}`))continue;g&&qn.add(`${n.string}:${n.fret}`),Xn.add(`${n.string}:${n.fret}`);const{a:S,open:x,x:k}=ge(n),J=an(n,k,-i),F=ln(n),z=Ft(n.string),W=(x?(S.width-.2)/2:.32)+2/p,O=(x?.1:.36)*_+2/p;if(Tt(J,F,0,W,O),g)tt(!zn(n,i),z,14),t.fillStyle=z,Y(),tt(!1),t.strokeStyle="rgba(255, 255, 255, 0.7)",t.lineWidth=1.5,N();else{const nt=(1-i/fn)**2;t.globalAlpha=.35*nt,t.fillStyle=z,Y(),t.globalAlpha=.25+.75*nt,t.strokeStyle=z,t.lineWidth=2.2,N()}const lt=n.finger??(h?.fingers?.[n.string]>=0?h.fingers[n.string]:null);if(!x&<!==null&&At(lt===0?"T":String(lt),J,F,0,_*.55,g?Zt:o.text,800,"center",!g||We),!x&&Oe(n)>0){const nt=Ht(n.string),X=n.bendCurve?.[0]?.[1]>0&&n.bendCurve.at(-1)[1]<Oe(n),[at,b]=v(J,F+nt*O,0);Ai(t,at,b-nt*(X?.14:.05)*p,.17*p*mt,.085*p,(X?1:-1)*nt,"#ffffff",I(o.ink,.9))}t.globalAlpha=1}for(const n of l.handShapes??[])!n.arpeggio||n.startTime-f>fn||n.endTime<=f||(t.globalAlpha=.3+.5*Math.min(1,1-(n.startTime-f)/fn)**2,n.frets.forEach((i,h)=>{if(i<=0||h>=U||Xn.has(`${h}:${i}`))return;const s=i-.5,r=st(h),g=n.fingers[h];Tt(s,r,0,.32+2/p,.36*_+2/p),t.strokeStyle=Ft(h),t.lineWidth=2.2,N(),g>=0&&At(g===0?"T":String(g),s,r,0,_*.55,o.text,800)}),t.globalAlpha=1);ue("targets");const jn=to(l),Ln=jn.findLast(n=>n.time<=f&&f<n.end+.3),Ii=Ln?null:jn.find(n=>n.time>f&&n.time-f<1.2),Ue=Ln??Ii;if(Ue){const[n,i]=v(e.right+.4,$+.5,0),h=Jt(t,ce[700]??=`700 ${Bt}px ${o.num}`,Ue.name).width*52/Bt;t.globalAlpha=Ln?1:Math.max(.35,1-(Ue.time-f)/1.2),t.fillStyle=o.text,oe(Ue.name,Math.min(n,m-24-h),i,52,700,"left"),t.fillText(Ue.name,0,0),Ut(),t.globalAlpha=1}ue("labels")}const io=240,oo=64,xe=100,Be=24,wi=150;function ao(a,l){if(a.tabPages?.length===l)return a.tabPages.pages;const f=a.notes.at(-1),o=Math.max(f?f.time+f.sustain:0,a.beats.at(-1)?.time??0)+.5;let e=a.beats.filter(d=>d.measure>=0).map(d=>d.time);e.length<2&&(e=Array.from({length:Math.ceil(o/l)+1},(d,t)=>t*l)),e=[Math.min(0,e[0]),...e.filter(d=>d>0),Math.max(o,e.at(-1)+.01)];const M=[];let m=e[0];for(let d=1;d<e.length;d++)e[d]-m>l&&e[d-1]>m&&M.push({start:m,end:m=e[d-1]});M.push({start:m,end:e.at(-1)});for(let d=0;d<M.length-1;d++)M[d].end=M[d+1].start;return a.tabPages={length:l,pages:M},M}function fo(a,l,f,o){const{g:e,W:M}=Pi(a);if(!l)return;const m=l.strings,d=Math.min(oo,320/Math.max(1,m-1))*(o.boardHeight??1),t=Ot*.62-d*(m-1)/2,L=t+d*(m-1),R=t-d*1.65,kt=L+d*1.45,U=w=>t+(o.stringOrder==="high"?m-1-w:w)*d,wt=io*(o.noteSpeed??1),_=o.tabLayout==="pages",xt=xe+30,st=M-Be-30,Ht=_?Math.min(170,(st-xt)*.14):0,dt=st-(_?Ht+24:0);let E,j,$,P,Nt=null;if(_){const w=ao(l,(dt-xt)/wt),Q=Math.max(0,w.findLastIndex(Ct=>Ct.start<=f)),V=w[Q],bt=(dt-xt)/(V.end-V.start);E=Ct=>xt+(Ct-V.start)*bt,[$,P]=[V.start,V.end-.001],j=E(Math.min(Math.max(f,V.start),V.end)),w[Q+1]&&(Nt={start:w[Q+1].start,scale:bt})}else j=Math.max(xe+wi+60,M*.2),E=w=>j+(w-f)*wt,[$,P]=[f-(j-xe)/wt,f+(M-j)/wt];const ct=w=>o.str[w%o.str.length],Ft=w=>w.chord===null||w.chord===void 0?null:l.chords[w.chord],Lt=(w,Q,V,bt)=>{e.beginPath(),e.moveTo(w,Q),e.lineTo(V,bt),e.stroke()},he=(w,Q,V,bt)=>{const Ct=Math.hypot(V,bt),[te,zt]=[V/Ct,bt/Ct];Lt(w,Q,w-6*te-4*zt,Q-6*zt+4*te),Lt(w,Q,w-6*te+4*zt,Q-6*zt-4*te)},Vt=w=>w>=j-1?1:.4;e.lineCap="round",e.lineJoin="round",e.textBaseline="alphabetic";const vt=[],we=w=>{w&&(e.save(),e.beginPath(),e.rect(w[0],0,w[1]-w[0],Ot),e.clip());const Q=`600 ${Me(Math.min(15,d*.26))}px ${o.num}`,V=`700 ${Me(Math.min(13,d*.22))}px ${o.num}`,bt=new Map;e.font=Q,e.textAlign="left";const Ct=new Path2D,te=new Path2D;e.fillStyle=o.muted;for(let p=_e(l.beats,$-1);p<l.beats.length;p++){const c=l.beats[p];if(c.time>P)break;const D=E(c.time),gt=c.measure>=0,A=gt?Ct:te;A.moveTo(D,t-d*.35),A.lineTo(D,L+d*.35),gt&&(e.fillText(String(c.measure),D+6,R+d*.36),bt.set(Math.round(c.time*50),Jt(e,Q,String(c.measure)).width+16))}e.lineWidth=1,e.strokeStyle=I(o.text,.05),e.stroke(te),e.lineWidth=1.5,e.strokeStyle=I(o.text,.16),e.stroke(Ct),e.fillStyle=o.accent;const zt=new Map;for(const p of l.markers??[])p.time>=$&&p.time<=P&&zt.set(Math.round(p.time*50),[...zt.get(Math.round(p.time*50))??[],p.text]);for(const[p,c]of zt)e.fillText([...new Set(c)].join(" · "),E(p/50)+6+(bt.get(p)??0),R+d*.36);e.strokeStyle=I(o.text,.14),e.beginPath();for(let p=0;p<m;p++)e.moveTo(xe,U(p)),e.lineTo(M-Be,U(p));e.stroke();const ve=L+d*.92,Rt=L+d*1.24;if(o.guides!==!1){e.font=Q,e.fillStyle=e.strokeStyle=o.anchorLane,e.lineWidth=2;let p=-1/0;const c=l.anchors??[];for(let D=Math.max(1,_e(c,$));D<c.length&&c[D].time<=P;D++){const gt=c[D],A=E(gt.time);if(A<p)continue;const H=`fret ${gt.fret}`;e.globalAlpha=Vt(A),Lt(A,L+d*.6,A,ve-2),e.fillText(H,A+5,ve),p=A+5+Jt(e,Q,H).width+8}e.globalAlpha=1}e.strokeStyle=o.text,e.lineWidth=1.5;for(const p of l.hairpins??[]){if(p.endTime<$||p.time>P)continue;const c=E(p.time),D=Math.max(c+30,E(p.endTime)),[gt,A]=p.kind==="cresc"?[c,D]:[D,c];e.globalAlpha=Vt(D),e.beginPath(),e.moveTo(A,Rt-11),e.lineTo(gt,Rt-5),e.lineTo(A,Rt+1),e.stroke()}e.globalAlpha=1;const be=Me(Math.min(26,d*.42)),Gt=be*1.3,Ke=be*.32,Je=o.gem==="pill"?Gt/2:5,mt={note:`700 ${be}px ${o.num}`,grace:`700 ${Me(be*.72)}px ${o.num}`,finger:`700 ${Me(be*.5)}px ${o.num}`},Ve=o.markings==="white";for(const p of l.handShapes??[]){if(!p.arpeggio||p.endTime<$||p.startTime>P)continue;const c=p.frets.flatMap((A,H)=>A>=0&&H<m?[U(H)]:[]);if(!c.length)continue;const D=E(p.startTime)-12,gt=E(p.endTime);e.globalAlpha=Vt(gt),e.strokeStyle=I(o.text,.4),e.lineWidth=1.5,e.setLineDash([6,5]),e.beginPath(),e.roundRect(D,Math.min(...c)-Gt/2-6,gt-D,Math.max(...c)-Math.min(...c)+Gt+12,8),e.stroke(),e.setLineDash([]),p.name&&(e.font=`700 ${Me(Math.min(24,d*.4))}px ${o.num}`,e.fillStyle=o.text,e.fillText(p.name,D,t-d*.72))}e.globalAlpha=1;const Ne=p=>(p.slideTo??p.slideUnpitchTo??null)!==null||!!p.slideOut,bn=p=>{const c=Ft(p);return!!c&&!p.repeat&&!c.highDensity&&c.notes.length>1},yn=(p,c)=>4+(Ne(p)?16:0)+(bn(c)?10:0)+(c.slideIn?18:0)+(c.showString?20:0);let Ze=0,Fe=0;const ye=(p,c)=>{c(Fe-p/2),Fe-=p+3},Sn={"":V,"italic ":`italic ${V}`},Se=(p,c="")=>ye(10,D=>{e.font=Sn[c],e.fillText(p,Ze,D+5)}),{next:kn,prev:Qe,held:Tn}=hi(l),tn=new Map,en=new Set,v=[],nn=[];for(let p=_e(l.notes,$-Tn-.5);p<l.notes.length;p++){const c=l.notes[p];if(c.time>P)break;if(E(c.time+c.sustain)<xe-40-Gt*4||w&&c.time<$&&E(c.time+c.sustain)-2<=E($)&&typeof c.tieTo!="number")continue;const D=Ft(c),gt=c.grace?.72:1,A=Gt*gt,H=U(c.string),Tt=ct(c.string),rt=E(c.time),fe=c.mute||D?.fretHandMute,We=c.palmMute||D?.palmMute,Zt=c.repeat||D?.highDensity,Ie=fe?"×":c.harmonic||c.harmonicPinch?`<${c.fret}>`:c.ghost?`(${c.fret})`:String(c.fret),Qt=c.finger??(D?.fingers?.[c.string]>=0?D.fingers[c.string]:null),_t=fe||c.fret===0||Qt===null?"":Qt===0?"T":String(Qt),ke=c.grace?mt.grace:mt.note,ce=Jt(e,ke,Ie).width,oe=_t?Jt(e,mt.finger,_t).width+3:0,Ut=l.notes[kn[p]],ze=Ut?E(Ut.time)-yn(c,Ut):1/0,At=Math.min(Math.max(A,ce+oe+Ke*2*gt),Math.max(10,ze-rt)),ee=Math.max(rt+At,Math.min(E(c.time+c.sustain)-2,ze)),pt=rt+At/2,$e=Math.min(1,(At-4)/(ce+oe)),Wt=tn.get(c.string)??(Qe[p]>=0?{x0:E(l.notes[Qe[p]].time),w:Gt}:null);if(tn.set(c.string,{x0:rt,w:At}),ee<xe-40&&typeof c.tieTo!="number")continue;const Yt=c.time<=f&&f<c.time+Math.max(c.sustain,.15),tt=(Yt||rt>=j-1?1:.4)*(c.ghost?.55:1);if(e.globalAlpha=tt,D&&!en.has(D)){en.add(D);const de=D.notes.map(B=>U(l.notes[B].string)),ae=Math.min(...de)-Gt/2,N=Math.max(...de)+Gt/2,Y=rt-7;if(de.length>1&&!Zt&&(e.strokeStyle=D.accent?"#ffffff":I(o.text,.7),e.lineWidth=D.accent==="heavy"?4:D.accent?3:2,e.beginPath(),e.moveTo(Y+4,ae),e.lineTo(Y,ae),e.lineTo(Y,N),e.lineTo(Y+4,N),e.stroke()),e.font=V,e.fillStyle=e.strokeStyle=Zt?o.muted:o.text,e.lineWidth=1.8,e.textAlign="left",D.barre&&!Zt&&e.fillText(`${D.barre.half?"½":""}B${D.barre.fret}`,Y,ae-5),D.strum||D.roll){const B=D.notes.map(ie=>l.notes[ie].string),ot=U(Math.min(...B)),ft=U(Math.max(...B)),[ut,ne]=(D.strum??D.roll)==="down"?[ot,ft]:[ft,ot],Te=Y-9;e.beginPath();for(let ie=0;ie<=16;ie++)e.lineTo(Te+(D.roll?Math.sin(ie/16*Math.PI*6)*2.5:0),ut+(ne-ut)*ie/16);e.stroke(),he(Te,ne,0,ne-ut||1)}const se=l.chords[c.chord-1];D.name&&!Zt&&(!se||c.time-se.time>1||se.name!==D.name)&&(e.font=`700 ${Me(Math.min(24,d*.4))}px ${o.num}`,e.fillStyle=o.text,e.fillText(D.name,rt,t-d*.72))}e.beginPath(),e.roundRect(rt,H-A/2,ee-rt,A,Je*gt),Yt&&!Zt&&(e.shadowColor=Tt,e.shadowBlur=18),Zt?(e.strokeStyle=Tt,e.lineWidth=2,e.stroke()):c.letRing&&ee>rt+At+2?(e.fillStyle=I(Tt,.3),e.fill(),e.shadowBlur=0,e.strokeStyle=Tt,e.lineWidth=2,e.setLineDash([6,5]),Lt(rt+At+4,H,ee-4,H),e.setLineDash([]),e.beginPath(),e.roundRect(rt,H-A/2,At,A,Je*gt),e.fillStyle=Tt,e.fill()):(e.fillStyle=fe?I(o.text,.22):Tt,e.fill()),e.shadowBlur=0,Yt&&vt.push({y:H,c:Tt});const An=Zt?Tt:fe?o.text:Ve?"#ffffff":o.ink;v.push({text:Ie,font:ke,finger:_t,fill:An,shown:tt,squeeze:$e,x:pt,y:H+Jt(e,ke,Ie).middle,left:-(ce+oe)/2,textWidth:ce}),nn.push(()=>{e.globalAlpha=tt;const de=Zt?o.muted:o.text;e.strokeStyle=e.fillStyle=de,e.lineWidth=1.6;const ae=c.slideTo??c.slideUnpitchTo??null,N=ae===null?c.slideOut==="up"?1:c.slideOut?-1:0:Math.sign(ae-c.fret)||1;if(N){const B=c.slideTo===null&&c.slideUnpitchTo!==null&&c.slideUnpitchTo!==void 0;B&&e.setLineDash([3,3]),Lt(ee+4,H+N*A*.3,ee+14,H-N*A*.3),B&&e.setLineDash([])}if(c.slideIn&&Lt(rt-16,H+(c.slideIn==="below"?1:-1)*A*.3,rt-6,H-(c.slideIn==="below"?1:-1)*A*.3),typeof c.tieTo=="number"){const B=E(l.notes[c.tieTo].time)+A/2;e.setLineDash([4,3]),e.beginPath(),e.moveTo(pt,H+A/2+3),e.quadraticCurveTo((pt+B)/2,H+A/2+14,B,H+A/2+3),e.stroke(),e.setLineDash([])}if(c.showString){const B=rt-(D?26:13);e.beginPath(),e.arc(B,H,8,0,Math.PI*2),e.stroke(),e.font=mt.finger,e.textAlign="center",e.fillText(String(m-c.string),B,H+Jt(e,mt.finger,"1").middle)}c.dynamicLabel&&(e.font=`italic ${V}`,e.textAlign="left",e.fillStyle=o.text,e.fillText(c.dynamicLabel,rt,Rt),e.fillStyle=de);let Y=H-A/2-6;if(c.vibrato){e.beginPath();for(let B=rt+2;B<=Math.max(ee,rt+24)-2;B+=2)e.lineTo(B,Y+Math.sin((B-rt)/3)*(c.vibratoWide?3:1.8));e.stroke(),Y-=c.vibratoWide?10:8}if(e.textAlign="center",e.font=V,(c.hammerOn||c.pullOff)&&Wt){const B=Wt.x0+Wt.w/2,ot=(B+pt)/2;e.beginPath(),e.moveTo(B,Y),e.quadraticCurveTo(ot,Y-12,pt,Y),e.stroke(),e.fillText(c.hammerOn?"H":"P",ot,Y-9),Y-=10}const se=Oe(c);if(se>0){const B=c.bendCurve?.[0]?.[1]>0,ot=(c.bendCurve?.length??0)>1&&c.bendCurve.at(-1)[1]<se,ft=rt+At-2,ut=H-A/2,ne=ut-16;e.beginPath(),B?(e.moveTo(ft,ut),e.lineTo(ft,ne)):(e.moveTo(ft-4,ut+2),e.quadraticCurveTo(ft+4,ut,ft+6,ne)),e.stroke(),he(B?ft:ft+6,ne,B?0:.3,-1),ot&&(e.beginPath(),e.moveTo(ft+12,ne),e.quadraticCurveTo(ft+16,ut-6,ft+16,ut),e.stroke(),he(ft+16,ut,0,1)),e.textAlign="left",e.fillText(`${B?"pre ":""}${yi(se)}`,ft+(ot?20:10),ne+4),e.textAlign="center"}[Ze,Fe]=[pt,Y],c.tap&&!c.tapLeft&&Se("T"),c.staccato&&ye(4,B=>{e.beginPath(),e.arc(pt,B,2,0,Math.PI*2),e.fill()}),c.accent&&(c.accent==="tenuto"||!D?.accent)&&Se({heavy:"^",tenuto:"–"}[c.accent]??">"),We&&Se("PM");for(const B of[c.tapLeft?"m.g.":"",bi[c.harmonicType]??(c.harmonicPinch?"PH":""),c.slap?"slap":c.pop?"pop":"",c.golpe?`golpe (${c.golpe})`:"",c.rasgueado?`rasg. ${c.rasgueado}`:"",typeof c.trill=="number"?`tr ${c.trill}`:"",c.ornament??"",c.fade??"",c.whammy?"w/bar":"",c.wah==="open"?"o":c.wah==="closed"?"+":""])B&&Se(B);c.rightFinger&&Se(c.rightFinger,"italic "),c.pick&&ye(9,B=>{e.beginPath(),c.pick==="down"?[[-4,4.5],[-4,-4.5],[4,-4.5],[4,4.5]].forEach(([ot,ft],ut)=>e[ut?"lineTo":"moveTo"](pt+ot,B+ft)):[[-4,-4.5],[0,4.5],[4,-4.5]].forEach(([ot,ft],ut)=>e[ut?"lineTo":"moveTo"](pt+ot,B+ft)),e.stroke()}),c.fermata&&ye(9,B=>{e.beginPath(),e.arc(pt,B+4,7,Math.PI,0),e.stroke(),e.beginPath(),e.arc(pt,B+3,1.5,0,Math.PI*2),e.fill()}),c.tremolo&&ye(18,B=>{for(let ot=-1;ot<=1;ot++)Lt(pt-6,B+ot*4+5.5,pt+6,B+ot*4+.5);e.beginPath();for(let ot=0;ot<=12;ot++)e[ot?"lineTo":"moveTo"](pt-8+16*ot/12,B-7+Math.sin(ot/12*Math.PI*2)*2);e.stroke()})})}const on=(p,c,D,gt)=>{if(e.globalAlpha=p.shown*gt,e.fillStyle=p.fill,p.squeeze===1)return e.fillText(c,p.x+p.left+D,p.y);e.save(),e.translate(p.x,p.y),e.scale(p.squeeze,1),e.fillText(c,p.left+D,0),e.restore()};e.textAlign="left";for(const p of[mt.note,mt.grace]){e.font=p;for(const c of v)c.font===p&&on(c,c.text,0,1)}e.font=mt.finger;for(const p of v)p.finger&&on(p,p.finger,p.textWidth+3,.7);for(const p of nn)p();e.globalAlpha=1,w&&e.restore()};if(!_)we(null);else if(we([xt-40,dt+4]),Nt){const w=dt+24,Q=j;E=V=>w+(V-Nt.start)*Nt.scale,[$,P,j]=[Nt.start,Nt.start+Ht/Nt.scale,-1/0],we([w-8,st+4]),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0, 0, 0, 0.55)",e.fillRect(w-8,0,st+12-(w-8),Ot),e.restore(),e.strokeStyle=I(o.text,.22),e.lineWidth=1.5,e.setLineDash([3,5]),Lt(dt+12,t-d*.6,dt+12,L+d*.6),e.setLineDash([]),j=Q}e.shadowColor=o.accent,e.shadowBlur=16,e.strokeStyle=o.accent,e.lineWidth=3,Lt(j,t-d*.7,j,L+d*.7);for(const{y:w,c:Q}of vt)e.shadowColor=Q,e.fillStyle="#ffffff",e.beginPath(),e.arc(j,w,4,0,Math.PI*2),e.fill();e.shadowBlur=0,e.globalCompositeOperation="destination-out";for(const[w,Q,V]of _?[]:[[xe+10,1,wi],[M-Be,-1,80]]){const bt=e.createLinearGradient(w,0,w+Q*V,0);bt.addColorStop(0,"rgba(0, 0, 0, 1)"),bt.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=bt,e.fillRect(Q>0?0:w-V,0,Q>0?w+V:M-w+V,Ot)}e.globalCompositeOperation="destination-over",e.beginPath(),e.roundRect(Be,R,M-Be*2,kt-R,16),e.fillStyle=I(o.ink,.72),e.fill(),e.globalCompositeOperation="source-over",e.strokeStyle=o.chipBorder,e.lineWidth=1,e.stroke();const He=`700 ${Me(Math.min(14,d*.24))}px ${o.num}`,je=Math.min(13,d*.22);e.font=He,e.textAlign="center";for(let w=0;w<m&&l.open;w++){const Q=(Be+xe)/2,V=U(w);e.strokeStyle=e.fillStyle=ct(w),e.lineWidth=1.8,e.beginPath(),e.arc(Q,V,je,0,Math.PI*2),e.stroke(),e.fillText($i(l.open[w]),Q,V+Jt(e,He,"E").middle)}}export{Ui as HEADSTOCKS,Zi as bendAt,ho as drawHighway,fo as drawTab,Yi as headstockParts,Ri as lookAhead,no as moveCamera,ai as rounded,ri as spline};
|
|
1
|
+
import{lap as Ve}from"./perf.js";import{noteName as Qn}from"./music.js";const Ae=900,_o=84,to=28,eo=2.2,Ho=.9,Fo=2.4,No=a=>_o*(a.drawDistance??1)/(to*(a.noteSpeed??1)),Yo=.34,de=24,vn=1.2,qo=1.25,zo=1.25,gn=5,Pn=1,Go=1.6,Uo=2,pn=.19,no=.12,oo=3,Xo=11,jo=[{time:-1/0,endTime:1/0,fret:1,width:4}],En=[3,5,7,9,12,15,17,19,21,24],Bn=.15,io=.31,so=1.7,ao=1.4,lo=1,ro=1.2,Ko=18,ho=(a,s,h,n,e)=>{const[r,x,d,t]=[Math.min(a,s),Math.max(a,s),Math.min(h,n),Math.max(h,n)],F=Math.min(e,(x-r)/2,(t-d)/2),X=(_t,z,Et)=>{const G=Array.from({length:5},(Ht,yt)=>[_t+Math.cos(Et+yt*Math.PI/8)*F,z+Math.sin(Et+yt*Math.PI/8)*F]);return[G[0],...G,G[4]]};return[...X(x-F,t-F,0),...X(r+F,t-F,Math.PI/2),...X(r+F,d+F,Math.PI),...X(x-F,d+F,1.5*Math.PI)]},Jo=a=>[...a,a.at(-1),...a.slice(0,-1).reverse().map(([s,h])=>[s,-h])],Vo={inline:{label:"6 in line",outline:[[0,1],[.42,1.05],[.73,1.3],[1.01,1.53],[1.46,1.45],[2.73,1.08],[4.38,.62],[5.79,.17],[6.54,-.13],[6.88,-.35],[7.03,-.88],[6.98,-1.56],[6.64,-2.11],[6.14,-2.38],[5.59,-2.34],[5.21,-2.05],[4.99,-1.66],[4.75,-1.39],[4.25,-1.3],[3.5,-1.39],[2.6,-1.6],[1.85,-1.81],[1.18,-1.75],[.83,-1.36],[.47,-1.06],[0,-1]],posts:{from:[1.56,.95],to:[6.01,-.58]},keys:"machine",tree:2.47},fourTwo:{label:"4 + 2",outline:[[0,1],[.48,1.03],[.94,1.35],[1.21,1.72],[1.52,1.72],[2.99,1.31],[4.23,.95],[5.53,.57],[5.92,.28],[6.07,-.36],[6.05,-1.03],[5.79,-1.53],[5.36,-1.67],[4.95,-1.53],[4.68,-1.29],[4.36,-1.19],[4.02,-1.32],[3.67,-1.56],[2.99,-1.67],[2.08,-1.6],[1.4,-1.43],[.94,-1.16],[.48,-1.03],[0,-1]],posts:{from:[1.81,1.08],to:[4.94,-.03],treble:{share:1/3,from:[2.33,-1.03],to:[3.38,-.69]}},keys:"machine"},openBook:{label:"3 + 3 open book",outline:Jo([[0,1],[.48,1.07],[.96,1.33],[1.47,1.53],[3.16,1.67],[4.98,1.76],[6.25,1.8],[6.25,1.8],[6.42,.93],[6.3,0]]),posts:{from:[2.5,1.07],to:[5.1,1.07],treble:{share:1/2}},keys:"tulip",cover:[[.22,0],[.22,.4],[.36,.5],[.78,.4],[1.3,.25],[1.82,.16],[2.13,.1],[2.24,0],[2.13,-.1],[1.82,-.16],[1.3,-.25],[.78,-.4],[.36,-.5],[.22,-.4],[.22,0]],screws:[[.43,0],[1.98,0]]},pointed:{label:"3 + 3 pointed",outline:[[0,1],[.36,1.12],[.75,1.47],[1.07,1.84],[1.38,1.93],[2.29,1.73],[3.26,1.55],[4.36,1.35],[5.45,1.12],[5.75,.95],[5.86,.43],[5.98,-.22],[6.29,-.75],[6.75,-1.22],[6.75,-1.22],[6.17,-1.24],[5.33,-1.3],[4.36,-1.37],[3.26,-1.55],[2.29,-1.73],[1.38,-1.93],[1.07,-1.84],[.75,-1.47],[.36,-1.12],[0,-1]],posts:{from:[2.07,1],to:[4.65,.46],treble:{share:1/2}},keys:"machine",cover:[[.1,.44],[.1,.44],[.59,.4],[1.1,.28],[1.69,0],[1.69,0],[1.1,-.28],[.59,-.4],[.1,-.44],[.1,-.44],[.1,.44]],screws:[]},headless:{label:"Headless",outline:ho(.2,.95,-1.06,1.06,.2),clamps:.58}};function Zo(a,s){const h=s.length,n=mo(a.outline,10);let e=s.map(t=>[a.clamps,t]),r=s.map(()=>1);if(a.posts){const{from:t,to:F,treble:X}=a.posts,_t=X?Math.floor(h*X.share+1e-9):0,z=h-_t,Et=(V,v,pt)=>Mt=>V.map((K,N)=>K+(v[N]-K)*Mt/Math.max(1,pt-1)),G=([V,v])=>[V,-v],Ht=Et(t,F,z),yt=Et(X?.from??G(t),X?.to??G(F),_t);e=s.map((V,v)=>v<z?Ht(v):yt(h-1-v)),r=s.map((V,v)=>v<z?1:-1)}const x=(t,F)=>{let X=null;for(let _t=1;_t<n.length;_t++){const[z,Et]=n[_t-1],[G,Ht]=n[_t];if((z-t)*(G-t)>0||z===G)continue;const yt=Et+(Ht-Et)*(t-z)/(G-z);(X===null||yt*F>X*F)&&(X=yt)}return X??F},d=a.keys?e.map(([t],F)=>({u:t,side:r[F],edge:x(t,r[F])})):[];return{outline:n,ends:e,keys:d}}const fo=new WeakMap,yn=new Map,Qo=(a,s)=>{const h=s.join(),n=fo.get(a);if(n?.key===h)return n.parts;const e=Zo(a,s);return fo.set(a,{key:h,parts:e}),e},co=(a,s)=>(yn.has(a)||(yn.size>500&&yn.clear(),yn.set(a,s())),yn.get(a)),mo=(a,s=8)=>[...a.slice(0,-1).flatMap((h,n)=>{const e=a[Math.max(0,n-1)],r=a[n+1],x=a[Math.min(a.length-1,n+2)];return h[0]===r[0]&&h[1]===r[1]?[h]:Array.from({length:s},(d,t)=>{const F=t/s;return[0,1].map(X=>.5*(2*h[X]+(r[X]-e[X])*F+(2*e[X]-5*h[X]+4*r[X]-x[X])*F*F+(3*h[X]-e[X]-3*r[X]+x[X])*F**3))})}),a.at(-1)],Tn=(a,s)=>{if(!a.startsWith("#"))return a;const h=n=>{const e=parseInt(a.slice(n,n+2),16);return Math.round(s>0?e+(255-e)*s:e*(1+s)).toString(16).padStart(2,"0")};return`#${h(1)}${h(3)}${h(5)}`},wn=new Map,H=(a,s)=>{if(!a.startsWith("#"))return a;const h=a+s;let n=wn.get(h);return n||(wn.size>1e3&&wn.clear(),wn.set(h,n=`rgba(${parseInt(a.slice(1,3),16)}, ${parseInt(a.slice(3,5),16)}, ${parseInt(a.slice(5,7),16)}, ${s})`)),n},se=(a,s)=>{let h=0,n=a.length;for(;h<n;){const e=h+n>>1;a[e].time<s?h=e+1:n=e}return h};function uo(a){if(a.links?.next.length===a.notes.length)return a.links;const s=a.notes.length,h=new Array(s).fill(-1),n=new Array(s).fill(-1),e={};let r=0;for(let x=0;x<s;x++){const{string:d,sustain:t}=a.notes[x];e[d]!==void 0&&([n[x],h[e[d]]]=[e[d],x]),e[d]=x,r=Math.max(r,t)}return a.links={next:h,prev:n,held:r}}const ee=a=>Math.round(a*4)/4,We=32,An=new Map;let go=0;const Kt=(a,s,h)=>{let n=An.get(s);n||An.set(s,n=new Map);let e=n.get(h);if(!e){++go>5e3&&([go,n]=[0,new Map],An.clear(),An.set(s,n)),a.font=s;const r=a.measureText(h);n.set(h,e={width:r.width,middle:(r.actualBoundingBoxAscent-r.actualBoundingBoxDescent)/2,top:r.actualBoundingBoxAscent})}return e},Wn=128,_n=new WeakMap,ti=a=>{if(!_n.has(a)){const s=new OffscreenCanvas(1,Wn),h=s.getContext("2d"),[n,e]=[a.floor0,a.floor1].map(x=>[1,3,5].map(d=>parseInt(x.slice(d,d+2),16))),r=Array.from({length:Wn},(x,d)=>{const t=(d+.5)/Wn;return`rgba(${n.map((F,X)=>Math.round(F+(e[X]-F)*t))}, ${1-t})`});r.forEach((x,d)=>{h.fillStyle=x,h.fillRect(0,Wn-1-d,1,1)}),_n.set(a,{strip:s,near:r[0]})}return _n.get(a)},xn=new Map,po=new WeakMap,xo=(a,s,h)=>{let n=po.get(a);n||po.set(a,n=new Map);let e=n.get(s);if(!e){e=a.createLinearGradient(0,0,0,1);for(const[r,x]of h)e.addColorStop(r,x);n.set(s,e)}return e},$n=new Map,Mo=(a,s,h,n,e)=>{const r=`${s}|${h}|${n}|${e}`;let x=$n.get(r);return x||($n.size>20&&$n.clear(),x=a.createLinearGradient(0,s,0,h),x.addColorStop(0,n),x.addColorStop(1,e),$n.set(r,x)),x},In=(a,s)=>[a[0]-s[0],a[1]-s[1],a[2]-s[2]],Dn=(a,s)=>a[0]*s[0]+a[1]*s[1]+a[2]*s[2],ei=(a,s)=>[a[1]*s[2]-a[2]*s[1],a[2]*s[0]-a[0]*s[2],a[0]*s[1]-a[1]*s[0]],ni=a=>a.map(s=>s/Math.hypot(...a)),oi=(a,s)=>{let h=0;for(const n of a??[]){if(n.time>s)break;h=n.fret}return h},ii=.15,bo=new WeakMap,Hn=a=>{let s=bo.get(a);if(!s){s=[];for(const h of a){const n=s[s.length-1];n&&h.endTime-h.time<ii?n.endTime=h.endTime:s.push({...h})}bo.set(a,s)}return s},kn=(a,s)=>{let h=0,n=a.length;for(;h<n;){const e=h+n>>1;a[e].time<=s?h=e+1:n=e}return a[Math.max(0,h-1)]},yo=a=>a*a*(3-2*a),si=.3,To=new WeakMap;function ko(a,s){let h=To.get(a);if(h||To.set(a,h={}),!(s in h)){const n=Math.max(a.sustain,.05),r=(a[s]??(s==="bendCurve"&&a.bend?[[0,0],[.25,a.bend]]:null))?.map(([x,d])=>[x*n,d,!1])??[];r.length&&r[0][0]>.001&&(r[0][2]=!0,r.unshift([0,0,!1])),h[s]=r.length?r:null}return h[s]}function So(a,s){if(!a)return 0;let h=a[0][1];for(let n=1;n<a.length&&s>a[n-1][0];n++){const[[e,r],[x,d,t]]=[a[n-1],a[n]],F=Math.min(x-e,si)||1e-6;h=r+(d-r)*yo(Math.min(1,Math.max(0,(s-(t?x-F:e))/F)))}return h}const ai=(a,s)=>So(ko(a,"bendCurve"),s),li=(a,s)=>So(ko(a,"whammy"),s),vo=new WeakMap,rn=a=>{let s=vo.get(a);return s===void 0&&vo.set(a,s=Math.max(a.bend||0,...(a.bendCurve??[]).map(([,h])=>h))),s};function ri(a){if(a.chordSpans)return a.chordSpans;const s=[];for(const h of a.chords){const n=Math.max(h.time+.25,...h.notes.map(r=>a.notes[r].time+a.notes[r].sustain)),e=s.at(-1);e&&h.time-e.end<1&&(h.name?h.name===e.name:h.highDensity)?e.end=Math.max(e.end,n):h.name&&s.push({name:h.name,time:h.time,end:n})}for(const h of a.handShapes??[])h.arpeggio&&h.name&&s.push({name:h.name,time:h.startTime,end:h.endTime});return a.chordSpans=s.sort((h,n)=>h.time-n.time)}function hi(a){if(a.chordRails)return a.chordRails;const s=[],h=n=>Math.max(n.time+.15,...n.notes.map(e=>a.notes[e].time+a.notes[e].sustain));for(let n=0;n<a.chords.length;n++){const e=a.chords[n];if(e.highDensity)continue;let r=h(e),x=n+1;for(;a.chords[x]?.highDensity&&a.chords[x].time-r<1;x++)r=Math.max(r,h(a.chords[x]));r=Math.min(r,a.chords[x]?.time??1/0),r-e.time>.2&&s.push({time:e.time,end:r,frets:e.notes.map(d=>a.notes[d].fret)})}for(const n of a.handShapes??[])n.arpeggio&&s.push({time:n.startTime,end:n.endTime,frets:n.frets,arpeggio:n});return a.chordRails=s}const Po={artificial:"AH",pinch:"PH",tap:"TH",semi:"SH",feedback:"FH"},Fn=a=>a<.5?"¼":a===.5?"½":a===1?"full":a%1?`${Math.floor(a)}½`:String(a),wo=(a,s,h,n)=>{if(a===void 0)return s;const e=a+(s-a)*(1-Math.exp(-h/n));return Math.abs(s-e)<1e-6?s:e};function Ao(a,s,h,n,e){a[s]===void 0&&([a[s],a[s+"Speed"]]=[h,0]);const r=2/n,x=r*e,d=1/(1+x+.48*x*x+.235*x*x*x),t=a[s]-h,F=(a[s+"Speed"]+r*t)*e;a[s+"Speed"]=(a[s+"Speed"]-r*F)*d,a[s]=h+(t+F)*d,Math.abs(a[s]-h)<1e-6&&Math.abs(a[s+"Speed"])<1e-6&&([a[s],a[s+"Speed"]]=[h,0])}function Wo(a,s,h=0){let n=1/0,e=-1/0;for(const x of a)x.endTime<=s||x.time>=s+oo||(n=Math.min(n,x.fret-1),e=Math.max(e,x.fret-1+x.width));if(n===1/0){const x=kn(a,s);[n,e]=[x.fret-1,x.fret-1+x.width]}h&&(n=Math.min(n,h-1));const r=Math.max(Xo,e-n+2)+1;return{lo:n,hi:e,span:r,center:Math.min(25-r/2,Math.max(r/2-1,(n+e)/2))}}function fi(a,s,h,n,e=0){const r=Wo(s,h,e),x=a.target,d=!x||r.lo<x.center-x.span/2||r.hi>x.center+x.span/2,t=x&&x.span-Math.max(r.span,Wo(s,h+oo,e).span)>2;(d||t)&&(a.target=r);const F=Math.min(n-(a.at??n),100);a.at=n,Ao(a,"span",a.target.span,a.target.span>a.span?.8:1.4,F/1e3),Ao(a,"center",a.target.center,1,F/1e3);const X=kn(Hn(s),h);return a.left=wo(a.left,X.fret-1,F,90),a.right=wo(a.right,X.fret-1+X.width,F,90),X}function $o(a,s,h,n,e,r,x,d){a.beginPath(),a.moveTo(s-n,h-r*e),a.lineTo(s,h),a.lineTo(s+n,h-r*e),a.lineWidth=Math.max(3,e*1.15),a.strokeStyle=d,a.stroke(),a.lineWidth=Math.max(1.5,e*.65),a.strokeStyle=x,a.stroke(),a.lineWidth=Math.max(.6,e*.2),a.strokeStyle="rgba(255, 255, 255, 0.5)",a.stroke()}function Io(a,s,h,n,e){a.beginPath(),a.moveTo(s,h),a.lineTo(n,e),a.stroke()}function Nn(a){const s=devicePixelRatio||1,h=a.clientWidth,n=a.clientHeight;(a.width!==Math.round(h*s)||a.height!==Math.round(n*s))&&(a.width=Math.round(h*s),a.height=Math.round(n*s));const e=a.getContext("2d"),r=n/Ae,x=h/r,d=s*r;return e.setTransform(d,0,0,d,0,0),e.clearRect(0,0,x,Ae),{g:e,W:x,B:d}}function xi(a,s,h,n,e){const{g:r,W:x,B:d}=Nn(a);let t=r;if(!s)return;const F=s.anchors.length?s.anchors:jo,X=oi(s.capos,h),_t=fi(e,F,h,performance.now(),X),z=s.strings,Et=Math.min(.5,5*Yo/Math.max(1,z-1)),G=Et*zo*(n.boardHeight??1),Ht=G*(z-1),yt=o=>(n.stringOrder==="high"?o:z-1-o)*G,V=o=>(o>=z/2?1:-1)*(n.stringOrder==="high"?-1:1),v=to*(n.noteSpeed??1),pt=No(n),Mt=-.22,K=Ht+.22,N=Mt-.06,Tt=pt*v,ut=o=>Math.max(0,o)*v,It=o=>n.str[o%n.str.length],Jt=n.noteLines===0?null:`rgba(255, 255, 255, ${n.noteLines??.5})`,ne=+n.fretNumbers||0,ye=e.span,Ft=[e.center,Et*(z-1)/2,0],oe=(n.viewAngle??30)*Math.PI/180,ge=.6*Math.SQRT2*ye,Ze=[Ft[0],Ht+ge*Math.sin(oe),-ge*Math.cos(oe)],Te=ni(In([Ft[0],0,2.2*ye],Ze)),ke=ei(Te,[1,0,0]),Ne=(n.sideAngle??0)*Math.PI/180,[Se,Ye]=[Math.sin(Ne),Math.cos(Ne)],$e=In(Ze,Ft),C=Dn($e,Te),ft=Dn($e,ke),tt=[-Se,Te[1]*Ye,Te[2]*Ye],Ct=[Ye,Te[1]*Se,Te[2]*Se],Ot=[Ft[0]+ft*ke[0]+C*tt[0],Ft[1]+ft*ke[1]+C*tt[1],ft*ke[2]+C*tt[2]],ae=Math.min(x*.88,Ae*(n.fill?1.3:1.05)),Ie=ae*Dn(In(Ft,Ot),tt)/ye,le=Math.min(qo*(n.fretWidth??1),x*ye/(ae*Math.max(1,ye-2.5)));let re=0,ve=0;const[Vt,Xe,qe]=Ot,[De,hn,Le]=tt,[Ce,fn,Qe]=Ct,[pe,Zt,ze]=ke,A=(o,i,f)=>{const l=o-Vt,c=i-Xe,p=f-qe,T=Ie/Math.max(.05,l*De+c*hn+p*Le);return[x/2+(l*Ce+c*fn+p*Qe)*le*T+re,Ae/2-(l*pe+c*Zt+p*ze)*T+ve,T]},[on,Oe,qt]=A(...Ft);[re,ve]=[x/2-on,Ae*(n.fill?.83:.81)-Oe];const[,cn]=A(e.center-ye/2,N,0),[,Re]=A(e.center+ye/2,N,0),[,he]=A(e.center,N,0);ve-=Math.min(Ae*.08,Math.max(0,cn-he,Re-he)),Ve("setup");const gt=(o,i=!0)=>{t.beginPath();for(let f=0;f<o.length;f++){const[l,c]=A(o[f][0],o[f][1],o[f][2]);f?t.lineTo(l,c):t.moveTo(l,c)}i&&t.closePath()},St=(o,i)=>{gt([o,i],!1),q()},Ee=(o,i,f,l,c)=>{if(n.gem!=="pill")return gt([[o-l,i-c,f],[o+l,i-c,f],[o+l,i+c,f],[o-l,i+c,f]]);const[p,T]=A(o-l,i,f),[E,w]=A(o+l,i,f),[,O]=A(o,i+c,f),[,At]=A(o,i-c,f),st=Math.atan2(w-T,E-p),lt=Math.min(Math.abs(At-O),Math.hypot(E-p,w-T))/2,[U,nt]=[lt*Math.cos(st),lt*Math.sin(st)];t.beginPath(),t.arc(p+U,T+nt,lt,st+Math.PI/2,st+Math.PI*1.5),t.arc(E-U,w-nt,lt,st-Math.PI/2,st+Math.PI/2),t.closePath()},Je=(o,i)=>{const f=kn(F,i),l=o.filter(c=>c>0);return[Math.min(f.fret-1,...l.map(c=>c-1))+.05,Math.max(f.fret-1+Math.max(4,f.width),...l)-.05]},M=(o,i,f,l,c)=>{St([o-l,i-c,f],[o+l,i+c,f]),St([o-l,i+c,f],[o+l,i-c,f])},m=n.markings==="white",Y=m?"#ffffff":n.ink,P=(o,i,f,l,c,p,T,E=null)=>{const[w,O]=T?[c*.85,p*.8]:[Math.min(c,.34)*.72,p*.82];E||(t.strokeStyle=H(n.ink,T?.7:.35),t.lineWidth=T?Math.max(3.5,.1*l):Math.max(2.5,.06*l),M(o,i,f,w,O)),t.strokeStyle=E??(T?"#ffffff":H("#ffffff",.42)),t.lineWidth=Math.max(E?2:T?1.8:1.2,(T?.05:.035)*l),M(o,i,f,w,O)};let I=null,y=0;const ct=o=>{o!==I&&(t.font=I=o)},Z={},bt=(o,i,f,l,c,p)=>{const T=Z[c]??=`${c} ${We}px ${n.num}`,E=l/We;return Kt(t,T,o),ct(T),t.textAlign=p,t.setTransform(d*E,0,0,d*E,d*i,d*(f-y)),Kt(t,T,o).middle},Nt=()=>t.setTransform(d,0,0,d,0,-d*y),kt=(o,i,f)=>{t.fillStyle=o,t.setTransform(d,0,0,d*(f-i),0,d*(i-y)),t.fill(),Nt()},Yt=(o,i,f,l,c,p,T=700,E="center",w=!0,O=!1)=>{const[At,st,lt]=A(i,f,l),U=c*(O?lt:Math.sqrt(lt*qt));if(U<(O?1:8)||At<-60||At>x+60)return;t.textBaseline="alphabetic";const nt=bt(o,At,st,U,T,E);w&&(t.lineWidth=We*.2,t.strokeStyle=H(n.ink,.9),t.strokeText(o,0,nt)),t.fillStyle=p,t.fillText(o,0,nt),Nt(),t.textBaseline="middle"},Gt=(o,i,f,l,c,p,T=700)=>{const[E,w]=A(i,N,f),[O,At]=A(i+l,N,f),st=Math.hypot(O-E,At-w),lt=st>.01?Math.max(1,Ko/st):1,[U,nt]=A(i+l*lt,N,f),te=Math.hypot(U-E,nt-w);let Q=c*lt,[xt,D]=A(i,N,f+Q),Rt=Math.hypot(xt-E,D-w);for(let Ge=0;Ge<3&&Rt>te*ro;Ge++)Q*=te*ro/Rt,[xt,D]=A(i,N,f+Q),Rt=Math.hypot(xt-E,D-w);const Lt=Math.abs(Math.atan2(xt-E,w-D));if(E<-60||E>x+60||Rt<lo||Lt>ao)return;const Wt=t.globalAlpha;t.globalAlpha=Wt*Math.min(1,(ao-Lt)/.2,(Rt-lo)/3)*Math.max(.45,lt**-.5);const an=Z[T]??=`${T} ${We}px ${n.num}`;ct(an),t.textAlign="center",t.textBaseline="alphabetic";const{top:nn}=Kt(t,an,o);t.setTransform(d*(U-E)/We,d*(nt-w)/We,-d*(xt-E)/We,-d*(D-w)/We,d*E,d*(w-y)),t.fillStyle=p,t.fillText(o,0,nn),Nt(),t.globalAlpha=Wt,t.textBaseline="middle"},[,zt]=A(Ft[0],N,0),[,vt]=A(Ft[0],N,Tt),Dt=(o,i,f)=>{const l=`${zt}|${vt}`;(xn.span!==l||xn.size>300)&&(xn.clear(),xn.span=l);const c=`${o}|${i}|${f}`;let p=xn.get(c);return p||(p=t.createLinearGradient(0,zt,0,vt),p.addColorStop(0,H(o,i)),p.addColorStop(1,H(o,f)),xn.set(c,p)),p};let Ut=null;const B=(o,i,f=10,l=!1)=>Ut=o?{color:i,blur:f,faded:l}:null,ot=[[.6,.05],[.35,.13],[.15,.27]],at=[[.4,.3]],Bt=o=>{if(!Ut)return;const{lineWidth:i,globalAlpha:f}=t,l=o?1:Math.min(1,2*i/Ut.blur);t.save(),t.strokeStyle=Ut.faded?Dt(Ut.color,1,.1):Ut.color;for(const[c,p]of Ut.blur>4?ot:at)t.lineWidth=(o?0:i)+2*Ut.blur*c,t.globalAlpha=f*p*l,t.stroke();t.restore()},q=()=>{Bt(!1),t.stroke()},J=()=>{Bt(!0),t.fill()};t.textBaseline="middle",t.lineCap="round",t.lineJoin="round";const{strip:je,near:tn}=ti(n);let[Be,_e]=[-60,de+60];if(Ne){const o=Ft[0]+(1-Dn(In([Ft[0],N,0],Ot),tt))/tt[0];[Be,_e]=tt[0]>0?[Math.max(-60,o),de+60]:[-60,Math.min(de+60,o)]}t.save(),gt([[Be,N,0],[_e,N,0],[_e,N,Tt],[Be,N,Tt]]),t.clip(),Ne&&(t.fillStyle=tn,t.fillRect(0,zt,x,Ae-zt)),t.imageSmoothingEnabled=!1,t.drawImage(je,0,vt,x,zt-vt),t.restore();const fe=(o,i)=>{const[f,l]=A(...o),[c,p]=A(...i);t.moveTo(f,l),t.lineTo(c,p)};t.strokeStyle=Dt(n.lane,.5,.04),t.lineWidth=Ho,t.beginPath();for(let o=0;o<=de;o++)fe([o,N,0],[o,N,Tt]);q();for(const o of[!1,!0]){t.strokeStyle=o?n.measure:n.beat,t.lineWidth=o?1.6:1,t.beginPath();const i=[];for(let f=se(s.beats,h);f<s.beats.length;f++){const l=s.beats[f],c=l.time-h;if(c>pt)break;l.measure>=0===o&&(c>pt-.4?i.push(c):fe([0,N,ut(c)],[de,N,ut(c)]))}q();for(const f of i)t.globalAlpha=(pt-f)/.4,t.beginPath(),fe([0,N,ut(f)],[de,N,ut(f)]),q();t.globalAlpha=1}if(ne)for(let o=se(s.beats,h);o<s.beats.length;o++){const i=s.beats[o],f=i.time-h;if(f>pt)break;if(i.measure<0)continue;const l=kn(Hn(F),i.time),c=ut(f);t.globalAlpha=Math.min(1,(pt-f)/.4);for(const p of En)(p<l.fret||p>=l.fret+l.width)&&Gt(String(p),p-.5,c,io,so,H(n.inlay,ne))}t.globalAlpha=1,(n.guides===!1?[]:Hn(F).filter(o=>o.endTime>h&&o.time<h+pt)).forEach((o,i)=>{const f=ut(Math.max(0,o.time-h)),l=ut(Math.min(pt,o.endTime-h)),c=o.fret-1,p=c+o.width;t.fillStyle=Dt(n.anchorFill,n.anchorOpacity,.02),gt([[c,N,f],[p,N,f],[p,N,l],[c,N,l]]),J(),t.strokeStyle=Dt(n.anchorLane,.55,.04),t.lineWidth=Fo*.6;for(const T of[c,p])St([T,N,f],[T,N,l]);i&&o.time>h&&St([c,N,f],[p,N,f])});const u=new Map,g=o=>{const i=Math.round(o*100);return u.has(i)||u.set(i,{dt:o-h,texts:[],pins:[]}),u.get(i)};for(const o of s.markers??[])o.time>=h&&o.time<=h+pt&&!g(o.time).texts.includes(o.text)&&g(o.time).texts.push(o.text);for(const o of s.hairpins??[])o.time>=h&&o.time<=h+pt&&g(o.time).pins.push(o.kind);const L=Math.min(e.center-(e.span/2+.5)/le,-.5);for(const{dt:o,texts:i,pins:f}of u.values()){const[l,c,p]=A(L,N,ut(o)),T=Math.sqrt(p*qt),E=i.join(" · "),w=.25*T,O=`700 ${We}px ${n.num}`,At=.3*T/We,st=E?Kt(t,O,E).width*At:0,lt=st+f.length*(.9*T+w);ct(O);let U=Math.max(l-.3*T,16+lt);t.globalAlpha=Math.min(1,(pt-o)/.4),E&&(t.save(),t.translate(U,c),t.scale(At,At),t.textAlign="right",t.lineWidth=We*.2,t.strokeStyle=H(n.ink,.9),t.strokeText(E,0,0),t.fillStyle=n.accent,t.fillText(E,0,0),t.restore(),U-=st+w);for(const nt of f){const te=U-.9*T,Q=.14*T,[xt,D]=nt==="cresc"?[te,U]:[U,te];for(const[Rt,Lt]of[[H(n.ink,.9),Math.max(3.5,.12*T)],[n.text,Math.max(1.5,.05*T)]])t.strokeStyle=Rt,t.lineWidth=Lt,t.beginPath(),t.moveTo(D,c-Q),t.lineTo(xt,c),t.lineTo(D,c+Q),q();U=te-w}}t.globalAlpha=1,Ve("floor");const S=[];for(let o=se(s.notes,h-uo(s).held-.3);o<s.notes.length;o++){const i=s.notes[o];if(i.time>h+pt)break;const f=Math.max(i.sustain,(i.slideTo??i.slideUnpitchTo??null)===null?0:.25,.15);i.time+f>=h-.05&&S.push(i)}const k=o=>o.chord===null||o.chord===void 0?null:s.chords[o.chord],_=o=>k(o)?.fretHandMute||n.repeatMarks==="frame"&&(o.repeat||k(o)?.highDensity);if(!s.palmRuns){const o={};for(const i of s.notes){const f=i.palmMute||k(i)?.palmMute;i.palmAgain=!!f&&i.time-(o[i.string]??-1/0)<.8,f&&(o[i.string]=i.time)}s.palmRuns=!0}const R=o=>{const i=kn(F,o.time),f=o.fret===0;return{a:i,open:f,x:f?i.fret-1+i.width/2:o.fret-.5,y:yt(o.string)}},it=(o,i,f)=>{const l=o.slideSpan??Math.max(o.sustain,.25),c=o.slideTo??o.slideUnpitchTo??null,p=Math.min(1,Math.max(0,f/l));return c===null||o.fret===0?i:i+(c-.5-i)*p*p*p*(p*(p*6-15)+10)},Pt=(o,i)=>(ai(o,i)*V(o.string)+li(o,i))*G*Pn,ht=o=>{const i=h-o.time;return i<0||o.fret===0||!(rn(o)>0)?0:Pt(o,Math.min(i,Math.max(o.sustain,.15)))},et=new Map;for(const o of S){const i=o.time-h,f=Math.max(o.sustain,.15);i>0||-i>f||o.fret===0||!(rn(o)>0)||et.set(o.string,{note:o,x:o.fret-.5,dy:ht(o)})}const xe=(o,i=0,f=!1)=>{const l=et.get(o),c=yt(o)+i,p=f?[[0,c,0]]:[en?[en[o][0],en[o][1]+i,0]:[-.6,c,0],[0,c,0]];if(!l)return gt([...p,[de+.6,c,0]],!1);gt([...p,[l.x,c+l.dy,0],[de+.6,c,0]],!1)},Pe=o=>yt(o.string)+ht(o),ce=Vo[n.headstock],we=(K-Mt)/2,mn=n.stringOrder==="high"?-1:1,ue=([o,i])=>[-o*we/le,Ht/2+i*we*mn,0],wt=o=>(yt(o)-Ht/2)*mn/we,Xt=ce&&Qo(ce,Array.from({length:z},(o,i)=>wt(i))),en=Xt?.ends.map(ue),Qt=(o,i,f=1)=>{o&&(t.fillStyle=o,J()),i&&(t.strokeStyle=i,t.lineWidth=f,q())},sn=(o,i,f)=>{const[l,c]=ue(o),[p,T]=A(l,c,0),[E]=A(l+i*we/le,c,0),[,w]=A(l,c+f*we,0);t.beginPath(),t.ellipse(p,T,Math.abs(E-p),Math.abs(w-T),0,0,Math.PI*2)},dn=(o,i,f,l,c)=>gt(co(`${o},${i},${f},${l},${c}`,()=>ho(o,i,f,l,c)).map(ue)),qn=()=>{for(const{u:f,side:l,edge:c}of Xt.keys){const p=(T,E)=>[c+l*T,c+l*E];ce.keys==="machine"?(dn(f-.15,f+.15,...p(-.12,.08),.03),Qt(H(n.text,.12),H(n.anchorLane,.35)),dn(f-.03,f+.03,...p(.06,.22),0),Qt(H(n.text,.28)),dn(f-.11,f+.11,...p(.2,.68),.1),Qt(H(n.text,.18),H(n.anchorLane,.55))):(dn(f-.035,f+.035,...p(-.05,.22),0),Qt(H(n.text,.28)),sn([f,c+l*.18],.08,.04),Qt(H(n.text,.3)),sn([f,c+l*.4],.14,.2),Qt(H(n.text,.18),H(n.anchorLane,.55)))}gt(Xt.outline.map(ue));const[,o]=A(...ue([0,1.6])),[,i]=A(...ue([0,-1.2]));if(Qt(Mo(t,o,i,n.floor0,n.ink)),t.save(),t.clip(),Qt(null,H(n.text,.07),.3*we*qt),t.restore(),B(!0,n.anchorLane,8),Qt(null,H(n.anchorLane,.6),Math.max(1.5,.03*qt)),B(!1),ce.cover){gt(co(ce.cover,()=>mo(ce.cover)).map(ue)),Qt(H(n.text,.09),H(n.text,.4));for(const f of ce.screws)sn(f,.04,.04),Qt(H(n.nut,.85))}},zn=o=>eo*(.7+.14*(z-1-o)),Ro=()=>{if(e.plate?.key!==Ln||e.plate.t!==n)return e.plate={key:Ln,t:n},qn();const o=e.plate;if(!o.image){const[i,f]=[[],[]];for(const At of[...Xt.outline,...Xt.keys.map(({u:st,side:lt,edge:U})=>[st,U+lt*.8])]){const[st,lt]=A(...ue(At));i.push(st),f.push(lt)}const l=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,c=Math.min(x,Math.max(...i)+24),p=Math.floor(Math.max(0,Math.min(...f)-24)*d)/d,T=Math.min(Ae,Math.max(...f)+24);o.image=new OffscreenCanvas(Math.max(1,Math.ceil((c-l)*d)),Math.max(1,Math.ceil((T-p)*d)));const[E,w,O]=[t,y,I];[t,y,I,o.x,o.y]=[o.image.getContext("2d"),0,null,l,p],t.setTransform(d,0,0,d,-l*d,-p*d),t.lineCap=t.lineJoin="round",qn(),[t,y,I]=[E,w,O]}t.drawImage(o.image,o.x,o.y,o.image.width/d,o.image.height/d)},Gn=()=>{t.fillStyle=n.board,gt([[0,Mt,0],[de+.6,Mt,0],[de+.6,K,0],[0,K,0]]),J(),t.fillStyle=H(n.anchorFill,.16),gt([[e.left,Mt,0],[e.right,Mt,0],[e.right,K,0],[e.left,K,0]]),J(),t.fillStyle=n.inlayDot;const o=l=>(Math.max(0,Math.ceil(l)-1)+.5)*G;t.beginPath();for(const l of En)for(const c of l%12?[o((z-1)/2)]:[o((z-1)/4),Ht-o((z-1)/4)]){const[p,T,E]=A(l-.5,c,0);t.moveTo(p+.1*E,T),t.ellipse(p,T,.1*E,.08*E,0,0,Math.PI*2)}J(),X>0&&(t.fillStyle=H(n.ink,.5),gt([[0,Mt,0],[X-Bn,Mt,0],[X-Bn,K,0],[0,K,0]]),J()),Xt&&Ro();const[,i]=A(Ft[0],K,0),[,f]=A(Ft[0],Mt,0);t.strokeStyle=Mo(t,i,f,H(n.anchorPost,.75),n.post),t.lineWidth=Math.max(1.5,.05*qt),t.beginPath();for(let l=1;l<=de;l++)fe([l,Mt-.04,0],[l,K+.04,0]);q(),t.strokeStyle=n.nut,t.lineWidth=Math.max(3,.12*qt),St([0,Mt-.06,0],[0,K+.06,0]),B(!0,n.anchorPost,12),t.strokeStyle=n.anchorPost,t.lineWidth=Math.max(3,.07*qt);for(const l of[e.left,e.right])St([l,Mt-.14,0],[l,K+.14,0]);B(!1);for(let l=0;l<z;l++){const c=zn(l);B(!0,It(l),3),t.strokeStyle=H(It(l),.9),t.lineWidth=c,xe(l),q(),B(!1),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=Math.max(.6,c*.3),xe(l,.012),q()}if(Xt&&(Xt.ends.forEach(([l,c],p)=>{if(ce.clamps)dn(l-.1,l+.1,c-.1,c+.1,.04),Qt(H(n.text,.22),H(n.text,.45)),sn([l,c],.05,.05),Qt(n.nut);else{sn([l,c],.17,.17),Qt(H(n.ink,.5),H(n.nut,.4)),sn([l,c],.085,.085),Qt(n.nut),sn([l,c],.03,.03),Qt(H(n.ink,.85));const[T,E,w]=A(...en[p]),[O,At]=A(0,yt(p),0),st=Math.atan2(At-E,O-T);t.beginPath(),t.arc(T,E,.1*we*w,st-1.3,st+1.3),Qt(null,It(p),zn(p))}}),ce.tree)){const l=[z-2,z-1].map(c=>{const[p,T]=Xt.ends[c];return wt(c)+(T-wt(c))*ce.tree/p});dn(ce.tree-.05,ce.tree+.05,Math.min(...l)-.08,Math.max(...l)+.08,.04),Qt(H(n.nut,.7),H(n.ink,.6))}for(const l of[!1,!0])for(let c=1;c<=de;c++){const p=c>=_t.fret&&c<_t.fret+_t.width,T=En.includes(c);(p||T)===l&&Yt(String(c),c-.5,Mt-.3,0,p?.3:T?.26:.2,p?n.accent:T?n.inlay:n.numOff,l?800:500,"center",!1)}},Mn=(o,i)=>A(o,i,0).slice(0,2).map(f=>Math.round(f*d*10)).join(":"),Ln=[n.headstock,z,G,mn,x,d,Math.round(le*1e4),Mn(0,Mt),Mn(de,Mt),Mn(0,K),Mn(de,K),Mn(-4,Ht/2)].join(),Sn=!et.size&&[Ln,_t.fret,_t.width,X,Math.round(e.left*1e3),Math.round(e.right*1e3)].join();if(!Sn||e.board?.key!==Sn||e.board.t!==n)e.board=Sn&&{key:Sn,t:n},Gn();else{const o=e.board;if(!o.drawn){const i=[[0,K+.2],[de,K+.2],[0,Mt-.9],[de,Mt-.9]].map(([T,E])=>A(T,E,0)[1]);Xt&&i.push(...[...Xt.outline,...Xt.keys.map(({u:T,side:E,edge:w})=>[T,w+E*.8])].map(T=>A(...ue(T))[1]));const f=Math.floor(Math.max(0,Math.min(...i)-24)*d)/d,l=Math.min(Ae,Math.max(...i)+24),[c,p]=[Math.ceil(x*d),Math.max(1,Math.ceil((l-f)*d))];(e.boardImage?.width!==c||e.boardImage.height!==p)&&(e.boardImage=new OffscreenCanvas(c,p)),[t,y,I,o.y,o.drawn]=[e.boardImage.getContext("2d"),f,null,f,!0],t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,c,p),Nt(),t.lineCap=t.lineJoin="round",t.textBaseline="middle",Gn(),[t,y,I]=[r,0,null]}t.drawImage(e.boardImage,0,o.y,e.boardImage.width/d,e.boardImage.height/d)}Ve("board");const Un=(o,i)=>o.letRing&&-i>.25;for(const o of S){const i=o.time-h;if(i>0||-i>Math.max(o.sustain,.15)||o.mute)continue;const f=It(o.string),l=Pe(o);if(B(!Un(o,i),f,10),t.strokeStyle=f,t.lineWidth=eo+3,xe(o.string,0,!0),q(),B(!1),-i<.2){const[c,p,T]=A(R(o).x,l,0);t.save(),t.translate(c,p),t.scale(1,.4);const E=t.createRadialGradient(0,0,0,0,0,.5*T);E.addColorStop(0,H(n.flash,.8*(1+i/.2))),E.addColorStop(1,H(n.flash,0)),t.fillStyle=E,t.beginPath(),t.arc(0,0,.5*T,0,Math.PI*2),J(),t.restore()}}t.strokeStyle=n.anchorLane,t.lineWidth=2.5,B(!0,n.anchorLane,10);for(const o of s.handShapes??[]){if(o.startTime>h||o.endTime<=h||o.endTime-o.startTime<.3||!o.frets.some((l,c)=>l>=0&&c<z))continue;const[i,f]=Je(o.frets.filter((l,c)=>c<z),o.startTime);gt([[i,Mt,0],[f,Mt,0],[f,K,0],[i,K,0]]),q()}if(B(!1),X>0){const o=X-Bn;t.strokeStyle=n.nut,t.lineWidth=Math.max(4,.17*qt),St([o,Mt-.16,0],[o,K+.16,0]),t.strokeStyle=H(n.ink,.45),t.lineWidth=Math.max(1,.05*qt),St([o,Mt-.13,0],[o,K+.13,0])}Ve("strings");for(const o of S){const i=o.time-h,f=ut(i),l=k(o),{a:c,open:p,x:T,y:E}=R(o),w=it(o,T,-i);if(i<-.15||o.tied||Math.abs(A(w,E,f)[0]-x/2)>x/2+200)continue;const O=p?(c.width-.2)/2:.34;t.globalAlpha=i<0?Math.max(0,1+i/.15):Math.min(1,(pt-i)/.4),!l&&Jt&&(t.strokeStyle=Jt,t.lineWidth=2,St([w-O,N,f],[w+O,N,f])),!(p||_(o))&&(t.strokeStyle=H(It(o.string),o.repeat||l?.highDensity?.35:.75),t.lineWidth=1.5,St([w,Math.min(E,Pe(o))-.42*G,f],[w,N,f]))}t.globalAlpha=1;const Eo=(o,i,f)=>{const l=Array.from({length:13},(c,p)=>{const T=p/12;return[o[0]+(i[0]-o[0])*T,o[1]+(i[1]-o[1])*T+Math.sin(Math.PI*T)*f,o[2]+(i[2]-o[2])*T]});gt(l,!1),q()};for(const o of hi(s)){if(o.end<=h||o.time>=h+pt)continue;const[i,f]=Je(o.frets,o.time),l=o.time-h,c=ut(Math.max(l,0)),p=ut(Math.min(o.end-h,pt));t.globalAlpha=Math.min(1,(pt-Math.max(l,0))/.4),B(!o.arpeggio,n.anchorLane,10,!0),t.strokeStyle=Dt(n.anchorLane,1,.2),t.lineWidth=3.5;for(const T of[i,f])St([T,N,c],[T,N,p]);B(!1),o.arpeggio&&l>0&&(t.strokeStyle=H(n.anchorLane,.7),t.lineWidth=1.5,gt([[i,N,c],[i,K,c],[f,K,c],[f,N,c]],!1),q(),o.arpeggio.name&&c>gn&&Yt(o.arpeggio.name,i-.12,K/2,c,.34,n.text,600,"right"))}t.globalAlpha=1;const Cn=(o,i)=>{const f=R(o);return Math.abs(f.x-i)<(f.open?(f.a.width-.2)/2+.1:.45)};for(const[o,i]of S.entries()){const f=i.time-h,l=k(i),c=i.slideTo??i.slideUnpitchTo??null,{a:p,open:T,x:E,y:w}=R(i),O=It(i.string),At=ut(f),st=(T?(p.width-.2)/2:.34)*(i.grace?.6:1),lt=(T?.12:.42)*G*(i.grace?.6:1);f>-.15&&!l?.highDensity&&!i.repeat&&(t.globalAlpha=Math.min(1,(pt-f)/.4),t.strokeStyle=O,t.lineWidth=2,t.setLineDash([4,4]),i.slideIn&&St([E+(i.slideIn==="below"?-1.4:1.4),w-lt,Math.max(0,At-1)],[E+(i.slideIn==="below"?-st:st),w,At]),i.slideOut&&St([E+(i.slideOut==="up"?st:-st),w,At],[E+(i.slideOut==="up"?1.4:-1.4),w-lt,At+1]),t.setLineDash([]),t.globalAlpha=1);const U=c===null?i.sustain:Math.max(i.sustain,.25),nt=c!==null||i.bend||i.bendCurve||i.whammy,te=i.tied||typeof i.tieTo=="number";if(U<=.2&&!te||f+U<=0||l&&!nt&&!te||_(i))continue;T&&c&&(t.strokeStyle=O,t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]),Eo([E,w,ut(Math.max(f,0))],[c-.5,w,ut(Math.min(f+U,pt))],G*1.5),t.setLineDash([]));let Q=null;for(let dt=o+1;dt<S.length&&S[dt].time<=i.time+U+.02;dt++){const b=S[dt];if(!(b.time<=i.time+.005)&&(k(b)||b.string===i.string||Cn(b,E))){Q=b;break}}const xt=Math.max(f,0),D=i.bend||i.bendCurve||i.whammy,Rt=c!==null&&i.slideTo===null;let Lt=Math.min(f+U,pt,Q?Q.time-h:1/0);if(Lt<=xt)continue;const Wt=dt=>{const b=dt-f,$=ut(dt),j=i.bend||i.bendCurve||i.whammy,rt=i.vibrato&&!j?Math.sin($/1.6*Math.PI*2)*G*(i.vibratoWide?.45:.25):0,$t=i.tremolo?Math.floor($/.3)%2?.05:-.05:0,Me=Pn+(Go-Pn)*yo(Math.min(1,$/Uo));return[it(i,E,b)+$t,w+rt+Pt(i,b)*Me/Pn,$]},an=Q&&Wt(Lt)[0],nn=Q&&k(Q)?.notes.find(dt=>Cn(s.notes[dt],an)),Ge=typeof nn=="number"?s.notes[nn]:Q;if(Q&&!Q.tied&&(D||Cn(Ge,an))){const dt=R(Ge),b=ut(Ge.time-h),$=dt.open?(dt.a.width-.2)/2:.34,j=A(dt.x,dt.y-(dt.open?.12:.42)*G,b)[1]+3,[rt]=A(dt.x-$,dt.y,b),[$t]=A(dt.x+$,dt.y,b),Me=He=>{const[mt,jt]=A(...Wt(He));return jt<j&&mt>Math.min(rt,$t)-2&&mt<Math.max(rt,$t)+2};if(Me(Lt)&&!Me(xt)){let He=xt,mt=Lt;for(let jt=0;jt<24;jt++)[He,mt]=Me((He+mt)/2)?[He,(He+mt)/2]:[(He+mt)/2,mt];Lt=He}if(Lt<=xt+.001)continue}const ln=c===null&&!D&&!i.vibrato&&!i.tremolo?1:Math.min(400,Math.max(12,Math.ceil((Lt-xt)*v*8))),ie=Array.from({length:ln+1},(dt,b)=>Wt(xt+(Lt-xt)*b/ln));if(T&&!l){t.fillStyle=Dt(O,i.letRing?.14:.26,.03),gt([...ie.map(([dt,b,$])=>[dt-st,b,$]),...ie.slice().reverse().map(([dt,b,$])=>[dt+st,b,$])]),J(),B(!i.letRing,O,6,!0),t.strokeStyle=Dt(O,.95,.3),t.lineWidth=2.5,t.setLineDash(i.letRing?[7,6]:[]);for(const dt of[-st,st])gt(ie.map(([b,$,j])=>[b+dt,$,j]),!1),q();t.setLineDash([]),B(!1)}else if(i.bend||i.bendCurve||i.whammy){const dt=b=>gt([...ie.map(([$,j,rt])=>[$-b,j,rt]),...ie.slice().reverse().map(([$,j,rt])=>[$+b,j,rt])]);dt(pn),t.fillStyle=Dt(O,1,.6),J(),dt(pn*.35),t.fillStyle=Dt(Tn(O,-.22),1,.55),J(),B(!0,O,8,!0),t.strokeStyle=Dt(Tn(O,.6),1,.5),t.lineWidth=2;for(const b of[-pn,pn])gt(ie.map(([$,j,rt])=>[$+b,j,rt]),!1),q();B(!1)}else{B(!i.letRing,O,6,!0);const dt=b=>Rt?pn*Math.min(1,2*(1-b/(ie.length-1))):pn;gt([...ie.map(([b,$,j],rt)=>[b-dt(rt),$,j]),...ie.map(([b,$,j],rt)=>[b+dt(rt),$,j]).reverse()],!1),t.fillStyle=Rt?Dt(O,.9,0):Dt(O,i.letRing?.5:.9,i.letRing?.2:.45),J(),t.strokeStyle=Rt?Dt(Tn(O,.6),.85,0):Dt(Tn(O,.6),1,.5),t.lineWidth=2,t.setLineDash(i.letRing?[7,6]:[]),q(),t.setLineDash([]),B(!1)}}Ve("trails");const Xn=new Set;for(let o=S.length-1;o>=0;o--){const i=S[o],f=i.time-h,l=ut(f),c=k(i),{a:p,open:T,x:E}=R(i),w=it(i,E,-f),O=Pe(i),At=i.mute||c?.fretHandMute,st=i.palmMute||c?.palmMute,lt=It(i.string),U=(T?(p.width-.2)/2:.34)*(i.grace?.6:1),nt=(T?.12:.42)*G*(i.grace?.6:1);if(f<-.15)continue;const te=f<0?Math.max(0,1+f/.15):Math.min(1,(pt-f)/.4);if(t.globalAlpha=te,c&&!Xn.has(i.chord)){Xn.add(i.chord);const[b,$]=Je(c.notes.map(mt=>s.notes[mt].fret),i.time),j=t.globalAlpha,rt=l<gn,$t=rt?.65:c.highDensity&&n.repeatMarks!=="frame"?.18:.5;if(gt([[b,N,l],[$,N,l],[$,K,l],[b,K,l]]),n.frames==="gradient"){const[,mt]=A(b,N,l),[,jt]=A(b,K,l),me=rt?n.anchorLane:n.anchorFill;kt(xo(t,`${me}|${$t}`,[[0,H(me,$t*.6)],[1,H(me,0)]]),mt,jt)}else t.globalAlpha=j*$t,c.highDensity||(t.fillStyle=n.chordFill,J()),t.strokeStyle=rt?n.anchorLane:n.chordBox,t.lineWidth=rt||!c.highDensity?1.5:1.2,B(rt,n.anchorLane,8),q(),B(!1);if(t.globalAlpha=j,t.strokeStyle=Jt,t.lineWidth=2,Jt&&St([b,N,l],[$,N,l]),c.fretHandMute&&n.repeatMarks!=="hide"){const[,,mt]=A((b+$)/2,N,l),jt=(b+$)/2,me=(N+K)/2,Ue=($-b)/2*.78,be=(K-N)/2*.72;t.strokeStyle="rgba(255, 255, 255, 0.28)",t.lineWidth=Math.max(3,.28*mt),t.lineCap="round",M(jt,me,l,Ue,be),t.lineCap="butt"}if(c.accent){const mt=Math.min(.6,($-b)*.22),jt=(K-N)*.35,me=Math.min(1,A(b,K,l)[2]/A(b,K,gn)[2]);t.strokeStyle="#ffffff",t.lineWidth=Math.max(1,3.5*me*(c.accent==="heavy"?1.4:1)),t.lineCap="square",B(!0,"#ffffff",Math.max(2,12*me)),gt([[b,K-jt,l],[b,K,l],[b+mt,K,l]],!1),q(),gt([[$-mt,K,l],[$,K,l],[$,K-jt,l]],!1),q(),B(!1),t.lineCap="round"}if(c.barre&&(!c.highDensity||n.repeatMarks==="grey")){const mt=c.barre.fret-.5;t.strokeStyle=c.highDensity?n.muted:"rgba(255, 255, 255, 0.7)",t.lineWidth=Math.max(3,.1*A(mt,Ht/2,l)[2]);const[jt,me]=[yt(c.barre.from),yt(c.barre.to)].sort((Ue,be)=>Ue-be);St([mt,jt-G*.4,l],[mt,me+G*.4,l]),Yt(c.barre.half?"½B":"B",mt,K+.12,l,.22,c.highDensity?n.muted:n.text)}if(c.strum||c.roll){const mt=b-.25,jt=yt(0)>yt(z-1)?K-.1:N+.15,me=jt>Ht/2?N+.15:K-.1,[Ue,be]=(c.strum??c.roll)==="down"?[jt,me]:[me,jt];t.strokeStyle=n.text,t.lineWidth=2,c.roll?gt(Array.from({length:17},(ui,Zn)=>[mt+Math.sin(Zn/16*Math.PI*6)*.06,Ue+(be-Ue)*Zn/16,l]),!1):gt([[mt,Ue,l],[mt,be,l]],!1),q();const un=be<Ue?.14:-.14;St([mt-.08,be+un,l],[mt,be,l]),St([mt+.08,be+un,l],[mt,be,l])}const Me=s.chords[i.chord-1],He=!Me||i.time-Me.time>1||Me.name!==c.name;l>gn&&c.name&&!c.highDensity&&He&&Yt(c.name,b-.12,K/2,l,.34,n.text,600,"right")}const[Q,xt,D]=A(w,O,l);if(Q<-200||Q>x+200||_(i)){t.globalAlpha=1;continue}const Rt=i.repeat||c?.highDensity;if(Rt){const b=l<gn;t.globalAlpha*=b?.9:.4,t.strokeStyle=lt,t.lineWidth=b?2:1.5,B(b,lt,8),Ee(w,O,l,U,nt),q(),B(!1),(st||i.mute&&!c?.fretHandMute)&&n.repeatMarks!=="hide"&&P(w,O,l,D,T?.34:U,(T?G*.3:nt)*(i.palmAgain?.5:1),st,n.muted),t.globalAlpha=te}else if(!i.tied){if(!T&&ne){const b=i.harmonic||i.harmonicPinch?`<${i.fret}>`:i.ghost?`(${i.fret})`:String(i.fret),$=i.grace?.7:1;Gt(b,w,l,io*$,so*$,H(lt,ne))}if(i.dynamicLabel&&Yt(i.dynamicLabel,w-.6,N,l,.3,n.text,"italic 700","right"),i.ghost&&(t.globalAlpha=te*.5),n.gem==="pill")n.notes3d!==!1&&(Ee(w,O,l+no,U,nt),t.fillStyle=lt,J(),t.fillStyle="rgba(255, 255, 255, 0.35)",J()),Ee(w,O,l,U,nt),t.fillStyle=lt,J();else{const b=i.harmonic||i.harmonicPinch,$=no;if(!b&&n.notes3d!==!1)for(const[$t,Me]of[[[[w-U,O+nt,l],[w+U,O+nt,l],[w+U,O+nt,l+$],[w-U,O+nt,l+$]],"rgba(255, 255, 255, 0.35)"],[[[w-U,O-nt,l],[w-U,O+nt,l],[w-U,O+nt,l+$],[w-U,O-nt,l+$]],"rgba(0, 0, 0, 0.4)"],[[[w+U,O-nt,l],[w+U,O+nt,l],[w+U,O+nt,l+$],[w+U,O-nt,l+$]],"rgba(0, 0, 0, 0.4)"]])gt($t),t.fillStyle=lt,J(),t.fillStyle=Me,J();B(l<gn,lt,8),t.fillStyle=lt,b?gt([[w,O+nt*1.3,l],[w+U*.8,O,l],[w,O-nt*1.3,l],[w-U*.8,O,l]]):Ee(w,O,l,U,nt),J(),B(!1);const[,j]=A(w,O+nt,l),[,rt]=A(w,O-nt,l);kt(xo(t,"shine",[[0,"rgba(255, 255, 255, 0.45)"],[.5,"rgba(255, 255, 255, 0)"],[1,"rgba(0, 0, 0, 0.25)"]]),j,rt),t.strokeStyle="rgba(255, 255, 255, 0.6)",t.lineWidth=1,q()}if((st||i.mute&&!c?.fretHandMute)&&P(w,O,l,D,T?.34:U,(T?G*.3:nt)*(i.palmAgain?.5:1),st,T&&st?lt:null),!T&&!At&&!st){const b=i.finger??(c?.fingers?.[i.string]>=0?c.fingers[i.string]:null),$=b!==null?b===0?"T":String(b):"";if($){const j=t.globalAlpha;t.globalAlpha=j*Math.min(1,Math.max(0,(1-f/pt)/.4)),Yt($,w,O,l-.01,G*.62,Y,700,"center",m,!0),t.globalAlpha=j}}}if(Rt&&n.repeatMarks==="hide"){t.globalAlpha=1;continue}const Lt=Rt?n.muted:n.text;if(t.globalAlpha=te*(Rt?.8:1)*Math.min(1,Math.max(0,(1-f/pt)/.15)),i.ghost){const[b]=A(w-U,O,l),[$]=A(w+U,O,l),j=nt*D*1.5;t.strokeStyle=Rt?Lt:lt,t.lineWidth=Math.max(1.2,.035*D),t.beginPath(),t.arc(b+j*.35,xt,j,Math.PI*.7,Math.PI*1.3),q(),t.beginPath(),t.arc($-j*.35,xt,j,-Math.PI*.3,Math.PI*.3),q()}if(i.grace&&(t.strokeStyle=Lt,t.lineWidth=Math.max(1,.03*D),Io(t,Q-U*D*le*1.2,xt+nt*D*1.4,Q+U*D*le*1.2,xt-nt*D*1.4)),i.showString){const[b]=A(w-U,O,l),$=.12*D,j=b-$-.06*D;t.strokeStyle=t.fillStyle=Rt?Lt:lt,t.lineWidth=Math.max(1,.025*D),t.beginPath(),t.arc(j,xt,$,0,Math.PI*2),q(),bt(String(z-i.string),j,xt,.15*D,700,"center"),t.fillText(String(z-i.string),0,0),Nt()}let Wt=xt-nt*D-.18*D;t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D),t.textAlign="center";const an=(b,$,j)=>{t.beginPath();for(let rt=0;rt<=20;rt++)t[rt?"lineTo":"moveTo"](Q-b+2*b*rt/20,Wt+Math.sin(rt/20*Math.PI*2*j)*$);q()},nn=(b,$,j="700")=>{$*D<2||(bt(b,Q,Wt,$*D,j,"center"),t.fillText(b,0,0),Nt(),Wt-=($+.04)*D)};let Ge=xt-nt*D;const Rn=i.tap&&!i.tapLeft;if((i.hammerOn||i.pullOff)&&!Rn&&!i.tied){const b=i.grace?.6:1,$=.34*D*le*b,j=.72*G*D*b,[rt,$t]=i.hammerOn?[xt+j/2,xt-j/2]:[xt-j/2,xt+j/2];t.beginPath(),t.moveTo(Q-$,$t),t.lineTo(Q+$,$t),t.lineTo(Q,rt),t.closePath(),t.fillStyle=Rt?Lt:"#ffffff",t.strokeStyle=H(n.ink,.9),t.lineWidth=Math.max(2,.04*D),q(),J(),t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D)}if(Rn&&!i.tied){const b=i.grace?.6:1,$=.28*D*le*b,j=.62*G*D*b,rt=Ge+.15*j,$t=rt-j;t.beginPath(),t.moveTo(Q,rt),t.lineTo(Q+$,$t),t.lineTo(Q,$t+.38*j),t.lineTo(Q-$,$t),t.closePath(),t.strokeStyle=H(n.ink,.9),t.lineWidth=Math.max(3.5,.1*D),q(),t.fillStyle=Rt?H(Lt,.4):H(Tn(lt,.55),.85),J(),t.strokeStyle=Rt?Lt:lt,t.lineWidth=Math.max(1.8,.05*D),q(),Ge=$t,Wt=Math.min(Wt,Ge-.14*D),t.strokeStyle=t.fillStyle=Lt,t.lineWidth=Math.max(1.2,.04*D)}const ln=rn(i);if(ln>0){const b=i.bendCurve?.[0]?.[1]>0,$=(i.bendCurve?.length??0)>1&&i.bendCurve.at(-1)[1]<ln,j=Math.min(3,Math.max(1,Math.round(ln*2))),rt=U*D*le*.6,$t=U*D*.3,Me=$t*1.25,He=H(n.ink,.9);let mt=Ge-.04*D;const jt=be=>{for(let un=0;un<j;un++)$o(t,Q,mt-un*Me-(be>0?0:$t),rt,$t,be,Rt?Lt:lt,He);mt-=j*Me+.08*D},me=V(i.string);(!b||!$)&&jt(-me),$&&jt(me);const Ue=`${b?"pre ":""}${Fn(ln)}`;t.fillStyle=Lt,bt(Ue,Q+rt+.08*D,(xt-nt*D+mt)/2,.22*D,700,"left"),t.fillText(Ue,0,0),Nt(),t.textAlign="center",Wt=Math.min(Wt,mt-.1*D)}i.staccato&&(t.beginPath(),t.arc(Q,Wt+.04*D,Math.max(1.5,.045*D),0,Math.PI*2),J(),Wt-=.16*D);const ie=!i.tied;ie&&i.accent&&(i.accent==="tenuto"||!c?.accent)&&nn({heavy:"^",tenuto:"–"}[i.accent]??">",.3);const dt=[ie&&i.tapLeft?"m.g.":"",Po[i.harmonicType]??(ie&&i.harmonicPinch?"PH":""),ie&&(i.slap?"slap":i.pop?"pop":""),ie&&i.golpe?`golpe (${i.golpe})`:"",ie&&i.rasgueado?`rasg. ${i.rasgueado}`:"",typeof i.trill=="number"?`tr ${i.trill}`:"",i.ornament??"",i.fade??"",i.whammy?"w/bar":"",i.wah==="open"?"o":i.wah==="closed"?"+":""];for(const b of dt)b&&nn(b,b.length>2?.22:.28);if(ie&&i.rightFinger&&nn(i.rightFinger,.26,"italic 700"),i.pick){const b=.09*D,$=.13*D;t.beginPath(),i.pick==="down"?[[-b,$/2],[-b,-$/2],[b,-$/2],[b,$/2]].forEach(([j,rt],$t)=>t[$t?"lineTo":"moveTo"](Q+j,Wt+rt)):[[-b,-$/2],[0,$/2],[b,-$/2]].forEach(([j,rt],$t)=>t[$t?"lineTo":"moveTo"](Q+j,Wt+rt)),q(),Wt-=.22*D}if(i.fermata&&(t.beginPath(),t.arc(Q,Wt+.06*D,.14*D,Math.PI,0),q(),t.beginPath(),t.arc(Q,Wt+.02*D,Math.max(1.5,.03*D),0,Math.PI*2),J(),Wt-=.24*D),i.tremolo){for(let b=-1;b<=1;b++)Io(t,Q-.12*D,Wt+(b*.08+.05)*D,Q+.12*D,Wt+(b*.08-.05)*D);Wt-=.3*D,an(.14*D,.04*D,1.5),Wt-=.14*D}t.globalAlpha=1}Ve("notes");const jn=new Set;for(const o of S){const i=o.time-h,f=k(o);if(!f?.barre||jn.has(f)||i>.06||i<-Math.max(o.sustain,.12))continue;jn.add(f),t.strokeStyle="rgba(255, 255, 255, 0.85)",t.lineWidth=Math.max(4,.12*qt);const[l,c]=[yt(f.barre.from),yt(f.barre.to)].sort((p,T)=>p-T);St([f.barre.fret-.5,l-G*.45,0],[f.barre.fret-.5,c+G*.45,0])}const Kn=new Set,Jn=new Set;for(const o of S){const i=o.time-h,f=k(o),l=et.get(o.string),c=o.heldFrom??null,p=i<=.06||c!==null&&h>=c-.06,T=(o.slideTo??o.slideUnpitchTo??null)!==null;if(o.mute||i>vn||i<-Math.max(o.sustain,T?.25:.12)||(f?.highDensity||c!==null)&&!p||l&&l.note!==o&&!p||p&&Kn.has(`${o.string}:${o.fret}`))continue;p&&Kn.add(`${o.string}:${o.fret}`),Jn.add(`${o.string}:${o.fret}`);const{a:E,open:w,x:O}=R(o),At=it(o,O,-i),st=Pe(o),lt=It(o.string),U=(w?(E.width-.2)/2:.32)+2/qt,nt=(w?.1:.36)*G+2/qt;if(Ee(At,st,0,U,nt),p)B(!Un(o,i),lt,14),t.fillStyle=lt,J(),B(!1),t.strokeStyle="rgba(255, 255, 255, 0.7)",t.lineWidth=1.5,q();else{const Q=(1-i/vn)**2;t.globalAlpha=.35*Q,t.fillStyle=lt,J(),t.globalAlpha=.25+.75*Q,t.strokeStyle=lt,t.lineWidth=2.2,q()}const te=o.finger??(f?.fingers?.[o.string]>=0?f.fingers[o.string]:null);if(!w&&te!==null&&Yt(te===0?"T":String(te),At,st,0,G*.55,p?Y:n.text,800,"center",!p||m),!w&&rn(o)>0){const Q=V(o.string),xt=o.bendCurve?.[0]?.[1]>0&&o.bendCurve.at(-1)[1]<rn(o),[D,Rt]=A(At,st+Q*nt,0);$o(t,D,Rt-Q*(xt?.14:.05)*qt,.17*qt*le,.085*qt,(xt?1:-1)*Q,"#ffffff",H(n.ink,.9))}t.globalAlpha=1}for(const o of s.handShapes??[])!o.arpeggio||o.startTime-h>vn||o.endTime<=h||(t.globalAlpha=.3+.5*Math.min(1,1-(o.startTime-h)/vn)**2,o.frets.forEach((i,f)=>{if(i<=0||f>=z||Jn.has(`${f}:${i}`))return;const l=i-.5,c=yt(f),p=o.fingers[f];Ee(l,c,0,.32+2/qt,.36*G+2/qt),t.strokeStyle=It(f),t.lineWidth=2.2,q(),p>=0&&Yt(p===0?"T":String(p),l,c,0,G*.55,n.text,800)}),t.globalAlpha=1);Ve("targets");const Vn=ri(s),On=Vn.findLast(o=>o.time<=h&&h<o.end+.3),Bo=On?null:Vn.find(o=>o.time>h&&o.time-h<1.2),bn=On??Bo;if(bn){const[o,i]=A(e.right+.4,K+.5,0),f=Kt(t,Z[700]??=`700 ${We}px ${n.num}`,bn.name).width*52/We;t.globalAlpha=On?1:Math.max(.35,1-(bn.time-h)/1.2),t.fillStyle=n.text,bt(bn.name,Math.min(o,x-24-f),i,52,700,"left"),t.fillText(bn.name,0,0),Nt(),t.globalAlpha=1}Ve("labels")}const Do=298,ci=240,mi=64,Ke=100,Fe=24,Lo=150;function Co(a,s){if(a.tabPages?.length===s)return a.tabPages.pages;const h=a.notes.at(-1),n=Math.max(h?h.time+h.sustain:0,a.beats.at(-1)?.time??0)+.5;let e=a.beats.filter(d=>d.measure>=0).map(d=>d.time);e.length<2&&(e=Array.from({length:Math.ceil(n/s)+1},(d,t)=>t*s)),e=[Math.min(0,e[0]),...e.filter(d=>d>0),Math.max(n,e.at(-1)+.01)];const r=[];let x=e[0];for(let d=1;d<e.length;d++)e[d]-x>s&&e[d-1]>x&&r.push({start:x,end:x=e[d-1]});r.push({start:x,end:e.at(-1)});for(let d=0;d<r.length-1;d++)r[d].end=r[d+1].start;return a.tabPages={length:s,pages:r},r}const Yn=(a,s)=>a.str[s%a.str.length],Oo=110,di=15.75;function Mi(a,s,h,n,e={}){const{g:r,W:x}=Nn(a);if(!s)return;const d=s.strings,t=di*(n.boardHeight??1),F=t*(d-1),X=(n.tabMarks??"all")==="all",_t=n.paper==="light",z=_t?"#15181f":n.text,Et=_t?"#5c6472":n.muted,G=Fe+46,Ht=x-Fe-16,yt=Ht-G,V=!!n.sheetNotes,v=t*.6,pt=V&&typeof document<"u"&&!!document.fonts?.check(`${4*v}px "Noto Music"`,"𝄠"),Mt=P=>(Math.floor(P/12)-1)*7+[0,0,1,1,2,3,3,4,4,5,5,6][P%12];if(V&&!s.sheetRange){let P=38;for(const I of s.notes)P=Math.max(P,Mt((s.open?.[I.string]??40)+I.fret+12));s.sheetRange={over:Math.max(2,Math.ceil((P-38)/2)+1),under:Math.max(6,Math.floor((30-Mt((s.open?.[0]??40)+12))/2)+2.5)}}const K=V?s.sheetRange.over:0,N=V?s.sheetRange.under:0,Tt=V?v*(K+4+N):0,ut=s.lyrics?.length?t*1.3:0,It=n.tabMarks!=="notes",Jt=44+Tt,ne=t*1.3,ye=Math.max(2,t*.16),Ft=Jt+F+(V?t:ne)+ut+t*2.8,oe=V?s.keys?.findLast(P=>P.time<=h)?.fifths??0:0,ge=oe<0,Ze=`${4*v}px "Noto Music"`,Te={1:["♯",.9],"-1":["♭",.8],0:["♮",.7]},ke=V?v*(.6+2.84+.5+Math.abs(oe)*1.15+1):0,Ne=ge?[0,1,1,2,2,3,4,4,5,5,6,6]:[0,0,1,1,2,3,3,4,4,5,5,6],Se=ge?[0,-1,0,-1,0,0,-1,0,-1,0,-1,0]:[0,1,0,1,0,0,1,0,1,0,1,0],Ye=[0,0,0,0,0,0,0];for(let P=0;P<Math.abs(oe);P++)Ye[(ge?[6,2,5,1,4,0,3]:[3,0,4,1,5,2,6])[P]]=ge?-1:1;const $e=new Path2D,C=[];if(V&&!s.sheetShortest){let P=1/0;const I=s.rhythm??[];for(let y=1;y<I.length;y++)I[y].time-I[y-1].time>.001&&(P=Math.min(P,I[y].time-I[y-1].time));s.sheetShortest=P}const ft=V&&s.sheetShortest<1/0?Math.max(Oo,1.75*v/s.sheetShortest):Oo,tt=Co(s,(yt-ke)/ft),Ct=Math.max(0,tt.findLastIndex(P=>P.start<=h)),Ot=Do,ae=Ae-66,Ie=ae-Ot-22>=2*Ft?1:0;(e.sheetY===void 0||n.sheetScroll!=="manual"&&e.sheetAt!==Ct)&&(e.sheetY=Math.max(0,Ct-Ie)*Ft),e.sheetAt=Ct,e.sheetY=Math.min(Math.max(0,e.sheetY),Math.max(0,tt.length*Ft+22-(ae-Ot)));const le=Ot+22-e.sheetY,re=s.rhythm??[],ve=(d-1)/2;r.save(),r.beginPath(),r.rect(Fe,Ot,x-Fe*2,ae-Ot),r.clip();const Vt=(P,I)=>P+(n.stringOrder==="high"?d-1-I:I)*t,Xe=`700 ${ee(t*.95)}px ${n.num}`,qe=`600 ${ee(10.5)}px ${n.ui}`,De=`700 ${ee(t*.55)}px ${n.num}`,hn=`italic 600 ${ee(11.5)}px ${n.ui}`,Le=new Path2D,Ce=new Path2D,fn=new Path2D,Qe=new Path2D,pe=new Path2D,Zt=new Path2D,ze=new Path2D,A=new Path2D,on=new Path2D,Oe=`600 ${ee(9.5)}px ${n.ui}`,qt=`600 ${ee(12)}px ${n.num}`,cn=P=>P.chord===null||P.chord===void 0?null:s.chords?.[P.chord],Re=P=>P.value>=8?Math.round(Math.log2(P.value))-2:0,he=[],gt=[],St=[],Ee=[],Je=[],M={box:null,x:null},m=new Set((s.markers??[]).filter(P=>P.text.startsWith("repeat")).map(P=>Math.round(P.time*50))),Y=new Map((s.meters??[]).map(P=>[Math.round(P.time*50),P.text]));r.textAlign="center";for(let P=0;P<tt.length;P++){const I=le+P*Ft;if(I+Ft<Ot)continue;if(I>ae)break;const y=tt[P],ct=(yt-ke)/(y.end-y.start),Z=W=>G+ke+(W-y.start)*ct,bt=I+Jt,Nt=bt+F,kt=Nt+5+ne,Yt=bt-v*N,Gt=Yt-4*v,zt=W=>Yt-(W-30)*v/2,vt=V?Gt-v*K:bt;for(let W=0;W<d;W++)Le.moveTo(G,Vt(bt,W)),Le.lineTo(Ht,Vt(bt,W));if(V){for(let g=0;g<5;g++)Le.moveTo(G,Gt+g*v),Le.lineTo(Ht,Gt+g*v);Ce.moveTo(G,Gt),Ce.lineTo(G,Nt);const W=G+v*.6;C.push(["𝄠",W,Yt]);const u=ge?[34,37,33,36,32,35,31]:[38,35,39,36,33,37,34];for(let g=0;g<Math.abs(oe);g++)C.push([Te[ge?-1:1][0],W+v*(2.84+.5+g*(ge?1.05:1.15)),zt(u[g])+v*.52])}if(P===0&&s.open)for(let W=0;W<d;W++)Ee.push([Qn(s.open[W]),G-16,Vt(bt,W)+t*.32,Yn(n,W)]);for(let W=se(s.beats,y.start-.001);W<s.beats.length&&s.beats[W].time<y.end-.001;W++){const u=s.beats[W],g=Z(u.time),L=Math.round(u.time*50);if(u.measure<0){ze.moveTo(g+1.6,vt-11),ze.arc(g,vt-11,1.6,0,Math.PI*2);continue}const S=m.has(L)?fn:Ce;if(S.moveTo(g,bt),S.lineTo(g,Nt),V&&(S.moveTo(g,Gt),S.lineTo(g,Yt)),m.has(L))for(const _ of[ve-.5,ve+.5])ze.moveTo(g+8.6,Vt(bt,0)+_*t),ze.arc(g+7,Vt(bt,0)+_*t,1.6,0,Math.PI*2);he.push([qe,String(u.measure),g+1,vt-8,Et,"left"]);const k=Y.get(L)??(W===0?s.meters?.[0]?.text:null);if(k){const[_,R]=k.split("/"),it=g+12+(m.has(L)?6:0),Pt=`600 ${ee(F*.38)}px ${n.num}`;he.push([Pt,_,it,bt+F*.45,z,"center"],[Pt,R,it,bt+F*.97,z,"center"])}}let Dt=-1/0,Ut=-1/0;for(const W of s.sections??[])if(W.time>=y.start&&W.time<y.end){const u=Z(W.time)+1;he.push([hn,W.name,u,vt-34,z,"left"]),Ut=u+Kt(r,hn,W.name).width+16}for(const W of s.markers??[])if(W.time>=y.start&&W.time<y.end&&!W.text.startsWith("repeat")&&!/^\d+\/\d+$/.test(W.text)){const u=Math.max(Z(W.time)+1,Dt);he.push([qe,W.text,u,vt-21,W.text.startsWith("♩")?n.accent:z,"left"]),Dt=u+Kt(r,qe,W.text).width+10}const B=new Map,ot=new Map,at=new Set,Bt={palm:[],ring:[]};for(let W=se(s.notes,y.start-.001);W<s.notes.length&&s.notes[W].time<y.end-.001;W++){const u=s.notes[W],g=Z(u.time),L=Vt(bt,u.string),S=u.grace?.72:1,k=u.mute?"×":u.harmonic||u.harmonicPinch?`<${u.fret}>`:u.ghost?`(${u.fret})`:String(u.fret),_=at.has(W)?`(${k})`:k,R=Kt(r,Xe,_).width*S,it=g-(B.get(u.string)??-1/0)-2,Pt=Math.min(1,Math.max(.55,2*it/R)),ht=S*Pt<1?`700 ${ee(t*.95*S*Pt)}px ${n.num}`:Xe,et=Kt(r,ht,_).width;B.set(u.string,g+et/2),Qe.rect(g-et/2-2.5,L-t*.5,et+5,t);const xe=u.time<=h&&h<u.time+Math.max(u.sustain,.15);if((xe?St:Je).push([ht,_,g,L+Kt(r,ht,"5").middle,xe?Yn(n,u.string):z]),X&&Pt===1&&it>R/2+12&&!u.mute&&u.fret>0&&u.finger!==null&&u.finger!==void 0&>.push([u.finger===0?"T":String(u.finger),g+et/2+2,L+t*.45]),typeof u.tieTo=="number"&&(at.add(u.tieTo),s.notes[u.tieTo].time<y.end)){const Pe=Z(s.notes[u.tieTo].time);A.moveTo(g+et/2,L+t*.45),A.quadraticCurveTo((g+Pe)/2,L+t*1.2,Pe-et/2,L+t*.45)}if(It){const Pe=u.slideTo??u.slideUnpitchTo??null,ce=Pe!==null?Math.sign(Pe-u.fret)||1:u.slideOut==="up"?1:u.slideOut?-1:0;if(ce&&(A.moveTo(g+et/2+2,L+ce*t*.32),A.lineTo(g+et/2+t*.75,L-ce*t*.32)),u.slideIn){const wt=u.slideIn==="below"?1:-1;A.moveTo(g-et/2-t*.75,L+wt*t*.32),A.lineTo(g-et/2-2,L-wt*t*.32)}const we=ot.get(u.string);if((u.hammerOn||u.pullOff)&&we&&g-we.x<t*8&&(A.moveTo(we.x,L-t*.55),A.quadraticCurveTo((we.x+g)/2,L-t*1.5,g,L-t*.55),he.push([Oe,u.hammerOn?"H":"P",(we.x+g)/2,L-t*1.05,Et,"center"])),u.vibrato)for(let wt=g-et/2;wt<=g+et/2+1;wt+=2)A[wt===g-et/2?"moveTo":"lineTo"](wt,L-t*.62+Math.sin((wt-g)/1.6)*1.4);const mn=rn(u);if(mn>0){const wt=g+et/2+t*.6,Xt=L-t*1.25;A.moveTo(g+et/2+1,L-t*.15),A.quadraticCurveTo(wt,L-t*.5,wt,Xt),A.moveTo(wt-3,Xt+4),A.lineTo(wt,Xt),A.lineTo(wt+3,Xt+4),he.push([Oe,Fn(mn),wt,Xt-3,z,"center"])}const ue=cn(u);for(const[wt,Xt]of[["palm",u.palmMute||ue?.palmMute],["ring",u.letRing]])if(Xt){const en=Bt[wt].at(-1);en&&u.time-en.end<.8?Object.assign(en,{end:u.time,x1:g+et/2}):Bt[wt].push({x0:g-et/2,x1:g+et/2,end:u.time})}if(ue?.name&&ue.notes[0]===W){const wt=s.chords[u.chord-1];(!wt||u.time-wt.time>1||wt.name!==ue.name)&&he.push([qt,ue.name,Math.max(g-et/2,Ut),vt-34,z,"left"])}}ot.set(u.string,{x:g,y:L})}for(const[W,u]of[["palm","P.M."],["ring","let ring"]])for(const g of Bt[W]){const L=Kt(r,Oe,u).width;he.push([Oe,u,g.x0,vt-21,Et,"left"]),g.x1>g.x0+L+8&&(on.moveTo(g.x0+L+4,vt-24),on.lineTo(g.x1,vt-24),A.moveTo(g.x1,vt-27),A.lineTo(g.x1,vt-21))}if(s.lyrics?.length){let W=-1/0;for(let u=se(s.lyrics,y.start-.001);u<s.lyrics.length&&s.lyrics[u].time<y.end-.001;u++){const g=Math.max(Z(s.lyrics[u].time),W);he.push([qe,s.lyrics[u].text,g,Nt+(V?t:ne)+t*1.55,Et,"left"]),W=g+Kt(r,qe,s.lyrics[u].text).width+5}}const q=new Map;if(V){const W=[...Ye];let u=Math.max(0,se(s.beats,y.start)-1);for(let g=se(s.notes,y.start-.001);g<s.notes.length&&s.notes[g].time<y.end-.001;g++){const L=s.notes[g],S=Z(L.time),k=(s.open?.[L.string]??40)+L.fret+12,_=k%12,R=(Math.floor(k/12)-1)*7+Ne[_],it=zt(R),Pt=v*(L.grace?.35:.5);for(;s.beats[u+1]?.time<=L.time+1e-4;)s.beats[++u].measure>=0&&W.splice(0,7,...Ye);const ht=L.time<=h&&h<L.time+Math.max(L.sustain,.15);q.set(g,{x:S,y:it,r:Pt,step:R}),ht?St.push(["head",S,it,Pt,Yn(n,L.string)]):(Zt.moveTo(S+Pt,it),Zt.ellipse(S,it,Pt,Pt*.81,-.35,0,Math.PI*2));for(let et=28;et>=R;et-=2)$e.moveTo(S-v*.9,zt(et)),$e.lineTo(S+v*.9,zt(et));for(let et=40;et<=R;et+=2)$e.moveTo(S-v*.9,zt(et)),$e.lineTo(S+v*.9,zt(et));if(W[Ne[_]]!==Se[_]){W[Ne[_]]=Se[_];const[et,xe]=Te[Se[_]];C.push([et,S-v*(.5+.25+xe+.2),it+v*.52])}}}const J=[];let je=0,tn=-1,Be=Math.max(0,se(s.beats,y.start)-1);const _e=Gt+2*v,fe=()=>{if(!J.length)return;const W=V?J.filter(k=>k.up).length*2>=J.length:!1,u=V&&W?1:-1,g=V?v*.5:ye,L=V?v*.25:ye*.6;let S=kt;if(V){for(const R of J)R.sx=R.x+(W?v*.44:-v*.44),R.sy=W?R.lo:R.hi,R.tip=W?Math.min(R.hi-v*3.5,_e):Math.max(R.lo+v*3.5,_e);const k=J.map(R=>R.sy),_=k.reduce((R,it)=>R+it,0)/k.length;S=J.length===1?J[0].tip+(Re(J[0].r)>2?u*-v*.58:0):W?Math.min(_-v*3.5,Math.min(...J.map(R=>R.hi))-v*2.5):Math.max(_+v*3.5,Math.max(...J.map(R=>R.lo))+v*2.5)}for(const k of J)pe.moveTo(k.sx,k.sy),pe.lineTo(k.sx,S);for(let k=0;J.length>1&&k<je;k++){const _=S+u*k*(g+L)-(u<0?g:0);let R=-1;for(let it=0;it<=J.length;it++){const Pt=it<J.length&&Re(J[it].r)>k;if(Pt&&R<0&&(R=it),Pt||R<0)continue;const ht=J[R].sx-(V?v*.06:0),et=J[it-1].sx+(V?v*.06:0),xe=R===it-1,Pe=V?v*1.1:t*.8;Zt.rect(xe&&R?et-Pe:ht,_,xe?Pe:et-ht,g),R=-1}}if(J.length===1&&Re(J[0].r)){const k=J[0];if(V)C.push(["𝅥"+["𝅮","𝅯","𝅰"][Math.min(3,Re(k.r))-1],k.sx-v*.06,k.sy+v*.54,W?1:-1,k.sy]);else for(let _=0;_<Re(k.r);_++)Zt.rect(k.x,S-_*(g+L)-g,t*.8,g)}J.length=je=0};for(let W=Math.max(0,se(re,y.start)-1);W<re.length;W++){const u=re[W];if(u.time>=y.end-.001)break;if(u.time<y.start-.001)continue;const g=Z(u.time),L=t*1.1/20;for(;s.beats[Be+1]?.time<=u.time+1e-4;)Be++;if((Be!==tn||u.rest)&&fe(),tn=Be,u.rest&&V){if(u.value<=2)Zt.rect(g-v*.6,u.value===1?Gt+v:Gt+v*1.5,v*1.2,v*.5);else{const k=Math.min(3,Math.round(Math.log2(u.value))-2),_=[1.03,1.05,1.32,1.6][k];C.push([["𝄽","𝄾","𝄿","𝅀"][k],g-v*.2-_*v/2,Yt])}continue}if(u.rest){const k=bt+ve*t;if(u.value<=2)Zt.rect(g-6*L,k-(u.value===1?5:0)*L,12*L,5*L);else{if(pe.moveTo(g+(u.value===4?-3:4)*L,k+(u.value===4?-10:-7)*L),u.value>4)pe.lineTo(g-3*L,k+9*L);else for(const[_,R]of[[3,-3],[-3,3],[4,9]])pe.lineTo(g+_*L,k+R*L);for(let _=0;_<Re(u);_++)Zt.moveTo(g+(4-_*1.6)*L,k+(-5+_*5)*L),Zt.arc(g+(2-_*1.6)*L,k+(-5+_*5)*L,2*L,0,Math.PI*2)}continue}let S={r:u,x:g,stems:pe,up:!1,lo:Nt+5,hi:Nt+5,sx:g,sy:Nt+5,tip:kt};if(V){const k=[];for(let ht=se(s.notes,u.time-.001);ht<s.notes.length&&s.notes[ht].time<=u.time+.001;ht++)q.has(ht)&&!s.notes[ht].grace&&k.push(q.get(ht));if(!k.length)continue;const _=k.map(ht=>ht.y),R=Math.max(..._),it=Math.min(..._),Pt=Math.abs(R-_e)>=Math.abs(it-_e);if(S={r:u,x:g,stems:pe,up:Pt,lo:R,hi:it,sx:g+(Pt?v*.44:-v*.44),sy:Pt?R:it,tip:Pt?Math.min(it-v*3.5,_e):Math.max(R+v*3.5,_e)},u.value<=2)for(const ht of k)Qe.moveTo(ht.x+v*.32,ht.y),Qe.ellipse(ht.x,ht.y,v*.32,v*.17,-.6,0,Math.PI*2);for(const ht of k)for(let et=0;et<u.dots;et++){const xe=ht.step%2===0?-v*.5:0;Zt.moveTo(ht.x+v*(1.2+et*.5)+v*.2,ht.y+xe),Zt.arc(ht.x+v*(1.2+et*.5),ht.y+xe,v*.2,0,Math.PI*2)}}else for(let k=0;k<u.dots;k++)Zt.moveTo(g+t*.5+k*t*.4+t*.13,kt-t*.4),Zt.arc(g+t*.5+k*t*.4,kt-t*.4,t*.13,0,Math.PI*2);if(u.value===1){fe();continue}Re(u)?(J.push(S),je=Math.max(je,Re(u))):(fe(),pe.moveTo(S.sx,S.sy),pe.lineTo(S.sx,S.tip))}if(fe(),P===Ct){const W=Math.max(0,se(re,h+1e-4)-1),u=re[W];if(u&&u.time>=y.start-.001&&u.time<y.end){const g=re[W+1]&&re[W+1].time<y.end?re[W+1].time:y.end,L=Z(u.time)-t*(V?1:.75),S=Z(g)-t*(V?.3:.35),k=V?vt-t*.5:bt-t*.7;n.beatBox!==!1&&(M.box=[L,k,Math.max(S-L,t*1.5),Nt+t*.5-k+(V?0:ne*.45+t*.2)])}M.x=[Z(Math.min(h,y.end)),(V?vt:bt)-t*.5,Nt+t*.5]}}if(r.lineCap="butt",r.strokeStyle=H(z,.42),r.lineWidth=V?Math.max(1,v*.13):1,r.stroke(Le),r.strokeStyle=H(z,.7),r.lineWidth=V?Math.max(1.2,v*.16):1.2,r.stroke(Ce),r.lineWidth=V?v*.5:3,r.stroke(fn),r.fillStyle=Et,r.fill(ze),r.strokeStyle=r.fillStyle=z,r.lineWidth=V?Math.max(1,v*.12):Math.max(1.2,t*.09),r.stroke(pe),r.lineWidth=Math.max(1,v*.16),r.stroke($e),r.lineCap="round",r.fill(Zt),r.strokeStyle=z,r.lineWidth=1.1,r.stroke(A),r.setLineDash([4,3]),r.stroke(on),r.setLineDash([]),pt){r.font=Ze,r.textAlign="left",r.textBaseline="alphabetic";for(const[P,I,y,ct,Z]of C)ct===-1?(r.save(),r.translate(I,Z),r.scale(1,-1),r.fillText(P,0,v*.54),r.restore()):r.fillText(P,I,y)}r.globalCompositeOperation="destination-out",r.fill(Qe),r.globalCompositeOperation="source-over";for(const[P,I,y,ct,Z,bt]of he)r.font=P,r.fillStyle=Z,r.textAlign=bt,r.fillText(I,y,ct);r.textAlign="center",r.font=Xe,r.fillStyle=z;for(const[P,I,y,ct]of Je)P!==Xe&&(r.font=P),r.fillText(I,y,ct),P!==Xe&&(r.font=Xe);r.font=De,r.textAlign="left",r.globalAlpha=.7;for(const[P,I,y]of gt)r.fillText(P,I,y);r.globalAlpha=1,r.textAlign="center";for(const[P,I,y,ct,Z]of St)r.fillStyle=r.shadowColor=Z,r.shadowBlur=12,P==="head"?(r.beginPath(),r.ellipse(I,y,ct,ct*.81,-.35,0,Math.PI*2),r.fill()):(r.font=P,r.fillText(I,y,ct));r.shadowBlur=0,r.font=qe;for(const[P,I,y,ct]of Ee)r.fillStyle=ct,r.fillText(P,I,y);if(M.box&&(r.strokeStyle=H(n.accent,.35),r.fillStyle=H(n.accent,.1),r.lineWidth=1,r.beginPath(),r.roundRect(...M.box,4),r.fill(),r.stroke()),M.x){const[P,I,y]=M.x,ct=t*.9;r.strokeStyle=n.accent,r.lineWidth=1.5,r.beginPath(),r.roundRect(P-ct/2,I,ct,y-I,ct/2),r.stroke()}r.restore(),r.globalCompositeOperation="destination-over",r.beginPath(),r.roundRect(Fe,Ot,x-Fe*2,ae-Ot,16),r.fillStyle=_t?"#ffffff":H(n.ink,.72),r.fill(),r.globalCompositeOperation="source-over",r.strokeStyle=_t?"#d3d7df":n.chipBorder,r.lineWidth=1,r.stroke(),Ve("sheet")}function bi(a,s,h,n){const{g:e,W:r}=Nn(a);if(!s)return;const x=s.strings,d=Math.min(mi,320/Math.max(1,x-1))*(n.boardHeight??1),t=Do,F=t+d*2.2,X=F+d*(x-1),_t=X+d*1.45,z=F-d*1.55,Et=Math.min(20,d*.32),G=C=>F+(n.stringOrder==="high"?x-1-C:C)*d,Ht=ci*(n.noteSpeed??1),yt=n.tabLayout==="pages",V=(n.tabMarks??"all")==="all",v=n.tabMarks==="notes",pt=Ke+30,Mt=r-Fe-30,K=yt?Math.min(170,(Mt-pt)*.14):0,N=Mt-(yt?K+24:0);let Tt,ut,It,Jt,ne=null;if(yt){const C=Co(s,(N-pt)/Ht),ft=Math.max(0,C.findLastIndex(Ot=>Ot.start<=h)),tt=C[ft],Ct=(N-pt)/(tt.end-tt.start);Tt=Ot=>pt+(Ot-tt.start)*Ct,[It,Jt]=[tt.start,tt.end-.001],ut=Tt(Math.min(Math.max(h,tt.start),tt.end)),C[ft+1]&&(ne={start:C[ft+1].start,scale:Ct})}else ut=Math.max(Ke+Lo+60,r*.2),Tt=C=>ut+(C-h)*Ht,[It,Jt]=[h-(ut-Ke)/Ht,h+(r-ut)/Ht];const ye=C=>n.str[C%n.str.length],Ft=C=>C.chord===null||C.chord===void 0?null:s.chords[C.chord],oe=(C,ft,tt,Ct)=>{e.beginPath(),e.moveTo(C,ft),e.lineTo(tt,Ct),e.stroke()},ge=(C,ft,tt,Ct)=>{const Ot=Math.hypot(tt,Ct),[ae,Ie]=[tt/Ot,Ct/Ot];oe(C,ft,C-6*ae-4*Ie,ft-6*Ie+4*ae),oe(C,ft,C-6*ae+4*Ie,ft-6*Ie-4*ae)},Ze=C=>C>=ut-1?1:.4;e.lineCap="round",e.lineJoin="round",e.textBaseline="alphabetic";const Te=[],ke=C=>{C&&(e.save(),e.beginPath(),e.rect(C[0],0,C[1]-C[0],Ae),e.clip());const ft=`600 ${ee(Math.min(15,d*.26))}px ${n.num}`,tt=`700 ${ee(Math.min(13,d*.22))}px ${n.num}`,Ct=new Map;e.font=ft,e.textAlign="left";const Ot=new Path2D,ae=new Path2D;e.fillStyle=n.muted;for(let M=se(s.beats,It-1);M<s.beats.length;M++){const m=s.beats[M];if(m.time>Jt)break;const Y=Tt(m.time),P=m.measure>=0,I=P?Ot:ae;I.moveTo(Y,F-d*.35),I.lineTo(Y,X+d*.35),P&&(e.fillText(String(m.measure),Y+6,t+d*.3),Ct.set(Math.round(m.time*50),Kt(e,ft,String(m.measure)).width+16))}e.lineWidth=1,e.strokeStyle=H(n.text,.05),e.stroke(ae),e.lineWidth=1.5,e.strokeStyle=H(n.text,.16),e.stroke(Ot),e.fillStyle=n.accent;const Ie=new Map;for(const M of s.markers??[])M.time>=It&&M.time<=Jt&&Ie.set(Math.round(M.time*50),[...Ie.get(Math.round(M.time*50))??[],M.text]);for(const[M,m]of Ie)e.fillText([...new Set(m)].join(" · "),Tt(M/50)+6+(Ct.get(M)??0),t+d*.3);e.strokeStyle=H(n.text,.14),e.beginPath();for(let M=0;M<x;M++)e.moveTo(Ke,G(M)),e.lineTo(r-Fe,G(M));e.stroke();const le=X+d*.92,re=X+d*1.24;if(n.guides!==!1&&!v){e.font=ft,e.fillStyle=e.strokeStyle=n.anchorLane,e.lineWidth=2;let M=-1/0;const m=s.anchors??[];for(let Y=Math.max(1,se(m,It));Y<m.length&&m[Y].time<=Jt;Y++){const P=m[Y],I=Tt(P.time);if(I<M)continue;const y=`fret ${P.fret}`;e.globalAlpha=Ze(I),oe(I,X+d*.6,I,le-2),e.fillText(y,I+5,le),M=I+5+Kt(e,ft,y).width+8}e.globalAlpha=1}e.strokeStyle=n.text,e.lineWidth=1.5;for(const M of v?[]:s.hairpins??[]){if(M.endTime<It||M.time>Jt)continue;const m=Tt(M.time),Y=Math.max(m+30,Tt(M.endTime)),[P,I]=M.kind==="cresc"?[m,Y]:[Y,m];e.globalAlpha=Ze(Y),e.beginPath(),e.moveTo(I,re-11),e.lineTo(P,re-5),e.lineTo(I,re+1),e.stroke()}e.globalAlpha=1;const ve=ee(Math.min(26,d*.42)),Vt=ve*1.3,Xe=ve*.32,qe=n.gem==="pill"?Vt/2:5,De={note:`700 ${ve}px ${n.num}`,grace:`700 ${ee(ve*.72)}px ${n.num}`,finger:`700 ${ee(ve*.5)}px ${n.num}`},hn=n.markings==="white",Le=s.rhythm,Ce=M=>Tt(M.time)+Vt/2;if(Le?.length){const M=new Path2D,m=new Path2D,Y=Math.max(2.5,d*.055),P=Math.max(2,d*.045),I=Math.max(5,d*.13),y=Et/20,ct=B=>B.value>=8?Math.round(Math.log2(B.value))-2:0,Z=(B,ot,at)=>{M.moveTo(B+at,ot),M.arc(B,ot,at,0,Math.PI*2)},bt=(B,ot)=>{if(ot.value<=2)return M.rect(B-7*y,z+Et*(ot.value===1?.3:.62),14*y,5*y);if(m.moveTo(B+(ot.value===4?-3:4)*y,z+(ot.value===4?2:3)*y),ot.value>4)m.lineTo(B-3*y,z+19*y);else for(const[at,Bt]of[[3,9],[-3,15],[4,21]])m.lineTo(B+at*y,z+Bt*y);for(let at=0;at<ct(ot);at++)Z(B+(2-at*1.6)*y,z+(5+at*5)*y,2*y)},Nt=(B,ot)=>{const at=z+Et;ot.value>=4?Z(B,at,Y):(m.moveTo(B+Y,at),m.arc(B,at,Y,0,Math.PI*2)),ot.value>1&&(m.moveTo(B,z),m.lineTo(B,at-Y*.7))},kt=[],Yt=[];let Gt=0,zt=0;const vt=()=>{for(let B=0;B<Gt;B++){let ot=-1;for(let at=0;at<=kt.length;at++){const Bt=at<kt.length&&ct(kt[at])>B;if(Bt&&ot<0&&(ot=at),Bt||ot<0)continue;const q=Ce(kt[ot]);M.rect(ot===at-1&&ot?q-I:q,z+B*P*2,Math.max(Ce(kt[at-1])-q,I),P),ot=-1}}zt&&kt.length>1&&Yt.push([(Ce(kt[0])+Ce(kt.at(-1)))/2,String(zt)]),kt.length=Gt=zt=0};let Dt=-1,Ut=Math.max(0,se(s.beats,It)-1);for(let B=Math.max(0,se(Le,It)-1);B<Le.length;B++){const ot=Le[B],at=Ce(ot);if(ot.time>Jt)break;for(;s.beats[Ut+1]?.time<=ot.time+1e-4;)Ut++;(Ut!==Dt||ot.rest)&&vt(),Dt=Ut,ot.rest?bt(at,ot):(Nt(at,ot),ct(ot)?(kt.push(ot),Gt=Math.max(Gt,ct(ot)),zt||=ot.tuplet):vt());for(let Bt=0;Bt<ot.dots;Bt++)Z(at+Y*(2.2+Bt*1.5),z+Et+Y*.8,Math.max(1.3,Y*.45))}if(vt(),e.fillStyle=e.strokeStyle=n.muted,e.lineWidth=Math.max(1.2,d*.022),e.stroke(m),e.fill(M),Yt.length){e.font=tt,e.textAlign="center";for(const[B,ot]of Yt)e.fillText(ot,B,z-P*2);e.textAlign="left"}}for(const M of v?[]:s.handShapes??[]){if(!M.arpeggio||M.endTime<It||M.startTime>Jt)continue;const m=M.frets.flatMap((I,y)=>I>=0&&y<x?[G(y)]:[]);if(!m.length)continue;const Y=Tt(M.startTime)-12,P=Tt(M.endTime);e.globalAlpha=Ze(P),e.strokeStyle=H(n.text,.4),e.lineWidth=1.5,e.setLineDash([6,5]),e.beginPath(),e.roundRect(Y,Math.min(...m)-Vt/2-6,P-Y,Math.max(...m)-Math.min(...m)+Vt+12,8),e.stroke(),e.setLineDash([]),M.name&&(e.font=`700 ${ee(Math.min(24,d*.4))}px ${n.num}`,e.fillStyle=n.text,e.fillText(M.name,Y,F-d*.72))}e.globalAlpha=1;const fn=M=>(M.slideTo??M.slideUnpitchTo??null)!==null||!!M.slideOut,Qe=M=>{const m=Ft(M);return!!m&&!M.repeat&&!m.highDensity&&m.notes.length>1},pe=(M,m)=>v?4:4+(fn(M)?16:0)+(Qe(m)?10:0)+(m.slideIn?18:0)+(m.showString?20:0);let Zt=0,ze=0;const A=(M,m)=>{m(ze-M/2),ze-=M+3},on={"":tt,"italic ":`italic ${tt}`},Oe=(M,m="")=>A(10,Y=>{e.font=on[m],e.fillText(M,Zt,Y+5)}),{next:qt,prev:cn,held:Re}=uo(s),he=new Map,gt=new Set,St=[],Ee=[];for(let M=se(s.notes,It-Re-.5);M<s.notes.length;M++){const m=s.notes[M];if(m.time>Jt)break;if(Tt(m.time+m.sustain)<Ke-40-Vt*4||C&&m.time<It&&Tt(m.time+m.sustain)-2<=Tt(It)&&typeof m.tieTo!="number")continue;const Y=Ft(m),P=m.grace?.72:1,I=Vt*P,y=G(m.string),ct=ye(m.string),Z=Tt(m.time),bt=m.mute||Y?.fretHandMute,Nt=m.palmMute||Y?.palmMute,kt=m.repeat||Y?.highDensity,Yt=bt?"×":m.harmonic||m.harmonicPinch?`<${m.fret}>`:m.ghost?`(${m.fret})`:String(m.fret),Gt=m.finger??(Y?.fingers?.[m.string]>=0?Y.fingers[m.string]:null),zt=!V||bt||m.fret===0||Gt===null?"":Gt===0?"T":String(Gt),vt=m.grace?De.grace:De.note,Dt=Kt(e,vt,Yt).width,Ut=zt?Kt(e,De.finger,zt).width+3:0,B=s.notes[qt[M]],ot=B?Tt(B.time)-pe(m,B):1/0,at=Math.min(Math.max(I,Dt+Ut+Xe*2*P),Math.max(10,ot-Z)),Bt=Math.max(Z+at,Math.min(Tt(m.time+m.sustain)-2,ot)),q=Z+at/2,J=Math.min(1,(at-4)/(Dt+Ut)),je=he.get(m.string)??(cn[M]>=0?{x0:Tt(s.notes[cn[M]].time),w:Vt}:null);if(he.set(m.string,{x0:Z,w:at}),Bt<Ke-40&&typeof m.tieTo!="number")continue;const tn=m.time<=h&&h<m.time+Math.max(m.sustain,.15),Be=(tn||Z>=ut-1?1:.4)*(m.ghost?.55:1);if(e.globalAlpha=Be,Y&&!gt.has(Y)&&!v){gt.add(Y);const fe=Y.notes.map(S=>G(s.notes[S].string)),W=Math.min(...fe)-Vt/2,u=Math.max(...fe)+Vt/2,g=Z-7;if(fe.length>1&&!kt&&(e.strokeStyle=Y.accent?"#ffffff":H(n.text,.7),e.lineWidth=Y.accent==="heavy"?4:Y.accent?3:2,e.beginPath(),e.moveTo(g+4,W),e.lineTo(g,W),e.lineTo(g,u),e.lineTo(g+4,u),e.stroke()),e.font=tt,e.fillStyle=e.strokeStyle=kt?n.muted:n.text,e.lineWidth=1.8,e.textAlign="left",Y.barre&&!kt&&e.fillText(`${Y.barre.half?"½":""}B${Y.barre.fret}`,g,W-5),Y.strum||Y.roll){const S=Y.notes.map(ht=>s.notes[ht].string),k=G(Math.min(...S)),_=G(Math.max(...S)),[R,it]=(Y.strum??Y.roll)==="down"?[k,_]:[_,k],Pt=g-9;e.beginPath();for(let ht=0;ht<=16;ht++)e.lineTo(Pt+(Y.roll?Math.sin(ht/16*Math.PI*6)*2.5:0),R+(it-R)*ht/16);e.stroke(),ge(Pt,it,0,it-R||1)}const L=s.chords[m.chord-1];Y.name&&!kt&&(!L||m.time-L.time>1||L.name!==Y.name)&&(e.font=`700 ${ee(Math.min(24,d*.4))}px ${n.num}`,e.fillStyle=n.text,e.fillText(Y.name,Z,F-d*.72))}e.beginPath(),e.roundRect(Z,y-I/2,Bt-Z,I,qe*P),tn&&!kt&&(e.shadowColor=ct,e.shadowBlur=18),kt?(e.strokeStyle=ct,e.lineWidth=2,e.stroke()):m.letRing&&Bt>Z+at+2?(e.fillStyle=H(ct,.3),e.fill(),e.shadowBlur=0,e.strokeStyle=ct,e.lineWidth=2,e.setLineDash([6,5]),oe(Z+at+4,y,Bt-4,y),e.setLineDash([]),e.beginPath(),e.roundRect(Z,y-I/2,at,I,qe*P),e.fillStyle=ct,e.fill()):(e.fillStyle=bt?H(n.text,.22):ct,e.fill()),e.shadowBlur=0,tn&&Te.push({y,c:ct});const _e=kt?ct:bt?n.text:hn?"#ffffff":n.ink;St.push({text:Yt,font:vt,finger:zt,fill:_e,shown:Be,squeeze:J,x:q,y:y+Kt(e,vt,Yt).middle,left:-(Dt+Ut)/2,textWidth:Dt}),v||Ee.push(()=>{e.globalAlpha=Be;const fe=kt?n.muted:n.text;e.strokeStyle=e.fillStyle=fe,e.lineWidth=1.6;const W=m.slideTo??m.slideUnpitchTo??null,u=W===null?m.slideOut==="up"?1:m.slideOut?-1:0:Math.sign(W-m.fret)||1;if(u){const S=m.slideTo===null&&m.slideUnpitchTo!==null&&m.slideUnpitchTo!==void 0;S&&e.setLineDash([3,3]),oe(Bt+4,y+u*I*.3,Bt+14,y-u*I*.3),S&&e.setLineDash([])}if(m.slideIn&&oe(Z-16,y+(m.slideIn==="below"?1:-1)*I*.3,Z-6,y-(m.slideIn==="below"?1:-1)*I*.3),typeof m.tieTo=="number"){const S=Tt(s.notes[m.tieTo].time)+I/2;e.setLineDash([4,3]),e.beginPath(),e.moveTo(q,y+I/2+3),e.quadraticCurveTo((q+S)/2,y+I/2+14,S,y+I/2+3),e.stroke(),e.setLineDash([])}if(m.showString){const S=Z-(Y?26:13);e.beginPath(),e.arc(S,y,8,0,Math.PI*2),e.stroke(),e.font=De.finger,e.textAlign="center",e.fillText(String(x-m.string),S,y+Kt(e,De.finger,"1").middle)}m.dynamicLabel&&(e.font=`italic ${tt}`,e.textAlign="left",e.fillStyle=n.text,e.fillText(m.dynamicLabel,Z,re),e.fillStyle=fe);let g=y-I/2-6;if(m.vibrato){e.beginPath();for(let S=Z+2;S<=Math.max(Bt,Z+24)-2;S+=2)e.lineTo(S,g+Math.sin((S-Z)/3)*(m.vibratoWide?3:1.8));e.stroke(),g-=m.vibratoWide?10:8}if(e.textAlign="center",e.font=tt,(m.hammerOn||m.pullOff)&&je){const S=je.x0+je.w/2,k=(S+q)/2;e.beginPath(),e.moveTo(S,g),e.quadraticCurveTo(k,g-12,q,g),e.stroke(),e.fillText(m.hammerOn?"H":"P",k,g-9),g-=10}const L=rn(m);if(L>0){const S=m.bendCurve?.[0]?.[1]>0,k=(m.bendCurve?.length??0)>1&&m.bendCurve.at(-1)[1]<L,_=Z+at-2,R=y-I/2,it=R-16;e.beginPath(),S?(e.moveTo(_,R),e.lineTo(_,it)):(e.moveTo(_-4,R+2),e.quadraticCurveTo(_+4,R,_+6,it)),e.stroke(),ge(S?_:_+6,it,S?0:.3,-1),k&&(e.beginPath(),e.moveTo(_+12,it),e.quadraticCurveTo(_+16,R-6,_+16,R),e.stroke(),ge(_+16,R,0,1)),e.textAlign="left",e.fillText(`${S?"pre ":""}${Fn(L)}`,_+(k?20:10),it+4),e.textAlign="center"}[Zt,ze]=[q,g],m.tap&&!m.tapLeft&&Oe("T"),m.staccato&&A(4,S=>{e.beginPath(),e.arc(q,S,2,0,Math.PI*2),e.fill()}),m.accent&&(m.accent==="tenuto"||!Y?.accent)&&Oe({heavy:"^",tenuto:"–"}[m.accent]??">"),Nt&&Oe("PM");for(const S of[m.tapLeft?"m.g.":"",Po[m.harmonicType]??(m.harmonicPinch?"PH":""),m.slap?"slap":m.pop?"pop":"",m.golpe?`golpe (${m.golpe})`:"",m.rasgueado?`rasg. ${m.rasgueado}`:"",typeof m.trill=="number"?`tr ${m.trill}`:"",m.ornament??"",m.fade??"",m.whammy?"w/bar":"",m.wah==="open"?"o":m.wah==="closed"?"+":""])S&&Oe(S);m.rightFinger&&Oe(m.rightFinger,"italic "),m.pick&&A(9,S=>{e.beginPath(),m.pick==="down"?[[-4,4.5],[-4,-4.5],[4,-4.5],[4,4.5]].forEach(([k,_],R)=>e[R?"lineTo":"moveTo"](q+k,S+_)):[[-4,-4.5],[0,4.5],[4,-4.5]].forEach(([k,_],R)=>e[R?"lineTo":"moveTo"](q+k,S+_)),e.stroke()}),m.fermata&&A(9,S=>{e.beginPath(),e.arc(q,S+4,7,Math.PI,0),e.stroke(),e.beginPath(),e.arc(q,S+3,1.5,0,Math.PI*2),e.fill()}),m.tremolo&&A(18,S=>{for(let k=-1;k<=1;k++)oe(q-6,S+k*4+5.5,q+6,S+k*4+.5);e.beginPath();for(let k=0;k<=12;k++)e[k?"lineTo":"moveTo"](q-8+16*k/12,S-7+Math.sin(k/12*Math.PI*2)*2);e.stroke()})})}const Je=(M,m,Y,P)=>{if(e.globalAlpha=M.shown*P,e.fillStyle=M.fill,M.squeeze===1)return e.fillText(m,M.x+M.left+Y,M.y);e.save(),e.translate(M.x,M.y),e.scale(M.squeeze,1),e.fillText(m,M.left+Y,0),e.restore()};e.textAlign="left";for(const M of[De.note,De.grace]){e.font=M;for(const m of St)m.font===M&&Je(m,m.text,0,1)}e.font=De.finger;for(const M of St)M.finger&&Je(M,M.finger,M.textWidth+3,.7);for(const M of Ee)M();e.globalAlpha=1,C&&e.restore()};if(!yt)ke(null);else if(ke([pt-40,N+4]),ne){const C=N+24,ft=ut;Tt=tt=>C+(tt-ne.start)*ne.scale,[It,Jt,ut]=[ne.start,ne.start+K/ne.scale,-1/0],ke([C-8,Mt+4]),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0, 0, 0, 0.55)",e.fillRect(C-8,0,Mt+12-(C-8),Ae),e.restore(),e.strokeStyle=H(n.text,.22),e.lineWidth=1.5,e.setLineDash([3,5]),oe(N+12,F-d*.6,N+12,X+d*.6),e.setLineDash([]),ut=ft}e.shadowColor=n.accent,e.shadowBlur=16,e.strokeStyle=n.accent,e.lineWidth=3,oe(ut,F-d*.7,ut,X+d*.7);for(const{y:C,c:ft}of Te)e.shadowColor=ft,e.fillStyle="#ffffff",e.beginPath(),e.arc(ut,C,4,0,Math.PI*2),e.fill();e.shadowBlur=0,e.globalCompositeOperation="destination-out";for(const[C,ft,tt]of yt?[]:[[Ke+10,1,Lo],[r-Fe,-1,80]]){const Ct=e.createLinearGradient(C,0,C+ft*tt,0);Ct.addColorStop(0,"rgba(0, 0, 0, 1)"),Ct.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=Ct,e.fillRect(ft>0?0:C-tt,0,ft>0?C+tt:r-C+tt,Ae)}if(e.globalCompositeOperation="destination-over",e.beginPath(),e.roundRect(Fe,t,r-Fe*2,_t-t,16),e.fillStyle=H(n.ink,.72),e.fill(),e.globalCompositeOperation="source-over",e.strokeStyle=n.chipBorder,e.lineWidth=1,e.stroke(),!s.open)return;const Ne=`700 ${ee(Math.min(14,d*.24))}px ${n.num}`,Se=Math.min(13,d*.22),Ye=(Fe+Ke)/2;e.textAlign="center",e.fillStyle=n.muted,e.font=`700 ${ee(Math.min(12,d*.2))}px ${n.ui}`,e.fillText("TAB",Ye,z+Et*.7);const $e=s.meters?.findLast(C=>C.time<=h)?.text.split("/");if($e){const C=(F+X)/2,ft=`700 ${ee(Math.min(30,d*.52))}px ${n.num}`;e.font=ft,e.fillText($e[0],Ke+20,C-d*.04),e.fillText($e[1],Ke+20,C+d*.56)}e.font=Ne;for(let C=0;C<x;C++){const ft=G(C),tt=ye(C),Ct=Te.some(Ot=>Ot.y===ft);e.fillStyle=Ct?tt:H(tt,.16),e.beginPath(),e.roundRect(Ye-Se*1.2,ft-Se*.95,Se*2.4,Se*1.9,Se*.55),e.fill(),e.fillStyle=Ct?n.ink:tt,e.fillText(Qn(s.open[C]),Ye,ft+Kt(e,Ne,"E").middle)}}export{Vo as HEADSTOCKS,ai as bendAt,xi as drawHighway,Mi as drawSheet,bi as drawTab,Zo as headstockParts,No as lookAhead,fi as moveCamera,ho as rounded,mo as spline};
|