@dsebastien/music-notation 0.19.2 → 0.21.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.
- package/README.md +1 -1
- package/dist/blocks/renderers.d.ts +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +866 -9
- package/dist/index.js.map +16 -12
- package/dist/music-notation.css +85 -1
- package/dist/music-notation.publish.min.js +120 -36
- package/dist/music-notation.tab.min.js +92 -8
- package/dist/playback/bar-parts.d.ts +3 -0
- package/dist/playback/controls.d.ts +5 -0
- package/dist/playback/copy-image.d.ts +6 -2
- package/dist/playback/full-screen.d.ts +52 -0
- package/dist/playback/player.d.ts +5 -0
- package/dist/playback/sampled.d.ts +42 -0
- package/dist/playback/soundfont.d.ts +82 -0
- package/dist/playback/soundfont.fixture.d.ts +28 -0
- package/dist/publish/index.js +266 -9
- package/dist/publish/index.js.map +14 -13
- package/dist/tab/auto.d.ts +11 -1
- package/dist/tab/index.d.ts +14 -0
- package/dist/tab/index.js +528 -17
- package/dist/tab/index.js.map +8 -5
- package/dist/tab/instruments.d.ts +63 -0
- package/dist/tab/score-fit.d.ts +18 -0
- package/package.json +6 -2
|
@@ -1,9 +1,9 @@
|
|
|
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 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
|
|
4
|
-
`);let i=r?.join(" ")===
|
|
5
|
-
`)}var
|
|
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.21.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
|
|
2
|
+
(()=>{var ot=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],st=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],ue={C:0,D:2,E:4,F:5,G:7,A:9,B:11};function z(e){let n=/^([A-Ga-g])([#♯b♭]*)$/.exec(e.trim());if(!n)return null;let t=ue[n[1].toUpperCase()];for(let r of n[2])t+=r==="#"||r==="♯"?1:-1;return(t%12+12)%12}function J(e){let n=/^([A-Ga-g][#♯b♭]*)(-?\d)$/.exec(e.trim());if(!n)return null;let t=z(n[1]);if(t===null)return null;let r=ue[n[1][0].toUpperCase()],o=Math.round((t-r)/12);return(Number(n[2])+1)*12+t-o*12}var at=(e,n=!1)=>(n?st:ot)[((Math.round(e)||0)%12+12)%12];var de=(e,n=!1)=>`${at(e,n)}${Math.floor(e/12)-1}`;var it="http://www.w3.org/2000/svg",lt=(e,n)=>{for(let[t,r]of Object.entries(n))if(r!==void 0)e.setAttribute(t,String(r))};function Q(e,n,t={},r=[]){let o=e.createElementNS(it,n);lt(o,t);for(let s of r)if(s)o.appendChild(s);return o}function C(e,n,t,r){let o=e.createElement(n);if(t)o.className=t;if(r!==void 0)o.textContent=r;return o}var On=`mn-name-${Math.random().toString(36).slice(2,8)}-`;var ct=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 W(e){let n=e.trim(),t=ct.get(n.toLowerCase().replace(/\s*\(.*\)$/,""));if(t)return W(t);let r=n.split(/[\s,]+/).filter(Boolean);if(r.length>1&&r.every((a)=>J(a)!==null))return r.map((a)=>J(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=z(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 mt=/^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/,ut=/^[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/,dt=/^\s*([A-Za-z][A-Za-z0-9. -]{0,14}?)\s*[|:]([-xXoOgfdb#@*+|:\s]*)$/,ft=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 pt(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 ht=(e)=>e==="X"||e==="O"?["ac"]:e==="g"?["g"]:[],gt=/[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/,bt=/^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;function yt(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 gt.test(r)||bt.test(r)||/^\s/.test(t)&&!r.includes("--")?{line:e.slice(0,n+1),text:r}:{line:e,text:null}}function vt(e){let{line:n,text:t}=yt(e.trimEnd()),r=null,o=mt.exec(n),s=n.slice(o[0].length);if(ut.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=dt.exec(n),c=l?l[1].toLowerCase().replace(/[ .-]/g,""):"",m=ft.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 Te=(e)=>[...new Set(e.map((n)=>n.text).filter((n)=>n!==null))];function xt(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 kt(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 wt=/^[\sPpMm.\-_|=~]*$/,Tt=/P\.?M/i;function Mt(e){if(!wt.test(e)||!Tt.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 fe(e,n=null){return xt(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 Mt(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:Te(t),muted:l,openStart:c}]})}function pe(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 kt(e).map((o)=>({kind:"drums",drums:o.map((s)=>s.drum.drum),lines:o.map((s)=>s.drum.body),texts:Te(o)}));if(e.every((o)=>o.string))return fe(e,n);let t=[],r=[];for(let o of[...e,null])if(o?.string)r.push(o);else{if(r.length)t.push(...fe(r,t.length?null:n));r=[]}return t}function St(e){let n=[],t=[],r=null,o=null;for(let s of e.split(/\r?\n/)){let a=vt(s);if(a){if(!t.length)r=o;t.push(a)}else n.push(...pe(t,r)),t=[];o=s}return n.push(...pe(t,r)),n}function he(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 I=(e)=>e!==void 0&&e>="0"&&e<="9",ge=(e,n)=>(e==="1"||e==="2")&&I(n)&&Number(e+n)<=24;function At(e){let n=new Map,t=new Map,r=new Set,o=(s)=>{let a=s,l=e[a]==="(";if(l)a++;if(!I(e[a]))return{fret:null,next:s};let c=ge(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(!I(e[s])||r.has(s)){s++;continue}let a=ge(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 y=h.fret===null?0:(h.fret-l)*2;g.push(Math.min(g[1],Math.max(0,y)))}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=I(e[i+1])||e[i+1]==="("&&I(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 Et=(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}},X={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]},be=[64,59,55,50,45,40,35,30],ee={names:["E","A","D","G","B","E"],midis:[40,45,50,55,59,64]},Ct=["E A D G","B E A D G"],te=(e)=>e[0].toUpperCase()+e.slice(1);function ne(e){let n=e.length;if(e.every((t)=>t!==null&&/^\d$/.test(t)))return e.every((t)=>be[Number(t)-1])?e.map((t)=>be[Number(t)-1]):null;if(e.every((t)=>t!==null&&/^[A-Ga-g]/.test(t))){let t=[...e].reverse(),r=t.map(te).join(" ");if(Ct.includes(r))return W(r).map((a)=>a-12).reverse();let o=[...ee.names.keys()].filter((a)=>t.every((l,c)=>ee.names[a+c]===te(l)));if(o.length){let a=o.length>1&&t[0]==="e"?o.at(-1):o[0];return ee.midis.slice(a,a+n).reverse()}if(n===1){let a=z(te(e[0]));return a===null?null:[48+(a-48+120)%12]}let s=W(r);if(s)return s.reverse()}return X[n]??null}function Lt(e){let n=[...X[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 Ft(e){if(e.length===1){let{tuning:r,string:o}=Lt(e[0]);return{tuning:r,strings:[o]}}let n=X[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 Nt=(e)=>(n,t)=>{let r=[];return n.forEach((o,s)=>{let a=o[t];if(!/[xXoOgfdb#@*+]/.test(a))return;let l=pt(e[s],a);if(!r.some((c)=>c.tex===l))r.push({tex:l,effects:ht(a)})}),{beat:r,skip:0}},Me=[[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 ye(e){let n=[];for(let t=e;t>0;){let[r,o,s]=Me.find(([a])=>a<=t);n.push({duration:o,dotted:s}),t-=r}return n}var H={ts:[4,4],length:16,beat:4,grids:[1,2,4,8,16]},ve={ts:[3,4],length:12,beat:4,grids:[1,3,6,12]},Ot={ts:[6,8],length:12,beat:6,grids:[1,2,6,12]},Pt={ts:[12,8],length:24,beat:6,grids:[1,2,4,12,24]};function Dt(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 Rt=new Set(Me.map(([e])=>e));function Ht(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)=>!Rt.has((c[u+1]??a)-i)))return null;return Dt(e,c)?{at:c,error:m}:null}function re(e,n,t,r=H){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)=>Ht(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 K(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 $t(e,n=H,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})),...K(c,n)]}return e.map((a,l)=>({beat:l,sixteenths:1}))}var Bt=new Set(["h","sl"]),zt=(e)=>e.flatMap((n,t)=>n.notes.some((r)=>r.effects.some((o)=>Bt.has(o)))?[t]:[]);function It(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=re([...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,...K(u,t)]}}let l=re(a,o,e.pad,t);if(!l){let i=$t(e.beats.map((f)=>f.col),t,zt(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:[...K(0,t,r-d),...u]}let c=l[0],m=c===0||e.pickup?[]:e.part==="end"?K(0,t,c):[{beat:-1,sixteenths:c}];return l.forEach((i,u)=>m.push({beat:u,sixteenths:(l[u+1]??r)-i})),m}var Gt=(e)=>e.reduce((n,t)=>t.beats.length?Math.min(n,t.beats[0].col-t.start):n,3);function xe(e,n,t,r){let o=Math.max(...e.map((s)=>s.length));return{bars:n,pad:Gt(n),texts:t,openStart:r&&n[0]?.start===0,openEnd:n.at(-1)?.end===o}}function Vt(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 Se(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 Ut(e,n){if(n===null)return H;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 H;let a=[],l=0,c=0;for(let{bar:i,pad:u}of t){let d=i.beats.map((y)=>(y.col-i.start-u)/s);if(d.some((y)=>Math.abs(y-Math.round(y))*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((y,v)=>v.notes.reduce((k,S)=>Math.max(k,S.string??0),y),0),h=f.filter((y,v)=>i.beats[v].notes.some((k)=>k.string===g));for(let y of[f,h.length<f.length?h:[]])if(y.some((v)=>v!==0&&v%2===0)&&y.every((v)=>v%2===0))l++;else if(y.includes(3)&&y.every((v)=>v%3===0))c++}let m=Se(a);if(m.count*3<t.length*2)return H;if(m.value===3)return ve;if(m.value===6)return l>c?ve:Ot;return m.value===12?Pt:H}function jt(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((y)=>({notes:y.notes,col:y.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],y=h?f.width+h.end-h.start-c.pad:0;if(h&&(s.openEnd||t(h.end-h.start)&&(c.openStart||y<=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 _t(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(re(r,t.width,t.pad,n))return[t];let o=r.slice(1).map((u,d)=>u-r[d]),s=Se(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 Wt=(e)=>`"${e.replace(/[\\"]/g,(n)=>`\\${n}`)}"`,q=(e,n)=>n.length?`${e}{${n.join(" ")}}`:e;function qt(e,n){if(!e.length)return q("r",n);if(e.length===1)return q(e[0].tex,[...e[0].effects,...n]);return q(`(${e.map((t)=>q(t.tex,t.effects)).join(" ")})`,n)}var ke=new Set(["h","sl","sou","sod"]);function Kt(e,n){if(n===1)return[e];let t=[e.map((r)=>({...r,effects:r.effects.filter((o)=>!ke.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&&ke.has(s))})));return t}function we(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===H?[{duration:1,dotted:!1}]:ye(n.length))c.push({notes:[],...u});for(let{beat:u,sixteenths:d}of s){let f=ye(d),p=Kt(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 ${Wt(a)}`);let p=u.duration===t?"":`:${u.duration} `;return t=u.duration,p+qt(u.notes,f)}).join(" ");return l?`\\ac ${i}`:i}).join(` |
|
|
3
|
+
`)}function Ae(e){let n=St(e),t=n[0];if(!t)return null;let r=t.kind==="strings"?ne(t.names):null,o=r?Ft(r):null;if(o)r=o.tuning;let s=[];if(t.kind==="drums"){for(let d of n)if(d.kind==="drums")s.push(xe(d.lines,he(d.lines,Nt(d.drums)),d.texts,!1))}else{let d=JSON.stringify(ne(t.names)),f=o?.strings??[];for(let p of n){if(p.kind!=="strings"||JSON.stringify(ne(p.names))!==d)continue;let g=Et(p.lines.map(At),p.muted,f);s.push(xe(p.lines,he(p.lines,g),p.texts,p.openStart))}}let a=Vt(s),l=Ut(s,a),c=_t(jt(s,a),l).map((d)=>({beats:d.beats.map((f)=>f.notes),rhythm:It(d,a??0,l),text:d.text,pickup:d.pickup}));if(!c.length)return null;let m=l===H?[]:[`\\ts ${l.ts.join(" ")}`];if(t.kind==="drums")return["\\instrument percussion","\\articulation defaults",...m,we(c,l)].join(`
|
|
4
|
+
`);let i=r?.join(" ")===X[6].join(" ");return[...r&&!i?[`\\tuning (${r.map((d)=>de(d)).join(" ")})`]:[],...m,we(c,l)].join(`
|
|
5
|
+
`)}var Xt={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"},Yt=new Set(["loop","count","click","copy","full","exit"]);function G(e,n){let t=Q(e,"svg",{class:`mn-play-icon mn-play-icon-${n}${Yt.has(n)?" mn-play-icon-line":""}`,viewBox:"0 0 16 16",width:12,height:12,"aria-hidden":"true"});return t.appendChild(Q(e,"path",{d:Xt[n]})),t}function Ee(e,n,t){let r=C(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 B(e,n,t,r){let o=C(e,"button",n);return o.type="button",o.appendChild(G(e,r)),o.title=t,o.setAttribute("aria-label",t),o}function Y(e,n,t,r,o,s){let a=B(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 Ce(e,n,t,r,o,s,a,l){let c=C(e,"label","mn-play-field"),m=C(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=C(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 oe=0.8;function Le(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)):oe}var Zt=Symbol.for("@dsebastien/music-notation/volume"),Jt=globalThis,Fe=Jt[Zt]??=new Set,Ne=(e)=>typeof e==="number"&&Number.isFinite(e)?Math.min(1,Math.max(0,e)):null;function Oe(e,n,t){let r=Ne(t),o=()=>{let s=Ne(e());if(s===null||s===r)return;r=s;for(let a of n())a.setVolume?.(s)};return Fe.add(o),()=>{Fe.delete(o)}}var Qt=new Set(["PageUp","PageDown","Home","End","ArrowUp","ArrowDown"]);function en(e){let n=e.ownerDocument.defaultView;if(!n)return"";for(let t=e.parentElement;t;t=t.parentElement){let r=n.getComputedStyle(t).backgroundColor;if(r&&r!=="transparent"&&!/^rgba\(.*,\s*0\)$/.test(r))return r}return""}function Pe(e,n,t,r=()=>{},o={}){let s=o.redraws!==!1,a=e.defaultView,l=B(e,"mn-tab-full","Full screen","full");l.classList.add("mn-play-full");let c=!1,m=!1,i=!1,u=null,d=null,f=!1,p="",g=(b)=>{if(i===b)return;i=b,r(b)},h=()=>{n.classList.toggle("mn-fullscreen",c),l.classList.toggle("mn-on",c),l.setAttribute("aria-pressed",String(c)),l.title=c?"Exit full screen":"Full screen",l.replaceChildren(G(e,c?"exit":"full"))},y=()=>{if(c)return;if(c=!0,u={x:a?.scrollX??0,y:a?.scrollY??0,background:n.style.backgroundColor},!f)p=n.style.minHeight;f=!1,d=e.createElement("div"),d.className="mn-fullscreen-place",d.style.height=`${n.offsetHeight}px`;let b=a?.getComputedStyle(n);if(b)d.style.marginTop=b.marginTop,d.style.marginBottom=b.marginBottom;n.before(d);let w=en(n);if(w)n.style.backgroundColor=w;h(),t.tabIndex=0,t.focus({preventScroll:!0}),g(!0),o.changed?.(!0);try{n.requestFullscreen?.().catch(()=>{})}catch{}},v=(b=!0)=>{if(!c)return;if(c=!1,g(!1),h(),n.style.backgroundColor=u?.background??"",d){if(s)n.style.minHeight=d.style.height,f=!0;d.remove(),d=null}if(t.removeAttribute("tabindex"),t.scrollTop=0,m&&e.fullscreenElement===n)e.exitFullscreen?.().catch(()=>{});if(m=!1,u&&a)a.scrollTo(u.x,u.y);if(u=null,o.changed?.(!1),b)l.focus({preventScroll:!0})};l.addEventListener("click",()=>c?v():y()),n.addEventListener("keydown",(b)=>{if(!c||b.key!=="Escape")return;b.stopPropagation(),b.preventDefault(),v()});let k=()=>{if(c)g(!1)};t.addEventListener("wheel",k,{passive:!0}),t.addEventListener("touchmove",k,{passive:!0}),t.addEventListener("keydown",(b)=>{if(Qt.has(b.key))k()});let S=(b)=>{if(!c||b.key!==" "||b.ctrlKey||b.metaKey||b.altKey)return;if(!n.isConnected){v(!1);return}if(b.target?.closest("input:not([type=range]), textarea, select, [contenteditable=true]"))return;if(b.preventDefault(),b.stopPropagation(),b.type!=="keydown"||b.repeat)return;n.querySelector(".mn-play .mn-play-toggle")?.click()};e.addEventListener("keydown",S,!0),e.addEventListener("keyup",S,!0);let N=()=>{if(e.fullscreenElement===n)m=!0;else if(m)v()};return e.addEventListener("fullscreenchange",N),h(),{button:l,active:()=>c,playing:()=>{if(c)g(!0)},drawn:()=>{if(c||!f)return;f=!1,n.style.minHeight=p},destroy:()=>{v(!1),e.removeEventListener("fullscreenchange",N),e.removeEventListener("keydown",S,!0),e.removeEventListener("keyup",S,!0)}}}function De(e){if(!e||typeof e!=="object")return!0;return e.fullScreen!==!1}var Re=[1,1.25,1.5,1.75,2,2.5,3];function He(e,n){let t=null,r=!1,o=(s)=>{t=s,e(Re[s],!0)};return{enter(){r=!1,o(0)},leave(){t=null,r=!1,e(1,!1)},drawn(){if(t===null)return;if(r){t=null;return}if(n()){if(t+1<Re.length)o(t+1);else t=null;return}if(t>0)r=!0,o(t-1);else t=null}}}function Be(e){if(!e||typeof e!=="object"||!("play"in e))return;let n=e.play;if(!n||typeof n!=="object"||!("instruments"in n))return;let t=n.instruments;return typeof t==="string"&&t.trim()?t.trim():void 0}function ze(e){let n=new Set,t=!1;for(let r of e.tracks)if(r.isPercussion)t=!0;else n.add(r.playbackInfo.program);return{programs:[...n].sort((r,o)=>r-o),drums:t}}function tn(e,n){let t=[];for(let r of n.programs){let o=e.programs[String(r)];if(!o?.file)return null;t.push(o.file)}if(n.drums){if(!e.drums?.file)return null;t.push(e.drums.file)}else if(e.click?.file&&n.click!==!1)t.push(e.click.file);return t.length?t:null}var $e=new WeakMap,nn=(e)=>typeof e==="object"&&e!==null&&("programs"in e)&&typeof e.programs==="object"&&e.programs!==null;async function Ie(e,n,t){let r=$e.get(t);if(!r)$e.set(t,r=new Map);let o=r.get(e);if(!o)r.set(e,o={index:null,files:new Map});let s=async(i)=>{try{if(typeof e==="function")return await e(i);let u=await t.fetch(`${e.replace(/\/+$/,"")}/${i}`);return u.ok?new Uint8Array(await u.arrayBuffer()):null}catch{return null}},a=(i)=>{let u=o.files.get(i);if(!u)u=s(i),o.files.set(i,u),u.then((d)=>{if(!d)o.files.delete(i)});return u};o.index??=s("index.json").then((i)=>{if(!i)return null;try{let u=JSON.parse(new TextDecoder().decode(i));return nn(u)?u:null}catch{return null}});let l=await o.index;if(!l)return o.index=null,null;let c=tn(l,n);if(!c)return null;let m=await Promise.all(c.map(a));return m.every((i)=>i!==null)?m:null}var rn="1.9.0",j=(e=rn)=>{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`}};async function ae(e,n,t,r,o=!1){let s=n.defaultView,a=Z(n),l=null;if(t.instruments&&s)l=await Ie(t.instruments,r,s);let c=l?"instruments":"whole";if(!l)if(typeof t.soundFont==="string"){try{let u=await s?.fetch(t.soundFont);l=u?.ok?[new Uint8Array(await u.arrayBuffer())]:null}catch{l=null}if(!l)throw Error(`Couldn't load the soundfont (${t.soundFont})`)}else l=[t.soundFont];let m=l,i=0;return await new Promise((u)=>{e.soundFontLoaded.on(()=>{if(++i>=m.length)u()}),setTimeout(u,8000),m.forEach((d,f)=>e.loadSoundFont(a.bytes(d),o||f>0))}),c}var on=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function sn(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=on.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:Ae(r.tex);if(s!==null)r.tex=s,r.fromText=!0;return r}function Ge(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 an=0;function Ve(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=an;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 ln=5;function cn(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!==ln))))))e.stylesheet.hideDynamics=!0}var mn="rendered by alphaTab";function un(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(mn);o.style.visibility=s?"hidden":""}})}function Ue(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 dn(e){let n=e.ownerDocument,t=n.defaultView?.getComputedStyle(e).color||"",r=t&&Ue(n,t)||(/^rgba?\(/.test(t)?t:"rgba(0, 0, 0, 1)"),o=t&&Ue(n,t,0.6)||r;return{mainGlyphColor:r,secondaryGlyphColor:o,scoreInfoColor:r,staffLineColor:o,barSeparatorColor:r,barNumberColor:o}}var Z=(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}}},je=(e)=>{let n=Math.max(0,Math.round(e/1000));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`};function fn(e,n,t,r,o){let s=Ee(e,"mn-tab-bar","Playback"),a={loop:!1,metronome:!1,countIn:!1,speed:1},l=()=>Le(o),c=()=>{},m=null,i=null,u=()=>(m??=new Promise((b)=>{if(i=()=>b(!1),n.settings.player.playerMode=t.PlayerMode.EnabledSynthesizer,n.settings.player.enableCursor=!0,!r.instruments){if(n.playerReady.on(()=>b(!0)),typeof r.soundFont==="string")n.settings.player.soundFont=r.soundFont;if(n.updateSettings(),r.soundFont instanceof Uint8Array)n.loadSoundFont(Z(e).bytes(r.soundFont),!1);return}let w=!1,D=!1,x=()=>{if(w&&D)b(!0)};n.playerReady.on(()=>{w=!0,x()}),n.updateSettings();let L=n.score?ze(n.score):{programs:[],drums:!1};ae(n,e,r,L).then(()=>{D=!0,x()},(T)=>{b(!1),c(T instanceof Error?T.message:String(T))})}).then((b)=>{if(b)n.isLooping=a.loop,n.metronomeVolume=a.metronome?1:0,n.countInVolume=a.countIn?1:0,n.playbackSpeed=a.speed,n.masterVolume=l();return b}),m),d=(b)=>{if(n.player)b()},f=B(e,"mn-play-toggle","Play","play");f.addEventListener("click",()=>{u().then((b)=>{if(b)n.playPause()})}),c=(b)=>{f.disabled=!0,f.title=`Can't play: ${b}`,f.setAttribute("aria-label",f.title)};let p=B(e,"mn-tab-stop","Stop","stop");p.addEventListener("click",()=>d(()=>n.stop()));let g=()=>d(()=>{n.isLooping=a.loop,n.metronomeVolume=a.metronome?1:0,n.countInVolume=a.countIn?1:0}),h=Y(e,"mn-tab-loop","Loop","loop",!1,(b)=>{a.loop=b,g()}),y=Y(e,"mn-tab-click","Metronome","click",!1,(b)=>{a.metronome=b,g()}),v=Y(e,"mn-tab-count","Count-in","count",!1,(b)=>{a.countIn=b,g()}),k=Ce(e,"Speed","%",25,150,100,(b)=>{a.speed=b/100,d(()=>n.playbackSpeed=a.speed)}),S=C(e,"span","mn-tab-time","");s.append(f,p,h,y,v,k.field,S);let N=Oe(l,()=>[{stop(){},setVolume:(b)=>d(()=>n.masterVolume=b)}],l());return n.playerStateChanged.on((b)=>{let w=Number(b.state)===Number(t.synth.PlayerState.Playing);f.replaceChildren(G(e,w?"pause":"play")),f.title=w?"Pause":"Play",f.setAttribute("aria-label",f.title)}),n.playerPositionChanged.on((b)=>{S.textContent=`${je(b.currentTime)} / ${je(b.endTime)}`}),{bar:s,speed:()=>a.speed,destroy:N,failed:(b)=>{i?.(),c(b)}}}function pn(e,n){return e.tracks.some((t,r)=>(!n||n.includes(r+1))&&t.staves.some((o)=>!o.isPercussion&&o.tuning.length>0))}var hn=[{staves:"tab",label:"Tab",what:"tablature"},{staves:"score",label:"Score",what:"standard notation"},{staves:"both",label:"Both",what:"standard notation and tablature"}];function gn(e,n,t,r){let o=C(e,"span","mn-tab-views");o.setAttribute("role","group"),o.setAttribute("aria-label","View");let s=n.staves,a=r?C(e,"button","mn-tab-keep","Keep this view"):null,l=hn.map(({staves:m,label:i,what:u})=>{let d=C(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 ie(e,n,t,r){let o=t.ownerDocument,s=C(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(C(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=sn(e,n),g={staves:p.stavesWritten?p.staves:r.defaultStaves??p.staves,written:p.stavesWritten},h=g.staves,y=!1,v=r.alphaTab;if(!v?.AlphaTabApi)throw Error("alphaTab isn't loaded");let k=C(o,"div","mn-tab-surface");s.appendChild(k);let{assets:S}=r,N=Z(o),b={core:{useWorkers:Boolean(S.scriptFile),...S.scriptFile?{scriptFile:S.scriptFile}:{},smuflFontSources:N.map([[v.FontFileFormat.Woff2,S.font]]),logLevel:v.LogLevel.Warning,enableLazyLoading:!1},display:{staveProfile:"Default",resources:dn(s)},player:{playerMode:v.PlayerMode.Disabled,enableSeekToClick:!0,enablePlaybackRangeSelection:!0,scrollMode:v.ScrollMode.Off}},w=new v.AlphaTabApi(k,b);if(a=w,w.settings.player.scrollElement=k,m){w.destroy();return}r.onApi?.(w);let D=[];w.scoreLoaded.on((T)=>{D=T.tracks.flatMap((A)=>A.staves.map((E)=>({showSlash:E.showSlash,showNumbered:E.showNumbered}))),Ve(h,T),y=pn(T,p.tracks),cn(T,p.file?null:p.tex)}),un(w,k);let x=null;w.renderFinished.on(()=>{if(i||m)return;if(r.player!==!1){if(x=fn(o,w,v,S,r.volume),c=x.destroy,l=x.speed,s.appendChild(x.bar),r.views!==!1&&y)x.bar.appendChild(gn(o,g,(T)=>{h=T;let A=w.score;if(m||!A)return;A.tracks.flatMap((R)=>R.staves).forEach((R,M)=>Object.assign(R,D[M])),Ve(T,A),w.render()},r.onKeepView));if(r.fullScreen!==!1){let T=null,A=He((M,P)=>{let F=w.settings.display;if(m||!F)return;T??={scale:F.scale,fill:F.lastSystemFillThreshold},F.scale=P?M:T.scale,F.lastSystemFillThreshold=P?0:T.fill,w.updateSettings(),w.render()},()=>k.scrollHeight<=k.clientHeight+1),E=Pe(o,s,k,(M)=>{w.settings.player.scrollMode=M?v.ScrollMode.OffScreen:v.ScrollMode.Off,w.updateSettings()},{changed:(M)=>M?A.enter():A.leave()});w.postRenderFinished.on(()=>{let M=k.querySelector(".at-surface");if(M&&E.active()){let P=Math.max(0,...[...M.children].map((F)=>{let O=F;return O.offsetTop+O.offsetHeight}));if(P>M.offsetHeight)M.style.height=`${P}px`}A.drawn()}),w.playerStateChanged.on((M)=>{if(Number(M.state)===Number(v.synth.PlayerState.Playing))E.playing()}),w.renderFinished.on(()=>E.drawn()),x.bar.appendChild(E.button);let R=c;c=()=>{E.destroy(),R()}}s.addEventListener("pointerdown",(T)=>{if(T.pointerType!=="touch"||x?.bar.contains(T.target))return;s.classList.toggle("mn-play-open")})}u({ok:!0,error:null})}),w.error.on((T)=>{let A=p.fromText?`Couldn't draw this text tab: ${Ge(T,null)}`:Ge(T,p.texLine);if(i)x?.failed(A);else f(A)});let L=p.tracks?.map((T)=>T-1);if(p.file){let T;try{T=r.resolveFile?await r.resolveFile(p.file):null}catch(E){throw Error(`Couldn't read "${p.file}": ${E instanceof Error?E.message:String(E)}`,{cause:E})}if(m)return;if(!T)throw Error(`Couldn't find the file "${p.file}"`);if(!w.load(N.bytes(T),L))throw Error(`Couldn't read "${p.file}": not a score file alphaTab knows`)}else w.tex(p.tex,L??"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 V={guitar:25,piano:0},U={channel:1,program:28},se={channel:9,key:33},bn=0.5;function yn(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,V[r]),r==="guitar"&&t.some((h)=>h.kind==="muted"))i.addProgramChange(0,0,U.channel,U.program);if(t.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 t){let y=h.velocity===void 0||!Number.isFinite(h.velocity)?100:Math.round(Math.min(127,Math.max(1,h.velocity))),v=h.kind==="click"?se.channel:h.kind==="muted"&&r==="guitar"?U.channel:0;i.addNote(0,u(h.time),Math.max(1,u(h.duration)),h.kind==="click"?se.key:h.midi,y,v)}let f=Math.max(...t.map((h)=>h.time+h.duration),0);i.addControlChange(0,u(f+bn),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 le(e,n,t,r){let o=null,s=null,a=null,l=new Set,c=new Map,m=!n.instruments,i=(p)=>p==="guitar"?[V.guitar,U.program]:[V[p]],u=(p="guitar")=>{if(a)return a;s=C(t,"div","mn-tab-hidden"),s.setAttribute("aria-hidden","true"),t.body.appendChild(s);let g=Z(t);o=new e.AlphaTabApi(s,{core:{useWorkers:Boolean(n.scriptFile),...n.scriptFile?{scriptFile:n.scriptFile}:{},smuflFontSources:g.map([[e.FontFileFormat.Woff2,n.font]])},player:{playerMode:e.PlayerMode.EnabledSynthesizer,enableCursor:!1,scrollMode:e.ScrollMode.Off,...typeof n.soundFont==="string"&&!n.instruments?{soundFont:n.soundFont}:{}}});let h=o;if(a=new Promise((y)=>{let v=!1,k=!h.playerReady,S=()=>{if(v&&k)y(!0)},N=()=>{v=!0,S(),setTimeout(()=>{k=!0,S()},4000)};if(h.playerReady?.on(()=>{k=!0,S()}),h.error.on(()=>y(!1)),n.instruments)ae(h,t,n,{programs:i(p),drums:!1}).then((b)=>{if(b==="whole")m=!0;else l.add(p);N()},()=>y(!1));else h.soundFontLoaded.on(N)}),n.soundFont instanceof Uint8Array&&!n.instruments)h.loadSoundFont(g.bytes(n.soundFont),!1);return h.tex(`\\track "Guitar" \\instrument ${V.guitar} r \\track "Piano" \\instrument ${V.piano} r \\track "Muted" \\instrument ${U.program} r`),a},d=async(p)=>{if(!await u(p))return!1;if(m||l.has(p)||!o)return!0;let g=o,h=c.get(p);if(!h)h=ae(g,t,n,{programs:i(p),drums:!1,click:!1},!0).then((y)=>{if(y==="whole")m=!0;else l.add(p);return!0},()=>!1),c.set(p,h);return h},f=yn(e,()=>o);return{reportsStart:!0,play(p,g){let h=null,y=!1,v=g.volume;return d(g.sound).then((k)=>{if(y)return;try{if(k){h=f.play(p,{...g,volume:v});return}}catch{}if(!r)return;if(h=r.play(p,{...g,volume:v}),!r.reportsStart)g.onStart?.()}),{stop(){y=!0,h?.stop()},setVolume(k){v=k,h?.setVolume?.(k)}}},destroy(){try{o?.destroy()}catch{}s?.remove(),o=null,a=null,l.clear(),c.clear(),m=!n.instruments}}}function _e(e=()=>j().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 We=`/* 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 {
|
|
@@ -323,7 +323,7 @@
|
|
|
323
323
|
.mn-play input[type='range'] {
|
|
324
324
|
all: unset;
|
|
325
325
|
appearance: none;
|
|
326
|
-
width:
|
|
326
|
+
width: 36px;
|
|
327
327
|
/* As tall as the thumb, so no host or browser has to center it: the visible 3px track is a
|
|
328
328
|
centered line drawn by the background. */
|
|
329
329
|
height: 9px;
|
|
@@ -1245,4 +1245,88 @@
|
|
|
1245
1245
|
align-items: center;
|
|
1246
1246
|
gap: 2px 6px;
|
|
1247
1247
|
}
|
|
1248
|
-
|
|
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
|
+
/* Room on the sides, more on a wide screen. */
|
|
1264
|
+
padding: 12px max(24px, 3vw) 8px;
|
|
1265
|
+
overflow: hidden;
|
|
1266
|
+
background: Canvas;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
.mn-tab.mn-fullscreen .mn-tab-surface {
|
|
1270
|
+
flex: 1 1 auto;
|
|
1271
|
+
min-height: 0;
|
|
1272
|
+
overflow: auto;
|
|
1273
|
+
overscroll-behavior: contain;
|
|
1274
|
+
/* The scroll bar has its room from the start: the score is drawn once, at the width left. */
|
|
1275
|
+
scrollbar-gutter: stable;
|
|
1276
|
+
outline: none;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
.mn-tab.mn-fullscreen .mn-play.mn-play-static.mn-tab-bar {
|
|
1280
|
+
position: static;
|
|
1281
|
+
flex: none;
|
|
1282
|
+
margin-top: 8px;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/* Full screen for the other blocks (#113): diagrams, charts, patterns, progressions, the circle of
|
|
1286
|
+
fifths. What the block holds is zoomed to the largest size that fits the screen (the control
|
|
1287
|
+
sets --mn-zoom), centered; a block that can't fit scrolls. The bar keeps its size, at the
|
|
1288
|
+
bottom. */
|
|
1289
|
+
.mn-block.mn-fullscreen-fit {
|
|
1290
|
+
position: fixed;
|
|
1291
|
+
inset: 0;
|
|
1292
|
+
z-index: 9999;
|
|
1293
|
+
display: flex;
|
|
1294
|
+
flex-direction: column;
|
|
1295
|
+
align-items: center;
|
|
1296
|
+
box-sizing: border-box;
|
|
1297
|
+
width: auto;
|
|
1298
|
+
max-width: none;
|
|
1299
|
+
height: auto;
|
|
1300
|
+
margin: 0;
|
|
1301
|
+
padding: 16px max(32px, 4vw) 0;
|
|
1302
|
+
overflow: auto;
|
|
1303
|
+
overscroll-behavior: contain;
|
|
1304
|
+
background: Canvas;
|
|
1305
|
+
outline: none;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
.mn-block.mn-fullscreen-fit > :not(.mn-play) {
|
|
1309
|
+
zoom: var(--mn-zoom, 1);
|
|
1310
|
+
flex: none;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
/* A row of diagrams is centered on the screen. */
|
|
1314
|
+
.mn-block.mn-fullscreen-fit .mn-row {
|
|
1315
|
+
justify-content: center;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
/* Centered while it fits; from the top when it scrolls. */
|
|
1319
|
+
.mn-block.mn-fullscreen-fit > :first-child {
|
|
1320
|
+
margin-top: auto;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
.mn-block.mn-fullscreen-fit > .mn-play {
|
|
1324
|
+
position: sticky;
|
|
1325
|
+
bottom: 0;
|
|
1326
|
+
flex: none;
|
|
1327
|
+
align-self: stretch;
|
|
1328
|
+
margin-top: auto;
|
|
1329
|
+
padding: 6px 0 8px;
|
|
1330
|
+
background: inherit;
|
|
1331
|
+
}
|
|
1332
|
+
`;var xn=We,qe="music-notation-styles";function Ke(e){if(e.getElementById(qe))return;let n=e.createElement("style");n.id=qe,n.textContent=xn,e.head.appendChild(n)}var kn=(e)=>e.reduce((n,t)=>Math.max(n,t.time+t.duration),0),me=(e)=>440*Math.pow(2,(e-69)/12);function wn(e,n,t,r=Math.random,o={}){let s=new Float32Array(Math.round(n*t)),a=Math.max(2,Math.round(n/me(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 y=0;y<a;y++)l[y]=h+=g*(l[y]-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((y,v)=>y+v,0)/a,h=l.reduce((y,v)=>Math.max(y,Math.abs(v-g)),0)||1;for(let y=0;y<a;y++)l[y]=(l[y]-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,y=l[p];l[p]=f*0.5*(y+l[h]),s[g]=y*0.5,p=h}return s}var Xe=0.07,Ye=0.03,Tn=(e)=>e>=88?2800:e>=84?2100:1400;function Mn(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=Tn(t.midi),m=u,i=Ye,c.gain.setValueAtTime(0,a),c.gain.linearRampToValueAtTime(0.5*l||0.0001,a+0.001),c.gain.exponentialRampToValueAtTime(0.0001,a+Ye)}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=me(t.midi),m=d}i=Xe,c.gain.setValueAtTime(1.2*l||0.0001,a),c.gain.exponentialRampToValueAtTime(0.0001,a+Xe),m.connect(u)}if(t.kind==="click")m.connect(c);return m.start(a),m.stop(a+i+0.02),m}var Ze=new WeakMap;function Sn(e){let n=Ze.get(e);if(n)return n;let t=e.AudioContext;if(!t)return null;let r=new t;return Ze.set(e,r),r}var An=4,Je=[0,1,0.5,0.3,0.15,0.08,0.04],ce=4,En={guitar:0.15,piano:0.3},Qe=(e,n)=>Math.min(En[e],Math.max(0.03,n/2)),Cn=(e)=>Math.min(2.5,Math.max(0.35,Math.pow(2,(60-e)/24)));function et(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*ce+m,u=t.get(i);if(!u){let d=wn(c,l.sampleRate,An,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=Sn(e);if(!d||!l.length)return{stop(){}};let f=d.resume(),p=l.map(()=>({pluck:Math.min(ce-1,Math.floor(n()*ce)),cents:o(-4,4),level:o(0.93,1.07),decay:o(0.9,1.1)}));if(c==="guitar")l.forEach((x,L)=>{if(x.kind==="muted")s(d,x.midi,0);else if(!x.kind)s(d,x.midi,p[L].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,y=l.map((x,L)=>{if(x.kind)return Mn(d,g,x,h,c,(O,rt)=>s(O,rt,0));let T=p[L],A=h+x.time,E=A+x.duration,R=Qe(c,x.duration),M=d.createGain();M.connect(g);let P=(x.velocity===void 0||!Number.isFinite(x.velocity)?1:Math.min(127,Math.max(0,x.velocity))/100)*T.level,F;if(c==="guitar"){let O=d.createBufferSource();O.buffer=s(d,x.midi,T.pluck),O.playbackRate.value=Math.pow(2,T.cents/1200),F=O,M.gain.setValueAtTime(P,A),M.gain.setValueAtTime(P,E)}else{let O=d.createOscillator();O.setPeriodicWave(a(d)),O.frequency.value=me(x.midi),O.detune.value=T.cents,F=O,M.gain.setValueAtTime(0,A),M.gain.linearRampToValueAtTime(0.35*P,A+0.005),M.gain.setTargetAtTime(0,A+0.005,Cn(x.midi)*T.decay)}return M.gain.setTargetAtTime(0,Math.max(A+0.006,E),R/4),F.connect(M),F.start(A),F.stop(Math.max(A+0.006,E)+R),F}),v=()=>g.disconnect(),k=!1,S,N=()=>{if(k||!u)return;let x=Number.isFinite(d.outputLatency)?d.outputLatency:0;S=e.setTimeout(()=>{if(!k)u()},Math.max(0,h-d.currentTime+x)*1000)};if(u)Promise.resolve(f).then(N,N);let b=e.setTimeout(()=>i?.(),(kn(l)+0.15)*1000),w=l.reduce((x,L)=>Math.max(x,L.time+L.duration+Qe(c,L.duration)),0),D=e.setTimeout(v,(w+0.15)*1000);return{stop(){if(k)return;k=!0,e.clearTimeout(b),e.clearTimeout(S),e.clearTimeout(D);let x=d.currentTime;g.gain.setTargetAtTime(0,x,0.01);for(let L of y)try{L.stop(x+0.05)}catch{}D=e.setTimeout(v,80)},setVolume(x){if(k||!Number.isFinite(x))return;g.gain.setTargetAtTime(Math.min(1,Math.max(0,x)),d.currentTime,0.015)}}}}}var Ln=()=>{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},Fn="pre > code.language-tab, pre > code.language-score",_=new Map,nt=_e();function tt(e){for(let[t,{result:r,holder:o}]of _)if(!t.isConnected||!r.el.isConnected){if(r.destroy(),o.remove(),_.delete(t),t.isConnected)t.style.removeProperty("display")}let n=[...e.querySelectorAll(Fn)].filter((t)=>{let r=t.parentElement,o=_.get(r);if(!o)return r.dataset.mpRendered!=="pending";if(o.source===(t.textContent??""))return!1;return o.result.destroy(),o.holder.remove(),_.delete(r),!0});if(!n.length)return;for(let t of n)t.parentElement.dataset.mpRendered="pending";nt(e).then((t)=>{let r=j(),o=Be(window.musicNotationOptions),s={scriptFile:null,font:r.font,soundFont:r.soundFont,...o?{instruments:o}:{}},a=e.defaultView;a.musicNotationSoundfontPlayer??=le(t,s,e,et(a));for(let l of n){let c=l.parentElement;if(!c.parentElement)continue;let m=l.classList.contains("language-score")?"score":"tab",i=l.textContent??"",u=e.createElement("div");u.className="mn-tab-holder",c.insertAdjacentElement("afterend",u);let d=ie(m,i,u,{alphaTab:t,assets:s,volume:()=>Ln()??oe,fullScreen:De(window.musicNotationOptions)});_.set(c,{result:d,source:i,holder:u}),d.ready.then(({ok:f})=>{if(c.dataset.mpRendered=f?"done":"error",f&&d.el.isConnected)c.style.display="none"})}}).catch(()=>{for(let t of n)t.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0,window.MusicNotationTab={renderTab:ie,createSoundfontPlayer:le,loadAlphaTab:()=>nt(document),alphaTabCdn:j};let e=()=>{Ke(document),tt(document);let n=!1;new MutationObserver(()=>{if(n)return;n=!0,requestAnimationFrame(()=>{n=!1,tt(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;
|
|
@@ -42,6 +42,11 @@ export interface PlayOptions {
|
|
|
42
42
|
* its own `copy` option, which also works without playback.
|
|
43
43
|
*/
|
|
44
44
|
copy?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* `false` leaves Full screen out of the bars (#113). On by default. `renderBlock` sets it from
|
|
47
|
+
* its own `fullScreen` option, which also works without playback.
|
|
48
|
+
*/
|
|
49
|
+
fullScreen?: boolean;
|
|
45
50
|
}
|
|
46
51
|
/** A bar that plays a piece in time, as an app sees it (`PlayOptions.timedBar`, #77). */
|
|
47
52
|
export interface TimedBar {
|
|
@@ -16,6 +16,10 @@ export declare function copyImageButton(doc: Document, win: Window, target: (who
|
|
|
16
16
|
* Copy as image without playback (#11): each block of `el` that draws (a drawing without a pick
|
|
17
17
|
* layer, a progression or a chart) and has no bar yet gets a small bar of its own, in the place
|
|
18
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.
|
|
19
|
+
* copies the whole block, with or without Shift. The bar also has Full screen (#113). `options`
|
|
20
|
+
* leaves either one out (`false`); a bar with neither isn't made. Returns a function that frees it.
|
|
20
21
|
*/
|
|
21
|
-
export declare function attachCopy(el: HTMLElement, make?: (el: Element) => Promise<Blob
|
|
22
|
+
export declare function attachCopy(el: HTMLElement, make?: (el: Element) => Promise<Blob>, options?: {
|
|
23
|
+
copy?: boolean;
|
|
24
|
+
fullScreen?: boolean;
|
|
25
|
+
}): () => void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface FullScreen {
|
|
2
|
+
/** The bar's button. */
|
|
3
|
+
button: HTMLButtonElement;
|
|
4
|
+
/** Whether the block fills the screen. */
|
|
5
|
+
active(): boolean;
|
|
6
|
+
/** Tells the control that the music plays: the score follows it again in full screen. */
|
|
7
|
+
playing(): void;
|
|
8
|
+
/** Tells the control that the score was drawn (again): out of full screen, at its own size. */
|
|
9
|
+
drawn(): void;
|
|
10
|
+
/** Leaves full screen and stops listening to the page. */
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
13
|
+
export interface FullScreenOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Whether the block is drawn again at its own size after full screen (a score: true, the
|
|
16
|
+
* default). It then keeps its height until `drawn()`, so the page doesn't move.
|
|
17
|
+
*/
|
|
18
|
+
redraws?: boolean;
|
|
19
|
+
/** Called after the block entered (true) or left (false) full screen. */
|
|
20
|
+
changed?: (on: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The full screen control of a block. `block` fills the screen and `surface` (a score's drawing,
|
|
24
|
+
* or the block itself) becomes its scroll area. `follow(true)` is called when the score may follow the music (in full
|
|
25
|
+
* screen, where only its own area scrolls), `follow(false)` when it must not: out of full screen
|
|
26
|
+
* (the page never moves, #89), and after a scroll by hand, until the music plays again.
|
|
27
|
+
*/
|
|
28
|
+
export declare function fullScreenControl(doc: Document, block: HTMLElement, surface: HTMLElement, follow?: (on: boolean) => void, options?: FullScreenOptions): FullScreen;
|
|
29
|
+
/**
|
|
30
|
+
* The zoom of a block in full screen: the largest that fits the screen, both ways. A block that
|
|
31
|
+
* never fits (a long chart) takes the largest zoom up to `TALL_ZOOM` whose width fits, and
|
|
32
|
+
* scrolls. `fits(zoom)` says how the block fits at that zoom.
|
|
33
|
+
*/
|
|
34
|
+
export declare function chooseZoom(fits: (zoom: number) => {
|
|
35
|
+
width: boolean;
|
|
36
|
+
height: boolean;
|
|
37
|
+
}): number;
|
|
38
|
+
/**
|
|
39
|
+
* Full screen for a block that isn't a score: diagrams, a chart, a pattern, a progression, the
|
|
40
|
+
* circle of fifths. Nothing is drawn again: what the block holds is zoomed (CSS `zoom`, so text
|
|
41
|
+
* wraps again and drawings stay sharp) to the largest size that fits the screen, and again when
|
|
42
|
+
* the screen's size changes. The bar keeps its size, at the bottom.
|
|
43
|
+
*/
|
|
44
|
+
export declare function blockFullScreen(doc: Document, block: HTMLElement): FullScreen;
|
|
45
|
+
/**
|
|
46
|
+
* Puts the Full screen button at the end of a block's bar (#113), unless `on` is false or the block
|
|
47
|
+
* has one already (a chart's diagrams and its timed bar share the block). Returns a function that
|
|
48
|
+
* frees it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function addFullScreen(doc: Document, bar: HTMLElement, block: Element | null, on?: boolean): () => void;
|
|
51
|
+
/** Full screen on a web page (#113): on unless the page options say `fullScreen: false`. */
|
|
52
|
+
export declare function pageFullScreen(options: unknown): boolean;
|
|
@@ -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;
|