@dsebastien/music-notation 0.18.1 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/THIRD_PARTY_LICENSES.md +208 -27
- package/dist/blocks/captions.d.ts +10 -0
- package/dist/blocks/renderers.d.ts +11 -0
- package/dist/cli.js +26 -46
- package/dist/export/image.d.ts +83 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3944 -3000
- package/dist/index.js.map +24 -19
- package/dist/music-notation.css +52 -2
- package/dist/music-notation.publish.min.js +88 -35
- package/dist/music-notation.tab.min.js +59 -9
- package/dist/playback/bar-parts.d.ts +8 -0
- package/dist/playback/controls.d.ts +5 -0
- package/dist/playback/copy-image.d.ts +21 -0
- package/dist/publish/auto.d.ts +5 -0
- package/dist/publish/index.js +3907 -3023
- package/dist/publish/index.js.map +24 -19
- package/dist/render/dom.d.ts +8 -0
- package/dist/render/root-mark.d.ts +29 -0
- package/dist/tab/index.d.ts +1 -1
- package/dist/tab/index.js +43 -6
- package/dist/tab/index.js.map +5 -5
- package/dist/theory/formula.d.ts +11 -0
- package/dist/voicings/index.js +1022 -756
- package/dist/voicings/index.js.map +8 -6
- package/package.json +11 -11
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
/*! @dsebastien/music-notation 0.
|
|
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 ce=(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 m=s[s.length-1];if(m===void 0){let c=[28,40,52].map((i)=>i-i%12+l);s.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;s.push(c)}}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 ct(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),m=l?l[1].toLowerCase().replace(/[ .-]/g,""):"",c=rt.get(m);if(l&&c&&(l[2].match(/[^\s|:]/g)?.length??0)>=4)a={drum:c,name:m,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 mt(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 me(e,n=null){return mt(e).flatMap((t,r)=>{let o=t.map((c)=>c.string.name);if(t.length<3&&o.some((c)=>c===null))return[];let s=t.map((c)=>c.string.body),a=t[0].string.offset,l=new Set;if(r===0&&n!==null)for(let[c,i]of ft(n))for(let u=Math.max(c,a);u<=i;u++)l.add(u-a);let m=t.some((c)=>!c.string.barred);return[{kind:"strings",names:o,lines:s,texts:ke(t),muted:l,openStart:m}]})}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 me(e,n);let t=[],r=[];for(let o of[...e,null])if(o?.string)r.push(o);else{if(r.length)t.push(...me(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=ct(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((m)=>m.length)),r=e.map((m)=>m.padEnd(t,"-")),o=[],s=[],a=!1,l=0;for(let m=0;m<t;m++){if(r.every((d)=>d[m]==="|"||d[m]===":")){if(a)o.push({beats:s,start:l,end:m});s=[],a=!1,l=m+1;continue}if(r.some((d)=>d[m]!==" "))a=!0;let{beat:c,skip:i,at:u}=n(r,m);if(c.length)s.push({notes:c,col:u??m});m+=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 m=pe(e[a],e[a+1])?2:1,c=Number(e.slice(a,a+m));for(let i=0;i<m;i++)r.add(a+i);if(a+=m,l&&e[a]===")")a++;return{fret:c,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 m=[],c=e[s-1],i=s+a;if(c==="<"&&e[i]===">")m.push("nh"),i++;else if((c==="/"||c==="\\")&&!/[\d)>]/.test(e[s-2]??"-"))m.push(c==="/"?"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)))}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=G(e[i+1])||e[i+1]==="("&&G(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)t.set(s,m);s+=a}return{frets:n,effects:t}}var bt=(e,n,t=[])=>(r,o)=>{let s=[],a=new Set,l=o,m=!1,c=(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)m=!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)=>c(u,o)),m)r.forEach((i,u)=>a.has(u)||c(u,o+1));return{beat:s,skip:m?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,m)=>J.names[a+m]===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((m)=>m.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 F={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 m=[],c=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||m.length&&d*(a/n)<=m.at(-1))return null;c=Math.max(c,f),m.push(d*(a/n))}if(!s&&m.some((i,u)=>!At.has((m[u+1]??a)-i)))return null;return Mt(e,m)?{at:m,error:c}:null}function ee(e,n,t,r=F){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 m=o.map((c)=>St(e,l,c,s,a,r.length)).filter((c)=>c!==null);if(m.length)return m.reduce((c,i)=>i.error<c.error?i:c).at}return null}function z(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]:[],c=(a%2?[1]:a%o?[2,1]:[...l,o,2,1]).find((i)=>i<=t-a);r.push({beat:-1,sixteenths:c}),a+=c}return r}function Et(e,n=F,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((c,i)=>a*(i<r.length?Math.max(1,Math.round(r[i]/s)):1)),m=l.reduce((c,i)=>c+i,0);if(a===2)for(let c of t){if(m<=n.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>n.length)continue;return[...l.map((c,i)=>({beat:i,sixteenths:c})),...z(m,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,...z(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:[...z(0,t,r-d),...u]}let m=l[0],c=m===0||e.pickup?[]:e.part==="end"?z(0,t,m):[{beat:-1,sixteenths:m}];return l.forEach((i,u)=>c.push({beat:u,sixteenths:(l[u+1]??r)-i})),c}var Ft=(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:Ft(n),texts:t,openStart:r&&n[0]?.start===0,openEnd:n.at(-1)?.end===o}}function Ot(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 F;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 F;let a=[],l=0,m=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))m++}let c=we(a);if(c.count*3<t.length*2)return F;if(c.value===3)return ge;if(c.value===6)return l>m?ge:wt;return c.value===12?Tt:F}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,m=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=m?.bars[0],b=h?f.width+h.end-h.start-m.pad:0;if(h&&(s.openEnd||t(h.end-h.start)&&(m.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 c=o??(r.length>l?r.at(-1):null);if(s.texts.length&&c){let i=s.texts.join(" / ");c.text=c.text?`${c.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,m=s*l;if(a<=l||t.width-t.pad<m*1.5)return[t];let c=Math.floor((r.at(-1)-t.pad)/m)+1,i=Array.from({length:c},()=>[]);for(let u of t.beats){let d=Math.min(c-1,Math.max(0,Math.floor((u.col-t.pad)/m)));while(d<c-1&&u.col>=t.pad+(d+1)*m)d++;while(d>0&&u.col<t.pad+d*m)d--;i[d].push({notes:u.notes,col:u.col-d*m})}return i.map((u,d)=>({beats:u,width:t.pad+m,pad:t.pad,part:"whole",pickup:!1,text:d===c-1?t.text:null}))})}var $t=(e)=>`"${e.replace(/[\\"]/g,(n)=>`\\${n}`)}"`,I=(e,n)=>n.length?`${e}{${n.join(" ")}}`:e;function Bt(e,n){if(!e.length)return I("r",n);if(e.length===1)return I(e[0].tex,[...e[0].effects,...n]);return I(`(${e.map((t)=>I(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 m=[];if(!o.length)for(let u of n===F?[{duration:1,dotted:!1}]:he(n.length))m.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)=>m.push({notes:p[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 f=u.dotted?["d"]:[];if(a&&d===c)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=Ot(s),l=Dt(s,a),
|
|
4
|
-
`);let i=r?.join(" ")===j[6].join(" ");return[...r&&!i?[`\\tuning (${r.map((d)=>
|
|
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"},Vt=new Set(["loop","count","click"]);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
|
|
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 Fe(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 Oe(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&&Oe(n,t)||(/^rgba?\(/.test(t)?t:"rgba(0, 0, 0, 1)"),o=t&&Oe(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),m=null,c=null,i=()=>(m??=new Promise((v)=>{if(n.playerReady.on(()=>v(!0)),c=()=>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}),m),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 O=Number(v.state)===Number(t.synth.PlayerState.Playing);d.replaceChildren(te(e,O?"pause":"play")),d.title=O?"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)=>{c?.(),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:c,label:i,what:u})=>{let d=M(e,"button","mn-tab-view",i);d.type="button",d.dataset.staves=c;let f=c!==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(c===s)return;s=c,m(),t(c)}),o.appendChild(d),d}),m=()=>{for(let c of l){let i=c.dataset.staves===s;c.classList.toggle("mn-on",i),c.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 m(),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,m=()=>{},c=!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),O={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,enableUserInteraction:!0,scrollMode:k.ScrollMode.Off}},A=new k.AlphaTabApi(T,O);if(a=A,c){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}))),Fe(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||c)return;if(r.player!==!1){if(y=Zt(o,A,k,S,r.volume),m=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(c||!w)return;w.tracks.flatMap((D)=>D.staves).forEach((D,N)=>Object.assign(D,R[N])),Fe(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)}`)}if(c)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(!c)f(p instanceof Error?p.message:String(p))});return{el:s,ready:d,get api(){return a},speed:()=>l(),destroy(){c=!0,m();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(),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,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,m.playOneTimeMidiFile(c);let p=!1;queueMicrotask(()=>{if(!p)a?.()});let g=setTimeout(()=>s?.(),(f+0.2)*1000);return{stop(){p=!0,clearTimeout(g),m.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 c=se(t);o=new e.AlphaTabApi(s,{core:{useWorkers:Boolean(n.scriptFile),...n.scriptFile?{scriptFile:n.scriptFile}:{},smuflFontSources:c.map([[e.FontFileFormat.Woff2,n.font]])},player:{playerMode:e.PlayerMode.EnabledSynthesizer,...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(c.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},m=rn(e,()=>o);return{reportsStart:!0,play(c,i){let u=null,d=!1,f=i.volume;return l().then((p)=>{if(d)return;try{if(p){u=m.play(c,{...i,volume:f});return}}catch{}if(!r)return;if(u=r.play(c,{...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 m=(c)=>{if(l&&r.define===void 0)r.define=l;if(c===null&&r.alphaTab){o(r.alphaTab);return}n=null,a.remove(),s(Error(c??"alphaTab's script didn't define alphaTab"))};a.onload=()=>m(null),a.onerror=()=>m("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.19.1 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 F={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=F){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=F,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 Ft=(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:Ft(n),texts:t,openStart:r&&n[0]?.start===0,openEnd:n.at(-1)?.end===o}}function Ot(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 F;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 F;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 F;if(m.value===3)return ge;if(m.value===6)return l>c?ge:wt;return m.value===12?Tt:F}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===F?[{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=Ot(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===F?[]:[`\\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 Fe(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 Oe(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&&Oe(n,t)||(/^rgba?\(/.test(t)?t:"rgba(0, 0, 0, 1)"),o=t&&Oe(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 O=Number(v.state)===Number(t.synth.PlayerState.Playing);d.replaceChildren(te(e,O?"pause":"play")),d.title=O?"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),O={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,O);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}))),Fe(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])),Fe(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,...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. */
|
|
7
7
|
.mn-block,
|
|
8
8
|
.mn-svg,
|
|
9
9
|
.mn-chart {
|
|
10
10
|
--mn-fg: var(--text-normal, currentColor);
|
|
11
11
|
--mn-muted: var(--text-muted, #8a8a8a);
|
|
12
12
|
--mn-faint: var(--background-modifier-border, #d0d0d0);
|
|
13
|
-
|
|
13
|
+
/* The fallbacks (pages without Obsidian's variables) pass WCAG on white and on a dark page
|
|
14
|
+
(#14): 3:1 for marks against the page, 4.5:1 for the white labels on them. */
|
|
15
|
+
--mn-accent: var(--interactive-accent, #8250df);
|
|
14
16
|
--mn-bg: var(--background-primary, #fff);
|
|
15
17
|
--mn-on-accent: var(--text-on-accent, #fff);
|
|
16
18
|
/* Dark enough for white labels in light and dark themes. */
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
/* Marks of the pick layer (Music Practice #73): right and wrong, dark enough for a white check
|
|
31
33
|
or cross in light and dark themes; the shape tells them apart too. */
|
|
32
34
|
--mn-right: #15803d;
|
|
33
|
-
--mn-wrong: #
|
|
35
|
+
--mn-wrong: #dc2626;
|
|
34
36
|
font-family: var(--font-interface, system-ui, sans-serif);
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -299,6 +301,16 @@
|
|
|
299
301
|
opacity: 0.85;
|
|
300
302
|
}
|
|
301
303
|
|
|
304
|
+
/* What Copy as image says (#11): "Copied", or what to do when the browser refuses. */
|
|
305
|
+
.mn-play-said {
|
|
306
|
+
font-size: 0.85em;
|
|
307
|
+
opacity: 0.85;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.mn-play-said:empty {
|
|
311
|
+
display: none;
|
|
312
|
+
}
|
|
313
|
+
|
|
302
314
|
/* The selected diagram's name on the bar of a row. */
|
|
303
315
|
.mn-play-name {
|
|
304
316
|
max-width: 16ch;
|
|
@@ -616,6 +628,28 @@
|
|
|
616
628
|
display: none;
|
|
617
629
|
}
|
|
618
630
|
|
|
631
|
+
/* The formula (#52): under the diagram, as the fingering; both are lines of one caption. A scale's
|
|
632
|
+
formula may be as wide as its fretboard. */
|
|
633
|
+
.mn-block .mn-formula,
|
|
634
|
+
.mn-block .mn-captions {
|
|
635
|
+
max-width: 24em;
|
|
636
|
+
margin: 0;
|
|
637
|
+
font-size: 0.85em;
|
|
638
|
+
line-height: 1.4;
|
|
639
|
+
color: var(--text-muted, currentColor);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
.mn-block .mn-captions > .mn-fingering,
|
|
643
|
+
.mn-block .mn-captions > .mn-formula {
|
|
644
|
+
display: block;
|
|
645
|
+
max-width: none;
|
|
646
|
+
font-size: 1em;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
.mn-block .mn-captions > .mn-formula {
|
|
650
|
+
margin-top: 0.25em;
|
|
651
|
+
}
|
|
652
|
+
|
|
619
653
|
.mn-block .mn-fingering {
|
|
620
654
|
max-width: 16em;
|
|
621
655
|
margin: 0;
|
|
@@ -1084,6 +1118,22 @@
|
|
|
1084
1118
|
fill: var(--mn-on-playing);
|
|
1085
1119
|
}
|
|
1086
1120
|
|
|
1121
|
+
/* The root as a shape (#14, \`root-mark: shape\`): a small square on a root key, in the key label's
|
|
1122
|
+
color; dark on a pale (passing) white root key and while the key plays. */
|
|
1123
|
+
.mn-svg .mn-root-mark {
|
|
1124
|
+
fill: var(--mn-on-accent);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
.mn-svg .mn-key-white.mn-passing.mn-root + .mn-key-label + .mn-root-mark,
|
|
1128
|
+
.mn-svg .mn-key-white.mn-passing.mn-root + .mn-root-mark {
|
|
1129
|
+
fill: var(--mn-key-black);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
.mn-playable .mn-svg [data-midi].mn-playing + .mn-key-label + .mn-root-mark,
|
|
1133
|
+
.mn-playable .mn-svg [data-midi].mn-playing + .mn-root-mark {
|
|
1134
|
+
fill: var(--mn-on-playing);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1087
1137
|
/* A fretboard exercise (#47): the run's tab under the diagram, as wide as the block. */
|
|
1088
1138
|
.mn-block .mn-exercise-block {
|
|
1089
1139
|
display: flex;
|
|
@@ -1195,4 +1245,4 @@
|
|
|
1195
1245
|
align-items: center;
|
|
1196
1246
|
gap: 2px 6px;
|
|
1197
1247
|
}
|
|
1198
|
-
`;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
|
|
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 O=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(O),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()}})();
|
|
@@ -10,6 +10,8 @@ export declare const ICONS: {
|
|
|
10
10
|
readonly count: "M5.5 14h5L9 2.5H7zM8 11.5l4.5-7";
|
|
11
11
|
/** Beats, for the click. */
|
|
12
12
|
readonly click: "M3 5v6M8 5v6M13 5v6";
|
|
13
|
+
/** A picture: Copy as image (#11). */
|
|
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";
|
|
13
15
|
};
|
|
14
16
|
export type IconName = keyof typeof ICONS;
|
|
15
17
|
export declare function icon(doc: Document, name: IconName): SVGElement;
|
|
@@ -19,6 +21,12 @@ export declare function icon(doc: Document, name: IconName): SVGElement;
|
|
|
19
21
|
* opens its source.
|
|
20
22
|
*/
|
|
21
23
|
export declare function playBar(doc: Document, cls: string, label: string): HTMLElement;
|
|
24
|
+
/**
|
|
25
|
+
* Where the bar goes: below the element of the block that holds its diagrams (a row, a figure
|
|
26
|
+
* with its caption), inside the block (never between a page's source `<pre>` and the block); in
|
|
27
|
+
* a fretboard exercise, between the fretboard and its tab.
|
|
28
|
+
*/
|
|
29
|
+
export declare function placeBar(block: Element, last: Element, bar: HTMLElement): void;
|
|
22
30
|
/** A button that shows an icon, named for screen readers and in its tooltip. */
|
|
23
31
|
export declare function iconButton(doc: Document, cls: string, label: string, name: IconName): HTMLButtonElement;
|
|
24
32
|
/** A button that stays pressed (loop, count-in, click); `set` hears each change. */
|
|
@@ -37,6 +37,11 @@ export interface PlayOptions {
|
|
|
37
37
|
* throws leaves the bar as it is.
|
|
38
38
|
*/
|
|
39
39
|
timedBar?: (bar: TimedBar) => void | (() => void);
|
|
40
|
+
/**
|
|
41
|
+
* `false` leaves Copy as image out of the bars (#11). On by default. `renderBlock` sets it from
|
|
42
|
+
* its own `copy` option, which also works without playback.
|
|
43
|
+
*/
|
|
44
|
+
copy?: boolean;
|
|
40
45
|
}
|
|
41
46
|
/** A bar that plays a piece in time, as an app sees it (`PlayOptions.timedBar`, #77). */
|
|
42
47
|
export interface TimedBar {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What the button says after a click. */
|
|
2
|
+
export declare const COPY_SAID: {
|
|
3
|
+
readonly copied: "Copied";
|
|
4
|
+
readonly refused: "Allow clipboard access for this page, then try again.";
|
|
5
|
+
readonly unsupported: "This browser can't copy images: use a recent Chrome, Edge, Safari or Firefox.";
|
|
6
|
+
readonly failed: "The image couldn't be made.";
|
|
7
|
+
};
|
|
8
|
+
/** The image of a block bar's diagram: its captioned figure when it has one, else its wrapper. */
|
|
9
|
+
export declare function diagramImage(wrap: HTMLElement): HTMLElement;
|
|
10
|
+
/**
|
|
11
|
+
* The button and its message (a polite live region). `target(whole)` is what to copy, `whole`
|
|
12
|
+
* when Shift is held; nothing is copied when it returns null.
|
|
13
|
+
*/
|
|
14
|
+
export declare function copyImageButton(doc: Document, win: Window, target: (whole: boolean) => Element | null, make?: (el: Element) => Promise<Blob>): [HTMLButtonElement, HTMLElement];
|
|
15
|
+
/**
|
|
16
|
+
* Copy as image without playback (#11): each block of `el` that draws (a drawing without a pick
|
|
17
|
+
* layer, a progression or a chart) and has no bar yet gets a small bar of its own, in the place
|
|
18
|
+
* and look of a play bar, with only the button. No diagram is selected without playback, so it
|
|
19
|
+
* copies the whole block, with or without Shift. Returns a function that frees it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function attachCopy(el: HTMLElement, make?: (el: Element) => Promise<Blob>): () => void;
|
package/dist/publish/auto.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import * as api from '../index.js';
|
|
8
8
|
import { lookupGuitarVoicing } from '../voicings/index.js';
|
|
9
9
|
import { type Naming } from '../theory/naming.js';
|
|
10
|
+
import { type RootMark } from '../render/root-mark.js';
|
|
10
11
|
import type { NotePlayer } from '../playback/player.js';
|
|
11
12
|
declare global {
|
|
12
13
|
interface Window {
|
|
@@ -20,5 +21,9 @@ declare global {
|
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
/** Copy as image on the site (#11): on unless the page options say `copy: false`. */
|
|
25
|
+
export declare function pageCopy(options: unknown): boolean;
|
|
23
26
|
/** The site's note names (#12): `naming` of the page options when valid, else letters (undefined). */
|
|
24
27
|
export declare function pageNaming(options: unknown): Naming | undefined;
|
|
28
|
+
/** The site's root mark (#14): `rootMark` of the page options when valid, else color (undefined). */
|
|
29
|
+
export declare function pageRootMark(options: unknown): RootMark | undefined;
|