@dsebastien/music-notation 0.21.0 → 0.21.2
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/properties.d.ts +4 -0
- package/dist/index.js +23 -5
- package/dist/index.js.map +5 -5
- package/dist/music-notation.publish.min.js +28 -28
- package/dist/music-notation.tab.min.js +1 -1
- package/dist/playback/follow.d.ts +6 -0
- package/dist/publish/index.js +23 -5
- package/dist/publish/index.js.map +5 -5
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @dsebastien/music-notation 0.21.
|
|
1
|
+
/*! @dsebastien/music-notation 0.21.2 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
|
|
2
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
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
4
|
`);let i=r?.join(" ")===X[6].join(" ");return[...r&&!i?[`\\tuning (${r.map((d)=>de(d)).join(" ")})`]:[],...m,we(c,l)].join(`
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
import type { NoteEvent, NotePlayer, PlayKind } from './player.js';
|
|
7
7
|
/** The class a sounding note's element gets. */
|
|
8
8
|
export declare const PLAYING_CLASS = "mn-playing";
|
|
9
|
+
/**
|
|
10
|
+
* A drawing whose parts touch (the circle of fifths' cells) groups each part with its labels in an
|
|
11
|
+
* element marked `data-mn-raise`. The part that plays is drawn last, so its outline isn't covered
|
|
12
|
+
* by the parts drawn after it (they hid part of the playing cell's border).
|
|
13
|
+
*/
|
|
14
|
+
export declare function raise(el: Element): void;
|
|
9
15
|
/**
|
|
10
16
|
* How long (ms) the bar waits for a player that doesn't say when its notes start (no
|
|
11
17
|
* `reportsStart`) before it lights notes from the play call.
|
package/dist/publish/index.js
CHANGED
|
@@ -4502,6 +4502,12 @@ function lightPlayer(win, random = Math.random) {
|
|
|
4502
4502
|
|
|
4503
4503
|
// src/playback/follow.ts
|
|
4504
4504
|
var PLAYING_CLASS = "mn-playing";
|
|
4505
|
+
function raise(el) {
|
|
4506
|
+
const group = el.closest("[data-mn-raise]");
|
|
4507
|
+
const parent = group?.parentNode;
|
|
4508
|
+
if (group && parent && parent.lastChild !== group)
|
|
4509
|
+
parent.appendChild(group);
|
|
4510
|
+
}
|
|
4505
4511
|
var START_WAIT = 300;
|
|
4506
4512
|
var reporting = new WeakSet;
|
|
4507
4513
|
function startsReported(player) {
|
|
@@ -4614,6 +4620,7 @@ function followNotes(win, drawing, targets, events, wait = START_WAIT) {
|
|
|
4614
4620
|
if (!lit.has(el)) {
|
|
4615
4621
|
el.classList.add(PLAYING_CLASS);
|
|
4616
4622
|
lit.add(el);
|
|
4623
|
+
raise(el);
|
|
4617
4624
|
}
|
|
4618
4625
|
if (next === Infinity)
|
|
4619
4626
|
return end();
|
|
@@ -11262,7 +11269,9 @@ function renderCircle(doc, options = {}) {
|
|
|
11262
11269
|
const title = svg(doc, "title");
|
|
11263
11270
|
title.textContent = chord ? `${chord.numeral}: ${name}` : name.replace("/", " or ");
|
|
11264
11271
|
cell.appendChild(title);
|
|
11265
|
-
g
|
|
11272
|
+
const slot = svg(doc, "g", { class: "mn-circle-slot", "data-mn-raise": "" });
|
|
11273
|
+
slot.appendChild(cell);
|
|
11274
|
+
g.appendChild(slot);
|
|
11266
11275
|
const mid = (outer + inner) / 2;
|
|
11267
11276
|
const solid = mark === " mn-circle-tonic" || mark === " mn-circle-neighbour";
|
|
11268
11277
|
const textClass = `mn-circle-label mn-circle-label-${ring}${solid ? " mn-circle-on" : ""}`;
|
|
@@ -11273,7 +11282,7 @@ function renderCircle(doc, options = {}) {
|
|
|
11273
11282
|
lines.forEach((line, i) => {
|
|
11274
11283
|
const [x, y] = point(mid, position * 30, top);
|
|
11275
11284
|
const isNumeral = chord !== undefined && i === lines.length - 1;
|
|
11276
|
-
|
|
11285
|
+
slot.appendChild(svgText(doc, line, {
|
|
11277
11286
|
class: isNumeral ? `${textClass} mn-circle-numeral` : textClass,
|
|
11278
11287
|
x,
|
|
11279
11288
|
y: y + 4 + (i - (lines.length - 1) / 2) * step,
|
|
@@ -12360,6 +12369,8 @@ var RENDERERS = {
|
|
|
12360
12369
|
// src/blocks/properties.ts
|
|
12361
12370
|
var DEFAULT_PROPERTY_NAMES = {
|
|
12362
12371
|
chordSymbol: "chord_symbol",
|
|
12372
|
+
chordRoot: "chord_root",
|
|
12373
|
+
chordQuality: "chord_quality",
|
|
12363
12374
|
frets: "frets",
|
|
12364
12375
|
fingers: "fingers",
|
|
12365
12376
|
position: "position",
|
|
@@ -12427,9 +12438,16 @@ function cagedShape(value) {
|
|
|
12427
12438
|
return m ? m[1].toUpperCase() : null;
|
|
12428
12439
|
}
|
|
12429
12440
|
function chordOf2(properties, names) {
|
|
12430
|
-
const value = first(properties[names.chordSymbol]);
|
|
12441
|
+
const value = first(properties[names.chordSymbol]) || rootAndQuality(properties, names);
|
|
12431
12442
|
return value ? readChord(value)?.symbol ?? null : null;
|
|
12432
12443
|
}
|
|
12444
|
+
function rootAndQuality(properties, names) {
|
|
12445
|
+
const root = first(properties[names.chordRoot]);
|
|
12446
|
+
if (!root)
|
|
12447
|
+
return "";
|
|
12448
|
+
const quality = first(properties[names.chordQuality]).replace(/\([^)]*\)/g, "").trim();
|
|
12449
|
+
return quality ? `${root} ${quality}` : root;
|
|
12450
|
+
}
|
|
12433
12451
|
function arpeggioSource(language, properties, names, instrument) {
|
|
12434
12452
|
const kind = kindOf(properties, names);
|
|
12435
12453
|
const guitar = instrument !== "piano";
|
|
@@ -12496,7 +12514,7 @@ function blockFromProperties(language, properties, options = {}) {
|
|
|
12496
12514
|
if (language === "picking")
|
|
12497
12515
|
return pickingSource(properties, names);
|
|
12498
12516
|
if (language === "chord") {
|
|
12499
|
-
const symbol = get(names.chordSymbol);
|
|
12517
|
+
const symbol = get(names.chordSymbol) ?? chordOf2(properties, names) ?? undefined;
|
|
12500
12518
|
if (symbol)
|
|
12501
12519
|
lines.push(`symbol: ${symbol}`);
|
|
12502
12520
|
if (instrument === "piano") {
|
|
@@ -13566,5 +13584,5 @@ export {
|
|
|
13566
13584
|
renderAll
|
|
13567
13585
|
};
|
|
13568
13586
|
|
|
13569
|
-
//# debugId=
|
|
13587
|
+
//# debugId=E12FEC1174ED9FAD64756E2164756E21
|
|
13570
13588
|
//# sourceMappingURL=index.js.map
|