@dsebastien/music-notation 0.19.2 → 0.20.0

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.
@@ -1,9 +1,9 @@
1
- /*! @dsebastien/music-notation 0.19.2 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
2
- (()=>{var Ke=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],Xe=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],le={C:0,D:2,E:4,F:5,G:7,A:9,B:11};function B(e){let n=/^([A-Ga-g])([#♯b♭]*)$/.exec(e.trim());if(!n)return null;let t=le[n[1].toUpperCase()];for(let r of n[2])t+=r==="#"||r==="♯"?1:-1;return(t%12+12)%12}function X(e){let n=/^([A-Ga-g][#♯b♭]*)(-?\d)$/.exec(e.trim());if(!n)return null;let t=B(n[1]);if(t===null)return null;let r=le[n[1][0].toUpperCase()],o=Math.round((t-r)/12);return(Number(n[2])+1)*12+t-o*12}var Ye=(e,n=!1)=>(n?Xe:Ke)[((Math.round(e)||0)%12+12)%12];var me=(e,n=!1)=>`${Ye(e,n)}${Math.floor(e/12)-1}`;var Je="http://www.w3.org/2000/svg",Ze=(e,n)=>{for(let[t,r]of Object.entries(n))if(r!==void 0)e.setAttribute(t,String(r))};function Y(e,n,t={},r=[]){let o=e.createElementNS(Je,n);Ze(o,t);for(let s of r)if(s)o.appendChild(s);return o}function M(e,n,t,r){let o=e.createElement(n);if(t)o.className=t;if(r!==void 0)o.textContent=r;return o}var vn=`mn-name-${Math.random().toString(36).slice(2,8)}-`;var Qe=new Map(Object.entries({standard:"E2 A2 D3 G3 B3 E4","drop d":"D2 A2 D3 G3 B3 E4","drop c":"C2 G2 C3 F3 A3 D4","drop b":"B1 F#2 B2 E3 G#3 C#4","drop a":"A1 E2 A2 D3 F#3 B3","double drop d":"D2 A2 D3 G3 B3 D4",dadgad:"D2 A2 D3 G3 A3 D4","open g":"D2 G2 D3 G3 B3 D4","open d":"D2 A2 D3 F#3 A3 D4","open e":"E2 B2 E3 G#3 B3 E4","open c":"C2 G2 C3 G3 C4 E4","open a":"E2 A2 E3 A3 C#4 E4","half step down":"Eb2 Ab2 Db3 Gb3 Bb3 Eb4","whole step down":"D2 G2 C3 F3 A3 D4","modal c6":"C2 A2 C3 G3 C4 E4",c6:"C2 A2 C3 G3 C4 E4",bass:"E1 A1 D2 G2",ukulele:"G4 C4 E4 A4"}));function V(e){let n=e.trim(),t=Qe.get(n.toLowerCase().replace(/\s*\(.*\)$/,""));if(t)return V(t);let r=n.split(/[\s,]+/).filter(Boolean);if(r.length>1&&r.every((a)=>X(a)!==null))return r.map((a)=>X(a));let o=r.length>1?r:n.match(/[A-G][#♯b♭]?|[a-g][#♯♭]?/g)??[];if(o.length<2||o.join("")!==r.join(""))return null;let s=[];for(let a of o){let l=B(a);if(l===null)return null;let c=s[s.length-1];if(c===void 0){let m=[28,40,52].map((i)=>i-i%12+l);s.push(m.reduce((i,u)=>Math.abs(u-40)<Math.abs(i-40)?u:i))}else{let m=c-c%12+l;while(m<=c)m+=12;s.push(m)}}return s}var et=/^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/,tt=/^[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/,nt=/^\s*([A-Za-z][A-Za-z0-9. -]{0,14}?)\s*[|:]([-xXoOgfdb#@*+|:\s]*)$/,rt=new Map(Object.entries({hihat:"h hh hat hihat hihats","hihat-open":"oh openhat openhihat","hihat-foot":"hf fh hp ph pedal hihatfoot hihatpedal",crash:"c c1 cc cr cy cym crash crash1 cymbal",crash2:"c2 cr2 crash2",ride:"r rd rc ride",splash:"sp spl splash",china:"ch cn chi china",cowbell:"cb cow cowbell",snare:"s sd sn sr snare snaredrum",tom1:"t t1 ht tom1 hightom hitom",tom2:"t2 mt tom2 midtom",tom3:"t3 lt tom3 lowtom",floor:"f ft fl t4 tom4 floor floortom",kick:"b bd bs k kd bass kick bassdrum kickdrum"}).flatMap(([e,n])=>n.split(" ").map((t)=>[t,e])));function ot(e,n){let t=n==="#";switch(e){case"hihat":return n==="o"||n==="O"?"HiHatOpen":"HiHatClosed";case"hihat-open":return"HiHatOpen";case"hihat-foot":return"PedalHiHatHit";case"crash":return t?"CrashHighChoke":"CrashHighHit";case"crash2":return t?"CrashMediumChoke":"CrashMediumHit";case"ride":return t?"RideChoke":"RideMiddle";case"splash":return t?"SplashChoke":"SplashHit";case"china":return t?"ChinaChoke":"ChinaHit";case"cowbell":return"CowbellMediumHit";case"snare":return"SnareHit";case"tom1":return"HighTomHit";case"tom2":return"MidTomHit";case"tom3":return"LowTomHit";case"floor":return"VeryLowTomHit";case"kick":return"KickHit"}}var st=(e)=>e==="X"||e==="O"?["ac"]:e==="g"?["g"]:[],at=/[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/,it=/^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;function lt(e){let n=e.lastIndexOf("|");if(n<0)return{line:e,text:null};let t=e.slice(n+1),r=t.trim();if(!r)return{line:e,text:null};return at.test(r)||it.test(r)||/^\s/.test(t)&&!r.includes("--")?{line:e.slice(0,n+1),text:r}:{line:e,text:null}}function mt(e){let{line:n,text:t}=lt(e.trimEnd()),r=null,o=et.exec(n),s=n.slice(o[0].length);if(tt.test(s)&&(n.match(/-/g)?.length??0)>=4&&(n.includes("|")||/^\s*[A-Ga-g][#b]?\s*[-|:]/.test(n)))r={name:o[1]??null,body:s,offset:o[0].length,barred:/[|:]$/.test(o[0])};let a=null,l=nt.exec(n),c=l?l[1].toLowerCase().replace(/[ .-]/g,""):"",m=rt.get(c);if(l&&m&&(l[2].match(/[^\s|:]/g)?.length??0)>=4)a={drum:m,name:c,body:l[2],lettered:/^[A-Ga-g]$/.test(l[1])};return r||a?{string:r,drum:a,text:t}:null}var ke=(e)=>[...new Set(e.map((n)=>n.text).filter((n)=>n!==null))];function ct(e){let n=[],t=0;for(let r=2;r<e.length-1;r++){let[o,s]=[e[t].string.name,e[t+1].string.name];if(o!==null&&e[r].string.name===o&&e[r+1].string.name===s&&r-t>=2)n.push(e.slice(t,r)),t=r}return n.push(e.slice(t)),n}function ut(e){let n=[],t=[];for(let r of e){if(t.some((o)=>o.drum.name===r.drum.name))n.push(t),t=[];t.push(r)}return n.push(t),n}var dt=/^[\sPpMm.\-_|=~]*$/,pt=/P\.?M/i;function ft(e){if(!dt.test(e)||!pt.test(e))return[];let n=[];for(let t=0;t<e.length;t++){let r=e[t];if((r==="P"||r==="p")&&/^\.?[Mm]/.test(e.slice(t+1,t+3)))n.push([t,t]);else if(r!==" "&&n.length)n[n.length-1][1]=t}return n}function ce(e,n=null){return ct(e).flatMap((t,r)=>{let o=t.map((m)=>m.string.name);if(t.length<3&&o.some((m)=>m===null))return[];let s=t.map((m)=>m.string.body),a=t[0].string.offset,l=new Set;if(r===0&&n!==null)for(let[m,i]of ft(n))for(let u=Math.max(m,a);u<=i;u++)l.add(u-a);let c=t.some((m)=>!m.string.barred);return[{kind:"strings",names:o,lines:s,texts:ke(t),muted:l,openStart:c}]})}function ue(e,n){if(!e.length)return[];if(e.every((o)=>o.drum)&&e.some((o)=>!o.string||!o.drum.lettered||/[xXoOgfdb#@*+]/.test(o.drum.body)))return ut(e).map((o)=>({kind:"drums",drums:o.map((s)=>s.drum.drum),lines:o.map((s)=>s.drum.body),texts:ke(o)}));if(e.every((o)=>o.string))return ce(e,n);let t=[],r=[];for(let o of[...e,null])if(o?.string)r.push(o);else{if(r.length)t.push(...ce(r,t.length?null:n));r=[]}return t}function ht(e){let n=[],t=[],r=null,o=null;for(let s of e.split(/\r?\n/)){let a=mt(s);if(a){if(!t.length)r=o;t.push(a)}else n.push(...ue(t,r)),t=[];o=s}return n.push(...ue(t,r)),n}function de(e,n){let t=Math.max(...e.map((c)=>c.length)),r=e.map((c)=>c.padEnd(t,"-")),o=[],s=[],a=!1,l=0;for(let c=0;c<t;c++){if(r.every((d)=>d[c]==="|"||d[c]===":")){if(a)o.push({beats:s,start:l,end:c});s=[],a=!1,l=c+1;continue}if(r.some((d)=>d[c]!==" "))a=!0;let{beat:m,skip:i,at:u}=n(r,c);if(m.length)s.push({notes:m,col:u??c});c+=i}if(a)o.push({beats:s,start:l,end:t});return o}var G=(e)=>e!==void 0&&e>="0"&&e<="9",pe=(e,n)=>(e==="1"||e==="2")&&G(n)&&Number(e+n)<=24;function gt(e){let n=new Map,t=new Map,r=new Set,o=(s)=>{let a=s,l=e[a]==="(";if(l)a++;if(!G(e[a]))return{fret:null,next:s};let c=pe(e[a],e[a+1])?2:1,m=Number(e.slice(a,a+c));for(let i=0;i<c;i++)r.add(a+i);if(a+=c,l&&e[a]===")")a++;return{fret:m,next:a}};for(let s=0;s<e.length;){if(!G(e[s])||r.has(s)){s++;continue}let a=pe(e[s],e[s+1])?2:1,l=Number(e.slice(s,s+a));n.set(s,{fret:l,width:a});let c=[],m=e[s-1],i=s+a;if(m==="<"&&e[i]===">")c.push("nh"),i++;else if((m==="/"||m==="\\")&&!/[\d)>]/.test(e[s-2]??"-"))c.push(m==="/"?"sib":"sia");if(e[i]==="b"||e[i]==="^"){let f=o(i+1);i=f.next;let g=[0,(f.fret!==null&&f.fret>l?Math.min(f.fret-l,4):2)*2];if(e[i]==="r"){let h=o(i+1);i=h.next;let b=h.fret===null?0:(h.fret-l)*2;g.push(Math.min(g[1],Math.max(0,b)))}c.push(`b (${g.join(" ")})`)}if(e[i]==="~"||e[i]==="v"){c.push("v");while(e[i]==="~"||e[i]==="v")i++}let u=e[i],d=G(e[i+1])||e[i+1]==="("&&G(e[i+2]);if((u==="h"||u==="p")&&d)c.push("h");else if(u==="/"||u==="\\"||u==="s"){if(d)c.push("sl");else if(u!=="s")c.push(u==="/"?"sou":"sod")}if(c.length)t.set(s,c);s+=a}return{frets:n,effects:t}}var bt=(e,n,t=[])=>(r,o)=>{let s=[],a=new Set,l=o,c=!1,m=(i,u)=>{let d=r[i][u],f=n.has(u)?["pm"]:[];if(d==="x"||d==="X"){s.push({tex:`x.${t[i]??i+1}`,effects:f}),a.add(i);return}let p=e[i].frets.get(u);if(!p)return;if(p.width===2&&u===o)c=!0;if(r[i][u-1]==="<")l=Math.min(l,u-1);s.push({tex:`${p.fret}.${t[i]??i+1}`,effects:[...e[i].effects.get(u)??[],...f],string:t[i]??i+1}),a.add(i)};if(r.forEach((i,u)=>m(u,o)),c)r.forEach((i,u)=>a.has(u)||m(u,o+1));return{beat:s,skip:c?1:0,at:l}},j={3:[64,59,55],4:[43,38,33,28],5:[43,38,33,28,23],6:[64,59,55,50,45,40],7:[64,59,55,50,45,40,35]},fe=[64,59,55,50,45,40,35,30],J={names:["E","A","D","G","B","E"],midis:[40,45,50,55,59,64]},yt=["E A D G","B E A D G"],Z=(e)=>e[0].toUpperCase()+e.slice(1);function Q(e){let n=e.length;if(e.every((t)=>t!==null&&/^\d$/.test(t)))return e.every((t)=>fe[Number(t)-1])?e.map((t)=>fe[Number(t)-1]):null;if(e.every((t)=>t!==null&&/^[A-Ga-g]/.test(t))){let t=[...e].reverse(),r=t.map(Z).join(" ");if(yt.includes(r))return V(r).map((a)=>a-12).reverse();let o=[...J.names.keys()].filter((a)=>t.every((l,c)=>J.names[a+c]===Z(l)));if(o.length){let a=o.length>1&&t[0]==="e"?o.at(-1):o[0];return J.midis.slice(a,a+n).reverse()}if(n===1){let a=B(Z(e[0]));return a===null?null:[48+(a-48+120)%12]}let s=V(r);if(s)return s.reverse()}return j[n]??null}function vt(e){let n=[...j[6]],t=n.indexOf(e);if(t<0)t=n.reduce((r,o,s)=>Math.abs(o-e)<Math.abs(n[r]-e)?s:r,0),n[t]=e;return{tuning:n,string:t+1}}function kt(e){if(e.length===1){let{tuning:r,string:o}=vt(e[0]);return{tuning:r,strings:[o]}}let n=j[6];if(e.length>5)return null;let t=e.map((r)=>n.indexOf(r));if(t[0]<0||t.some((r,o)=>r!==t[0]+o))return null;return{tuning:[...n],strings:t.map((r)=>r+1)}}var xt=(e)=>(n,t)=>{let r=[];return n.forEach((o,s)=>{let a=o[t];if(!/[xXoOgfdb#@*+]/.test(a))return;let l=ot(e[s],a);if(!r.some((c)=>c.tex===l))r.push({tex:l,effects:st(a)})}),{beat:r,skip:0}},xe=[[24,1,!0],[16,1,!1],[12,2,!0],[8,2,!1],[6,4,!0],[4,4,!1],[3,8,!0],[2,8,!1],[1,16,!1]];function he(e){let n=[];for(let t=e;t>0;){let[r,o,s]=xe.find(([a])=>a<=t);n.push({duration:o,dotted:s}),t-=r}return n}var O={ts:[4,4],length:16,beat:4,grids:[1,2,4,8,16]},ge={ts:[3,4],length:12,beat:4,grids:[1,3,6,12]},wt={ts:[6,8],length:12,beat:6,grids:[1,2,6,12]},Tt={ts:[12,8],length:24,beat:6,grids:[1,2,4,12,24]};function Mt(e,n){let t=new Map;for(let o=1;o<e.length;o++){let s=e[o]-e[o-1],a=n[o]-n[o-1];if((t.get(s)??a)!==a)return!1;t.set(s,a)}let r=[...t].sort((o,s)=>o[0]-s[0]);return r.every(([,o],s)=>s===0||o>=r[s-1][1])}var At=new Set(xe.map(([e])=>e));function St(e,n,[t,r],o,s,a){let l=r/n;if(l<1||s&&!Number.isInteger(l))return null;let c=[],m=0;for(let i of e){let u=(i-t)/l,d=Math.round(u),f=Math.abs(u-d)*l;if(d<0||d>=n||f>o+0.000000001||c.length&&d*(a/n)<=c.at(-1))return null;m=Math.max(m,f),c.push(d*(a/n))}if(!s&&c.some((i,u)=>!At.has((c[u+1]??a)-i)))return null;return Mt(e,c)?{at:c,error:m}:null}function ee(e,n,t,r=O){if(!e.length)return[];let o=[[t,n-t],[t,n]];for(let s=1;s<t;s++)o.push([s,n-s]);if(e[0]>t)o.push([0,n]);for(let[s,a]of[[0.4,!1],[1,!1],[0.4,!0]])for(let l of r.grids){let c=o.map((m)=>St(e,l,m,s,a,r.length)).filter((m)=>m!==null);if(c.length)return c.reduce((m,i)=>i.error<m.error?i:m).at}return null}function I(e,n,t=n.length){let r=[],{beat:o,length:s}=n;for(let a=e;a<t;){let l=s===4*o&&a%(2*o)===0&&a<=s/2?[2*o]:[],m=(a%2?[1]:a%o?[2,1]:[...l,o,2,1]).find((i)=>i<=t-a);r.push({beat:-1,sixteenths:m}),a+=m}return r}function Et(e,n=O,t=[]){let r=e.slice(1).map((a,l)=>a-e[l]),o=new Map;for(let a of r)o.set(a,(o.get(a)??0)+1);let s=[...o].reduce((a,l)=>!a||l[1]>a[1]||l[1]===a[1]&&l[0]<a[0]?l:a,null)?.[0];for(let a of[2,1]){let l=e.map((m,i)=>a*(i<r.length?Math.max(1,Math.round(r[i]/s)):1)),c=l.reduce((m,i)=>m+i,0);if(a===2)for(let m of t){if(c<=n.length)break;if(m+1>=l.length||l[m]!==2)continue;let i=Math.max(1,l[m+1]-1);c-=1+l[m+1]-i,l[m]=1,l[m+1]=i}if(c>n.length)continue;return[...l.map((m,i)=>({beat:i,sixteenths:m})),...I(c,n)]}return e.map((a,l)=>({beat:l,sixteenths:1}))}var Ct=new Set(["h","sl"]),Nt=(e)=>e.flatMap((n,t)=>n.notes.some((r)=>r.effects.some((o)=>Ct.has(o)))?[t]:[]);function Lt(e,n,t){let r=t.length,o=e.part==="whole"?e.width:n,s=e.part==="end"?n-e.width:0,a=e.beats.map((i)=>i.col+s);if(e.part==="start"&&a.length){let i=ee([...a,e.width],o,e.pad,t);if(i){let u=i.pop(),d=i[0]>0?[{beat:-1,sixteenths:i[0]}]:[];return i.forEach((f,p)=>d.push({beat:p,sixteenths:(i[p+1]??u)-f})),[...d,...I(u,t)]}}let l=ee(a,o,e.pad,t);if(!l){let i=Et(e.beats.map((f)=>f.col),t,Nt(e.beats));if(e.part!=="end")return i;let u=i.filter((f)=>f.beat>=0),d=u.reduce((f,p)=>f+p.sixteenths,0);return e.pickup?u:[...I(0,t,r-d),...u]}let c=l[0],m=c===0||e.pickup?[]:e.part==="end"?I(0,t,c):[{beat:-1,sixteenths:c}];return l.forEach((i,u)=>m.push({beat:u,sixteenths:(l[u+1]??r)-i})),m}var Ot=(e)=>e.reduce((n,t)=>t.beats.length?Math.min(n,t.beats[0].col-t.start):n,3);function be(e,n,t,r){let o=Math.max(...e.map((s)=>s.length));return{bars:n,pad:Ot(n),texts:t,openStart:r&&n[0]?.start===0,openEnd:n.at(-1)?.end===o}}function Ft(e){let n=[];for(let t of e)t.bars.forEach((r,o)=>{if((o>0||!t.openStart)&&(o<t.bars.length-1||!t.openEnd)&&r.beats.length)n.push(r.end-r.start)});if(n.length<2)return null;return n.sort((t,r)=>t-r),n[n.length>>1]}function we(e){let n=new Map;for(let r of e)n.set(r,(n.get(r)??0)+1);let t;for(let[r,o]of n)if(!t||o>t.count||o===t.count&&r<t.value)t={value:r,count:o};return t}function Dt(e,n){if(n===null)return O;let t=[];for(let i of e)i.bars.forEach((u,d)=>{let f=(d>0||!i.openStart)&&(d<i.bars.length-1||!i.openEnd),p=u.end-u.start;if(f&&u.beats.length&&Math.abs(p-n)<=1)t.push({bar:u,pad:i.pad})});let r=new Map;for(let{bar:i}of t)for(let u=1;u<i.beats.length;u++){let d=i.beats[u].col-i.beats[u-1].col;r.set(d,(r.get(d)??0)+1)}let o=Math.max(0,...r.values()),s=Math.min(...[...r].filter(([,i])=>i*2>=o).map(([i])=>i));if(t.length<2||!Number.isFinite(s))return O;let a=[],l=0,c=0;for(let{bar:i,pad:u}of t){let d=i.beats.map((b)=>(b.col-i.start-u)/s);if(d.some((b)=>Math.abs(b-Math.round(b))*s>0.40000000100000005)){a.push(0);continue}let f=d.map(Math.round),p=Math.max(Math.ceil((i.end-i.start-u)/s-0.5),f.at(-1)+1);if(a.push(p),p!==6)continue;let g=i.beats.reduce((b,k)=>k.notes.reduce((T,S)=>Math.max(T,S.string??0),b),0),h=f.filter((b,k)=>i.beats[k].notes.some((T)=>T.string===g));for(let b of[f,h.length<f.length?h:[]])if(b.some((k)=>k!==0&&k%2===0)&&b.every((k)=>k%2===0))l++;else if(b.includes(3)&&b.every((k)=>k%3===0))c++}let m=we(a);if(m.count*3<t.length*2)return O;if(m.value===3)return ge;if(m.value===6)return l>c?ge:wt;return m.value===12?Tt:O}function Pt(e,n){let t=(s)=>n!==null&&s<=n*2/3,r=[],o=null;return e.forEach((s,a)=>{let l=r.length,c=e[a+1];s.bars.forEach((i,u)=>{let d=i.beats.map((h)=>({notes:h.notes,col:h.col-i.start})),f={beats:d,width:i.end-i.start,pad:s.pad,part:"whole",pickup:!1,text:null},p=u===0&&o!==null;if(o&&u===0){let h=o.width-s.pad;f={...o,beats:[...o.beats,...d.map((b)=>({notes:b.notes,col:b.col+h}))],width:o.width+f.width-s.pad},o=null}if(u===s.bars.length-1&&t(f.width)){let h=c?.bars[0],b=h?f.width+h.end-h.start-c.pad:0;if(h&&(s.openEnd||t(h.end-h.start)&&(c.openStart||b<=n*1.25))){if(f.beats.length||!s.openEnd)o=f;return}if(s.openEnd&&!p){if(!f.beats.length)return;f.part="start"}}let g=!r.length;if(u===0&&!p&&f.part==="whole"&&t(f.width)&&f.beats.length){if(g||s.openStart)f.part="end",f.pickup=g}r.push(f)});let m=o??(r.length>l?r.at(-1):null);if(s.texts.length&&m){let i=s.texts.join(" / ");m.text=m.text?`${m.text} / ${i}`:i}}),r}function Rt(e,n){return e.flatMap((t)=>{if(t.part!=="whole"||t.beats.length<2)return[t];let r=t.beats.map((u)=>u.col);if(ee(r,t.width,t.pad,n))return[t];let o=r.slice(1).map((u,d)=>u-r[d]),s=we(o).value,a=o.reduce((u,d)=>u+Math.max(1,Math.round(d/s)),1),l=n.length/2,c=s*l;if(a<=l||t.width-t.pad<c*1.5)return[t];let m=Math.floor((r.at(-1)-t.pad)/c)+1,i=Array.from({length:m},()=>[]);for(let u of t.beats){let d=Math.min(m-1,Math.max(0,Math.floor((u.col-t.pad)/c)));while(d<m-1&&u.col>=t.pad+(d+1)*c)d++;while(d>0&&u.col<t.pad+d*c)d--;i[d].push({notes:u.notes,col:u.col-d*c})}return i.map((u,d)=>({beats:u,width:t.pad+c,pad:t.pad,part:"whole",pickup:!1,text:d===m-1?t.text:null}))})}var $t=(e)=>`"${e.replace(/[\\"]/g,(n)=>`\\${n}`)}"`,z=(e,n)=>n.length?`${e}{${n.join(" ")}}`:e;function Bt(e,n){if(!e.length)return z("r",n);if(e.length===1)return z(e[0].tex,[...e[0].effects,...n]);return z(`(${e.map((t)=>z(t.tex,t.effects)).join(" ")})`,n)}var ye=new Set(["h","sl","sou","sod"]);function Gt(e,n){if(n===1)return[e];let t=[e.map((r)=>({...r,effects:r.effects.filter((o)=>!ye.has(o))}))];for(let r=1;r<n;r++)t.push(e.filter((o)=>o.string!==void 0).map((o)=>({tex:`-.${o.string}`,effects:o.effects.filter((s)=>s==="pm"||r===n-1&&ye.has(s))})));return t}function ve(e,n){let t=0;return e.map(({beats:o,rhythm:s,text:a,pickup:l})=>{let c=[];if(!o.length)for(let u of n===O?[{duration:1,dotted:!1}]:he(n.length))c.push({notes:[],...u});for(let{beat:u,sixteenths:d}of s){let f=he(d),p=Gt(u>=0?o[u]:[],f.length);f.forEach((g,h)=>c.push({notes:p[h],...g}))}let m=c.length-1;while(m>0&&!c[m].notes.length)m--;if(!c[m].notes.length)m=c.length-1;let i=c.map((u,d)=>{let f=u.dotted?["d"]:[];if(a&&d===m)f.push(`txt ${$t(a)}`);let p=u.duration===t?"":`:${u.duration} `;return t=u.duration,p+Bt(u.notes,f)}).join(" ");return l?`\\ac ${i}`:i}).join(` |
3
- `)}function Te(e){let n=ht(e),t=n[0];if(!t)return null;let r=t.kind==="strings"?Q(t.names):null,o=r?kt(r):null;if(o)r=o.tuning;let s=[];if(t.kind==="drums"){for(let d of n)if(d.kind==="drums")s.push(be(d.lines,de(d.lines,xt(d.drums)),d.texts,!1))}else{let d=JSON.stringify(Q(t.names)),f=o?.strings??[];for(let p of n){if(p.kind!=="strings"||JSON.stringify(Q(p.names))!==d)continue;let g=bt(p.lines.map(gt),p.muted,f);s.push(be(p.lines,de(p.lines,g),p.texts,p.openStart))}}let a=Ft(s),l=Dt(s,a),c=Rt(Pt(s,a),l).map((d)=>({beats:d.beats.map((f)=>f.notes),rhythm:Lt(d,a??0,l),text:d.text,pickup:d.pickup}));if(!c.length)return null;let m=l===O?[]:[`\\ts ${l.ts.join(" ")}`];if(t.kind==="drums")return["\\instrument percussion","\\articulation defaults",...m,ve(c,l)].join(`
4
- `);let i=r?.join(" ")===j[6].join(" ");return[...r&&!i?[`\\tuning (${r.map((d)=>me(d)).join(" ")})`]:[],...m,ve(c,l)].join(`
5
- `)}var Ht={play:"M4 2.5v11l9-5.5z",pause:"M4 3h3v10H4zM9 3h3v10H9z",stop:"M4 4h8v8H4z",all:"M1.5 2.5v11l6.5-5.5zM8 2.5v11l6.5-5.5z",loop:"M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",count:"M5.5 14h5L9 2.5H7zM8 11.5l4.5-7",click:"M3 5v6M8 5v6M13 5v6",copy:"M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6.5h.01"},Vt=new Set(["loop","count","click","copy"]);function te(e,n){let t=Y(e,"svg",{class:`mn-play-icon mn-play-icon-${n}${Vt.has(n)?" mn-play-icon-line":""}`,viewBox:"0 0 16 16",width:12,height:12,"aria-hidden":"true"});return t.appendChild(Y(e,"path",{d:Ht[n]})),t}function Me(e,n,t){let r=M(e,"div",`mn-play mn-play-static ${n}`);return r.addEventListener("mousedown",(o)=>o.stopPropagation()),r.setAttribute("role","group"),r.setAttribute("aria-label",t),r}function U(e,n,t,r){let o=M(e,"button",n);return o.type="button",o.appendChild(te(e,r)),o.title=t,o.setAttribute("aria-label",t),o}function _(e,n,t,r,o,s){let a=U(e,n,t,r),l=()=>{a.setAttribute("aria-pressed",String(o)),a.classList.toggle("mn-on",o)};return a.addEventListener("click",()=>{o=!o,s(o),l()}),l(),a}function Ae(e,n,t,r,o,s,a,l){let c=M(e,"label","mn-play-field"),m=M(e,"input");if(m.type="range",m.min=String(r),m.max=String(o),m.setAttribute("aria-label",n),l)m.setAttribute("aria-description",l);let i=M(e,"span","mn-play-value");i.setAttribute("aria-hidden","true");let u=(d)=>{m.value=String(d);let f=`${d} ${t}`;i.textContent=f,m.setAttribute("aria-valuetext",f),c.title=`${n}: ${f}${l?` (${l})`:""}`};return m.addEventListener("input",()=>{let d=Number(m.value);a(d),u(d)}),u(s),c.append(m,i),{field:c,input:m,show:u}}var ne=0.8;function Se(e){let n=e;if(typeof e==="function")try{n=e()}catch{n=void 0}return typeof n==="number"&&Number.isFinite(n)?Math.min(1,Math.max(0,n)):ne}var zt=Symbol.for("@dsebastien/music-notation/volume"),It=globalThis,Ee=It[zt]??=new Set,Ce=(e)=>typeof e==="number"&&Number.isFinite(e)?Math.min(1,Math.max(0,e)):null;function Ne(e,n,t){let r=Ce(t),o=()=>{let s=Ce(e());if(s===null||s===r)return;r=s;for(let a of n())a.setVolume?.(s)};return Ee.add(o),()=>{Ee.delete(o)}}var jt="1.9.0",q=(e=jt)=>{let n=`https://cdn.jsdelivr.net/npm/@coderline/alphatab@${e}/dist`;return{script:`${n}/alphaTab.min.js`,font:`${n}/font/Bravura.woff2`,soundFont:`${n}/soundfont/sonivox.sf3`}},Ut=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function _t(e,n){let t=n.split(/\r?\n/),r={staves:e,stavesWritten:!1,file:null,tracks:null,tex:"",texLine:0,fromText:!1},o=0;for(;o<t.length;o++){let a=t[o];if(!a.trim()||/^\s*\/\//.test(a))continue;let l=Ut.exec(a);if(!l)break;let c=l[1].toLowerCase(),m=l[2].trim();if(c==="staves"){let i=m.toLowerCase();if(i!=="tab"&&i!=="score"&&i!=="both")throw Error(`staves: use tab, score or both, got "${m}"`);r.staves=i,r.stavesWritten=!0}else if(c==="file")r.file=m.replace(/^!?\[\[|\]\]$/g,"").split(/[|#]/)[0].trim()||null;else{let i=m.split(/[\s,]+/).filter(Boolean).map(Number);if(!i.length||i.some((u)=>!Number.isInteger(u)||u<1))throw Error(`tracks: use track numbers from 1, got "${m}"`);r.tracks=i}}while(o<t.length&&!t[o].trim())o++;if(r.texLine=o,r.tex=t.slice(o).join(`
6
- `).trimEnd(),!r.file&&!r.tex)throw Error("Write the music in alphaTex, or give a file: [[Song.gp]]");let s=r.file?null:Te(r.tex);if(s!==null)r.tex=s,r.fromText=!0;return r}function Le(e,n){let t=e?.cause??e;for(let r of["lexerDiagnostics","parserDiagnostics","semanticDiagnostics"]){let o=t?.[r]?.items;if(!Array.isArray(o))continue;let s=o.find((a)=>a.severity===2&&a.message);if(s)return`${s.start&&n!==null?`line ${s.start.line+n}, column ${s.start.col}: `:""}${s.message}`}return e instanceof Error?e.message:String(e)}var Wt=0;function Oe(e,n){for(let t of n.tracks)for(let r of t.staves){if(r.isPercussion)for(let s of r.bars??[])s.clef=Wt;let o=!r.isPercussion&&r.tuning.length>0;if(e==="both"){r.showStandardNotation=!0,r.showTablature=o;continue}r.showSlash=!1,r.showNumbered=!1,r.showTablature=e==="tab"&&o,r.showStandardNotation=!r.showTablature}}var qt=5;function Kt(e,n){if(n!==null&&/\bdy\b|\\showdynamics/i.test(n))return;if(!e.tracks.some((r)=>r.staves.some((o)=>o.bars.some((s)=>s.voices.some((a)=>a.beats.some((l)=>!l.isRest&&l.dynamics!==qt))))))e.stylesheet.hideDynamics=!0}var Xt="rendered by alphaTab";function Yt(e,n){e.renderer?.partialRenderFinished?.on((r)=>{for(let o of n.querySelectorAll(".at-surface > div")){if(o.layoutResultId!==r.id)continue;let s=typeof r.renderResult==="string"&&r.renderResult.includes(Xt);o.style.visibility=s?"hidden":""}})}function Fe(e,n,t=1){let r=e.createElement("canvas");r.width=1,r.height=1;let o=r.getContext("2d",{willReadFrequently:!0});if(!o)return null;o.fillStyle="#000",o.fillStyle=n,o.fillRect(0,0,1,1);let s=o.getImageData(0,0,1,1).data;if(s.length<4)return null;return`rgba(${s[0]}, ${s[1]}, ${s[2]}, ${(s[3]/255*t).toFixed(3)})`}function Jt(e){let n=e.ownerDocument,t=n.defaultView?.getComputedStyle(e).color||"",r=t&&Fe(n,t)||(/^rgba?\(/.test(t)?t:"rgba(0, 0, 0, 1)"),o=t&&Fe(n,t,0.6)||r;return{mainGlyphColor:r,secondaryGlyphColor:o,scoreInfoColor:r,staffLineColor:o,barSeparatorColor:r,barNumberColor:o}}var se=(e)=>{let n=e.defaultView??globalThis;return{map:(t)=>new n.Map(t),bytes:(t)=>{let r=new n.Uint8Array(t.length);return r.set(t),r}}},De=(e)=>{let n=Math.max(0,Math.round(e/1000));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`};function Zt(e,n,t,r,o){let s=Me(e,"mn-tab-bar","Playback"),a={loop:!1,metronome:!1,countIn:!1,speed:1},l=()=>Se(o),c=null,m=null,i=()=>(c??=new Promise((v)=>{if(n.playerReady.on(()=>v(!0)),m=()=>v(!1),n.settings.player.playerMode=t.PlayerMode.EnabledSynthesizer,n.settings.player.enableCursor=!0,typeof r.soundFont==="string")n.settings.player.soundFont=r.soundFont;if(n.updateSettings(),r.soundFont instanceof Uint8Array)n.loadSoundFont(se(e).bytes(r.soundFont),!1)}).then((v)=>{if(v)n.isLooping=a.loop,n.metronomeVolume=a.metronome?1:0,n.countInVolume=a.countIn?1:0,n.playbackSpeed=a.speed,n.masterVolume=l();return v}),c),u=(v)=>{if(n.player)v()},d=U(e,"mn-play-toggle","Play","play");d.addEventListener("click",()=>{i().then((v)=>{if(v)n.playPause()})});let f=U(e,"mn-tab-stop","Stop","stop");f.addEventListener("click",()=>u(()=>n.stop()));let p=()=>u(()=>{n.isLooping=a.loop,n.metronomeVolume=a.metronome?1:0,n.countInVolume=a.countIn?1:0}),g=_(e,"mn-tab-loop","Loop","loop",!1,(v)=>{a.loop=v,p()}),h=_(e,"mn-tab-click","Metronome","click",!1,(v)=>{a.metronome=v,p()}),b=_(e,"mn-tab-count","Count-in","count",!1,(v)=>{a.countIn=v,p()}),k=Ae(e,"Speed","%",25,150,100,(v)=>{a.speed=v/100,u(()=>n.playbackSpeed=a.speed)}),T=M(e,"span","mn-tab-time","");s.append(d,f,g,h,b,k.field,T);let S=Ne(l,()=>[{stop(){},setVolume:(v)=>u(()=>n.masterVolume=v)}],l());return n.playerStateChanged.on((v)=>{let F=Number(v.state)===Number(t.synth.PlayerState.Playing);d.replaceChildren(te(e,F?"pause":"play")),d.title=F?"Pause":"Play",d.setAttribute("aria-label",d.title)}),n.playerPositionChanged.on((v)=>{T.textContent=`${De(v.currentTime)} / ${De(v.endTime)}`}),{bar:s,speed:()=>a.speed,destroy:S,failed:(v)=>{m?.(),d.disabled=!0,d.title=`Can't play: ${v}`,d.setAttribute("aria-label",d.title)}}}function Qt(e,n){return e.tracks.some((t,r)=>(!n||n.includes(r+1))&&t.staves.some((o)=>!o.isPercussion&&o.tuning.length>0))}var en=[{staves:"tab",label:"Tab",what:"tablature"},{staves:"score",label:"Score",what:"standard notation"},{staves:"both",label:"Both",what:"standard notation and tablature"}];function tn(e,n,t,r){let o=M(e,"span","mn-tab-views");o.setAttribute("role","group"),o.setAttribute("aria-label","View");let s=n.staves,a=r?M(e,"button","mn-tab-keep","Keep this view"):null,l=en.map(({staves:m,label:i,what:u})=>{let d=M(e,"button","mn-tab-view",i);d.type="button",d.dataset.staves=m;let f=m!==n.staves?"":n.written?" (this block's staves: line)":" (the default: the block has no staves: line)";return d.title=`Draw as ${u}${f}`,d.addEventListener("click",()=>{if(m===s)return;s=m,c(),t(m)}),o.appendChild(d),d}),c=()=>{for(let m of l){let i=m.dataset.staves===s;m.classList.toggle("mn-on",i),m.setAttribute("aria-pressed",String(i))}if(a)a.hidden=s===n.staves,a.title=`Write staves: ${s} at the top of the block`};if(a&&r)a.type="button",a.addEventListener("click",()=>r(s)),o.appendChild(a);return c(),o}function Pe(e,n,t,r){let o=t.ownerDocument,s=M(o,"div",`mn-block mn-block-${e} mn-tab`);t.appendChild(s);let a=null,l=()=>1,c=()=>{},m=!1,i=!1,u=()=>{},d=new Promise((p)=>{u=(g)=>{if(i)return;i=!0,p(g)}}),f=(p)=>{s.replaceChildren(M(o,"div","mn-error-message",`${e}: ${p}`)),s.classList.add("mn-error"),u({ok:!1,error:p})};if(!n.trim())s.classList.add("mn-empty"),u({ok:!0,error:null});else(async()=>{await Promise.resolve();let p=_t(e,n),g={staves:p.stavesWritten?p.staves:r.defaultStaves??p.staves,written:p.stavesWritten},h=g.staves,b=!1,k=r.alphaTab;if(!k?.AlphaTabApi)throw Error("alphaTab isn't loaded");let T=M(o,"div","mn-tab-surface");s.appendChild(T);let{assets:S}=r,v=se(o),F={core:{useWorkers:Boolean(S.scriptFile),...S.scriptFile?{scriptFile:S.scriptFile}:{},smuflFontSources:v.map([[k.FontFileFormat.Woff2,S.font]]),logLevel:k.LogLevel.Warning,enableLazyLoading:!1},display:{staveProfile:"Default",resources:Jt(s)},player:{playerMode:k.PlayerMode.Disabled,enableSeekToClick:!0,enablePlaybackRangeSelection:!0,scrollMode:k.ScrollMode.Off}},A=new k.AlphaTabApi(T,F);if(a=A,m){A.destroy();return}r.onApi?.(A);let R=[];A.scoreLoaded.on((x)=>{R=x.tracks.flatMap((w)=>w.staves.map((C)=>({showSlash:C.showSlash,showNumbered:C.showNumbered}))),Oe(h,x),b=Qt(x,p.tracks),Kt(x,p.file?null:p.tex)}),Yt(A,T);let y=null;A.renderFinished.on(()=>{if(i||m)return;if(r.player!==!1){if(y=Zt(o,A,k,S,r.volume),c=y.destroy,l=y.speed,s.appendChild(y.bar),r.views!==!1&&b)y.bar.appendChild(tn(o,g,(x)=>{h=x;let w=A.score;if(m||!w)return;w.tracks.flatMap((D)=>D.staves).forEach((D,N)=>Object.assign(D,R[N])),Oe(x,w),A.render()},r.onKeepView));s.addEventListener("pointerdown",(x)=>{if(x.pointerType!=="touch"||y?.bar.contains(x.target))return;s.classList.toggle("mn-play-open")})}u({ok:!0,error:null})}),A.error.on((x)=>{let w=p.fromText?`Couldn't draw this text tab: ${Le(x,null)}`:Le(x,p.texLine);if(i)y?.failed(w);else f(w)});let E=p.tracks?.map((x)=>x-1);if(p.file){let x;try{x=r.resolveFile?await r.resolveFile(p.file):null}catch(C){throw Error(`Couldn't read "${p.file}": ${C instanceof Error?C.message:String(C)}`,{cause:C})}if(m)return;if(!x)throw Error(`Couldn't find the file "${p.file}"`);if(!A.load(v.bytes(x),E))throw Error(`Couldn't read "${p.file}": not a score file alphaTab knows`)}else A.tex(p.tex,E??"all")})().catch((p)=>{if(!m)f(p instanceof Error?p.message:String(p))});return{el:s,ready:d,get api(){return a},speed:()=>l(),destroy(){m=!0,c();try{a?.destroy()}catch{}s.remove(),u({ok:!1,error:null})}}}var oe={guitar:25,piano:0},W={channel:1,program:28},re={channel:9,key:33},nn=0.5;function rn(e,n){return{reportsStart:!0,play(t,{sound:r,volume:o,onEnd:s,onStart:a}){let l=n(),c=l?.player;if(!l||!c)throw Error("The soundfont player is not ready");let m=new e.midi.MidiFile,i=new e.midi.AlphaSynthMidiFileHandler(m,!0),u=(h)=>Math.round(h*m.division);if(i.addTempo(0,60),i.addProgramChange(0,0,0,oe[r]),r==="guitar"&&t.some((h)=>h.kind==="muted"))i.addProgramChange(0,0,W.channel,W.program);if(t.some((h)=>h.kind==="click"))i.addProgramChange(0,0,re.channel,0);let d=Number.isFinite(o)?Math.min(1,Math.max(0,o)):0.8;l.masterVolume=d;for(let h of t){let b=h.velocity===void 0||!Number.isFinite(h.velocity)?100:Math.round(Math.min(127,Math.max(1,h.velocity))),k=h.kind==="click"?re.channel:h.kind==="muted"&&r==="guitar"?W.channel:0;i.addNote(0,u(h.time),Math.max(1,u(h.duration)),h.kind==="click"?re.key:h.midi,b,k)}let f=Math.max(...t.map((h)=>h.time+h.duration),0);i.addControlChange(0,u(f+nn),0,e.midi.ControllerType.HoldPedal,0),l.playbackSpeed=1,c.playOneTimeMidiFile(m);let p=!1;queueMicrotask(()=>{if(!p)a?.()});let g=setTimeout(()=>s?.(),(f+0.2)*1000);return{stop(){p=!0,clearTimeout(g),c.stop()},setVolume(h){if(p||!Number.isFinite(h))return;l.masterVolume=Math.min(1,Math.max(0,h))}}}}}function Re(e,n,t,r){let o=null,s=null,a=null,l=()=>{if(a)return a;s=M(t,"div","mn-tab-hidden"),s.setAttribute("aria-hidden","true"),t.body.appendChild(s);let m=se(t);o=new e.AlphaTabApi(s,{core:{useWorkers:Boolean(n.scriptFile),...n.scriptFile?{scriptFile:n.scriptFile}:{},smuflFontSources:m.map([[e.FontFileFormat.Woff2,n.font]])},player:{playerMode:e.PlayerMode.EnabledSynthesizer,enableCursor:!1,scrollMode:e.ScrollMode.Off,...typeof n.soundFont==="string"?{soundFont:n.soundFont}:{}}});let i=o;if(a=new Promise((u)=>{let d=!1,f=!i.playerReady,p=()=>{if(d&&f)u(!0)};i.soundFontLoaded.on(()=>{d=!0,p(),setTimeout(()=>{f=!0,p()},4000)}),i.playerReady?.on(()=>{f=!0,p()}),i.error.on(()=>u(!1))}),n.soundFont instanceof Uint8Array)i.loadSoundFont(m.bytes(n.soundFont),!1);return i.tex(`\\track "Guitar" \\instrument ${oe.guitar} r \\track "Piano" \\instrument ${oe.piano} r \\track "Muted" \\instrument ${W.program} r`),a},c=rn(e,()=>o);return{reportsStart:!0,play(m,i){let u=null,d=!1,f=i.volume;return l().then((p)=>{if(d)return;try{if(p){u=c.play(m,{...i,volume:f});return}}catch{}if(!r)return;if(u=r.play(m,{...i,volume:f}),!r.reportsStart)i.onStart?.()}),{stop(){d=!0,u?.stop()},setVolume(p){f=p,u?.setVolume?.(p)}}},destroy(){try{o?.destroy()}catch{}s?.remove(),o=null,a=null}}}function $e(e=()=>q().script){let n=null;return(t)=>{let r=t.defaultView;if(r.alphaTab)return Promise.resolve(r.alphaTab);return n??=new Promise((o,s)=>{let a=t.createElement("script");a.src=e();let l=r.define?.amd?r.define:void 0;if(l)r.define=void 0;let c=(m)=>{if(l&&r.define===void 0)r.define=l;if(m===null&&r.alphaTab){o(r.alphaTab);return}n=null,a.remove(),s(Error(m??"alphaTab's script didn't define alphaTab"))};a.onload=()=>c(null),a.onerror=()=>c("Couldn't load alphaTab"),t.head.appendChild(a)}),n}}var Be=`/* Music notation. Colors follow Obsidian's theme variables when present, with fallbacks for any page. */
1
+ /*! @dsebastien/music-notation 0.20.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
2
+ (()=>{var et=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],tt=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],ce={C:0,D:2,E:4,F:5,G:7,A:9,B:11};function B(e){let t=/^([A-Ga-g])([#♯b♭]*)$/.exec(e.trim());if(!t)return null;let n=ce[t[1].toUpperCase()];for(let r of t[2])n+=r==="#"||r==="♯"?1:-1;return(n%12+12)%12}function Z(e){let t=/^([A-Ga-g][#♯b♭]*)(-?\d)$/.exec(e.trim());if(!t)return null;let n=B(t[1]);if(n===null)return null;let r=ce[t[1][0].toUpperCase()],o=Math.round((n-r)/12);return(Number(t[2])+1)*12+n-o*12}var nt=(e,t=!1)=>(t?tt:et)[((Math.round(e)||0)%12+12)%12];var me=(e,t=!1)=>`${nt(e,t)}${Math.floor(e/12)-1}`;var rt="http://www.w3.org/2000/svg",ot=(e,t)=>{for(let[n,r]of Object.entries(t))if(r!==void 0)e.setAttribute(n,String(r))};function Q(e,t,n={},r=[]){let o=e.createElementNS(rt,t);ot(o,n);for(let a of r)if(a)o.appendChild(a);return o}function E(e,t,n,r){let o=e.createElement(t);if(n)o.className=n;if(r!==void 0)o.textContent=r;return o}var Ln=`mn-name-${Math.random().toString(36).slice(2,8)}-`;var st=new Map(Object.entries({standard:"E2 A2 D3 G3 B3 E4","drop d":"D2 A2 D3 G3 B3 E4","drop c":"C2 G2 C3 F3 A3 D4","drop b":"B1 F#2 B2 E3 G#3 C#4","drop a":"A1 E2 A2 D3 F#3 B3","double drop d":"D2 A2 D3 G3 B3 D4",dadgad:"D2 A2 D3 G3 A3 D4","open g":"D2 G2 D3 G3 B3 D4","open d":"D2 A2 D3 F#3 A3 D4","open e":"E2 B2 E3 G#3 B3 E4","open c":"C2 G2 C3 G3 C4 E4","open a":"E2 A2 E3 A3 C#4 E4","half step down":"Eb2 Ab2 Db3 Gb3 Bb3 Eb4","whole step down":"D2 G2 C3 F3 A3 D4","modal c6":"C2 A2 C3 G3 C4 E4",c6:"C2 A2 C3 G3 C4 E4",bass:"E1 A1 D2 G2",ukulele:"G4 C4 E4 A4"}));function j(e){let t=e.trim(),n=st.get(t.toLowerCase().replace(/\s*\(.*\)$/,""));if(n)return j(n);let r=t.split(/[\s,]+/).filter(Boolean);if(r.length>1&&r.every((s)=>Z(s)!==null))return r.map((s)=>Z(s));let o=r.length>1?r:t.match(/[A-G][#♯b♭]?|[a-g][#♯♭]?/g)??[];if(o.length<2||o.join("")!==r.join(""))return null;let a=[];for(let s of o){let l=B(s);if(l===null)return null;let m=a[a.length-1];if(m===void 0){let c=[28,40,52].map((i)=>i-i%12+l);a.push(c.reduce((i,u)=>Math.abs(u-40)<Math.abs(i-40)?u:i))}else{let c=m-m%12+l;while(c<=m)c+=12;a.push(c)}}return a}var at=/^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/,it=/^[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/,lt=/^\s*([A-Za-z][A-Za-z0-9. -]{0,14}?)\s*[|:]([-xXoOgfdb#@*+|:\s]*)$/,ct=new Map(Object.entries({hihat:"h hh hat hihat hihats","hihat-open":"oh openhat openhihat","hihat-foot":"hf fh hp ph pedal hihatfoot hihatpedal",crash:"c c1 cc cr cy cym crash crash1 cymbal",crash2:"c2 cr2 crash2",ride:"r rd rc ride",splash:"sp spl splash",china:"ch cn chi china",cowbell:"cb cow cowbell",snare:"s sd sn sr snare snaredrum",tom1:"t t1 ht tom1 hightom hitom",tom2:"t2 mt tom2 midtom",tom3:"t3 lt tom3 lowtom",floor:"f ft fl t4 tom4 floor floortom",kick:"b bd bs k kd bass kick bassdrum kickdrum"}).flatMap(([e,t])=>t.split(" ").map((n)=>[n,e])));function mt(e,t){let n=t==="#";switch(e){case"hihat":return t==="o"||t==="O"?"HiHatOpen":"HiHatClosed";case"hihat-open":return"HiHatOpen";case"hihat-foot":return"PedalHiHatHit";case"crash":return n?"CrashHighChoke":"CrashHighHit";case"crash2":return n?"CrashMediumChoke":"CrashMediumHit";case"ride":return n?"RideChoke":"RideMiddle";case"splash":return n?"SplashChoke":"SplashHit";case"china":return n?"ChinaChoke":"ChinaHit";case"cowbell":return"CowbellMediumHit";case"snare":return"SnareHit";case"tom1":return"HighTomHit";case"tom2":return"MidTomHit";case"tom3":return"LowTomHit";case"floor":return"VeryLowTomHit";case"kick":return"KickHit"}}var ut=(e)=>e==="X"||e==="O"?["ac"]:e==="g"?["g"]:[],dt=/[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/,ft=/^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;function pt(e){let t=e.lastIndexOf("|");if(t<0)return{line:e,text:null};let n=e.slice(t+1),r=n.trim();if(!r)return{line:e,text:null};return dt.test(r)||ft.test(r)||/^\s/.test(n)&&!r.includes("--")?{line:e.slice(0,t+1),text:r}:{line:e,text:null}}function ht(e){let{line:t,text:n}=pt(e.trimEnd()),r=null,o=at.exec(t),a=t.slice(o[0].length);if(it.test(a)&&(t.match(/-/g)?.length??0)>=4&&(t.includes("|")||/^\s*[A-Ga-g][#b]?\s*[-|:]/.test(t)))r={name:o[1]??null,body:a,offset:o[0].length,barred:/[|:]$/.test(o[0])};let s=null,l=lt.exec(t),m=l?l[1].toLowerCase().replace(/[ .-]/g,""):"",c=ct.get(m);if(l&&c&&(l[2].match(/[^\s|:]/g)?.length??0)>=4)s={drum:c,name:m,body:l[2],lettered:/^[A-Ga-g]$/.test(l[1])};return r||s?{string:r,drum:s,text:n}:null}var xe=(e)=>[...new Set(e.map((t)=>t.text).filter((t)=>t!==null))];function gt(e){let t=[],n=0;for(let r=2;r<e.length-1;r++){let[o,a]=[e[n].string.name,e[n+1].string.name];if(o!==null&&e[r].string.name===o&&e[r+1].string.name===a&&r-n>=2)t.push(e.slice(n,r)),n=r}return t.push(e.slice(n)),t}function bt(e){let t=[],n=[];for(let r of e){if(n.some((o)=>o.drum.name===r.drum.name))t.push(n),n=[];n.push(r)}return t.push(n),t}var yt=/^[\sPpMm.\-_|=~]*$/,vt=/P\.?M/i;function kt(e){if(!yt.test(e)||!vt.test(e))return[];let t=[];for(let n=0;n<e.length;n++){let r=e[n];if((r==="P"||r==="p")&&/^\.?[Mm]/.test(e.slice(n+1,n+3)))t.push([n,n]);else if(r!==" "&&t.length)t[t.length-1][1]=n}return t}function ue(e,t=null){return gt(e).flatMap((n,r)=>{let o=n.map((c)=>c.string.name);if(n.length<3&&o.some((c)=>c===null))return[];let a=n.map((c)=>c.string.body),s=n[0].string.offset,l=new Set;if(r===0&&t!==null)for(let[c,i]of kt(t))for(let u=Math.max(c,s);u<=i;u++)l.add(u-s);let m=n.some((c)=>!c.string.barred);return[{kind:"strings",names:o,lines:a,texts:xe(n),muted:l,openStart:m}]})}function de(e,t){if(!e.length)return[];if(e.every((o)=>o.drum)&&e.some((o)=>!o.string||!o.drum.lettered||/[xXoOgfdb#@*+]/.test(o.drum.body)))return bt(e).map((o)=>({kind:"drums",drums:o.map((a)=>a.drum.drum),lines:o.map((a)=>a.drum.body),texts:xe(o)}));if(e.every((o)=>o.string))return ue(e,t);let n=[],r=[];for(let o of[...e,null])if(o?.string)r.push(o);else{if(r.length)n.push(...ue(r,n.length?null:t));r=[]}return n}function xt(e){let t=[],n=[],r=null,o=null;for(let a of e.split(/\r?\n/)){let s=ht(a);if(s){if(!n.length)r=o;n.push(s)}else t.push(...de(n,r)),n=[];o=a}return t.push(...de(n,r)),t}function fe(e,t){let n=Math.max(...e.map((m)=>m.length)),r=e.map((m)=>m.padEnd(n,"-")),o=[],a=[],s=!1,l=0;for(let m=0;m<n;m++){if(r.every((d)=>d[m]==="|"||d[m]===":")){if(s)o.push({beats:a,start:l,end:m});a=[],s=!1,l=m+1;continue}if(r.some((d)=>d[m]!==" "))s=!0;let{beat:c,skip:i,at:u}=t(r,m);if(c.length)a.push({notes:c,col:u??m});m+=i}if(s)o.push({beats:a,start:l,end:n});return o}var I=(e)=>e!==void 0&&e>="0"&&e<="9",pe=(e,t)=>(e==="1"||e==="2")&&I(t)&&Number(e+t)<=24;function wt(e){let t=new Map,n=new Map,r=new Set,o=(a)=>{let s=a,l=e[s]==="(";if(l)s++;if(!I(e[s]))return{fret:null,next:a};let m=pe(e[s],e[s+1])?2:1,c=Number(e.slice(s,s+m));for(let i=0;i<m;i++)r.add(s+i);if(s+=m,l&&e[s]===")")s++;return{fret:c,next:s}};for(let a=0;a<e.length;){if(!I(e[a])||r.has(a)){a++;continue}let s=pe(e[a],e[a+1])?2:1,l=Number(e.slice(a,a+s));t.set(a,{fret:l,width:s});let m=[],c=e[a-1],i=a+s;if(c==="<"&&e[i]===">")m.push("nh"),i++;else if((c==="/"||c==="\\")&&!/[\d)>]/.test(e[a-2]??"-"))m.push(c==="/"?"sib":"sia");if(e[i]==="b"||e[i]==="^"){let p=o(i+1);i=p.next;let g=[0,(p.fret!==null&&p.fret>l?Math.min(p.fret-l,4):2)*2];if(e[i]==="r"){let h=o(i+1);i=h.next;let b=h.fret===null?0:(h.fret-l)*2;g.push(Math.min(g[1],Math.max(0,b)))}m.push(`b (${g.join(" ")})`)}if(e[i]==="~"||e[i]==="v"){m.push("v");while(e[i]==="~"||e[i]==="v")i++}let u=e[i],d=I(e[i+1])||e[i+1]==="("&&I(e[i+2]);if((u==="h"||u==="p")&&d)m.push("h");else if(u==="/"||u==="\\"||u==="s"){if(d)m.push("sl");else if(u!=="s")m.push(u==="/"?"sou":"sod")}if(m.length)n.set(a,m);a+=s}return{frets:t,effects:n}}var Tt=(e,t,n=[])=>(r,o)=>{let a=[],s=new Set,l=o,m=!1,c=(i,u)=>{let d=r[i][u],p=t.has(u)?["pm"]:[];if(d==="x"||d==="X"){a.push({tex:`x.${n[i]??i+1}`,effects:p}),s.add(i);return}let f=e[i].frets.get(u);if(!f)return;if(f.width===2&&u===o)m=!0;if(r[i][u-1]==="<")l=Math.min(l,u-1);a.push({tex:`${f.fret}.${n[i]??i+1}`,effects:[...e[i].effects.get(u)??[],...p],string:n[i]??i+1}),s.add(i)};if(r.forEach((i,u)=>c(u,o)),m)r.forEach((i,u)=>s.has(u)||c(u,o+1));return{beat:a,skip:m?1:0,at:l}},q={3:[64,59,55],4:[43,38,33,28],5:[43,38,33,28,23],6:[64,59,55,50,45,40],7:[64,59,55,50,45,40,35]},he=[64,59,55,50,45,40,35,30],ee={names:["E","A","D","G","B","E"],midis:[40,45,50,55,59,64]},Mt=["E A D G","B E A D G"],te=(e)=>e[0].toUpperCase()+e.slice(1);function ne(e){let t=e.length;if(e.every((n)=>n!==null&&/^\d$/.test(n)))return e.every((n)=>he[Number(n)-1])?e.map((n)=>he[Number(n)-1]):null;if(e.every((n)=>n!==null&&/^[A-Ga-g]/.test(n))){let n=[...e].reverse(),r=n.map(te).join(" ");if(Mt.includes(r))return j(r).map((s)=>s-12).reverse();let o=[...ee.names.keys()].filter((s)=>n.every((l,m)=>ee.names[s+m]===te(l)));if(o.length){let s=o.length>1&&n[0]==="e"?o.at(-1):o[0];return ee.midis.slice(s,s+t).reverse()}if(t===1){let s=B(te(e[0]));return s===null?null:[48+(s-48+120)%12]}let a=j(r);if(a)return a.reverse()}return q[t]??null}function St(e){let t=[...q[6]],n=t.indexOf(e);if(n<0)n=t.reduce((r,o,a)=>Math.abs(o-e)<Math.abs(t[r]-e)?a:r,0),t[n]=e;return{tuning:t,string:n+1}}function At(e){if(e.length===1){let{tuning:r,string:o}=St(e[0]);return{tuning:r,strings:[o]}}let t=q[6];if(e.length>5)return null;let n=e.map((r)=>t.indexOf(r));if(n[0]<0||n.some((r,o)=>r!==n[0]+o))return null;return{tuning:[...t],strings:n.map((r)=>r+1)}}var Et=(e)=>(t,n)=>{let r=[];return t.forEach((o,a)=>{let s=o[n];if(!/[xXoOgfdb#@*+]/.test(s))return;let l=mt(e[a],s);if(!r.some((m)=>m.tex===l))r.push({tex:l,effects:ut(s)})}),{beat:r,skip:0}},we=[[24,1,!0],[16,1,!1],[12,2,!0],[8,2,!1],[6,4,!0],[4,4,!1],[3,8,!0],[2,8,!1],[1,16,!1]];function ge(e){let t=[];for(let n=e;n>0;){let[r,o,a]=we.find(([s])=>s<=n);t.push({duration:o,dotted:a}),n-=r}return t}var P={ts:[4,4],length:16,beat:4,grids:[1,2,4,8,16]},be={ts:[3,4],length:12,beat:4,grids:[1,3,6,12]},Ct={ts:[6,8],length:12,beat:6,grids:[1,2,6,12]},Lt={ts:[12,8],length:24,beat:6,grids:[1,2,4,12,24]};function Nt(e,t){let n=new Map;for(let o=1;o<e.length;o++){let a=e[o]-e[o-1],s=t[o]-t[o-1];if((n.get(a)??s)!==s)return!1;n.set(a,s)}let r=[...n].sort((o,a)=>o[0]-a[0]);return r.every(([,o],a)=>a===0||o>=r[a-1][1])}var Ft=new Set(we.map(([e])=>e));function Ot(e,t,[n,r],o,a,s){let l=r/t;if(l<1||a&&!Number.isInteger(l))return null;let m=[],c=0;for(let i of e){let u=(i-n)/l,d=Math.round(u),p=Math.abs(u-d)*l;if(d<0||d>=t||p>o+0.000000001||m.length&&d*(s/t)<=m.at(-1))return null;c=Math.max(c,p),m.push(d*(s/t))}if(!a&&m.some((i,u)=>!Ft.has((m[u+1]??s)-i)))return null;return Nt(e,m)?{at:m,error:c}:null}function re(e,t,n,r=P){if(!e.length)return[];let o=[[n,t-n],[n,t]];for(let a=1;a<n;a++)o.push([a,t-a]);if(e[0]>n)o.push([0,t]);for(let[a,s]of[[0.4,!1],[1,!1],[0.4,!0]])for(let l of r.grids){let m=o.map((c)=>Ot(e,l,c,a,s,r.length)).filter((c)=>c!==null);if(m.length)return m.reduce((c,i)=>i.error<c.error?i:c).at}return null}function W(e,t,n=t.length){let r=[],{beat:o,length:a}=t;for(let s=e;s<n;){let l=a===4*o&&s%(2*o)===0&&s<=a/2?[2*o]:[],c=(s%2?[1]:s%o?[2,1]:[...l,o,2,1]).find((i)=>i<=n-s);r.push({beat:-1,sixteenths:c}),s+=c}return r}function Pt(e,t=P,n=[]){let r=e.slice(1).map((s,l)=>s-e[l]),o=new Map;for(let s of r)o.set(s,(o.get(s)??0)+1);let a=[...o].reduce((s,l)=>!s||l[1]>s[1]||l[1]===s[1]&&l[0]<s[0]?l:s,null)?.[0];for(let s of[2,1]){let l=e.map((c,i)=>s*(i<r.length?Math.max(1,Math.round(r[i]/a)):1)),m=l.reduce((c,i)=>c+i,0);if(s===2)for(let c of n){if(m<=t.length)break;if(c+1>=l.length||l[c]!==2)continue;let i=Math.max(1,l[c+1]-1);m-=1+l[c+1]-i,l[c]=1,l[c+1]=i}if(m>t.length)continue;return[...l.map((c,i)=>({beat:i,sixteenths:c})),...W(m,t)]}return e.map((s,l)=>({beat:l,sixteenths:1}))}var Dt=new Set(["h","sl"]),Rt=(e)=>e.flatMap((t,n)=>t.notes.some((r)=>r.effects.some((o)=>Dt.has(o)))?[n]:[]);function $t(e,t,n){let r=n.length,o=e.part==="whole"?e.width:t,a=e.part==="end"?t-e.width:0,s=e.beats.map((i)=>i.col+a);if(e.part==="start"&&s.length){let i=re([...s,e.width],o,e.pad,n);if(i){let u=i.pop(),d=i[0]>0?[{beat:-1,sixteenths:i[0]}]:[];return i.forEach((p,f)=>d.push({beat:f,sixteenths:(i[f+1]??u)-p})),[...d,...W(u,n)]}}let l=re(s,o,e.pad,n);if(!l){let i=Pt(e.beats.map((p)=>p.col),n,Rt(e.beats));if(e.part!=="end")return i;let u=i.filter((p)=>p.beat>=0),d=u.reduce((p,f)=>p+f.sixteenths,0);return e.pickup?u:[...W(0,n,r-d),...u]}let m=l[0],c=m===0||e.pickup?[]:e.part==="end"?W(0,n,m):[{beat:-1,sixteenths:m}];return l.forEach((i,u)=>c.push({beat:u,sixteenths:(l[u+1]??r)-i})),c}var Ht=(e)=>e.reduce((t,n)=>n.beats.length?Math.min(t,n.beats[0].col-n.start):t,3);function ye(e,t,n,r){let o=Math.max(...e.map((a)=>a.length));return{bars:t,pad:Ht(t),texts:n,openStart:r&&t[0]?.start===0,openEnd:t.at(-1)?.end===o}}function Bt(e){let t=[];for(let n of e)n.bars.forEach((r,o)=>{if((o>0||!n.openStart)&&(o<n.bars.length-1||!n.openEnd)&&r.beats.length)t.push(r.end-r.start)});if(t.length<2)return null;return t.sort((n,r)=>n-r),t[t.length>>1]}function Te(e){let t=new Map;for(let r of e)t.set(r,(t.get(r)??0)+1);let n;for(let[r,o]of t)if(!n||o>n.count||o===n.count&&r<n.value)n={value:r,count:o};return n}function It(e,t){if(t===null)return P;let n=[];for(let i of e)i.bars.forEach((u,d)=>{let p=(d>0||!i.openStart)&&(d<i.bars.length-1||!i.openEnd),f=u.end-u.start;if(p&&u.beats.length&&Math.abs(f-t)<=1)n.push({bar:u,pad:i.pad})});let r=new Map;for(let{bar:i}of n)for(let u=1;u<i.beats.length;u++){let d=i.beats[u].col-i.beats[u-1].col;r.set(d,(r.get(d)??0)+1)}let o=Math.max(0,...r.values()),a=Math.min(...[...r].filter(([,i])=>i*2>=o).map(([i])=>i));if(n.length<2||!Number.isFinite(a))return P;let s=[],l=0,m=0;for(let{bar:i,pad:u}of n){let d=i.beats.map((b)=>(b.col-i.start-u)/a);if(d.some((b)=>Math.abs(b-Math.round(b))*a>0.40000000100000005)){s.push(0);continue}let p=d.map(Math.round),f=Math.max(Math.ceil((i.end-i.start-u)/a-0.5),p.at(-1)+1);if(s.push(f),f!==6)continue;let g=i.beats.reduce((b,y)=>y.notes.reduce((v,M)=>Math.max(v,M.string??0),b),0),h=p.filter((b,y)=>i.beats[y].notes.some((v)=>v.string===g));for(let b of[p,h.length<p.length?h:[]])if(b.some((y)=>y!==0&&y%2===0)&&b.every((y)=>y%2===0))l++;else if(b.includes(3)&&b.every((y)=>y%3===0))m++}let c=Te(s);if(c.count*3<n.length*2)return P;if(c.value===3)return be;if(c.value===6)return l>m?be:Ct;return c.value===12?Lt:P}function Gt(e,t){let n=(a)=>t!==null&&a<=t*2/3,r=[],o=null;return e.forEach((a,s)=>{let l=r.length,m=e[s+1];a.bars.forEach((i,u)=>{let d=i.beats.map((h)=>({notes:h.notes,col:h.col-i.start})),p={beats:d,width:i.end-i.start,pad:a.pad,part:"whole",pickup:!1,text:null},f=u===0&&o!==null;if(o&&u===0){let h=o.width-a.pad;p={...o,beats:[...o.beats,...d.map((b)=>({notes:b.notes,col:b.col+h}))],width:o.width+p.width-a.pad},o=null}if(u===a.bars.length-1&&n(p.width)){let h=m?.bars[0],b=h?p.width+h.end-h.start-m.pad:0;if(h&&(a.openEnd||n(h.end-h.start)&&(m.openStart||b<=t*1.25))){if(p.beats.length||!a.openEnd)o=p;return}if(a.openEnd&&!f){if(!p.beats.length)return;p.part="start"}}let g=!r.length;if(u===0&&!f&&p.part==="whole"&&n(p.width)&&p.beats.length){if(g||a.openStart)p.part="end",p.pickup=g}r.push(p)});let c=o??(r.length>l?r.at(-1):null);if(a.texts.length&&c){let i=a.texts.join(" / ");c.text=c.text?`${c.text} / ${i}`:i}}),r}function Vt(e,t){return e.flatMap((n)=>{if(n.part!=="whole"||n.beats.length<2)return[n];let r=n.beats.map((u)=>u.col);if(re(r,n.width,n.pad,t))return[n];let o=r.slice(1).map((u,d)=>u-r[d]),a=Te(o).value,s=o.reduce((u,d)=>u+Math.max(1,Math.round(d/a)),1),l=t.length/2,m=a*l;if(s<=l||n.width-n.pad<m*1.5)return[n];let c=Math.floor((r.at(-1)-n.pad)/m)+1,i=Array.from({length:c},()=>[]);for(let u of n.beats){let d=Math.min(c-1,Math.max(0,Math.floor((u.col-n.pad)/m)));while(d<c-1&&u.col>=n.pad+(d+1)*m)d++;while(d>0&&u.col<n.pad+d*m)d--;i[d].push({notes:u.notes,col:u.col-d*m})}return i.map((u,d)=>({beats:u,width:n.pad+m,pad:n.pad,part:"whole",pickup:!1,text:d===c-1?n.text:null}))})}var zt=(e)=>`"${e.replace(/[\\"]/g,(t)=>`\\${t}`)}"`,_=(e,t)=>t.length?`${e}{${t.join(" ")}}`:e;function Ut(e,t){if(!e.length)return _("r",t);if(e.length===1)return _(e[0].tex,[...e[0].effects,...t]);return _(`(${e.map((n)=>_(n.tex,n.effects)).join(" ")})`,t)}var ve=new Set(["h","sl","sou","sod"]);function jt(e,t){if(t===1)return[e];let n=[e.map((r)=>({...r,effects:r.effects.filter((o)=>!ve.has(o))}))];for(let r=1;r<t;r++)n.push(e.filter((o)=>o.string!==void 0).map((o)=>({tex:`-.${o.string}`,effects:o.effects.filter((a)=>a==="pm"||r===t-1&&ve.has(a))})));return n}function ke(e,t){let n=0;return e.map(({beats:o,rhythm:a,text:s,pickup:l})=>{let m=[];if(!o.length)for(let u of t===P?[{duration:1,dotted:!1}]:ge(t.length))m.push({notes:[],...u});for(let{beat:u,sixteenths:d}of a){let p=ge(d),f=jt(u>=0?o[u]:[],p.length);p.forEach((g,h)=>m.push({notes:f[h],...g}))}let c=m.length-1;while(c>0&&!m[c].notes.length)c--;if(!m[c].notes.length)c=m.length-1;let i=m.map((u,d)=>{let p=u.dotted?["d"]:[];if(s&&d===c)p.push(`txt ${zt(s)}`);let f=u.duration===n?"":`:${u.duration} `;return n=u.duration,f+Ut(u.notes,p)}).join(" ");return l?`\\ac ${i}`:i}).join(` |
3
+ `)}function Me(e){let t=xt(e),n=t[0];if(!n)return null;let r=n.kind==="strings"?ne(n.names):null,o=r?At(r):null;if(o)r=o.tuning;let a=[];if(n.kind==="drums"){for(let d of t)if(d.kind==="drums")a.push(ye(d.lines,fe(d.lines,Et(d.drums)),d.texts,!1))}else{let d=JSON.stringify(ne(n.names)),p=o?.strings??[];for(let f of t){if(f.kind!=="strings"||JSON.stringify(ne(f.names))!==d)continue;let g=Tt(f.lines.map(wt),f.muted,p);a.push(ye(f.lines,fe(f.lines,g),f.texts,f.openStart))}}let s=Bt(a),l=It(a,s),m=Vt(Gt(a,s),l).map((d)=>({beats:d.beats.map((p)=>p.notes),rhythm:$t(d,s??0,l),text:d.text,pickup:d.pickup}));if(!m.length)return null;let c=l===P?[]:[`\\ts ${l.ts.join(" ")}`];if(n.kind==="drums")return["\\instrument percussion","\\articulation defaults",...c,ke(m,l)].join(`
4
+ `);let i=r?.join(" ")===q[6].join(" ");return[...r&&!i?[`\\tuning (${r.map((d)=>me(d)).join(" ")})`]:[],...c,ke(m,l)].join(`
5
+ `)}var _t={play:"M4 2.5v11l9-5.5z",pause:"M4 3h3v10H4zM9 3h3v10H9z",stop:"M4 4h8v8H4z",all:"M1.5 2.5v11l6.5-5.5zM8 2.5v11l6.5-5.5z",loop:"M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",count:"M5.5 14h5L9 2.5H7zM8 11.5l4.5-7",click:"M3 5v6M8 5v6M13 5v6",copy:"M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6.5h.01",full:"M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",exit:"M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"},Wt=new Set(["loop","count","click","copy","full","exit"]);function G(e,t){let n=Q(e,"svg",{class:`mn-play-icon mn-play-icon-${t}${Wt.has(t)?" mn-play-icon-line":""}`,viewBox:"0 0 16 16",width:12,height:12,"aria-hidden":"true"});return n.appendChild(Q(e,"path",{d:_t[t]})),n}function Se(e,t,n){let r=E(e,"div",`mn-play mn-play-static ${t}`);return r.addEventListener("mousedown",(o)=>o.stopPropagation()),r.setAttribute("role","group"),r.setAttribute("aria-label",n),r}function H(e,t,n,r){let o=E(e,"button",t);return o.type="button",o.appendChild(G(e,r)),o.title=n,o.setAttribute("aria-label",n),o}function K(e,t,n,r,o,a){let s=H(e,t,n,r),l=()=>{s.setAttribute("aria-pressed",String(o)),s.classList.toggle("mn-on",o)};return s.addEventListener("click",()=>{o=!o,a(o),l()}),l(),s}function Ae(e,t,n,r,o,a,s,l){let m=E(e,"label","mn-play-field"),c=E(e,"input");if(c.type="range",c.min=String(r),c.max=String(o),c.setAttribute("aria-label",t),l)c.setAttribute("aria-description",l);let i=E(e,"span","mn-play-value");i.setAttribute("aria-hidden","true");let u=(d)=>{c.value=String(d);let p=`${d} ${n}`;i.textContent=p,c.setAttribute("aria-valuetext",p),m.title=`${t}: ${p}${l?` (${l})`:""}`};return c.addEventListener("input",()=>{let d=Number(c.value);s(d),u(d)}),u(a),m.append(c,i),{field:m,input:c,show:u}}var oe=0.8;function Ee(e){let t=e;if(typeof e==="function")try{t=e()}catch{t=void 0}return typeof t==="number"&&Number.isFinite(t)?Math.min(1,Math.max(0,t)):oe}var qt=Symbol.for("@dsebastien/music-notation/volume"),Kt=globalThis,Ce=Kt[qt]??=new Set,Le=(e)=>typeof e==="number"&&Number.isFinite(e)?Math.min(1,Math.max(0,e)):null;function Ne(e,t,n){let r=Le(n),o=()=>{let a=Le(e());if(a===null||a===r)return;r=a;for(let s of t())s.setVolume?.(a)};return Ce.add(o),()=>{Ce.delete(o)}}var Xt=new Set(["PageUp","PageDown","Home","End","ArrowUp","ArrowDown"," "]);function Yt(e){let t=e.ownerDocument.defaultView;if(!t)return"";for(let n=e.parentElement;n;n=n.parentElement){let r=t.getComputedStyle(n).backgroundColor;if(r&&r!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(r))return r}return""}function Fe(e,t,n,r){let o=e.defaultView,a=H(e,"mn-tab-full","Full screen","full"),s=!1,l=!1,m=!1,c=null,i=null,u=!1,d="",p=(v)=>{if(m===v)return;m=v,r(v)},f=()=>{t.classList.toggle("mn-fullscreen",s),a.classList.toggle("mn-on",s),a.setAttribute("aria-pressed",String(s)),a.title=s?"Exit full screen":"Full screen",a.replaceChildren(G(e,s?"exit":"full"))},g=()=>{if(s)return;if(s=!0,c={x:o?.scrollX??0,y:o?.scrollY??0,background:t.style.backgroundColor},!u)d=t.style.minHeight;u=!1,i=e.createElement("div"),i.className="mn-fullscreen-place",i.style.height=`${t.offsetHeight}px`;let v=o?.getComputedStyle(t);if(v)i.style.marginTop=v.marginTop,i.style.marginBottom=v.marginBottom;t.before(i);let M=Yt(t);if(M)t.style.backgroundColor=M;f(),n.tabIndex=0,n.focus({preventScroll:!0}),p(!0);try{t.requestFullscreen?.().catch(()=>{})}catch{}},h=(v=!0)=>{if(!s)return;if(s=!1,p(!1),f(),t.style.backgroundColor=c?.background??"",i)t.style.minHeight=i.style.height,u=!0,i.remove(),i=null;if(n.removeAttribute("tabindex"),n.scrollTop=0,l&&e.fullscreenElement===t)e.exitFullscreen?.().catch(()=>{});if(l=!1,c&&o)o.scrollTo(c.x,c.y);if(c=null,v)a.focus({preventScroll:!0})};a.addEventListener("click",()=>s?h():g()),t.addEventListener("keydown",(v)=>{if(!s||v.key!=="Escape")return;v.stopPropagation(),v.preventDefault(),h()});let b=()=>{if(s)p(!1)};n.addEventListener("wheel",b,{passive:!0}),n.addEventListener("touchmove",b,{passive:!0}),n.addEventListener("keydown",(v)=>{if(Xt.has(v.key))b()});let y=()=>{if(e.fullscreenElement===t)l=!0;else if(l)h()};return e.addEventListener("fullscreenchange",y),f(),{button:a,active:()=>s,playing:()=>{if(s)p(!0)},drawn:()=>{if(s||!u)return;u=!1,t.style.minHeight=d},destroy:()=>{h(!1),e.removeEventListener("fullscreenchange",y)}}}function Pe(e){if(!e||typeof e!=="object"||!("play"in e))return;let t=e.play;if(!t||typeof t!=="object"||!("instruments"in t))return;let n=t.instruments;return typeof n==="string"&&n.trim()?n.trim():void 0}function De(e){let t=new Set,n=!1;for(let r of e.tracks)if(r.isPercussion)n=!0;else t.add(r.playbackInfo.program);return{programs:[...t].sort((r,o)=>r-o),drums:n}}function Jt(e,t){let n=[];for(let r of t.programs){let o=e.programs[String(r)];if(!o?.file)return null;n.push(o.file)}if(t.drums){if(!e.drums?.file)return null;n.push(e.drums.file)}else if(e.click?.file&&t.click!==!1)n.push(e.click.file);return n.length?n:null}var Oe=new WeakMap,Zt=(e)=>typeof e==="object"&&e!==null&&("programs"in e)&&typeof e.programs==="object"&&e.programs!==null;async function Re(e,t,n){let r=Oe.get(n);if(!r)Oe.set(n,r=new Map);let o=r.get(e);if(!o)r.set(e,o={index:null,files:new Map});let a=async(i)=>{try{if(typeof e==="function")return await e(i);let u=await n.fetch(`${e.replace(/\/+$/,"")}/${i}`);return u.ok?new Uint8Array(await u.arrayBuffer()):null}catch{return null}},s=(i)=>{let u=o.files.get(i);if(!u)u=a(i),o.files.set(i,u),u.then((d)=>{if(!d)o.files.delete(i)});return u};o.index??=a("index.json").then((i)=>{if(!i)return null;try{let u=JSON.parse(new TextDecoder().decode(i));return Zt(u)?u:null}catch{return null}});let l=await o.index;if(!l)return o.index=null,null;let m=Jt(l,t);if(!m)return null;let c=await Promise.all(m.map(s));return c.every((i)=>i!==null)?c:null}var Qt="1.9.0",X=(e=Qt)=>{let t=`https://cdn.jsdelivr.net/npm/@coderline/alphatab@${e}/dist`;return{script:`${t}/alphaTab.min.js`,font:`${t}/font/Bravura.woff2`,soundFont:`${t}/soundfont/sonivox.sf3`}};async function ae(e,t,n,r,o=!1){let a=t.defaultView,s=Y(t),l=null;if(n.instruments&&a)l=await Re(n.instruments,r,a);let m=l?"instruments":"whole";if(!l)if(typeof n.soundFont==="string"){try{let u=await a?.fetch(n.soundFont);l=u?.ok?[new Uint8Array(await u.arrayBuffer())]:null}catch{l=null}if(!l)throw Error(`Couldn't load the soundfont (${n.soundFont})`)}else l=[n.soundFont];let c=l,i=0;return await new Promise((u)=>{e.soundFontLoaded.on(()=>{if(++i>=c.length)u()}),setTimeout(u,8000),c.forEach((d,p)=>e.loadSoundFont(s.bytes(d),o||p>0))}),m}var en=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function tn(e,t){let n=t.split(/\r?\n/),r={staves:e,stavesWritten:!1,file:null,tracks:null,tex:"",texLine:0,fromText:!1},o=0;for(;o<n.length;o++){let s=n[o];if(!s.trim()||/^\s*\/\//.test(s))continue;let l=en.exec(s);if(!l)break;let m=l[1].toLowerCase(),c=l[2].trim();if(m==="staves"){let i=c.toLowerCase();if(i!=="tab"&&i!=="score"&&i!=="both")throw Error(`staves: use tab, score or both, got "${c}"`);r.staves=i,r.stavesWritten=!0}else if(m==="file")r.file=c.replace(/^!?\[\[|\]\]$/g,"").split(/[|#]/)[0].trim()||null;else{let i=c.split(/[\s,]+/).filter(Boolean).map(Number);if(!i.length||i.some((u)=>!Number.isInteger(u)||u<1))throw Error(`tracks: use track numbers from 1, got "${c}"`);r.tracks=i}}while(o<n.length&&!n[o].trim())o++;if(r.texLine=o,r.tex=n.slice(o).join(`
6
+ `).trimEnd(),!r.file&&!r.tex)throw Error("Write the music in alphaTex, or give a file: [[Song.gp]]");let a=r.file?null:Me(r.tex);if(a!==null)r.tex=a,r.fromText=!0;return r}function $e(e,t){let n=e?.cause??e;for(let r of["lexerDiagnostics","parserDiagnostics","semanticDiagnostics"]){let o=n?.[r]?.items;if(!Array.isArray(o))continue;let a=o.find((s)=>s.severity===2&&s.message);if(a)return`${a.start&&t!==null?`line ${a.start.line+t}, column ${a.start.col}: `:""}${a.message}`}return e instanceof Error?e.message:String(e)}var nn=0;function He(e,t){for(let n of t.tracks)for(let r of n.staves){if(r.isPercussion)for(let a of r.bars??[])a.clef=nn;let o=!r.isPercussion&&r.tuning.length>0;if(e==="both"){r.showStandardNotation=!0,r.showTablature=o;continue}r.showSlash=!1,r.showNumbered=!1,r.showTablature=e==="tab"&&o,r.showStandardNotation=!r.showTablature}}var rn=5;function on(e,t){if(t!==null&&/\bdy\b|\\showdynamics/i.test(t))return;if(!e.tracks.some((r)=>r.staves.some((o)=>o.bars.some((a)=>a.voices.some((s)=>s.beats.some((l)=>!l.isRest&&l.dynamics!==rn))))))e.stylesheet.hideDynamics=!0}var sn="rendered by alphaTab";function an(e,t){e.renderer?.partialRenderFinished?.on((r)=>{for(let o of t.querySelectorAll(".at-surface > div")){if(o.layoutResultId!==r.id)continue;let a=typeof r.renderResult==="string"&&r.renderResult.includes(sn);o.style.visibility=a?"hidden":""}})}function Be(e,t,n=1){let r=e.createElement("canvas");r.width=1,r.height=1;let o=r.getContext("2d",{willReadFrequently:!0});if(!o)return null;o.fillStyle="#000",o.fillStyle=t,o.fillRect(0,0,1,1);let a=o.getImageData(0,0,1,1).data;if(a.length<4)return null;return`rgba(${a[0]}, ${a[1]}, ${a[2]}, ${(a[3]/255*n).toFixed(3)})`}function ln(e){let t=e.ownerDocument,n=t.defaultView?.getComputedStyle(e).color||"",r=n&&Be(t,n)||(/^rgba?\(/.test(n)?n:"rgba(0, 0, 0, 1)"),o=n&&Be(t,n,0.6)||r;return{mainGlyphColor:r,secondaryGlyphColor:o,scoreInfoColor:r,staffLineColor:o,barSeparatorColor:r,barNumberColor:o}}var Y=(e)=>{let t=e.defaultView??globalThis;return{map:(n)=>new t.Map(n),bytes:(n)=>{let r=new t.Uint8Array(n.length);return r.set(n),r}}},Ie=(e)=>{let t=Math.max(0,Math.round(e/1000));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`};function cn(e,t,n,r,o){let a=Se(e,"mn-tab-bar","Playback"),s={loop:!1,metronome:!1,countIn:!1,speed:1},l=()=>Ee(o),m=()=>{},c=null,i=null,u=()=>(c??=new Promise((x)=>{if(i=()=>x(!1),t.settings.player.playerMode=n.PlayerMode.EnabledSynthesizer,t.settings.player.enableCursor=!0,!r.instruments){if(t.playerReady.on(()=>x(!0)),typeof r.soundFont==="string")t.settings.player.soundFont=r.soundFont;if(t.updateSettings(),r.soundFont instanceof Uint8Array)t.loadSoundFont(Y(e).bytes(r.soundFont),!1);return}let T=!1,O=!1,k=()=>{if(T&&O)x(!0)};t.playerReady.on(()=>{T=!0,k()}),t.updateSettings();let C=t.score?De(t.score):{programs:[],drums:!1};ae(t,e,r,C).then(()=>{O=!0,k()},(w)=>{x(!1),m(w instanceof Error?w.message:String(w))})}).then((x)=>{if(x)t.isLooping=s.loop,t.metronomeVolume=s.metronome?1:0,t.countInVolume=s.countIn?1:0,t.playbackSpeed=s.speed,t.masterVolume=l();return x}),c),d=(x)=>{if(t.player)x()},p=H(e,"mn-play-toggle","Play","play");p.addEventListener("click",()=>{u().then((x)=>{if(x)t.playPause()})}),m=(x)=>{p.disabled=!0,p.title=`Can't play: ${x}`,p.setAttribute("aria-label",p.title)};let f=H(e,"mn-tab-stop","Stop","stop");f.addEventListener("click",()=>d(()=>t.stop()));let g=()=>d(()=>{t.isLooping=s.loop,t.metronomeVolume=s.metronome?1:0,t.countInVolume=s.countIn?1:0}),h=K(e,"mn-tab-loop","Loop","loop",!1,(x)=>{s.loop=x,g()}),b=K(e,"mn-tab-click","Metronome","click",!1,(x)=>{s.metronome=x,g()}),y=K(e,"mn-tab-count","Count-in","count",!1,(x)=>{s.countIn=x,g()}),v=Ae(e,"Speed","%",25,150,100,(x)=>{s.speed=x/100,d(()=>t.playbackSpeed=s.speed)}),M=E(e,"span","mn-tab-time","");a.append(p,f,h,b,y,v.field,M);let L=Ne(l,()=>[{stop(){},setVolume:(x)=>d(()=>t.masterVolume=x)}],l());return t.playerStateChanged.on((x)=>{let T=Number(x.state)===Number(n.synth.PlayerState.Playing);p.replaceChildren(G(e,T?"pause":"play")),p.title=T?"Pause":"Play",p.setAttribute("aria-label",p.title)}),t.playerPositionChanged.on((x)=>{M.textContent=`${Ie(x.currentTime)} / ${Ie(x.endTime)}`}),{bar:a,speed:()=>s.speed,destroy:L,failed:(x)=>{i?.(),m(x)}}}function mn(e,t){return e.tracks.some((n,r)=>(!t||t.includes(r+1))&&n.staves.some((o)=>!o.isPercussion&&o.tuning.length>0))}var un=[{staves:"tab",label:"Tab",what:"tablature"},{staves:"score",label:"Score",what:"standard notation"},{staves:"both",label:"Both",what:"standard notation and tablature"}];function dn(e,t,n,r){let o=E(e,"span","mn-tab-views");o.setAttribute("role","group"),o.setAttribute("aria-label","View");let a=t.staves,s=r?E(e,"button","mn-tab-keep","Keep this view"):null,l=un.map(({staves:c,label:i,what:u})=>{let d=E(e,"button","mn-tab-view",i);d.type="button",d.dataset.staves=c;let p=c!==t.staves?"":t.written?" (this block's staves: line)":" (the default: the block has no staves: line)";return d.title=`Draw as ${u}${p}`,d.addEventListener("click",()=>{if(c===a)return;a=c,m(),n(c)}),o.appendChild(d),d}),m=()=>{for(let c of l){let i=c.dataset.staves===a;c.classList.toggle("mn-on",i),c.setAttribute("aria-pressed",String(i))}if(s)s.hidden=a===t.staves,s.title=`Write staves: ${a} at the top of the block`};if(s&&r)s.type="button",s.addEventListener("click",()=>r(a)),o.appendChild(s);return m(),o}function Ge(e,t,n,r){let o=n.ownerDocument,a=E(o,"div",`mn-block mn-block-${e} mn-tab`);n.appendChild(a);let s=null,l=()=>1,m=()=>{},c=!1,i=!1,u=()=>{},d=new Promise((f)=>{u=(g)=>{if(i)return;i=!0,f(g)}}),p=(f)=>{a.replaceChildren(E(o,"div","mn-error-message",`${e}: ${f}`)),a.classList.add("mn-error"),u({ok:!1,error:f})};if(!t.trim())a.classList.add("mn-empty"),u({ok:!0,error:null});else(async()=>{await Promise.resolve();let f=tn(e,t),g={staves:f.stavesWritten?f.staves:r.defaultStaves??f.staves,written:f.stavesWritten},h=g.staves,b=!1,y=r.alphaTab;if(!y?.AlphaTabApi)throw Error("alphaTab isn't loaded");let v=E(o,"div","mn-tab-surface");a.appendChild(v);let{assets:M}=r,L=Y(o),x={core:{useWorkers:Boolean(M.scriptFile),...M.scriptFile?{scriptFile:M.scriptFile}:{},smuflFontSources:L.map([[y.FontFileFormat.Woff2,M.font]]),logLevel:y.LogLevel.Warning,enableLazyLoading:!1},display:{staveProfile:"Default",resources:ln(a)},player:{playerMode:y.PlayerMode.Disabled,enableSeekToClick:!0,enablePlaybackRangeSelection:!0,scrollMode:y.ScrollMode.Off}},T=new y.AlphaTabApi(v,x);if(s=T,T.settings.player.scrollElement=v,c){T.destroy();return}r.onApi?.(T);let O=[];T.scoreLoaded.on((w)=>{O=w.tracks.flatMap((S)=>S.staves.map((A)=>({showSlash:A.showSlash,showNumbered:A.showNumbered}))),He(h,w),b=mn(w,f.tracks),on(w,f.file?null:f.tex)}),an(T,v);let k=null;T.renderFinished.on(()=>{if(i||c)return;if(r.player!==!1){if(k=cn(o,T,y,M,r.volume),m=k.destroy,l=k.speed,a.appendChild(k.bar),r.views!==!1&&b)k.bar.appendChild(dn(o,g,(w)=>{h=w;let S=T.score;if(c||!S)return;S.tracks.flatMap((D)=>D.staves).forEach((D,N)=>Object.assign(D,O[N])),He(w,S),T.render()},r.onKeepView));if(r.fullScreen!==!1){let w=Fe(o,a,v,(A)=>{T.settings.player.scrollMode=A?y.ScrollMode.OffScreen:y.ScrollMode.Off,T.updateSettings()});T.playerStateChanged.on((A)=>{if(Number(A.state)===Number(y.synth.PlayerState.Playing))w.playing()}),T.renderFinished.on(()=>w.drawn()),k.bar.appendChild(w.button);let S=m;m=()=>{w.destroy(),S()}}a.addEventListener("pointerdown",(w)=>{if(w.pointerType!=="touch"||k?.bar.contains(w.target))return;a.classList.toggle("mn-play-open")})}u({ok:!0,error:null})}),T.error.on((w)=>{let S=f.fromText?`Couldn't draw this text tab: ${$e(w,null)}`:$e(w,f.texLine);if(i)k?.failed(S);else p(S)});let C=f.tracks?.map((w)=>w-1);if(f.file){let w;try{w=r.resolveFile?await r.resolveFile(f.file):null}catch(A){throw Error(`Couldn't read "${f.file}": ${A instanceof Error?A.message:String(A)}`,{cause:A})}if(c)return;if(!w)throw Error(`Couldn't find the file "${f.file}"`);if(!T.load(L.bytes(w),C))throw Error(`Couldn't read "${f.file}": not a score file alphaTab knows`)}else T.tex(f.tex,C??"all")})().catch((f)=>{if(!c)p(f instanceof Error?f.message:String(f))});return{el:a,ready:d,get api(){return s},speed:()=>l(),destroy(){c=!0,m();try{s?.destroy()}catch{}a.remove(),u({ok:!1,error:null})}}}var V={guitar:25,piano:0},z={channel:1,program:28},se={channel:9,key:33},fn=0.5;function pn(e,t){return{reportsStart:!0,play(n,{sound:r,volume:o,onEnd:a,onStart:s}){let l=t(),m=l?.player;if(!l||!m)throw Error("The soundfont player is not ready");let c=new e.midi.MidiFile,i=new e.midi.AlphaSynthMidiFileHandler(c,!0),u=(h)=>Math.round(h*c.division);if(i.addTempo(0,60),i.addProgramChange(0,0,0,V[r]),r==="guitar"&&n.some((h)=>h.kind==="muted"))i.addProgramChange(0,0,z.channel,z.program);if(n.some((h)=>h.kind==="click"))i.addProgramChange(0,0,se.channel,0);let d=Number.isFinite(o)?Math.min(1,Math.max(0,o)):0.8;l.masterVolume=d;for(let h of n){let b=h.velocity===void 0||!Number.isFinite(h.velocity)?100:Math.round(Math.min(127,Math.max(1,h.velocity))),y=h.kind==="click"?se.channel:h.kind==="muted"&&r==="guitar"?z.channel:0;i.addNote(0,u(h.time),Math.max(1,u(h.duration)),h.kind==="click"?se.key:h.midi,b,y)}let p=Math.max(...n.map((h)=>h.time+h.duration),0);i.addControlChange(0,u(p+fn),0,e.midi.ControllerType.HoldPedal,0),l.playbackSpeed=1,m.playOneTimeMidiFile(c);let f=!1;queueMicrotask(()=>{if(!f)s?.()});let g=setTimeout(()=>a?.(),(p+0.2)*1000);return{stop(){f=!0,clearTimeout(g),m.stop()},setVolume(h){if(f||!Number.isFinite(h))return;l.masterVolume=Math.min(1,Math.max(0,h))}}}}}function Ve(e,t,n,r){let o=null,a=null,s=null,l=new Set,m=new Map,c=!t.instruments,i=(f)=>f==="guitar"?[V.guitar,z.program]:[V[f]],u=(f="guitar")=>{if(s)return s;a=E(n,"div","mn-tab-hidden"),a.setAttribute("aria-hidden","true"),n.body.appendChild(a);let g=Y(n);o=new e.AlphaTabApi(a,{core:{useWorkers:Boolean(t.scriptFile),...t.scriptFile?{scriptFile:t.scriptFile}:{},smuflFontSources:g.map([[e.FontFileFormat.Woff2,t.font]])},player:{playerMode:e.PlayerMode.EnabledSynthesizer,enableCursor:!1,scrollMode:e.ScrollMode.Off,...typeof t.soundFont==="string"&&!t.instruments?{soundFont:t.soundFont}:{}}});let h=o;if(s=new Promise((b)=>{let y=!1,v=!h.playerReady,M=()=>{if(y&&v)b(!0)},L=()=>{y=!0,M(),setTimeout(()=>{v=!0,M()},4000)};if(h.playerReady?.on(()=>{v=!0,M()}),h.error.on(()=>b(!1)),t.instruments)ae(h,n,t,{programs:i(f),drums:!1}).then((x)=>{if(x==="whole")c=!0;else l.add(f);L()},()=>b(!1));else h.soundFontLoaded.on(L)}),t.soundFont instanceof Uint8Array&&!t.instruments)h.loadSoundFont(g.bytes(t.soundFont),!1);return h.tex(`\\track "Guitar" \\instrument ${V.guitar} r \\track "Piano" \\instrument ${V.piano} r \\track "Muted" \\instrument ${z.program} r`),s},d=async(f)=>{if(!await u(f))return!1;if(c||l.has(f)||!o)return!0;let g=o,h=m.get(f);if(!h)h=ae(g,n,t,{programs:i(f),drums:!1,click:!1},!0).then((b)=>{if(b==="whole")c=!0;else l.add(f);return!0},()=>!1),m.set(f,h);return h},p=pn(e,()=>o);return{reportsStart:!0,play(f,g){let h=null,b=!1,y=g.volume;return d(g.sound).then((v)=>{if(b)return;try{if(v){h=p.play(f,{...g,volume:y});return}}catch{}if(!r)return;if(h=r.play(f,{...g,volume:y}),!r.reportsStart)g.onStart?.()}),{stop(){b=!0,h?.stop()},setVolume(v){y=v,h?.setVolume?.(v)}}},destroy(){try{o?.destroy()}catch{}a?.remove(),o=null,s=null,l.clear(),m.clear(),c=!t.instruments}}}function ze(e=()=>X().script){let t=null;return(n)=>{let r=n.defaultView;if(r.alphaTab)return Promise.resolve(r.alphaTab);return t??=new Promise((o,a)=>{let s=n.createElement("script");s.src=e();let l=r.define?.amd?r.define:void 0;if(l)r.define=void 0;let m=(c)=>{if(l&&r.define===void 0)r.define=l;if(c===null&&r.alphaTab){o(r.alphaTab);return}t=null,s.remove(),a(Error(c??"alphaTab's script didn't define alphaTab"))};s.onload=()=>m(null),s.onerror=()=>m("Couldn't load alphaTab"),n.head.appendChild(s)}),t}}var Ue=`/* Music notation. Colors follow Obsidian's theme variables when present, with fallbacks for any page. */
7
7
  .mn-block,
8
8
  .mn-svg,
9
9
  .mn-chart {
@@ -1245,4 +1245,39 @@
1245
1245
  align-items: center;
1246
1246
  gap: 2px 6px;
1247
1247
  }
1248
- `;var sn=Be,Ge="music-notation-styles";function He(e){if(e.getElementById(Ge))return;let n=e.createElement("style");n.id=Ge,n.textContent=sn,e.head.appendChild(n)}var an=(e)=>e.reduce((n,t)=>Math.max(n,t.time+t.duration),0),ie=(e)=>440*Math.pow(2,(e-69)/12);function ln(e,n,t,r=Math.random,o={}){let s=new Float32Array(Math.round(n*t)),a=Math.max(2,Math.round(n/ie(e))),l=new Float32Array(a);for(let g=0;g<a;g++)l[g]=r()*2-1;let c=Math.min(1,Math.max(0,o.brightness??1));if(c<1){let g=0.2+0.8*c,h=l[a-1];for(let b=0;b<a;b++)l[b]=h+=g*(l[b]-h)}let m=Math.min(0.5,Math.max(0,o.pick??0)),i=Math.round(m*a);if(i>0){let g=Float32Array.from(l);for(let h=0;h<a;h++)l[h]=g[h]-g[(h-i+a)%a]}if(c<1||i>0){let g=l.reduce((b,k)=>b+k,0)/a,h=l.reduce((b,k)=>Math.max(b,Math.abs(k-g)),0)||1;for(let b=0;b<a;b++)l[b]=(l[b]-g)/h}let u=o.damping!==void 0&&Number.isFinite(o.damping)?o.damping:1,d=(0.004-Math.min(0.0035,0.00004*(90-e)))*u,f=1-Math.min(0.02,Math.max(0.0001,d)),p=0;for(let g=0;g<s.length;g++){let h=(p+1)%a,b=l[p];l[p]=f*0.5*(b+l[h]),s[g]=b*0.5,p=h}return s}var Ve=0.07,ze=0.03,mn=(e)=>e>=88?2800:e>=84?2100:1400;function cn(e,n,t,r,o,s){let a=r+t.time,l=t.velocity===void 0||!Number.isFinite(t.velocity)?1:Math.min(127,Math.max(0,t.velocity))/100,c=e.createGain();c.connect(n);let m,i;if(t.kind==="click"){let u=e.createOscillator();u.type="triangle",u.frequency.value=mn(t.midi),m=u,i=ze,c.gain.setValueAtTime(0,a),c.gain.linearRampToValueAtTime(0.5*l||0.0001,a+0.001),c.gain.exponentialRampToValueAtTime(0.0001,a+ze)}else{let u=e.createBiquadFilter();if(u.type="lowpass",u.frequency.value=o==="guitar"?1800:2500,u.connect(c),o==="guitar"){let d=e.createBufferSource();d.buffer=s(e,t.midi),m=d}else{let d=e.createOscillator();d.type="triangle",d.frequency.value=ie(t.midi),m=d}i=Ve,c.gain.setValueAtTime(1.2*l||0.0001,a),c.gain.exponentialRampToValueAtTime(0.0001,a+Ve),m.connect(u)}if(t.kind==="click")m.connect(c);return m.start(a),m.stop(a+i+0.02),m}var Ie=new WeakMap;function un(e){let n=Ie.get(e);if(n)return n;let t=e.AudioContext;if(!t)return null;let r=new t;return Ie.set(e,r),r}var dn=4,je=[0,1,0.5,0.3,0.15,0.08,0.04],ae=4,pn={guitar:0.15,piano:0.3},Ue=(e,n)=>Math.min(pn[e],Math.max(0.03,n/2)),fn=(e)=>Math.min(2.5,Math.max(0.35,Math.pow(2,(60-e)/24)));function _e(e,n=Math.random){let t=new Map,r=new WeakMap,o=(l,c)=>l+(c-l)*n(),s=(l,c,m)=>{let i=c*ae+m,u=t.get(i);if(!u){let d=ln(c,l.sampleRate,dn,n,{brightness:o(0.55,0.95),pick:o(0.08,0.2),damping:o(0.85,1.15)});u=l.createBuffer(1,d.length,l.sampleRate),u.getChannelData(0).set(d),t.set(i,u)}return u},a=(l)=>{let c=r.get(l);if(!c){let m=new Float32Array(je.length);c=l.createPeriodicWave(m,Float32Array.from(je)),r.set(l,c)}return c};return{reportsStart:!0,play(l,{sound:c,volume:m,onEnd:i,onStart:u}){let d=un(e);if(!d||!l.length)return{stop(){}};let f=d.resume(),p=l.map(()=>({pluck:Math.min(ae-1,Math.floor(n()*ae)),cents:o(-4,4),level:o(0.93,1.07),decay:o(0.9,1.1)}));if(c==="guitar")l.forEach((y,E)=>{if(y.kind==="muted")s(d,y.midi,0);else if(!y.kind)s(d,y.midi,p[E].pluck)});let g=d.createGain();g.gain.value=Number.isFinite(m)?Math.min(1,Math.max(0,m)):0.8,g.connect(d.destination);let h=d.currentTime+0.05,b=l.map((y,E)=>{if(y.kind)return cn(d,g,y,h,c,(L,qe)=>s(L,qe,0));let x=p[E],w=h+y.time,C=w+y.duration,D=Ue(c,y.duration),N=d.createGain();N.connect(g);let K=(y.velocity===void 0||!Number.isFinite(y.velocity)?1:Math.min(127,Math.max(0,y.velocity))/100)*x.level,P;if(c==="guitar"){let L=d.createBufferSource();L.buffer=s(d,y.midi,x.pluck),L.playbackRate.value=Math.pow(2,x.cents/1200),P=L,N.gain.setValueAtTime(K,w),N.gain.setValueAtTime(K,C)}else{let L=d.createOscillator();L.setPeriodicWave(a(d)),L.frequency.value=ie(y.midi),L.detune.value=x.cents,P=L,N.gain.setValueAtTime(0,w),N.gain.linearRampToValueAtTime(0.35*K,w+0.005),N.gain.setTargetAtTime(0,w+0.005,fn(y.midi)*x.decay)}return N.gain.setTargetAtTime(0,Math.max(w+0.006,C),D/4),P.connect(N),P.start(w),P.stop(Math.max(w+0.006,C)+D),P}),k=()=>g.disconnect(),T=!1,S,v=()=>{if(T||!u)return;let y=Number.isFinite(d.outputLatency)?d.outputLatency:0;S=e.setTimeout(()=>{if(!T)u()},Math.max(0,h-d.currentTime+y)*1000)};if(u)Promise.resolve(f).then(v,v);let F=e.setTimeout(()=>i?.(),(an(l)+0.15)*1000),A=l.reduce((y,E)=>Math.max(y,E.time+E.duration+Ue(c,E.duration)),0),R=e.setTimeout(k,(A+0.15)*1000);return{stop(){if(T)return;T=!0,e.clearTimeout(F),e.clearTimeout(S),e.clearTimeout(R);let y=d.currentTime;g.gain.setTargetAtTime(0,y,0.01);for(let E of b)try{E.stop(y+0.05)}catch{}R=e.setTimeout(k,80)},setVolume(y){if(T||!Number.isFinite(y))return;g.gain.setTargetAtTime(Math.min(1,Math.max(0,y)),d.currentTime,0.015)}}}}}var hn=()=>{let e=window.musicNotationOptions;if(!e||typeof e!=="object"||!("play"in e))return;let n=e.play;if(!n||typeof n!=="object"||!("volume"in n))return;let t=n.volume;return typeof t==="number"&&Number.isFinite(t)?t:void 0},gn="pre > code.language-tab, pre > code.language-score",H=new Map,bn=$e();function We(e){for(let[t,{result:r,holder:o}]of H)if(!t.isConnected||!r.el.isConnected){if(r.destroy(),o.remove(),H.delete(t),t.isConnected)t.style.removeProperty("display")}let n=[...e.querySelectorAll(gn)].filter((t)=>{let r=t.parentElement,o=H.get(r);if(!o)return r.dataset.mpRendered!=="pending";if(o.source===(t.textContent??""))return!1;return o.result.destroy(),o.holder.remove(),H.delete(r),!0});if(!n.length)return;for(let t of n)t.parentElement.dataset.mpRendered="pending";bn(e).then((t)=>{let r=q(),o={scriptFile:null,font:r.font,soundFont:r.soundFont},s=e.defaultView;s.musicNotationSoundfontPlayer??=Re(t,o,e,_e(s));for(let a of n){let l=a.parentElement;if(!l.parentElement)continue;let c=a.classList.contains("language-score")?"score":"tab",m=a.textContent??"",i=e.createElement("div");i.className="mn-tab-holder",l.insertAdjacentElement("afterend",i);let u=Pe(c,m,i,{alphaTab:t,assets:o,volume:()=>hn()??ne});H.set(l,{result:u,source:m,holder:i}),u.ready.then(({ok:d})=>{if(l.dataset.mpRendered=d?"done":"error",d&&u.el.isConnected)l.style.display="none"})}}).catch(()=>{for(let t of n)t.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0;let e=()=>{He(document),We(document);let n=!1;new MutationObserver(()=>{if(n)return;n=!0,requestAnimationFrame(()=>{n=!1,We(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e);else e()}})();
1248
+
1249
+ /* Full screen for a tab or a score (#113): the block fills the screen (the browser's full screen,
1250
+ or the window when the browser refuses it), the score in a scroll area of its own at the
1251
+ screen's width, the bar at the bottom. The background is the page's, set by the control. */
1252
+ .mn-tab.mn-fullscreen {
1253
+ position: fixed;
1254
+ inset: 0;
1255
+ z-index: 9999;
1256
+ display: flex;
1257
+ flex-direction: column;
1258
+ box-sizing: border-box;
1259
+ width: auto;
1260
+ max-width: none;
1261
+ height: auto;
1262
+ margin: 0;
1263
+ padding: 12px 16px 8px;
1264
+ overflow: hidden;
1265
+ background: Canvas;
1266
+ }
1267
+
1268
+ .mn-tab.mn-fullscreen .mn-tab-surface {
1269
+ flex: 1 1 auto;
1270
+ min-height: 0;
1271
+ overflow: auto;
1272
+ overscroll-behavior: contain;
1273
+ /* The scroll bar has its room from the start: the score is drawn once, at the width left. */
1274
+ scrollbar-gutter: stable;
1275
+ outline: none;
1276
+ }
1277
+
1278
+ .mn-tab.mn-fullscreen .mn-play.mn-play-static.mn-tab-bar {
1279
+ position: static;
1280
+ flex: none;
1281
+ margin-top: 8px;
1282
+ }
1283
+ `;var gn=Ue,je="music-notation-styles";function _e(e){if(e.getElementById(je))return;let t=e.createElement("style");t.id=je,t.textContent=gn,e.head.appendChild(t)}var bn=(e)=>e.reduce((t,n)=>Math.max(t,n.time+n.duration),0),le=(e)=>440*Math.pow(2,(e-69)/12);function yn(e,t,n,r=Math.random,o={}){let a=new Float32Array(Math.round(t*n)),s=Math.max(2,Math.round(t/le(e))),l=new Float32Array(s);for(let g=0;g<s;g++)l[g]=r()*2-1;let m=Math.min(1,Math.max(0,o.brightness??1));if(m<1){let g=0.2+0.8*m,h=l[s-1];for(let b=0;b<s;b++)l[b]=h+=g*(l[b]-h)}let c=Math.min(0.5,Math.max(0,o.pick??0)),i=Math.round(c*s);if(i>0){let g=Float32Array.from(l);for(let h=0;h<s;h++)l[h]=g[h]-g[(h-i+s)%s]}if(m<1||i>0){let g=l.reduce((b,y)=>b+y,0)/s,h=l.reduce((b,y)=>Math.max(b,Math.abs(y-g)),0)||1;for(let b=0;b<s;b++)l[b]=(l[b]-g)/h}let u=o.damping!==void 0&&Number.isFinite(o.damping)?o.damping:1,d=(0.004-Math.min(0.0035,0.00004*(90-e)))*u,p=1-Math.min(0.02,Math.max(0.0001,d)),f=0;for(let g=0;g<a.length;g++){let h=(f+1)%s,b=l[f];l[f]=p*0.5*(b+l[h]),a[g]=b*0.5,f=h}return a}var We=0.07,qe=0.03,vn=(e)=>e>=88?2800:e>=84?2100:1400;function kn(e,t,n,r,o,a){let s=r+n.time,l=n.velocity===void 0||!Number.isFinite(n.velocity)?1:Math.min(127,Math.max(0,n.velocity))/100,m=e.createGain();m.connect(t);let c,i;if(n.kind==="click"){let u=e.createOscillator();u.type="triangle",u.frequency.value=vn(n.midi),c=u,i=qe,m.gain.setValueAtTime(0,s),m.gain.linearRampToValueAtTime(0.5*l||0.0001,s+0.001),m.gain.exponentialRampToValueAtTime(0.0001,s+qe)}else{let u=e.createBiquadFilter();if(u.type="lowpass",u.frequency.value=o==="guitar"?1800:2500,u.connect(m),o==="guitar"){let d=e.createBufferSource();d.buffer=a(e,n.midi),c=d}else{let d=e.createOscillator();d.type="triangle",d.frequency.value=le(n.midi),c=d}i=We,m.gain.setValueAtTime(1.2*l||0.0001,s),m.gain.exponentialRampToValueAtTime(0.0001,s+We),c.connect(u)}if(n.kind==="click")c.connect(m);return c.start(s),c.stop(s+i+0.02),c}var Ke=new WeakMap;function xn(e){let t=Ke.get(e);if(t)return t;let n=e.AudioContext;if(!n)return null;let r=new n;return Ke.set(e,r),r}var wn=4,Xe=[0,1,0.5,0.3,0.15,0.08,0.04],ie=4,Tn={guitar:0.15,piano:0.3},Ye=(e,t)=>Math.min(Tn[e],Math.max(0.03,t/2)),Mn=(e)=>Math.min(2.5,Math.max(0.35,Math.pow(2,(60-e)/24)));function Je(e,t=Math.random){let n=new Map,r=new WeakMap,o=(l,m)=>l+(m-l)*t(),a=(l,m,c)=>{let i=m*ie+c,u=n.get(i);if(!u){let d=yn(m,l.sampleRate,wn,t,{brightness:o(0.55,0.95),pick:o(0.08,0.2),damping:o(0.85,1.15)});u=l.createBuffer(1,d.length,l.sampleRate),u.getChannelData(0).set(d),n.set(i,u)}return u},s=(l)=>{let m=r.get(l);if(!m){let c=new Float32Array(Xe.length);m=l.createPeriodicWave(c,Float32Array.from(Xe)),r.set(l,m)}return m};return{reportsStart:!0,play(l,{sound:m,volume:c,onEnd:i,onStart:u}){let d=xn(e);if(!d||!l.length)return{stop(){}};let p=d.resume(),f=l.map(()=>({pluck:Math.min(ie-1,Math.floor(t()*ie)),cents:o(-4,4),level:o(0.93,1.07),decay:o(0.9,1.1)}));if(m==="guitar")l.forEach((k,C)=>{if(k.kind==="muted")a(d,k.midi,0);else if(!k.kind)a(d,k.midi,f[C].pluck)});let g=d.createGain();g.gain.value=Number.isFinite(c)?Math.min(1,Math.max(0,c)):0.8,g.connect(d.destination);let h=d.currentTime+0.05,b=l.map((k,C)=>{if(k.kind)return kn(d,g,k,h,m,(F,Qe)=>a(F,Qe,0));let w=f[C],S=h+k.time,A=S+k.duration,D=Ye(m,k.duration),N=d.createGain();N.connect(g);let J=(k.velocity===void 0||!Number.isFinite(k.velocity)?1:Math.min(127,Math.max(0,k.velocity))/100)*w.level,R;if(m==="guitar"){let F=d.createBufferSource();F.buffer=a(d,k.midi,w.pluck),F.playbackRate.value=Math.pow(2,w.cents/1200),R=F,N.gain.setValueAtTime(J,S),N.gain.setValueAtTime(J,A)}else{let F=d.createOscillator();F.setPeriodicWave(s(d)),F.frequency.value=le(k.midi),F.detune.value=w.cents,R=F,N.gain.setValueAtTime(0,S),N.gain.linearRampToValueAtTime(0.35*J,S+0.005),N.gain.setTargetAtTime(0,S+0.005,Mn(k.midi)*w.decay)}return N.gain.setTargetAtTime(0,Math.max(S+0.006,A),D/4),R.connect(N),R.start(S),R.stop(Math.max(S+0.006,A)+D),R}),y=()=>g.disconnect(),v=!1,M,L=()=>{if(v||!u)return;let k=Number.isFinite(d.outputLatency)?d.outputLatency:0;M=e.setTimeout(()=>{if(!v)u()},Math.max(0,h-d.currentTime+k)*1000)};if(u)Promise.resolve(p).then(L,L);let x=e.setTimeout(()=>i?.(),(bn(l)+0.15)*1000),T=l.reduce((k,C)=>Math.max(k,C.time+C.duration+Ye(m,C.duration)),0),O=e.setTimeout(y,(T+0.15)*1000);return{stop(){if(v)return;v=!0,e.clearTimeout(x),e.clearTimeout(M),e.clearTimeout(O);let k=d.currentTime;g.gain.setTargetAtTime(0,k,0.01);for(let C of b)try{C.stop(k+0.05)}catch{}O=e.setTimeout(y,80)},setVolume(k){if(v||!Number.isFinite(k))return;g.gain.setTargetAtTime(Math.min(1,Math.max(0,k)),d.currentTime,0.015)}}}}}var Sn=()=>{let e=window.musicNotationOptions;if(!e||typeof e!=="object"||!("play"in e))return;let t=e.play;if(!t||typeof t!=="object"||!("volume"in t))return;let n=t.volume;return typeof n==="number"&&Number.isFinite(n)?n:void 0},An="pre > code.language-tab, pre > code.language-score",U=new Map,En=ze();function Ze(e){for(let[n,{result:r,holder:o}]of U)if(!n.isConnected||!r.el.isConnected){if(r.destroy(),o.remove(),U.delete(n),n.isConnected)n.style.removeProperty("display")}let t=[...e.querySelectorAll(An)].filter((n)=>{let r=n.parentElement,o=U.get(r);if(!o)return r.dataset.mpRendered!=="pending";if(o.source===(n.textContent??""))return!1;return o.result.destroy(),o.holder.remove(),U.delete(r),!0});if(!t.length)return;for(let n of t)n.parentElement.dataset.mpRendered="pending";En(e).then((n)=>{let r=X(),o=Pe(window.musicNotationOptions),a={scriptFile:null,font:r.font,soundFont:r.soundFont,...o?{instruments:o}:{}},s=e.defaultView;s.musicNotationSoundfontPlayer??=Ve(n,a,e,Je(s));for(let l of t){let m=l.parentElement;if(!m.parentElement)continue;let c=l.classList.contains("language-score")?"score":"tab",i=l.textContent??"",u=e.createElement("div");u.className="mn-tab-holder",m.insertAdjacentElement("afterend",u);let d=Ge(c,i,u,{alphaTab:n,assets:a,volume:()=>Sn()??oe});U.set(m,{result:d,source:i,holder:u}),d.ready.then(({ok:p})=>{if(m.dataset.mpRendered=p?"done":"error",p&&d.el.isConnected)m.style.display="none"})}}).catch(()=>{for(let n of t)n.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0;let e=()=>{_e(document),Ze(document);let t=!1;new MutationObserver(()=>{if(t)return;t=!0,requestAnimationFrame(()=>{t=!1,Ze(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e);else e()}})();
@@ -12,6 +12,9 @@ export declare const ICONS: {
12
12
  readonly click: "M3 5v6M8 5v6M13 5v6";
13
13
  /** A picture: Copy as image (#11). */
14
14
  readonly copy: "M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6.5h.01";
15
+ /** Four corners pointing out: full screen (#113); pointing in: leave it. */
16
+ readonly full: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10";
17
+ readonly exit: "M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5";
15
18
  };
16
19
  export type IconName = keyof typeof ICONS;
17
20
  export declare function icon(doc: Document, name: IconName): SVGElement;
@@ -110,6 +110,10 @@ export declare function pianoTone(midi: number, sampleRate: number, seconds: num
110
110
  * downbeat), 2.1 kHz from 84 (a counted beat), else 1.4 kHz (the other beats).
111
111
  */
112
112
  export declare const clickFrequency: (midi: number) => number;
113
+ type AudioContextClass = typeof AudioContext;
114
+ export declare function contextFor(win: Window & {
115
+ AudioContext?: AudioContextClass;
116
+ }): AudioContext | null;
113
117
  /**
114
118
  * Seconds a note takes to fade after its end (a finger lifting off a string, a piano's damper),
115
119
  * at most half the note (a muted strum stays short).
@@ -124,3 +128,4 @@ export declare const releaseOf: (sound: Sound, duration: number) => number;
124
128
  * for tests.
125
129
  */
126
130
  export declare function lightPlayer(win: Window, random?: () => number): NotePlayer;
131
+ export {};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A sample player without alphaTab (#109): plays the diagrams' notes with the instrument files of
3
+ * a folder (`p025.sf3`…, see `tab/instruments.ts`), read and decoded by the browser itself. A page
4
+ * of chord diagrams then sounds like the tabs' guitar after a download of about 150 KB, where
5
+ * alphaTab alone is about 1 MB of script.
6
+ *
7
+ * Each note plays the regions of its instrument's preset: the sample at the note's pitch, through
8
+ * the region's filter and volume envelope, at the level alphaTab gives it (velocity as a linear
9
+ * gain, the region's attenuation), so both players sound alike. What it can't read or decode
10
+ * plays through `fallback` (the light synthesizer).
11
+ */
12
+ import { type InstrumentSource } from '../tab/instruments.js';
13
+ import { type NotePlayer } from './player.js';
14
+ /**
15
+ * A sample's loop inside its decoded buffer (#128), in seconds. Browsers may decode an Ogg Vorbis
16
+ * sample a little shorter than it was (Chrome drops up to about 230 points at its end), and a loop
17
+ * whose end is past the buffer's end then jumps from the wrong point at each turn: a buzz while
18
+ * the note rings. Such a loop moves back as a whole, so it keeps its length: a held sound repeats
19
+ * about every loop length, so its two ends still meet. Null: no loop (none, or no room for it).
20
+ * The instrument files keep a tail after each compressed sample (`scripts/sounds`), so this only
21
+ * saves older files.
22
+ */
23
+ export declare function loopWithin(loop: {
24
+ start: number;
25
+ end: number;
26
+ } | undefined, duration: number): {
27
+ start: number;
28
+ end: number;
29
+ } | null;
30
+ export interface SampledOptions {
31
+ /**
32
+ * The audio context to play in (a function, called at each play); the window's own by
33
+ * default. An offline context renders the notes instead of playing them.
34
+ */
35
+ context?: () => BaseAudioContext | null;
36
+ }
37
+ /**
38
+ * A NotePlayer that plays `source`'s instrument files. The first note of a sound waits for its
39
+ * file (`onStart` says when the notes start); when it can't be had, the notes play through
40
+ * `fallback`.
41
+ */
42
+ export declare function sampledPlayer(win: Window, source: InstrumentSource, fallback: NotePlayer, options?: SampledOptions): NotePlayer;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Reading a small soundfont in the browser (#109): what the sample player needs to play one
3
+ * instrument file (`p025.sf3`) without alphaTab. A preset's zones are flattened to regions: a key
4
+ * and velocity range, a sample, its pitch, its level, its loop and its volume envelope.
5
+ *
6
+ * The SoundFont 2 rules kept here: an instrument's global zone (the first one, when it names no
7
+ * sample) gives the defaults of its other zones; a preset zone's values are added to the
8
+ * instrument's; a preset zone's own value replaces its global zone's. Modulators, the LFOs, the
9
+ * pitch part of the modulation envelope and panning are left out: a single instrument still
10
+ * sounds like itself.
11
+ */
12
+ /** A sample: where its data is, and how it loops. */
13
+ export interface SoundSample {
14
+ name: string;
15
+ /** Bytes in the sample data when compressed (an Ogg stream), else 16-bit points. */
16
+ start: number;
17
+ end: number;
18
+ /** The loop, in points from the sample's start. */
19
+ loopStart: number;
20
+ loopEnd: number;
21
+ rate: number;
22
+ /** The key the sample was recorded at (60 when unpitched). */
23
+ key: number;
24
+ /** Cents. */
25
+ correction: number;
26
+ compressed: boolean;
27
+ }
28
+ /** One sample on a range of keys and velocities, as it plays. */
29
+ export interface Region {
30
+ loKey: number;
31
+ hiKey: number;
32
+ loVel: number;
33
+ hiVel: number;
34
+ sample: number;
35
+ /** The key that plays the sample at its own pitch. */
36
+ rootKey: number;
37
+ /** Cents added to every note. */
38
+ tune: number;
39
+ /** Cents a key: 100, or 0 for sounds without a pitch. */
40
+ scale: number;
41
+ /** Decibels taken off (below zero: a gain, see `scripts/sounds`). */
42
+ attenuation: number;
43
+ loop: boolean;
44
+ /** The volume envelope: seconds, and the sustain level as decibels taken off. */
45
+ attack: number;
46
+ hold: number;
47
+ decay: number;
48
+ sustain: number;
49
+ release: number;
50
+ /** A low-pass filter's cutoff in hertz; null when it is open and nothing moves it. */
51
+ filter: number | null;
52
+ /** The filter's resonance, in decibels. */
53
+ filterQ: number;
54
+ /**
55
+ * What opens the filter as the note starts and closes it as it rings (the modulation
56
+ * envelope): `amount` cents at its peak, times in seconds, `sustain` the part of the amount
57
+ * that stays (0 to 1).
58
+ */
59
+ filterEnvelope: {
60
+ amount: number;
61
+ attack: number;
62
+ hold: number;
63
+ decay: number;
64
+ sustain: number;
65
+ };
66
+ }
67
+ export interface SoundPreset {
68
+ name: string;
69
+ bank: number;
70
+ program: number;
71
+ regions: Region[];
72
+ }
73
+ export interface Soundfont {
74
+ presets: SoundPreset[];
75
+ samples: SoundSample[];
76
+ /** The sample data. */
77
+ data: Uint8Array;
78
+ }
79
+ /** Reads a SoundFont 2 or 3 file. Throws when it isn't one. */
80
+ export declare function readSoundfont(bytes: Uint8Array): Soundfont;
81
+ /** The regions a note plays: every one whose keys and velocities hold it. */
82
+ export declare function regionsFor(preset: SoundPreset, key: number, velocity: number): Region[];
@@ -0,0 +1,28 @@
1
+ /** A zone: its generators as `[number, amount]`, in order (the instrument or the sample last). */
2
+ export type FixtureZone = [number, number][];
3
+ export interface FixtureSample {
4
+ name: string;
5
+ /** Its 16-bit points, or the bytes of its Ogg stream when `compressed`. */
6
+ data: number[];
7
+ /** The loop, in points from the sample's start. */
8
+ loop?: [number, number];
9
+ rate?: number;
10
+ key?: number;
11
+ correction?: number;
12
+ compressed?: boolean;
13
+ }
14
+ export interface Fixture {
15
+ name?: string;
16
+ bank?: number;
17
+ program?: number;
18
+ /** The preset's zones; a zone names an instrument with generator 41. */
19
+ preset: FixtureZone[];
20
+ /** Each instrument's zones; a zone names a sample with generator 53. */
21
+ instruments: FixtureZone[][];
22
+ samples: FixtureSample[];
23
+ }
24
+ /** A signed amount (an attenuation of -166, a time of -12000) as a generator's 16 bits. */
25
+ export declare const amount: (n: number) => number;
26
+ /** A key or velocity range as a generator's amount. */
27
+ export declare const range: (lo: number, hi: number) => number;
28
+ export declare function soundfontBytes(fixture: Fixture): Uint8Array;
@@ -5426,9 +5426,11 @@ var ICONS = {
5426
5426
  loop: "M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",
5427
5427
  count: "M5.5 14h5L9 2.5H7zM8 11.5l4.5-7",
5428
5428
  click: "M3 5v6M8 5v6M13 5v6",
5429
- copy: "M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6.5h.01"
5429
+ copy: "M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6.5h.01",
5430
+ full: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
5431
+ exit: "M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"
5430
5432
  };
5431
- var STROKED = new Set(["loop", "count", "click", "copy"]);
5433
+ var STROKED = new Set(["loop", "count", "click", "copy", "full", "exit"]);
5432
5434
  function icon(doc, name) {
5433
5435
  const root = svg(doc, "svg", {
5434
5436
  class: `mn-play-icon mn-play-icon-${name}${STROKED.has(name) ? " mn-play-icon-line" : ""}`,
@@ -13309,5 +13311,5 @@ export {
13309
13311
  renderAll
13310
13312
  };
13311
13313
 
13312
- //# debugId=DCB2B3D01E9B461264756E2164756E21
13314
+ //# debugId=18BCC952F6A414DC64756E2164756E21
13313
13315
  //# sourceMappingURL=index.js.map