@dsebastien/music-notation 0.11.0 → 0.12.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 +2 -2
- package/dist/chords/chart.d.ts +51 -1
- package/dist/cli.js +1 -1
- package/dist/fretboard/exercise.d.ts +6 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +495 -76
- package/dist/index.js.map +16 -15
- package/dist/music-notation.css +17 -0
- package/dist/music-notation.publish.min.js +44 -27
- package/dist/music-notation.tab.min.js +18 -1
- package/dist/playback/app-bar.d.ts +8 -0
- package/dist/playback/controls.d.ts +27 -0
- package/dist/playback/progression.d.ts +18 -5
- package/dist/playback/strum-bar.d.ts +2 -0
- package/dist/publish/index.js +470 -74
- package/dist/publish/index.js.map +16 -15
- package/dist/render/layout.d.ts +35 -0
- package/dist/voicings/index.js +107 -12
- package/dist/voicings/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @dsebastien/music-notation 0.
|
|
1
|
+
/*! @dsebastien/music-notation 0.12.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
|
|
2
2
|
(()=>{var He=(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("http://www.w3.org/2000/svg",n);He(o,t);for(let s of r)if(s)o.appendChild(s);return o}function S(e,n,t,r){let o=e.createElement(n);if(t)o.className=t;if(r!==void 0)o.textContent=r;return o}var rn=`mn-name-${Math.random().toString(36).slice(2,8)}-`;var Ve=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],Ie=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],se={C:0,D:2,E:4,F:5,G:7,A:9,B:11};function R(e){let n=/^([A-Ga-g])([#♯b♭]*)$/.exec(e.trim());if(!n)return null;let t=se[n[1].toUpperCase()];for(let r of n[2])t+=r==="#"||r==="♯"?1:-1;return(t%12+12)%12}function K(e){let n=/^([A-Ga-g][#♯b♭]*)(-?\d)$/.exec(e.trim());if(!n)return null;let t=R(n[1]);if(t===null)return null;let r=se[n[1][0].toUpperCase()],o=Math.round((t-r)/12);return(Number(n[2])+1)*12+t-o*12}var ze=(e,n=!1)=>(n?Ie:Ve)[((Math.round(e)||0)%12+12)%12];var ae=(e,n=!1)=>`${ze(e,n)}${Math.floor(e/12)-1}`;var je=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=je.get(n.toLowerCase().replace(/\s*\(.*\)$/,""));if(t)return V(t);let r=n.split(/[\s,]+/).filter(Boolean);if(r.length>1&&r.every((i)=>K(i)!==null))return r.map((i)=>K(i));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 i of o){let l=R(i);if(l===null)return null;let m=s[s.length-1];if(m===void 0){let c=[28,40,52].map((a)=>a-a%12+l);s.push(c.reduce((a,u)=>Math.abs(u-40)<Math.abs(a-40)?u:a))}else{let c=m-m%12+l;while(c<=m)c+=12;s.push(c)}}return s}var Ue=/^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/,_e=/^[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/,We=/^\s*([A-Za-z][A-Za-z0-9. -]{0,14}?)\s*[|:]([-xXoOgfdb#@*+|:\s]*)$/,qe=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 Ke(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 Xe=(e)=>e==="X"||e==="O"?["ac"]:e==="g"?["g"]:[],Ye=/[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/,Je=/^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;function Ze(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 Ye.test(r)||Je.test(r)||/^\s/.test(t)&&!r.includes("--")?{line:e.slice(0,n+1),text:r}:{line:e,text:null}}function Qe(e){let{line:n,text:t}=Ze(e.trimEnd()),r=null,o=Ue.exec(n),s=n.slice(o[0].length);if(_e.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 i=null,l=We.exec(n),m=l?l[1].toLowerCase().replace(/[ .-]/g,""):"",c=qe.get(m);if(l&&c&&(l[2].match(/[^\s|:]/g)?.length??0)>=4)i={drum:c,name:m,body:l[2],lettered:/^[A-Ga-g]$/.test(l[1])};return r||i?{string:r,drum:i,text:t}:null}var be=(e)=>[...new Set(e.map((n)=>n.text).filter((n)=>n!==null))];function et(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 tt(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 nt=/^[\sPpMm.\-_|=~]*$/,rt=/P\.?M/i;function ot(e){if(!nt.test(e)||!rt.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 ie(e,n=null){return et(e).flatMap((t,r)=>{let o=t.map((c)=>c.string.name);if(t.length<3&&o.some((c)=>c===null))return[];let s=t.map((c)=>c.string.body),i=t[0].string.offset,l=new Set;if(r===0&&n!==null)for(let[c,a]of ot(n))for(let u=Math.max(c,i);u<=a;u++)l.add(u-i);let m=t.some((c)=>!c.string.barred);return[{kind:"strings",names:o,lines:s,texts:be(t),muted:l,openStart:m}]})}function le(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 tt(e).map((o)=>({kind:"drums",drums:o.map((s)=>s.drum.drum),lines:o.map((s)=>s.drum.body),texts:be(o)}));if(e.every((o)=>o.string))return ie(e,n);let t=[],r=[];for(let o of[...e,null])if(o?.string)r.push(o);else{if(r.length)t.push(...ie(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 i=Qe(s);if(i){if(!t.length)r=o;t.push(i)}else n.push(...le(t,r)),t=[];o=s}return n.push(...le(t,r)),n}function me(e,n){let t=Math.max(...e.map((m)=>m.length)),r=e.map((m)=>m.padEnd(t,"-")),o=[],s=[],i=!1,l=0;for(let m=0;m<t;m++){if(r.every((d)=>d[m]==="|"||d[m]===":")){if(i)o.push({beats:s,start:l,end:m});s=[],i=!1,l=m+1;continue}if(r.some((d)=>d[m]!==" "))i=!0;let{beat:c,skip:a,at:u}=n(r,m);if(c.length)s.push({notes:c,col:u??m});m+=a}if(i)o.push({beats:s,start:l,end:t});return o}var G=(e)=>e!==void 0&&e>="0"&&e<="9",ce=(e,n)=>(e==="1"||e==="2")&&G(n)&&Number(e+n)<=24;function at(e){let n=new Map,t=new Map,r=new Set,o=(s)=>{let i=s,l=e[i]==="(";if(l)i++;if(!G(e[i]))return{fret:null,next:s};let m=ce(e[i],e[i+1])?2:1,c=Number(e.slice(i,i+m));for(let a=0;a<m;a++)r.add(i+a);if(i+=m,l&&e[i]===")")i++;return{fret:c,next:i}};for(let s=0;s<e.length;){if(!G(e[s])||r.has(s)){s++;continue}let i=ce(e[s],e[s+1])?2:1,l=Number(e.slice(s,s+i));n.set(s,{fret:l,width:i});let m=[],c=e[s-1],a=s+i;if(c==="<"&&e[a]===">")m.push("nh"),a++;else if((c==="/"||c==="\\")&&!/[\d)>]/.test(e[s-2]??"-"))m.push(c==="/"?"sib":"sia");if(e[a]==="b"||e[a]==="^"){let p=o(a+1);a=p.next;let f=[0,(p.fret!==null&&p.fret>l?Math.min(p.fret-l,4):2)*2];if(e[a]==="r"){let h=o(a+1);a=h.next;let g=h.fret===null?0:(h.fret-l)*2;f.push(Math.min(f[1],Math.max(0,g)))}m.push(`b (${f.join(" ")})`)}if(e[a]==="~"||e[a]==="v"){m.push("v");while(e[a]==="~"||e[a]==="v")a++}let u=e[a],d=G(e[a+1])||e[a+1]==="("&&G(e[a+2]);if((u==="h"||u==="p")&&d)m.push("h");else if(u==="/"||u==="\\"||u==="s"){if(d)m.push("sl");else if(u!=="s")m.push(u==="/"?"sou":"sod")}if(m.length)t.set(s,m);s+=i}return{frets:n,effects:t}}var it=(e,n,t=[])=>(r,o)=>{let s=[],i=new Set,l=o,m=!1,c=(a,u)=>{let d=r[a][u],p=n.has(u)?["pm"]:[];if(d==="x"||d==="X"){s.push({tex:`x.${t[a]??a+1}`,effects:p}),i.add(a);return}let b=e[a].frets.get(u);if(!b)return;if(b.width===2&&u===o)m=!0;if(r[a][u-1]==="<")l=Math.min(l,u-1);s.push({tex:`${b.fret}.${t[a]??a+1}`,effects:[...e[a].effects.get(u)??[],...p],string:t[a]??a+1}),i.add(a)};if(r.forEach((a,u)=>c(u,o)),m)r.forEach((a,u)=>i.has(u)||c(u,o+1));return{beat:s,skip:m?1:0,at:l}},j={3:[64,59,55],4:[43,38,33,28],5:[43,38,33,28,23],6:[64,59,55,50,45,40],7:[64,59,55,50,45,40,35]},ue=[64,59,55,50,45,40,35,30],X={names:["E","A","D","G","B","E"],midis:[40,45,50,55,59,64]},lt=["E A D G","B E A D G"],Y=(e)=>e[0].toUpperCase()+e.slice(1);function J(e){let n=e.length;if(e.every((t)=>t!==null&&/^\d$/.test(t)))return e.every((t)=>ue[Number(t)-1])?e.map((t)=>ue[Number(t)-1]):null;if(e.every((t)=>t!==null&&/^[A-Ga-g]/.test(t))){let t=[...e].reverse(),r=t.map(Y).join(" ");if(lt.includes(r))return V(r).map((i)=>i-12).reverse();let o=[...X.names.keys()].filter((i)=>t.every((l,m)=>X.names[i+m]===Y(l)));if(o.length){let i=o.length>1&&t[0]==="e"?o.at(-1):o[0];return X.midis.slice(i,i+n).reverse()}if(n===1){let i=R(Y(e[0]));return i===null?null:[48+(i-48+120)%12]}let s=V(r);if(s)return s.reverse()}return j[n]??null}function mt(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 ct(e){if(e.length===1){let{tuning:r,string:o}=mt(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 ut=(e)=>(n,t)=>{let r=[];return n.forEach((o,s)=>{let i=o[t];if(!/[xXoOgfdb#@*+]/.test(i))return;let l=Ke(e[s],i);if(!r.some((m)=>m.tex===l))r.push({tex:l,effects:Xe(i)})}),{beat:r,skip:0}},ye=[[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 de(e){let n=[];for(let t=e;t>0;){let[r,o,s]=ye.find(([i])=>i<=t);n.push({duration:o,dotted:s}),t-=r}return n}var F={ts:[4,4],length:16,beat:4,grids:[1,2,4,8,16]},pe={ts:[3,4],length:12,beat:4,grids:[1,3,6,12]},dt={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 ft(e,n){let t=new Map;for(let o=1;o<e.length;o++){let s=e[o]-e[o-1],i=n[o]-n[o-1];if((t.get(s)??i)!==i)return!1;t.set(s,i)}let r=[...t].sort((o,s)=>o[0]-s[0]);return r.every(([,o],s)=>s===0||o>=r[s-1][1])}var ht=new Set(ye.map(([e])=>e));function gt(e,n,[t,r],o,s,i){let l=r/n;if(l<1||s&&!Number.isInteger(l))return null;let m=[],c=0;for(let a of e){let u=(a-t)/l,d=Math.round(u),p=Math.abs(u-d)*l;if(d<0||d>=n||p>o+0.000000001||m.length&&d*(i/n)<=m.at(-1))return null;c=Math.max(c,p),m.push(d*(i/n))}if(!s&&m.some((a,u)=>!ht.has((m[u+1]??i)-a)))return null;return ft(e,m)?{at:m,error:c}:null}function Z(e,n,t,r=F){if(!e.length)return[];let o=[[t,n-t],[t,n]];for(let s=1;s<t;s++)o.push([s,n-s]);if(e[0]>t)o.push([0,n]);for(let[s,i]of[[0.4,!1],[1,!1],[0.4,!0]])for(let l of r.grids){let m=o.map((c)=>gt(e,l,c,s,i,r.length)).filter((c)=>c!==null);if(m.length)return m.reduce((c,a)=>a.error<c.error?a:c).at}return null}function z(e,n,t=n.length){let r=[],{beat:o,length:s}=n;for(let i=e;i<t;){let l=s===4*o&&i%(2*o)===0&&i<=s/2?[2*o]:[],c=(i%2?[1]:i%o?[2,1]:[...l,o,2,1]).find((a)=>a<=t-i);r.push({beat:-1,sixteenths:c}),i+=c}return r}function bt(e,n=F,t=[]){let r=e.slice(1).map((i,l)=>i-e[l]),o=new Map;for(let i of r)o.set(i,(o.get(i)??0)+1);let s=[...o].reduce((i,l)=>!i||l[1]>i[1]||l[1]===i[1]&&l[0]<i[0]?l:i,null)?.[0];for(let i of[2,1]){let l=e.map((c,a)=>i*(a<r.length?Math.max(1,Math.round(r[a]/s)):1)),m=l.reduce((c,a)=>c+a,0);if(i===2)for(let c of t){if(m<=n.length)break;if(c+1>=l.length||l[c]!==2)continue;let a=Math.max(1,l[c+1]-1);m-=1+l[c+1]-a,l[c]=1,l[c+1]=a}if(m>n.length)continue;return[...l.map((c,a)=>({beat:a,sixteenths:c})),...z(m,n)]}return e.map((i,l)=>({beat:l,sixteenths:1}))}var yt=new Set(["h","sl"]),vt=(e)=>e.flatMap((n,t)=>n.notes.some((r)=>r.effects.some((o)=>yt.has(o)))?[t]:[]);function xt(e,n,t){let r=t.length,o=e.part==="whole"?e.width:n,s=e.part==="end"?n-e.width:0,i=e.beats.map((a)=>a.col+s);if(e.part==="start"&&i.length){let a=Z([...i,e.width],o,e.pad,t);if(a){let u=a.pop(),d=a[0]>0?[{beat:-1,sixteenths:a[0]}]:[];return a.forEach((p,b)=>d.push({beat:b,sixteenths:(a[b+1]??u)-p})),[...d,...z(u,t)]}}let l=Z(i,o,e.pad,t);if(!l){let a=bt(e.beats.map((p)=>p.col),t,vt(e.beats));if(e.part!=="end")return a;let u=a.filter((p)=>p.beat>=0),d=u.reduce((p,b)=>p+b.sixteenths,0);return e.pickup?u:[...z(0,t,r-d),...u]}let m=l[0],c=m===0||e.pickup?[]:e.part==="end"?z(0,t,m):[{beat:-1,sixteenths:m}];return l.forEach((a,u)=>c.push({beat:u,sixteenths:(l[u+1]??r)-a})),c}var kt=(e)=>e.reduce((n,t)=>t.beats.length?Math.min(n,t.beats[0].col-t.start):n,3);function fe(e,n,t,r){let o=Math.max(...e.map((s)=>s.length));return{bars:n,pad:kt(n),texts:t,openStart:r&&n[0]?.start===0,openEnd:n.at(-1)?.end===o}}function wt(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 ve(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 Tt(e,n){if(n===null)return F;let t=[];for(let a of e)a.bars.forEach((u,d)=>{let p=(d>0||!a.openStart)&&(d<a.bars.length-1||!a.openEnd),b=u.end-u.start;if(p&&u.beats.length&&Math.abs(b-n)<=1)t.push({bar:u,pad:a.pad})});let r=new Map;for(let{bar:a}of t)for(let u=1;u<a.beats.length;u++){let d=a.beats[u].col-a.beats[u-1].col;r.set(d,(r.get(d)??0)+1)}let o=Math.max(0,...r.values()),s=Math.min(...[...r].filter(([,a])=>a*2>=o).map(([a])=>a));if(t.length<2||!Number.isFinite(s))return F;let i=[],l=0,m=0;for(let{bar:a,pad:u}of t){let d=a.beats.map((g)=>(g.col-a.start-u)/s);if(d.some((g)=>Math.abs(g-Math.round(g))*s>0.40000000100000005)){i.push(0);continue}let p=d.map(Math.round),b=Math.max(Math.ceil((a.end-a.start-u)/s-0.5),p.at(-1)+1);if(i.push(b),b!==6)continue;let f=a.beats.reduce((g,y)=>y.notes.reduce((T,C)=>Math.max(T,C.string??0),g),0),h=p.filter((g,y)=>a.beats[y].notes.some((T)=>T.string===f));for(let g of[p,h.length<p.length?h:[]])if(g.some((y)=>y!==0&&y%2===0)&&g.every((y)=>y%2===0))l++;else if(g.includes(3)&&g.every((y)=>y%3===0))m++}let c=ve(i);if(c.count*3<t.length*2)return F;if(c.value===3)return pe;if(c.value===6)return l>m?pe:dt;return c.value===12?pt:F}function At(e,n){let t=(s)=>n!==null&&s<=n*2/3,r=[],o=null;return e.forEach((s,i)=>{let l=r.length,m=e[i+1];s.bars.forEach((a,u)=>{let d=a.beats.map((h)=>({notes:h.notes,col:h.col-a.start})),p={beats:d,width:a.end-a.start,pad:s.pad,part:"whole",pickup:!1,text:null},b=u===0&&o!==null;if(o&&u===0){let h=o.width-s.pad;p={...o,beats:[...o.beats,...d.map((g)=>({notes:g.notes,col:g.col+h}))],width:o.width+p.width-s.pad},o=null}if(u===s.bars.length-1&&t(p.width)){let h=m?.bars[0],g=h?p.width+h.end-h.start-m.pad:0;if(h&&(s.openEnd||t(h.end-h.start)&&(m.openStart||g<=n*1.25))){if(p.beats.length||!s.openEnd)o=p;return}if(s.openEnd&&!b){if(!p.beats.length)return;p.part="start"}}let f=!r.length;if(u===0&&!b&&p.part==="whole"&&t(p.width)&&p.beats.length){if(f||s.openStart)p.part="end",p.pickup=f}r.push(p)});let c=o??(r.length>l?r.at(-1):null);if(s.texts.length&&c){let a=s.texts.join(" / ");c.text=c.text?`${c.text} / ${a}`:a}}),r}function Mt(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(Z(r,t.width,t.pad,n))return[t];let o=r.slice(1).map((u,d)=>u-r[d]),s=ve(o).value,i=o.reduce((u,d)=>u+Math.max(1,Math.round(d/s)),1),l=n.length/2,m=s*l;if(i<=l||t.width-t.pad<m*1.5)return[t];let c=Math.floor((r.at(-1)-t.pad)/m)+1,a=Array.from({length:c},()=>[]);for(let u of t.beats){let d=Math.min(c-1,Math.max(0,Math.floor((u.col-t.pad)/m)));while(d<c-1&&u.col>=t.pad+(d+1)*m)d++;while(d>0&&u.col<t.pad+d*m)d--;a[d].push({notes:u.notes,col:u.col-d*m})}return a.map((u,d)=>({beats:u,width:t.pad+m,pad:t.pad,part:"whole",pickup:!1,text:d===c-1?t.text:null}))})}var St=(e)=>`"${e.replace(/[\\"]/g,(n)=>`\\${n}`)}"`,I=(e,n)=>n.length?`${e}{${n.join(" ")}}`:e;function Et(e,n){if(!e.length)return I("r",n);if(e.length===1)return I(e[0].tex,[...e[0].effects,...n]);return I(`(${e.map((t)=>I(t.tex,t.effects)).join(" ")})`,n)}var he=new Set(["h","sl","sou","sod"]);function Ct(e,n){if(n===1)return[e];let t=[e.map((r)=>({...r,effects:r.effects.filter((o)=>!he.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&&he.has(s))})));return t}function ge(e,n){let t=0;return e.map(({beats:o,rhythm:s,text:i,pickup:l})=>{let m=[];if(!o.length)for(let u of n===F?[{duration:1,dotted:!1}]:de(n.length))m.push({notes:[],...u});for(let{beat:u,sixteenths:d}of s){let p=de(d),b=Ct(u>=0?o[u]:[],p.length);p.forEach((f,h)=>m.push({notes:b[h],...f}))}let c=m.length-1;while(c>0&&!m[c].notes.length)c--;if(!m[c].notes.length)c=m.length-1;let a=m.map((u,d)=>{let p=u.dotted?["d"]:[];if(i&&d===c)p.push(`txt ${St(i)}`);let b=u.duration===t?"":`:${u.duration} `;return t=u.duration,b+Et(u.notes,p)}).join(" ");return l?`\\ac ${a}`:a}).join(` |
|
|
3
3
|
`)}function xe(e){let n=st(e),t=n[0];if(!t)return null;let r=t.kind==="strings"?J(t.names):null,o=r?ct(r):null;if(o)r=o.tuning;let s=[];if(t.kind==="drums"){for(let d of n)if(d.kind==="drums")s.push(fe(d.lines,me(d.lines,ut(d.drums)),d.texts,!1))}else{let d=JSON.stringify(J(t.names)),p=o?.strings??[];for(let b of n){if(b.kind!=="strings"||JSON.stringify(J(b.names))!==d)continue;let f=it(b.lines.map(at),b.muted,p);s.push(fe(b.lines,me(b.lines,f),b.texts,b.openStart))}}let i=wt(s),l=Tt(s,i),m=Mt(At(s,i),l).map((d)=>({beats:d.beats.map((p)=>p.notes),rhythm:xt(d,i??0,l),text:d.text,pickup:d.pickup}));if(!m.length)return null;let c=l===F?[]:[`\\ts ${l.ts.join(" ")}`];if(t.kind==="drums")return["\\instrument percussion","\\articulation defaults",...c,ge(m,l)].join(`
|
|
4
4
|
`);let a=r?.join(" ")===j[6].join(" ");return[...r&&!a?[`\\tuning (${r.map((d)=>ae(d)).join(" ")})`]:[],...c,ge(m,l)].join(`
|
|
@@ -42,6 +42,16 @@
|
|
|
42
42
|
height: auto;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/* Touch screens (#73): chord diagrams and fretboards a third larger, so each string's lane (the
|
|
46
|
+
hit area of its marks across, 18 and 20 units) is at least 24 px, the minimum target size of
|
|
47
|
+
WCAG 2.5.8. max-width still keeps them inside the page. */
|
|
48
|
+
@media (pointer: coarse) {
|
|
49
|
+
.mn-svg.mn-guitar-chord,
|
|
50
|
+
.mn-svg.mn-fretboard {
|
|
51
|
+
zoom: 1.34;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
.mn-svg text {
|
|
46
56
|
fill: var(--mn-fg);
|
|
47
57
|
font-size: 11px;
|
|
@@ -1048,4 +1058,11 @@
|
|
|
1048
1058
|
.mn-playable .mn-svg .mn-picking-slot.mn-playing .mn-picking-fret {
|
|
1049
1059
|
fill: var(--mn-on-playing);
|
|
1050
1060
|
}
|
|
1061
|
+
|
|
1062
|
+
/* App controls in a timed play bar (#77): after the bar's own, styled like them. */
|
|
1063
|
+
.mn-play .mn-play-app {
|
|
1064
|
+
display: inline-flex;
|
|
1065
|
+
align-items: center;
|
|
1066
|
+
gap: 2px 6px;
|
|
1067
|
+
}
|
|
1051
1068
|
`;var Wt=Ce,Ne="music-notation-styles";function Le(e){if(e.getElementById(Ne))return;let n=e.createElement("style");n.id=Ne,n.textContent=Wt,e.head.appendChild(n)}var qt=(e)=>e.reduce((n,t)=>Math.max(n,t.time+t.duration),0),oe=(e)=>440*Math.pow(2,(e-69)/12);function Kt(e,n,t,r=Math.random,o={}){let s=new Float32Array(Math.round(n*t)),i=Math.max(2,Math.round(n/oe(e))),l=new Float32Array(i);for(let f=0;f<i;f++)l[f]=r()*2-1;let m=Math.min(1,Math.max(0,o.brightness??1));if(m<1){let f=0.2+0.8*m,h=l[i-1];for(let g=0;g<i;g++)l[g]=h+=f*(l[g]-h)}let c=Math.min(0.5,Math.max(0,o.pick??0)),a=Math.round(c*i);if(a>0){let f=Float32Array.from(l);for(let h=0;h<i;h++)l[h]=f[h]-f[(h-a+i)%i]}if(m<1||a>0){let f=l.reduce((g,y)=>g+y,0)/i,h=l.reduce((g,y)=>Math.max(g,Math.abs(y-f)),0)||1;for(let g=0;g<i;g++)l[g]=(l[g]-f)/h}let u=o.damping!==void 0&&Number.isFinite(o.damping)?o.damping:1,d=(0.004-Math.min(0.0035,0.00004*(90-e)))*u,p=1-Math.min(0.02,Math.max(0.0001,d)),b=0;for(let f=0;f<s.length;f++){let h=(b+1)%i,g=l[b];l[b]=p*0.5*(g+l[h]),s[f]=g*0.5,b=h}return s}var Fe=0.07,Oe=0.03,Xt=(e)=>e>=88?2800:e>=84?2100:1400;function Yt(e,n,t,r,o,s){let i=r+t.time,l=t.velocity===void 0||!Number.isFinite(t.velocity)?1:Math.min(127,Math.max(0,t.velocity))/100,m=e.createGain();m.connect(n);let c,a;if(t.kind==="click"){let u=e.createOscillator();u.type="triangle",u.frequency.value=Xt(t.midi),c=u,a=Oe,m.gain.setValueAtTime(0,i),m.gain.linearRampToValueAtTime(0.5*l||0.0001,i+0.001),m.gain.exponentialRampToValueAtTime(0.0001,i+Oe)}else{let u=e.createBiquadFilter();if(u.type="lowpass",u.frequency.value=o==="guitar"?1800:2500,u.connect(m),o==="guitar"){let d=e.createBufferSource();d.buffer=s(e,t.midi),c=d}else{let d=e.createOscillator();d.type="triangle",d.frequency.value=oe(t.midi),c=d}a=Fe,m.gain.setValueAtTime(1.2*l||0.0001,i),m.gain.exponentialRampToValueAtTime(0.0001,i+Fe),c.connect(u)}if(t.kind==="click")c.connect(m);return c.start(i),c.stop(i+a+0.02),c}var De=new WeakMap;function Jt(e){let n=De.get(e);if(n)return n;let t=e.AudioContext;if(!t)return null;let r=new t;return De.set(e,r),r}var Zt=4,Pe=[0,1,0.5,0.3,0.15,0.08,0.04],re=4,Qt={guitar:0.15,piano:0.3},Re=(e,n)=>Math.min(Qt[e],Math.max(0.03,n/2)),en=(e)=>Math.min(2.5,Math.max(0.35,Math.pow(2,(60-e)/24)));function $e(e,n=Math.random){let t=new Map,r=new WeakMap,o=(l,m)=>l+(m-l)*n(),s=(l,m,c)=>{let a=m*re+c,u=t.get(a);if(!u){let d=Kt(m,l.sampleRate,Zt,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(a,u)}return u},i=(l)=>{let m=r.get(l);if(!m){let c=new Float32Array(Pe.length);m=l.createPeriodicWave(c,Float32Array.from(Pe)),r.set(l,m)}return m};return{reportsStart:!0,play(l,{sound:m,volume:c,onEnd:a,onStart:u}){let d=Jt(e);if(!d||!l.length)return{stop(){}};let p=d.resume(),b=l.map(()=>({pluck:Math.min(re-1,Math.floor(n()*re)),cents:o(-4,4),level:o(0.93,1.07),decay:o(0.9,1.1)}));if(m==="guitar")l.forEach((x,v)=>{if(x.kind==="muted")s(d,x.midi,0);else if(!x.kind)s(d,x.midi,b[v].pluck)});let f=d.createGain();f.gain.value=Number.isFinite(c)?Math.min(1,Math.max(0,c)):0.8,f.connect(d.destination);let h=d.currentTime+0.05,g=l.map((x,v)=>{if(x.kind)return Yt(d,f,x,h,m,(E,Be)=>s(E,Be,0));let M=b[v],A=h+x.time,D=A+x.duration,H=Re(m,x.duration),L=d.createGain();L.connect(f);let W=(x.velocity===void 0||!Number.isFinite(x.velocity)?1:Math.min(127,Math.max(0,x.velocity))/100)*M.level,P;if(m==="guitar"){let E=d.createBufferSource();E.buffer=s(d,x.midi,M.pluck),E.playbackRate.value=Math.pow(2,M.cents/1200),P=E,L.gain.setValueAtTime(W,A),L.gain.setValueAtTime(W,D)}else{let E=d.createOscillator();E.setPeriodicWave(i(d)),E.frequency.value=oe(x.midi),E.detune.value=M.cents,P=E,L.gain.setValueAtTime(0,A),L.gain.linearRampToValueAtTime(0.35*W,A+0.005),L.gain.setTargetAtTime(0,A+0.005,en(x.midi)*M.decay)}return L.gain.setTargetAtTime(0,Math.max(A+0.006,D),H/4),P.connect(L),P.start(A),P.stop(Math.max(A+0.006,D)+H),P}),y=()=>f.disconnect(),T=!1,C,O=()=>{if(T||!u)return;let x=Number.isFinite(d.outputLatency)?d.outputLatency:0;C=e.setTimeout(()=>{if(!T)u()},Math.max(0,h-d.currentTime+x)*1000)};if(u)Promise.resolve(p).then(O,O);let k=e.setTimeout(()=>a?.(),(qt(l)+0.15)*1000),N=l.reduce((x,v)=>Math.max(x,v.time+v.duration+Re(m,v.duration)),0),w=e.setTimeout(y,(N+0.15)*1000);return{stop(){if(T)return;T=!0,e.clearTimeout(k),e.clearTimeout(C),e.clearTimeout(w);let x=d.currentTime;f.gain.setTargetAtTime(0,x,0.01);for(let v of g)try{v.stop(x+0.05)}catch{}w=e.setTimeout(y,80)}}}}}var tn="pre > code.language-tab, pre > code.language-score",B=new Map,nn=Ee();function Ge(e){for(let[t,{result:r,holder:o}]of B)if(!t.isConnected||!r.el.isConnected){if(r.destroy(),o.remove(),B.delete(t),t.isConnected)t.style.removeProperty("display")}let n=[...e.querySelectorAll(tn)].filter((t)=>{let r=t.parentElement,o=B.get(r);if(!o)return r.dataset.mpRendered!=="pending";if(o.source===(t.textContent??""))return!1;return o.result.destroy(),o.holder.remove(),B.delete(r),!0});if(!n.length)return;for(let t of n)t.parentElement.dataset.mpRendered="pending";nn(e).then((t)=>{let r=_(),o={scriptFile:null,font:r.font,soundFont:r.soundFont},s=e.defaultView;s.musicNotationSoundfontPlayer??=Se(t,o,e,$e(s));for(let i of n){let l=i.parentElement;if(!l.parentElement)continue;let m=i.classList.contains("language-score")?"score":"tab",c=i.textContent??"",a=e.createElement("div");a.className="mn-tab-holder",l.insertAdjacentElement("afterend",a);let u=Me(m,c,a,{alphaTab:t,assets:o});B.set(l,{result:u,source:c,holder:a}),u.ready.then(({ok:d})=>{if(l.dataset.mpRendered=d?"done":"error",d&&u.el.isConnected)l.style.display="none"})}}).catch(()=>{for(let t of n)t.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0;let e=()=>{Le(document),Ge(document);let n=!1;new MutationObserver(()=>{if(n)return;n=!0,requestAnimationFrame(()=>{n=!1,Ge(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e);else e()}})();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PlayOptions, TimedBar } from './controls.js';
|
|
2
|
+
export interface AppBar {
|
|
3
|
+
/** To call when the bar's tempo changes. */
|
|
4
|
+
tempoChanged(bpm: number): void;
|
|
5
|
+
/** Frees what the app set up (its returned function). */
|
|
6
|
+
free(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function handToApp(options: PlayOptions, bar: HTMLElement, info: Pick<TimedBar, 'kind' | 'drawing' | 'compound' | 'tempo'>): AppBar;
|
|
@@ -26,6 +26,33 @@ export interface PlayOptions {
|
|
|
26
26
|
* has no hand (a keyboard, a piano chord) is drawn for it. Right by default (#60).
|
|
27
27
|
*/
|
|
28
28
|
hand?: Hand;
|
|
29
|
+
/**
|
|
30
|
+
* Called with each bar that plays a piece in time (strum, picking, progression, ChordPro chart;
|
|
31
|
+
* #77), once it's built, so the app can add its own controls (`bar.add`) and read the tempo set
|
|
32
|
+
* on it. What it returns (a function) is called when the block is destroyed. A hook that
|
|
33
|
+
* throws leaves the bar as it is.
|
|
34
|
+
*/
|
|
35
|
+
timedBar?: (bar: TimedBar) => void | (() => void);
|
|
36
|
+
}
|
|
37
|
+
/** A bar that plays a piece in time, as an app sees it (`PlayOptions.timedBar`, #77). */
|
|
38
|
+
export interface TimedBar {
|
|
39
|
+
/** What it plays: a strumming or picking pattern, a progression block or a ChordPro chart. */
|
|
40
|
+
kind: 'strum' | 'picking' | 'progression' | 'chart';
|
|
41
|
+
/** The bar itself (`.mn-play`, role group). */
|
|
42
|
+
element: HTMLElement;
|
|
43
|
+
/** The drawing it plays: the pattern's SVG, the `.mn-progression` or the `.mn-chart`. */
|
|
44
|
+
drawing: Element;
|
|
45
|
+
/** Counted in dotted beats (6/8, 9/8, 12/8): the tempo counts dotted quarters. */
|
|
46
|
+
compound: boolean;
|
|
47
|
+
/** The tempo set on the bar (20 to 240), in the beat it counts: what the next pass plays at. */
|
|
48
|
+
tempo(): number;
|
|
49
|
+
/** Calls `listener` with each new tempo set on the bar; returns a function that stops it. */
|
|
50
|
+
onTempo(listener: (bpm: number) => void): () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Adds an app control at the end of the bar, after the bar's own (so they come last in the
|
|
53
|
+
* focus order), in its `.mn-play-app` slot. It shows and hides with the bar.
|
|
54
|
+
*/
|
|
55
|
+
add(control: HTMLElement): void;
|
|
29
56
|
}
|
|
30
57
|
/** A number within bounds; the fallback when it isn't a number at all. */
|
|
31
58
|
export declare const clamp: (n: number | undefined, lo: number, hi: number, fallback: number) => number;
|
|
@@ -5,10 +5,15 @@ import { type NotePlayer, type PlayHandle, type Sound } from './player.js';
|
|
|
5
5
|
/** How each bar's chord is played. */
|
|
6
6
|
export type ProgressionStrum = 'beats' | 'bar' | 'arpeggio';
|
|
7
7
|
export declare const PROGRESSION_STRUMS: readonly ProgressionStrum[];
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* One chord of a progression: its name (as shown, null when unnamed), the notes it sounds (lowest
|
|
10
|
+
* first) and how long it lasts: `beats` of the time signature as written (quarters in 4/4,
|
|
11
|
+
* eighths in 6/8), a bar when absent (#75). The last chord fills the last bar.
|
|
12
|
+
*/
|
|
9
13
|
export interface ProgressionBar {
|
|
10
14
|
chord: string | null;
|
|
11
15
|
pitches: readonly number[];
|
|
16
|
+
beats?: number;
|
|
12
17
|
}
|
|
13
18
|
export interface ProgressionEventOptions {
|
|
14
19
|
/** Counted beats a minute (a quarter in 4/4; a dotted quarter with a 6/8 pattern); 90. */
|
|
@@ -37,10 +42,16 @@ export interface ProgressionEventOptions {
|
|
|
37
42
|
* and when each bar is played (`strums`, one a bar: `slot` is the bar's index), to light it.
|
|
38
43
|
*/
|
|
39
44
|
export declare function progressionEvents(bars: readonly ProgressionBar[], options?: ProgressionEventOptions): Pass;
|
|
40
|
-
/**
|
|
45
|
+
/** The chord sounding at the start of each bar (its index in the progression). */
|
|
46
|
+
export declare function chordOfBars(bars: readonly ProgressionBar[], beatsPerBar: number): number[];
|
|
47
|
+
/**
|
|
48
|
+
* A chord to play: a symbol (or words), or an object with its name to show, its notes (lowest
|
|
49
|
+
* first; from the name when absent) and how long it lasts (`beats` as written, a bar by default).
|
|
50
|
+
*/
|
|
41
51
|
export type ProgressionChordInput = string | {
|
|
42
52
|
chord?: string | null;
|
|
43
|
-
pitches
|
|
53
|
+
pitches?: readonly number[];
|
|
54
|
+
beats?: number;
|
|
44
55
|
};
|
|
45
56
|
export interface PlayProgressionOptions {
|
|
46
57
|
/** Counted beats a minute (a quarter in 4/4, a dotted quarter with a 6/8 pattern); 90. */
|
|
@@ -70,8 +81,10 @@ export interface PlayProgressionOptions {
|
|
|
70
81
|
sound?: Sound;
|
|
71
82
|
/** 0 to 1, 0.8 by default. */
|
|
72
83
|
volume?: number;
|
|
73
|
-
/** Called as each bar starts sounding: its index,
|
|
84
|
+
/** Called as each bar starts sounding: its index, the chord sounding, the pass (from 1). */
|
|
74
85
|
onBar?: (bar: number, chord: string | null, pass: number) => void;
|
|
86
|
+
/** Called as each chord starts sounding: its index in `chords`, its name, the pass (#75). */
|
|
87
|
+
onChord?: (index: number, chord: string | null, pass: number) => void;
|
|
75
88
|
/** Called once the progression is over (not after stop). */
|
|
76
89
|
onEnd?: () => void;
|
|
77
90
|
}
|
|
@@ -101,7 +114,7 @@ export interface ProgressionSettings extends StrumSettings {
|
|
|
101
114
|
* Plays `bars` pass after pass (see `runStrum` for the timing), from `settings()` read at each
|
|
102
115
|
* pass. `follow` gets each pass's bars (`slot` is the bar's index), to light them.
|
|
103
116
|
*/
|
|
104
|
-
export declare function runProgression(bars: readonly ProgressionBar[], options: Pick<ProgressionEventOptions, 'beatsPerBar' | 'beatUnit' | 'strum' | 'pattern'>, player: () => NotePlayer, settings: () => ProgressionSettings, timers: Pick<Window, 'setTimeout' | 'clearTimeout'>, onEnd?: () => void, follow?: (
|
|
117
|
+
export declare function runProgression(bars: readonly ProgressionBar[], options: Pick<ProgressionEventOptions, 'beatsPerBar' | 'beatUnit' | 'strum' | 'pattern'>, player: () => NotePlayer, settings: () => ProgressionSettings, timers: Pick<Window, 'setTimeout' | 'clearTimeout'>, onEnd?: () => void, follow?: (chords: StrumTiming[], player: NotePlayer, pass: number, made: Pass) => StrumFollower): PlayHandle;
|
|
105
118
|
/**
|
|
106
119
|
* Plays chords in time, one a bar (#46): strummed on the beats by default, with a metronome
|
|
107
120
|
* click, a count-in when asked, and a loop. Chord symbols take the strum's guitar voicing (a piano
|
|
@@ -12,6 +12,8 @@ export declare function barPlayer(wrap: Element, win: Window, options: PlayOptio
|
|
|
12
12
|
export declare function strumBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions): () => void;
|
|
13
13
|
/** What a timed bar plays: its passes, and how it's counted. */
|
|
14
14
|
export interface TimedPiece {
|
|
15
|
+
/** What it plays, for the app (#77). */
|
|
16
|
+
kind: 'strum' | 'picking';
|
|
15
17
|
/** The wrapper's own class, beside `mn-playable`. */
|
|
16
18
|
cls: string;
|
|
17
19
|
/** The bar's name for screen readers. */
|