@dsebastien/music-notation 0.7.0 → 0.8.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.
Files changed (48) hide show
  1. package/README.md +28 -2
  2. package/dist/blocks/note-set-field.d.ts +3 -1
  3. package/dist/blocks/progression.d.ts +6 -0
  4. package/dist/blocks/renderers.d.ts +10 -1
  5. package/dist/blocks/scales-for.d.ts +16 -0
  6. package/dist/chord/capo.d.ts +26 -0
  7. package/dist/chord/guitar.d.ts +20 -0
  8. package/dist/chord/transitions.d.ts +15 -7
  9. package/dist/chords/chart-diagrams.d.ts +46 -0
  10. package/dist/chords/chart.d.ts +16 -0
  11. package/dist/chords/chordpro.d.ts +17 -1
  12. package/dist/chords/defines.d.ts +38 -0
  13. package/dist/circle/circle.d.ts +21 -0
  14. package/dist/cli.js +2 -2
  15. package/dist/convert/text-tab.d.ts +4 -2
  16. package/dist/fretboard/fretboard.d.ts +11 -0
  17. package/dist/fretboard/positions.d.ts +12 -5
  18. package/dist/index.d.ts +20 -5
  19. package/dist/index.js +5946 -1923
  20. package/dist/index.js.map +39 -22
  21. package/dist/keyboard/keyboard.d.ts +2 -0
  22. package/dist/keyboard/piano-chord.d.ts +44 -0
  23. package/dist/keyboard/voice-leading.d.ts +6 -0
  24. package/dist/music-notation.css +339 -0
  25. package/dist/music-notation.publish.min.js +362 -21
  26. package/dist/music-notation.tab.min.js +343 -4
  27. package/dist/playback/controls.d.ts +10 -1
  28. package/dist/playback/follow.d.ts +45 -0
  29. package/dist/playback/player.d.ts +13 -1
  30. package/dist/playback/strum-bar.d.ts +5 -0
  31. package/dist/publish/index.js +5271 -1852
  32. package/dist/publish/index.js.map +38 -21
  33. package/dist/strum/pattern.d.ts +49 -0
  34. package/dist/strum/play.d.ts +106 -0
  35. package/dist/strum/render.d.ts +17 -0
  36. package/dist/strum/voicing.d.ts +10 -0
  37. package/dist/tab/index.js +334 -78
  38. package/dist/tab/index.js.map +7 -7
  39. package/dist/theory/chord-symbol.d.ts +2 -0
  40. package/dist/theory/find.d.ts +82 -0
  41. package/dist/theory/keys.d.ts +79 -0
  42. package/dist/theory/note-set.d.ts +2 -0
  43. package/dist/theory/numerals.d.ts +40 -0
  44. package/dist/theory/pitch.d.ts +4 -1
  45. package/dist/theory/transpose.d.ts +16 -4
  46. package/dist/voicings/index.js +58 -14
  47. package/dist/voicings/index.js.map +5 -5
  48. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
- /*! @dsebastien/music-notation 0.7.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
2
- (()=>{var q=(t,e)=>{for(let[a,r]of Object.entries(e))if(r!==void 0)t.setAttribute(a,String(r))};function C(t,e,a={},r=[]){let o=t.createElementNS("http://www.w3.org/2000/svg",e);q(o,a);for(let n of r)if(n)o.appendChild(n);return o}function w(t,e,a,r){let o=t.createElement(e);if(a)o.className=a;if(r!==void 0)o.textContent=r;return o}var _="1.8.4",P=(t=_)=>{let e=`https://cdn.jsdelivr.net/npm/@coderline/alphatab@${t}/dist`;return{script:`${e}/alphaTab.min.js`,font:`${e}/font/Bravura.woff2`,soundFont:`${e}/soundfont/sonivox.sf3`}},K=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function Y(t,e){let a=e.split(/\r?\n/),r={staves:t,file:null,tracks:null,tex:"",texLine:0},o=0;for(;o<a.length;o++){let n=a[o];if(!n.trim()||/^\s*\/\//.test(n))continue;let s=K.exec(n);if(!s)break;let c=s[1].toLowerCase(),p=s[2].trim();if(c==="staves"){let i=p.toLowerCase();if(i!=="tab"&&i!=="score"&&i!=="both")throw Error(`staves: use tab, score or both, got "${p}"`);r.staves=i}else if(c==="file")r.file=p.replace(/^!?\[\[|\]\]$/g,"").split(/[|#]/)[0].trim()||null;else{let i=p.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 "${p}"`);r.tracks=i}}while(o<a.length&&!a[o].trim())o++;if(r.texLine=o,r.tex=a.slice(o).join(`
3
- `).trimEnd(),!r.file&&!r.tex)throw Error("Write the music in alphaTex, or give a file: [[Song.gp]]");return r}function J(t,e){let a=t?.cause??t;for(let r of["lexerDiagnostics","parserDiagnostics","semanticDiagnostics"]){let o=a?.[r]?.items;if(!Array.isArray(o))continue;let n=o.find((s)=>s.severity===2&&s.message);if(n)return`${n.start?`line ${n.start.line+e}, column ${n.start.col}: `:""}${n.message}`}return t instanceof Error?t.message:String(t)}var Q={tab:"Tab",score:"Score",both:"ScoreTab"};function V(t,e,a=1){let r=t.createElement("canvas");r.width=1,r.height=1;let o=r.getContext("2d",{willReadFrequently:!0});if(!o)return null;o.fillStyle="#000",o.fillStyle=e,o.fillRect(0,0,1,1);let n=o.getImageData(0,0,1,1).data;if(n.length<4)return null;return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${(n[3]/255*a).toFixed(3)})`}function X(t){let e=t.ownerDocument,a=e.defaultView?.getComputedStyle(t).color||"",r=a&&V(e,a)||(/^rgba?\(/.test(a)?a:"rgba(0, 0, 0, 1)"),o=a&&V(e,a,0.6)||r;return{mainGlyphColor:r,secondaryGlyphColor:o,scoreInfoColor:r,staffLineColor:o,barSeparatorColor:r,barNumberColor:o}}var N=(t)=>{let e=t.defaultView??globalThis;return{map:(a)=>new e.Map(a),bytes:(a)=>{let r=new e.Uint8Array(a.length);return r.set(a),r}}},Z={play:"M4 2.5v11l9-5.5z",pause:"M4 3h3v10H4zM9 3h3v10H9z",stop:"M4 4h8v8H4z",loop:"M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",metronome:"M6 2h4l3 12H3zM8 11l3-7",countIn:"M3 13h10M5 13V9M8 13V6M11 13V3",volume:"M2 6h3l4-3v10l-4-3H2zM11 5.5a3.5 3.5 0 0 1 0 5"};function E(t,e){let r=C(t,"svg",{class:`mn-play-icon${e==="play"||e==="pause"||e==="stop"?"":" mn-play-icon-loop"}`,viewBox:"0 0 16 16",width:12,height:12,"aria-hidden":"true"});return r.appendChild(C(t,"path",{d:Z[e]})),r}var R=(t)=>{let e=Math.max(0,Math.round(t/1000));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`};function ee(t,e,a,r){let o=w(t,"div","mn-play mn-tab-bar");o.setAttribute("role","group"),o.setAttribute("aria-label","Playback");let n={loop:!1,metronome:!1,countIn:!1,speed:1,volume:1},s=null,c=null,p=()=>(s??=new Promise((l)=>{if(e.playerReady.on(()=>l(!0)),c=()=>l(!1),e.settings.player.playerMode=a.PlayerMode.EnabledSynthesizer,e.settings.player.enableCursor=!0,typeof r.soundFont==="string")e.settings.player.soundFont=r.soundFont;if(e.updateSettings(),r.soundFont instanceof Uint8Array)e.loadSoundFont(N(t).bytes(r.soundFont),!1)}).then((l)=>{if(l)e.isLooping=n.loop,e.metronomeVolume=n.metronome?1:0,e.countInVolume=n.countIn?1:0,e.playbackSpeed=n.speed,e.masterVolume=n.volume;return l}),s),i=(l,g,y)=>{let d=w(t,"button");return d.type="button",d.title=g,d.setAttribute("aria-label",g),d.appendChild(E(t,l)),d.addEventListener("click",y),o.appendChild(d),d},u=(l)=>{if(e.player)l()},f=(l,g,y)=>{let d=i(l,g,()=>{n[y]=!n[y],u(()=>{e.isLooping=n.loop,e.metronomeVolume=n.metronome?1:0,e.countInVolume=n.countIn?1:0}),d.classList.toggle("mn-on",n[y]),d.setAttribute("aria-pressed",String(n[y]))});d.setAttribute("aria-pressed","false")},m=i("play","Play",()=>{p().then((l)=>{if(l)e.playPause()})});i("stop","Stop",()=>u(()=>e.stop())),f("loop","Loop","loop"),f("metronome","Metronome","metronome"),f("countIn","Count-in","countIn");let b=(l,g,y,d,v,k,x="")=>{let T=w(t,"label","mn-play-field"),S=w(t,"span","mn-play-label");S.setAttribute("aria-hidden","true"),S.append(g);let A=w(t,"input");A.type="range",A.min=String(y),A.max=String(d),A.value=String(v),A.setAttribute("aria-label",l),T.title=`${l}: ${v}${x}`,A.addEventListener("input",()=>{k(Number(A.value)),T.title=`${l}: ${A.value}${x}`}),T.append(S,A),o.appendChild(T)};b("Speed","%",25,150,100,(l)=>{n.speed=l/100,u(()=>e.playbackSpeed=n.speed)},"%"),b("Volume",E(t,"volume"),0,100,100,(l)=>{n.volume=l/100,u(()=>e.masterVolume=n.volume)});let h=w(t,"span","mn-tab-time","");return o.appendChild(h),e.playerStateChanged.on((l)=>{let g=Number(l.state)===Number(a.synth.PlayerState.Playing);m.replaceChildren(E(t,g?"pause":"play")),m.title=g?"Pause":"Play",m.setAttribute("aria-label",m.title)}),e.playerPositionChanged.on((l)=>{h.textContent=`${R(l.currentTime)} / ${R(l.endTime)}`}),{bar:o,failed:(l)=>{c?.(),m.disabled=!0,m.title=`Can't play: ${l}`,m.setAttribute("aria-label",m.title)}}}function O(t,e,a,r){let o=a.ownerDocument,n=w(o,"div",`mn-block mn-block-${t} mn-tab`);a.appendChild(n);let s=null,c=!1,p=!1,i=()=>{},u=new Promise((m)=>{i=(b)=>{if(p)return;p=!0,m(b)}}),f=(m)=>{n.replaceChildren(w(o,"div","mn-error-message",`${t}: ${m}`)),n.classList.add("mn-error"),i({ok:!1,error:m})};if(!e.trim())n.classList.add("mn-empty"),i({ok:!0,error:null});else(async()=>{await Promise.resolve();let m=Y(t,e),b=r.alphaTab;if(!b?.AlphaTabApi)throw Error("alphaTab isn't loaded");let h=w(o,"div","mn-tab-surface");n.appendChild(h);let{assets:l}=r,g=N(o),y={core:{useWorkers:Boolean(l.scriptFile),...l.scriptFile?{scriptFile:l.scriptFile}:{},smuflFontSources:g.map([[b.FontFileFormat.Woff2,l.font]]),logLevel:b.LogLevel.Warning},display:{staveProfile:Q[m.staves],resources:X(n)},player:{playerMode:b.PlayerMode.Disabled,enableUserInteraction:!0}},d=new b.AlphaTabApi(h,y);if(s=d,c){d.destroy();return}r.onApi?.(d);let v=null;d.renderFinished.on(()=>{if(p||c)return;if(r.player!==!1)v=ee(o,d,b,l),n.appendChild(v.bar),n.addEventListener("pointerdown",(x)=>{if(x.pointerType!=="touch"||v?.bar.contains(x.target))return;n.classList.toggle("mn-play-open")});i({ok:!0,error:null})}),d.error.on((x)=>{let T=J(x,m.texLine);if(p)v?.failed(T);else f(T)});let k=m.tracks?.map((x)=>x-1);if(m.file){let x;try{x=r.resolveFile?await r.resolveFile(m.file):null}catch(S){throw Error(`Couldn't read "${m.file}": ${S instanceof Error?S.message:String(S)}`)}if(c)return;if(!x)throw Error(`Couldn't find the file "${m.file}"`);if(!d.load(g.bytes(x),k))throw Error(`Couldn't read "${m.file}": not a score file alphaTab knows`)}else d.tex(m.tex,k??"all")})().catch((m)=>{if(!c)f(m instanceof Error?m.message:String(m))});return{el:n,ready:u,get api(){return s},destroy(){c=!0;try{s?.destroy()}catch{}n.remove(),i({ok:!1,error:null})}}}var F={guitar:25,piano:0};function te(t,e){return{play(a,{sound:r,volume:o,onEnd:n}){let s=e(),c=s?.player;if(!s||!c)throw Error("The soundfont player is not ready");let p=new t.midi.MidiFile,i=new t.midi.AlphaSynthMidiFileHandler(p,!0),u=(h)=>Math.round(h*p.division);i.addTempo(0,60),i.addProgramChange(0,0,0,F[r]);let f=Number.isFinite(o)?Math.min(1,Math.max(0,o)):0.8;s.masterVolume=f;for(let h of a)i.addNote(0,u(h.time),Math.max(1,u(h.duration)),h.midi,100,0);let m=Math.max(...a.map((h)=>h.time+h.duration),0);s.playbackSpeed=1,c.playOneTimeMidiFile(p);let b=setTimeout(()=>n?.(),(m+0.2)*1000);return{stop(){clearTimeout(b),c.stop()}}}}}function I(t,e,a,r){let o=null,n=null,s=null,c=()=>{if(s)return s;n=w(a,"div","mn-tab-hidden"),n.setAttribute("aria-hidden","true"),a.body.appendChild(n);let i=N(a);o=new t.AlphaTabApi(n,{core:{useWorkers:Boolean(e.scriptFile),...e.scriptFile?{scriptFile:e.scriptFile}:{},smuflFontSources:i.map([[t.FontFileFormat.Woff2,e.font]])},player:{playerMode:t.PlayerMode.EnabledSynthesizer,...typeof e.soundFont==="string"?{soundFont:e.soundFont}:{}}});let u=o;if(s=new Promise((f)=>{let m=!1,b=!u.playerReady,h=()=>{if(m&&b)f(!0)};u.soundFontLoaded.on(()=>{m=!0,h(),setTimeout(()=>{b=!0,h()},4000)}),u.playerReady?.on(()=>{b=!0,h()}),u.error.on(()=>f(!1))}),e.soundFont instanceof Uint8Array)u.loadSoundFont(i.bytes(e.soundFont),!1);return u.tex(`\\track "Guitar" \\instrument ${F.guitar} r \\track "Piano" \\instrument ${F.piano} r`),s},p=te(t,()=>o);return{play(i,u){let f=null,m=!1;return c().then((b)=>{if(m)return;try{if(b){f=p.play(i,u);return}}catch{}if(r)f=r.play(i,u)}),{stop(){m=!0,f?.stop()}}},destroy(){try{o?.destroy()}catch{}n?.remove(),o=null,s=null}}}var D=`/* Music notation. Colors follow Obsidian's theme variables when present, with fallbacks for any page. */
1
+ /*! @dsebastien/music-notation 0.8.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
2
+ (()=>{var K=(n,e)=>{for(let[a,t]of Object.entries(e))if(t!==void 0)n.setAttribute(a,String(t))};function F(n,e,a={},t=[]){let r=n.createElementNS("http://www.w3.org/2000/svg",e);K(r,a);for(let o of t)if(o)r.appendChild(o);return r}function A(n,e,a,t){let r=n.createElement(e);if(a)r.className=a;if(t!==void 0)r.textContent=t;return r}var Y="1.8.4",L=(n=Y)=>{let e=`https://cdn.jsdelivr.net/npm/@coderline/alphatab@${n}/dist`;return{script:`${e}/alphaTab.min.js`,font:`${e}/font/Bravura.woff2`,soundFont:`${e}/soundfont/sonivox.sf3`}},J=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function Q(n,e){let a=e.split(/\r?\n/),t={staves:n,file:null,tracks:null,tex:"",texLine:0},r=0;for(;r<a.length;r++){let o=a[r];if(!o.trim()||/^\s*\/\//.test(o))continue;let i=J.exec(o);if(!i)break;let u=i[1].toLowerCase(),d=i[2].trim();if(u==="staves"){let l=d.toLowerCase();if(l!=="tab"&&l!=="score"&&l!=="both")throw Error(`staves: use tab, score or both, got "${d}"`);t.staves=l}else if(u==="file")t.file=d.replace(/^!?\[\[|\]\]$/g,"").split(/[|#]/)[0].trim()||null;else{let l=d.split(/[\s,]+/).filter(Boolean).map(Number);if(!l.length||l.some((s)=>!Number.isInteger(s)||s<1))throw Error(`tracks: use track numbers from 1, got "${d}"`);t.tracks=l}}while(r<a.length&&!a[r].trim())r++;if(t.texLine=r,t.tex=a.slice(r).join(`
3
+ `).trimEnd(),!t.file&&!t.tex)throw Error("Write the music in alphaTex, or give a file: [[Song.gp]]");return t}function X(n,e){let a=n?.cause??n;for(let t of["lexerDiagnostics","parserDiagnostics","semanticDiagnostics"]){let r=a?.[t]?.items;if(!Array.isArray(r))continue;let o=r.find((i)=>i.severity===2&&i.message);if(o)return`${o.start?`line ${o.start.line+e}, column ${o.start.col}: `:""}${o.message}`}return n instanceof Error?n.message:String(n)}var Z=0;function ee(n,e){for(let a of e.tracks)for(let t of a.staves){if(t.isPercussion)for(let o of t.bars??[])o.clef=Z;let r=!t.isPercussion&&t.tuning.length>0;if(n==="both"){t.showStandardNotation=!0,t.showTablature=r;continue}t.showSlash=!1,t.showNumbered=!1,t.showTablature=n==="tab"&&r,t.showStandardNotation=!t.showTablature}}function R(n,e,a=1){let t=n.createElement("canvas");t.width=1,t.height=1;let r=t.getContext("2d",{willReadFrequently:!0});if(!r)return null;r.fillStyle="#000",r.fillStyle=e,r.fillRect(0,0,1,1);let o=r.getImageData(0,0,1,1).data;if(o.length<4)return null;return`rgba(${o[0]}, ${o[1]}, ${o[2]}, ${(o[3]/255*a).toFixed(3)})`}function ne(n){let e=n.ownerDocument,a=e.defaultView?.getComputedStyle(n).color||"",t=a&&R(e,a)||(/^rgba?\(/.test(a)?a:"rgba(0, 0, 0, 1)"),r=a&&R(e,a,0.6)||t;return{mainGlyphColor:t,secondaryGlyphColor:r,scoreInfoColor:t,staffLineColor:r,barSeparatorColor:t,barNumberColor:r}}var V=(n)=>{let e=n.defaultView??globalThis;return{map:(a)=>new e.Map(a),bytes:(a)=>{let t=new e.Uint8Array(a.length);return t.set(a),t}}},te={play:"M4 2.5v11l9-5.5z",pause:"M4 3h3v10H4zM9 3h3v10H9z",stop:"M4 4h8v8H4z",loop:"M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",metronome:"M6 2h4l3 12H3zM8 11l3-7",countIn:"M3 13h10M5 13V9M8 13V6M11 13V3",volume:"M2 6h3l4-3v10l-4-3H2zM11 5.5a3.5 3.5 0 0 1 0 5"};function P(n,e){let t=F(n,"svg",{class:`mn-play-icon${e==="play"||e==="pause"||e==="stop"?"":" mn-play-icon-loop"}`,viewBox:"0 0 16 16",width:12,height:12,"aria-hidden":"true"});return t.appendChild(F(n,"path",{d:te[e]})),t}var O=(n)=>{let e=Math.max(0,Math.round(n/1000));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`};function oe(n,e,a,t){let r=A(n,"div","mn-play mn-tab-bar");r.setAttribute("role","group"),r.setAttribute("aria-label","Playback");let o={loop:!1,metronome:!1,countIn:!1,speed:1,volume:1},i=null,u=null,d=()=>(i??=new Promise((c)=>{if(e.playerReady.on(()=>c(!0)),u=()=>c(!1),e.settings.player.playerMode=a.PlayerMode.EnabledSynthesizer,e.settings.player.enableCursor=!0,typeof t.soundFont==="string")e.settings.player.soundFont=t.soundFont;if(e.updateSettings(),t.soundFont instanceof Uint8Array)e.loadSoundFont(V(n).bytes(t.soundFont),!1)}).then((c)=>{if(c)e.isLooping=o.loop,e.metronomeVolume=o.metronome?1:0,e.countInVolume=o.countIn?1:0,e.playbackSpeed=o.speed,e.masterVolume=o.volume;return c}),i),l=(c,p,k)=>{let f=A(n,"button");return f.type="button",f.title=p,f.setAttribute("aria-label",p),f.appendChild(P(n,c)),f.addEventListener("click",k),r.appendChild(f),f},s=(c)=>{if(e.player)c()},g=(c,p,k)=>{let f=l(c,p,()=>{o[k]=!o[k],s(()=>{e.isLooping=o.loop,e.metronomeVolume=o.metronome?1:0,e.countInVolume=o.countIn?1:0}),f.classList.toggle("mn-on",o[k]),f.setAttribute("aria-pressed",String(o[k]))});f.setAttribute("aria-pressed","false")},m=l("play","Play",()=>{d().then((c)=>{if(c)e.playPause()})});l("stop","Stop",()=>s(()=>e.stop())),g("loop","Loop","loop"),g("metronome","Metronome","metronome"),g("countIn","Count-in","countIn");let h=(c,p,k,f,S,y,b="")=>{let T=A(n,"label","mn-play-field"),v=A(n,"span","mn-play-label");v.setAttribute("aria-hidden","true"),v.append(p);let x=A(n,"input");x.type="range",x.min=String(k),x.max=String(f),x.value=String(S),x.setAttribute("aria-label",c),T.title=`${c}: ${S}${b}`,x.addEventListener("input",()=>{y(Number(x.value)),T.title=`${c}: ${x.value}${b}`}),T.append(v,x),r.appendChild(T)};h("Speed","%",25,150,100,(c)=>{o.speed=c/100,s(()=>e.playbackSpeed=o.speed)},"%"),h("Volume",P(n,"volume"),0,100,100,(c)=>{o.volume=c/100,s(()=>e.masterVolume=o.volume)});let w=A(n,"span","mn-tab-time","");return r.appendChild(w),e.playerStateChanged.on((c)=>{let p=Number(c.state)===Number(a.synth.PlayerState.Playing);m.replaceChildren(P(n,p?"pause":"play")),m.title=p?"Pause":"Play",m.setAttribute("aria-label",m.title)}),e.playerPositionChanged.on((c)=>{w.textContent=`${O(c.currentTime)} / ${O(c.endTime)}`}),{bar:r,failed:(c)=>{u?.(),m.disabled=!0,m.title=`Can't play: ${c}`,m.setAttribute("aria-label",m.title)}}}function D(n,e,a,t){let r=a.ownerDocument,o=A(r,"div",`mn-block mn-block-${n} mn-tab`);a.appendChild(o);let i=null,u=!1,d=!1,l=()=>{},s=new Promise((m)=>{l=(h)=>{if(d)return;d=!0,m(h)}}),g=(m)=>{o.replaceChildren(A(r,"div","mn-error-message",`${n}: ${m}`)),o.classList.add("mn-error"),l({ok:!1,error:m})};if(!e.trim())o.classList.add("mn-empty"),l({ok:!0,error:null});else(async()=>{await Promise.resolve();let m=Q(n,e),h=t.alphaTab;if(!h?.AlphaTabApi)throw Error("alphaTab isn't loaded");let w=A(r,"div","mn-tab-surface");o.appendChild(w);let{assets:c}=t,p=V(r),k={core:{useWorkers:Boolean(c.scriptFile),...c.scriptFile?{scriptFile:c.scriptFile}:{},smuflFontSources:p.map([[h.FontFileFormat.Woff2,c.font]]),logLevel:h.LogLevel.Warning},display:{staveProfile:"Default",resources:ne(o)},player:{playerMode:h.PlayerMode.Disabled,enableUserInteraction:!0}},f=new h.AlphaTabApi(w,k);if(i=f,u){f.destroy();return}t.onApi?.(f),f.scoreLoaded.on((b)=>{ee(m.staves,b)});let S=null;f.renderFinished.on(()=>{if(d||u)return;if(t.player!==!1)S=oe(r,f,h,c),o.appendChild(S.bar),o.addEventListener("pointerdown",(b)=>{if(b.pointerType!=="touch"||S?.bar.contains(b.target))return;o.classList.toggle("mn-play-open")});l({ok:!0,error:null})}),f.error.on((b)=>{let T=X(b,m.texLine);if(d)S?.failed(T);else g(T)});let y=m.tracks?.map((b)=>b-1);if(m.file){let b;try{b=t.resolveFile?await t.resolveFile(m.file):null}catch(v){throw Error(`Couldn't read "${m.file}": ${v instanceof Error?v.message:String(v)}`)}if(u)return;if(!b)throw Error(`Couldn't find the file "${m.file}"`);if(!f.load(p.bytes(b),y))throw Error(`Couldn't read "${m.file}": not a score file alphaTab knows`)}else f.tex(m.tex,y??"all")})().catch((m)=>{if(!u)g(m instanceof Error?m.message:String(m))});return{el:o,ready:s,get api(){return i},destroy(){u=!0;try{i?.destroy()}catch{}o.remove(),l({ok:!1,error:null})}}}var N={guitar:25,piano:0};function re(n,e){return{reportsStart:!0,play(a,{sound:t,volume:r,onEnd:o,onStart:i}){let u=e(),d=u?.player;if(!u||!d)throw Error("The soundfont player is not ready");let l=new n.midi.MidiFile,s=new n.midi.AlphaSynthMidiFileHandler(l,!0),g=(p)=>Math.round(p*l.division);s.addTempo(0,60),s.addProgramChange(0,0,0,N[t]);let m=Number.isFinite(r)?Math.min(1,Math.max(0,r)):0.8;u.masterVolume=m;for(let p of a){let k=p.velocity===void 0||!Number.isFinite(p.velocity)?100:Math.round(Math.min(127,Math.max(1,p.velocity)));s.addNote(0,g(p.time),Math.max(1,g(p.duration)),p.midi,k,0)}let h=Math.max(...a.map((p)=>p.time+p.duration),0);u.playbackSpeed=1,d.playOneTimeMidiFile(l);let w=!1;queueMicrotask(()=>{if(!w)i?.()});let c=setTimeout(()=>o?.(),(h+0.2)*1000);return{stop(){w=!0,clearTimeout(c),d.stop()}}}}}function I(n,e,a,t){let r=null,o=null,i=null,u=()=>{if(i)return i;o=A(a,"div","mn-tab-hidden"),o.setAttribute("aria-hidden","true"),a.body.appendChild(o);let l=V(a);r=new n.AlphaTabApi(o,{core:{useWorkers:Boolean(e.scriptFile),...e.scriptFile?{scriptFile:e.scriptFile}:{},smuflFontSources:l.map([[n.FontFileFormat.Woff2,e.font]])},player:{playerMode:n.PlayerMode.EnabledSynthesizer,...typeof e.soundFont==="string"?{soundFont:e.soundFont}:{}}});let s=r;if(i=new Promise((g)=>{let m=!1,h=!s.playerReady,w=()=>{if(m&&h)g(!0)};s.soundFontLoaded.on(()=>{m=!0,w(),setTimeout(()=>{h=!0,w()},4000)}),s.playerReady?.on(()=>{h=!0,w()}),s.error.on(()=>g(!1))}),e.soundFont instanceof Uint8Array)s.loadSoundFont(l.bytes(e.soundFont),!1);return s.tex(`\\track "Guitar" \\instrument ${N.guitar} r \\track "Piano" \\instrument ${N.piano} r`),i},d=re(n,()=>r);return{reportsStart:!0,play(l,s){let g=null,m=!1;return u().then((h)=>{if(m)return;try{if(h){g=d.play(l,s);return}}catch{}if(!t)return;if(g=t.play(l,s),!t.reportsStart)s.onStart?.()}),{stop(){m=!0,g?.stop()}}},destroy(){try{r?.destroy()}catch{}o?.remove(),r=null,i=null}}}var G=`/* Music notation. Colors follow Obsidian's theme variables when present, with fallbacks for any page. */
4
4
  .mn-block,
5
5
  .mn-svg,
6
6
  .mn-chart {
@@ -14,6 +14,9 @@
14
14
  --mn-root: #c2410c;
15
15
  /* A mode's characteristic notes: dark enough for white labels too. */
16
16
  --mn-char: #047857;
17
+ /* A note that sounds while a diagram plays: bright, with dark labels, in both themes. */
18
+ --mn-playing: #facc15;
19
+ --mn-on-playing: #1c1917;
17
20
  /* Piano keys keep their real colors in every theme. */
18
21
  --mn-key-white: #fafafa;
19
22
  --mn-key-black: #222;
@@ -273,6 +276,31 @@
273
276
  pointer-events: auto;
274
277
  }
275
278
 
279
+ /* alphaTab's cursor (the bar that plays, the beat line) and the notes of the beat that sounds, in
280
+ the player bar's accent color: alphaTab ships no style for them, so they didn't show. */
281
+ .mn-tab .at-cursor-bar {
282
+ background: color-mix(in srgb, var(--mn-accent) 12%, transparent);
283
+ }
284
+
285
+ .mn-tab .at-cursor-beat {
286
+ background: var(--mn-accent);
287
+ }
288
+
289
+ .mn-tab .at-selection div {
290
+ background: color-mix(in srgb, var(--mn-accent) 15%, transparent);
291
+ }
292
+
293
+ .mn-tab .at-highlight,
294
+ .mn-tab .at-highlight * {
295
+ fill: var(--mn-accent);
296
+ stroke: var(--mn-accent);
297
+ }
298
+
299
+ /* alphaTab's outlined rectangles stay hollow. */
300
+ .mn-tab .at-highlight [fill='transparent'] {
301
+ fill: transparent;
302
+ }
303
+
276
304
  .mn-tab-time {
277
305
  font-variant-numeric: tabular-nums;
278
306
  opacity: 0.8;
@@ -337,6 +365,27 @@
337
365
  stroke: var(--mn-root);
338
366
  }
339
367
 
368
+ /* A capo: a bar across the strings, in the text color but lighter than the dots. */
369
+ .mn-svg .mn-capo {
370
+ fill: var(--mn-fg);
371
+ opacity: 0.55;
372
+ }
373
+
374
+ /* A string the capo plays (frets counted from the nut): a ring on the capo. */
375
+ .mn-svg .mn-capo-open {
376
+ fill: var(--mn-bg);
377
+ stroke: var(--mn-fg);
378
+ stroke-width: 1.5;
379
+ }
380
+
381
+ .mn-svg .mn-capo-open.mn-root {
382
+ stroke: var(--mn-root);
383
+ }
384
+
385
+ .mn-svg .mn-caption {
386
+ fill: var(--mn-muted);
387
+ }
388
+
340
389
  .mn-svg .mn-muted,
341
390
  .mn-svg .mn-base-fret,
342
391
  .mn-svg .mn-fret-number,
@@ -387,6 +436,17 @@
387
436
  font-weight: 600;
388
437
  }
389
438
 
439
+ /* Which hand plays each key of a piano chord (hands: left+right): L or R under the keys. */
440
+ .mn-svg .mn-key-hand {
441
+ font-size: 10px;
442
+ font-weight: 600;
443
+ fill: var(--mn-muted);
444
+ }
445
+
446
+ .mn-svg .mn-key-hand.mn-hand-left {
447
+ fill: var(--mn-fg);
448
+ }
449
+
390
450
  /* Several diagrams in one block: a row that wraps, or a grid of at most \`columns\` columns that
391
451
  also wraps on narrow screens rather than shrinking diagrams to nothing. */
392
452
  .mn-block .mn-row {
@@ -541,8 +601,287 @@
541
601
  white-space: pre;
542
602
  }
543
603
 
604
+ /* A chart's chord diagrams: the chords used row (wraps like a block's row) and {chord} in place. */
605
+ .mn-chart-diagrams {
606
+ margin: 0.75em 0;
607
+ }
608
+
609
+ .mn-chart .mn-chart-row {
610
+ display: flex;
611
+ flex-wrap: wrap;
612
+ align-items: flex-start;
613
+ gap: 0.75em 1.25em;
614
+ }
615
+
616
+ .mn-chart .mn-chart-row .mn-cell {
617
+ min-width: 0;
618
+ }
619
+
620
+ .mn-chart-diagrams-caption,
621
+ .mn-chart-diagrams-note {
622
+ color: var(--mn-muted);
623
+ font-size: 0.9em;
624
+ }
625
+
626
+ .mn-chart-diagrams-caption {
627
+ font-weight: 600;
628
+ margin-bottom: 0.3em;
629
+ }
630
+
631
+ .mn-chart-diagrams-note {
632
+ margin-top: 0.3em;
633
+ }
634
+
635
+ .mn-chart-chord {
636
+ margin: 0.4em 0;
637
+ }
638
+
544
639
  .mn-error-message {
545
640
  color: var(--text-error, #c92a2a);
546
641
  font-size: 0.9em;
547
642
  }
548
- `;var oe=D,G="music-notation-styles";function z(t){if(t.getElementById(G))return;let e=t.createElement("style");e.id=G,e.textContent=oe,t.head.appendChild(e)}var re=(t)=>t.reduce((e,a)=>Math.max(e,a.time+a.duration),0),U=(t)=>440*Math.pow(2,(t-69)/12);function ae(t,e,a,r=Math.random){let o=new Float32Array(Math.round(e*a)),n=Math.max(2,Math.round(e/U(t))),s=new Float32Array(n);for(let i=0;i<n;i++)s[i]=r()*2-1;let c=0.996+Math.min(0.0035,0.00004*(90-t)),p=0;for(let i=0;i<o.length;i++){let u=(p+1)%n,f=s[p];s[p]=c*0.5*(f+s[u]),o[i]=f*0.5,p=u}return o}var H=new WeakMap;function ie(t){let e=H.get(t);if(e)return e;let a=t.AudioContext;if(!a)return null;let r=new a;return H.set(t,r),r}var se=4,B=[0,1,0.5,0.3,0.15,0.08,0.04];function W(t){let e=new Map,a=new WeakMap,r=(n,s)=>{let c=e.get(s);if(!c){let p=ae(s,n.sampleRate,se);c=n.createBuffer(1,p.length,n.sampleRate),c.getChannelData(0).set(p),e.set(s,c)}return c},o=(n)=>{let s=a.get(n);if(!s){let c=new Float32Array(B.length);s=n.createPeriodicWave(c,Float32Array.from(B)),a.set(n,s)}return s};return{play(n,{sound:s,volume:c,onEnd:p}){let i=ie(t);if(!i||!n.length)return{stop(){}};if(i.resume(),s==="guitar")for(let l of n)r(i,l.midi);let u=i.createGain();u.gain.value=Number.isFinite(c)?Math.min(1,Math.max(0,c)):0.8,u.connect(i.destination);let f=i.currentTime+0.05,m=n.map((l)=>{let g=f+l.time,y=g+l.duration,d=i.createGain();d.connect(u);let v;if(s==="guitar"){let k=i.createBufferSource();k.buffer=r(i,l.midi),v=k,d.gain.setValueAtTime(1,y)}else{let k=i.createOscillator();k.setPeriodicWave(o(i)),k.frequency.value=U(l.midi),v=k,d.gain.setValueAtTime(0,g),d.gain.linearRampToValueAtTime(0.35,g+0.005),d.gain.exponentialRampToValueAtTime(0.02,Math.max(g+0.01,y))}return d.gain.linearRampToValueAtTime(0,y+0.08),v.connect(d),v.start(g),v.stop(y+0.1),v}),b=()=>u.disconnect(),h=t.setTimeout(()=>{b(),p?.()},(re(n)+0.15)*1000);return{stop(){t.clearTimeout(h);for(let l of m)try{l.stop()}catch{}b()}}}}}var le="pre > code.language-tab, pre > code.language-score",M=new Map,L=null;function me(t){let e=t.defaultView;if(e.alphaTab)return Promise.resolve(e.alphaTab);return L??=new Promise((a,r)=>{let o=t.createElement("script");o.src=P().script,o.onload=()=>e.alphaTab?a(e.alphaTab):r(Error("alphaTab")),o.onerror=()=>{L=null,r(Error("Couldn't load alphaTab"))},t.head.appendChild(o)}),L}function j(t){for(let[a,{result:r,holder:o}]of M)if(!a.isConnected||!r.el.isConnected){if(r.destroy(),o.remove(),M.delete(a),a.isConnected)a.style.removeProperty("display")}let e=[...t.querySelectorAll(le)].filter((a)=>{let r=a.parentElement,o=M.get(r);if(!o)return r.dataset.mpRendered!=="pending";if(o.source===(a.textContent??""))return!1;return o.result.destroy(),o.holder.remove(),M.delete(r),!0});if(!e.length)return;for(let a of e)a.parentElement.dataset.mpRendered="pending";me(t).then((a)=>{let r=P(),o={scriptFile:null,font:r.font,soundFont:r.soundFont},n=t.defaultView;n.musicNotationSoundfontPlayer??=I(a,o,t,W(n));for(let s of e){let c=s.parentElement;if(!c.parentElement)continue;let p=s.classList.contains("language-score")?"score":"tab",i=s.textContent??"",u=t.createElement("div");u.className="mn-tab-holder",c.insertAdjacentElement("afterend",u);let f=O(p,i,u,{alphaTab:a,assets:o});M.set(c,{result:f,source:i,holder:u}),f.ready.then(({ok:m})=>{if(c.dataset.mpRendered=m?"done":"error",m&&f.el.isConnected)c.style.display="none"})}}).catch(()=>{for(let a of e)a.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0;let t=()=>{z(document),j(document);let e=!1;new MutationObserver(()=>{if(e)return;e=!0,requestAnimationFrame(()=>{e=!1,j(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",t);else t()}})();
643
+
644
+ /* Strumming patterns: arrows and counts in the text color, accents and chords in the accent
645
+ color; ghost strums are smaller and in parentheses, so they don't rest on color alone. */
646
+ .mn-svg .mn-strum-arrow,
647
+ .mn-svg .mn-strum-mute {
648
+ stroke: var(--mn-fg);
649
+ stroke-width: 2;
650
+ stroke-linecap: round;
651
+ }
652
+
653
+ .mn-svg .mn-strum-head {
654
+ fill: var(--mn-fg);
655
+ stroke: none;
656
+ }
657
+
658
+ .mn-svg .mn-strum-arrow.mn-strum-accented,
659
+ .mn-svg .mn-strum-mute.mn-strum-accented {
660
+ stroke-width: 3;
661
+ }
662
+
663
+ .mn-svg .mn-strum-arrow.mn-strum-ghost,
664
+ .mn-svg .mn-strum-mute.mn-strum-ghost {
665
+ stroke: var(--mn-muted);
666
+ stroke-width: 1.5;
667
+ }
668
+
669
+ .mn-svg .mn-strum-head.mn-strum-ghost {
670
+ fill: var(--mn-muted);
671
+ }
672
+
673
+ .mn-svg .mn-strum-accent {
674
+ fill: none;
675
+ stroke: var(--mn-accent);
676
+ stroke-width: 1.8;
677
+ stroke-linecap: round;
678
+ stroke-linejoin: round;
679
+ }
680
+
681
+ .mn-svg .mn-strum-paren,
682
+ .mn-svg .mn-strum-count {
683
+ fill: var(--mn-muted);
684
+ }
685
+
686
+ .mn-svg .mn-strum-count-beat {
687
+ fill: var(--mn-fg);
688
+ font-weight: 600;
689
+ }
690
+
691
+ .mn-svg .mn-strum-chord {
692
+ fill: var(--mn-accent);
693
+ font-size: 12px;
694
+ font-weight: 700;
695
+ }
696
+
697
+ .mn-svg .mn-strum-line,
698
+ .mn-svg .mn-strum-tick {
699
+ stroke: var(--mn-muted);
700
+ stroke-width: 1;
701
+ }
702
+
703
+ .mn-svg .mn-strum-bar {
704
+ stroke: var(--mn-fg);
705
+ stroke-width: 1.5;
706
+ }
707
+
708
+ .mn-svg .mn-strum-cell {
709
+ fill: transparent;
710
+ stroke: none;
711
+ }
712
+
713
+ /* Following a strumming pattern: the slot that plays gets a band and its strum the playing
714
+ color (the band keeps it visible for a muted strum and in any theme). */
715
+ .mn-playable .mn-svg .mn-strum-slot.mn-playing .mn-strum-cell {
716
+ fill: color-mix(in srgb, var(--mn-playing) 35%, transparent);
717
+ }
718
+
719
+ .mn-playable .mn-svg .mn-strum-slot.mn-playing .mn-strum-arrow,
720
+ .mn-playable .mn-svg .mn-strum-slot.mn-playing .mn-strum-mute {
721
+ stroke: var(--mn-fg);
722
+ stroke-width: 3;
723
+ }
724
+
725
+ /* A chord over a scale (#48): chord tones solid, the scale's other notes hollow (passing notes), so
726
+ the difference doesn't rest on color alone. */
727
+ .mn-svg .mn-dot.mn-passing {
728
+ fill: var(--mn-bg);
729
+ stroke: var(--mn-accent);
730
+ stroke-width: 2;
731
+ }
732
+
733
+ .mn-svg .mn-dot.mn-passing.mn-root {
734
+ stroke: var(--mn-root);
735
+ }
736
+
737
+ .mn-svg .mn-dot.mn-passing + .mn-dot-text {
738
+ fill: var(--mn-fg);
739
+ }
740
+
741
+ .mn-svg .mn-key-white.mn-on.mn-passing {
742
+ fill: color-mix(in srgb, var(--mn-accent) 25%, var(--mn-key-white));
743
+ }
744
+
745
+ .mn-svg .mn-key-white.mn-on.mn-passing.mn-root {
746
+ fill: color-mix(in srgb, var(--mn-root) 25%, var(--mn-key-white));
747
+ }
748
+
749
+ .mn-svg .mn-key-black.mn-on.mn-passing {
750
+ fill: color-mix(in srgb, var(--mn-accent) 45%, var(--mn-key-black));
751
+ }
752
+
753
+ .mn-svg .mn-key-black.mn-on.mn-passing.mn-root {
754
+ fill: color-mix(in srgb, var(--mn-root) 45%, var(--mn-key-black));
755
+ }
756
+
757
+ /* Piano keys keep their colors in every theme: a light passing key takes dark text. */
758
+ .mn-svg .mn-key-white.mn-passing + .mn-key-label {
759
+ fill: var(--mn-key-black);
760
+ }
761
+
762
+ /* Progressions (#9): one column per chord (numeral, diagram or name, function). */
763
+ .mn-progression-title {
764
+ font-size: 1.1em;
765
+ font-weight: 700;
766
+ margin-bottom: 0.3em;
767
+ }
768
+
769
+ .mn-progression-section + .mn-progression-section,
770
+ .mn-progression-section-title {
771
+ margin-top: 0.75em;
772
+ }
773
+
774
+ .mn-progression-section-title {
775
+ font-weight: 600;
776
+ }
777
+
778
+ .mn-progression-key {
779
+ color: var(--mn-muted);
780
+ font-size: 0.85em;
781
+ margin-bottom: 0.3em;
782
+ }
783
+
784
+ .mn-block .mn-progression-chord {
785
+ display: flex;
786
+ flex-direction: column;
787
+ align-items: center;
788
+ text-align: center;
789
+ }
790
+
791
+ .mn-progression-numeral {
792
+ font-weight: 700;
793
+ font-size: 1.05em;
794
+ color: var(--mn-accent);
795
+ }
796
+
797
+ .mn-progression-name {
798
+ font-weight: 600;
799
+ min-width: 2.5em;
800
+ }
801
+
802
+ .mn-progression-function {
803
+ color: var(--mn-muted);
804
+ font-size: 0.8em;
805
+ }
806
+
807
+ /* Circle of fifths (#44): the key's chords tinted, its tonic and neighbours solid. */
808
+ .mn-svg .mn-circle-cell,
809
+ .mn-svg .mn-circle-chip {
810
+ fill: var(--mn-bg);
811
+ stroke: var(--mn-faint);
812
+ stroke-width: 1;
813
+ }
814
+
815
+ .mn-svg .mn-circle-diatonic {
816
+ fill: color-mix(in srgb, var(--mn-accent) 22%, var(--mn-bg));
817
+ }
818
+
819
+ .mn-svg .mn-circle-neighbour {
820
+ fill: var(--mn-accent);
821
+ }
822
+
823
+ .mn-svg .mn-circle-tonic {
824
+ fill: var(--mn-root);
825
+ }
826
+
827
+ .mn-svg .mn-circle-label {
828
+ font-size: 12px;
829
+ font-weight: 600;
830
+ }
831
+
832
+ .mn-svg .mn-circle-label-minor {
833
+ font-size: 11px;
834
+ }
835
+
836
+ .mn-svg .mn-circle-label-dim {
837
+ font-size: 9px;
838
+ font-weight: 400;
839
+ }
840
+
841
+ .mn-svg .mn-circle-numeral {
842
+ font-size: 10px;
843
+ font-weight: 700;
844
+ }
845
+
846
+ .mn-svg text.mn-circle-on {
847
+ fill: var(--mn-on-accent);
848
+ }
849
+
850
+ .mn-svg .mn-circle-sig {
851
+ fill: var(--mn-muted);
852
+ font-size: 9px;
853
+ }
854
+
855
+ .mn-svg .mn-circle-sig-key {
856
+ fill: var(--mn-fg);
857
+ font-weight: 700;
858
+ }
859
+
860
+ .mn-svg .mn-circle-key {
861
+ font-size: 13px;
862
+ font-weight: 700;
863
+ }
864
+
865
+ .mn-svg .mn-circle-key-sig,
866
+ .mn-svg .mn-circle-key-notes {
867
+ font-size: 9px;
868
+ fill: var(--mn-muted);
869
+ }
870
+
871
+ /* Following the notes: the dot, key or string mark that sounds while a diagram plays. Last in the
872
+ file and more specific than any other mark (a root, a characteristic note, a passing key), so
873
+ the playing color always wins. Most specific selector first: the tests' DOM (happy-dom) weighs
874
+ a selector list by its first match. */
875
+ .mn-playable .mn-svg .mn-passing.mn-root[data-midi].mn-playing,
876
+ .mn-playable .mn-svg .mn-passing[data-midi].mn-playing,
877
+ .mn-playable .mn-svg [data-midi].mn-playing {
878
+ fill: var(--mn-playing);
879
+ stroke: var(--mn-fg);
880
+ stroke-width: 2.5;
881
+ }
882
+
883
+ .mn-playable .mn-svg [data-midi].mn-playing + .mn-dot-text,
884
+ .mn-playable .mn-svg [data-midi].mn-playing + .mn-key-label {
885
+ fill: var(--mn-on-playing);
886
+ }
887
+ `;var se=G,H="music-notation-styles";function B(n){if(n.getElementById(H))return;let e=n.createElement("style");e.id=H,e.textContent=se,n.head.appendChild(e)}var ie=(n)=>n.reduce((e,a)=>Math.max(e,a.time+a.duration),0),j=(n)=>440*Math.pow(2,(n-69)/12);function le(n,e,a,t=Math.random){let r=new Float32Array(Math.round(e*a)),o=Math.max(2,Math.round(e/j(n))),i=new Float32Array(o);for(let l=0;l<o;l++)i[l]=t()*2-1;let u=0.996+Math.min(0.0035,0.00004*(90-n)),d=0;for(let l=0;l<r.length;l++){let s=(d+1)%o,g=i[d];i[d]=u*0.5*(g+i[s]),r[l]=g*0.5,d=s}return r}var U=new WeakMap;function me(n){let e=U.get(n);if(e)return e;let a=n.AudioContext;if(!a)return null;let t=new a;return U.set(n,t),t}var ce=4,W=[0,1,0.5,0.3,0.15,0.08,0.04];function q(n){let e=new Map,a=new WeakMap,t=(o,i)=>{let u=e.get(i);if(!u){let d=le(i,o.sampleRate,ce);u=o.createBuffer(1,d.length,o.sampleRate),u.getChannelData(0).set(d),e.set(i,u)}return u},r=(o)=>{let i=a.get(o);if(!i){let u=new Float32Array(W.length);i=o.createPeriodicWave(u,Float32Array.from(W)),a.set(o,i)}return i};return{reportsStart:!0,play(o,{sound:i,volume:u,onEnd:d,onStart:l}){let s=me(n);if(!s||!o.length)return{stop(){}};let g=s.resume();if(i==="guitar")for(let y of o)t(s,y.midi);let m=s.createGain();m.gain.value=Number.isFinite(u)?Math.min(1,Math.max(0,u)):0.8,m.connect(s.destination);let h=s.currentTime+0.05,w=o.map((y)=>{let b=h+y.time,T=b+y.duration,v=s.createGain();v.connect(m);let x=y.velocity===void 0||!Number.isFinite(y.velocity)?1:Math.min(127,Math.max(0,y.velocity))/100,M;if(i==="guitar"){let C=s.createBufferSource();C.buffer=t(s,y.midi),M=C,v.gain.setValueAtTime(x,b),v.gain.setValueAtTime(x,T)}else{let C=s.createOscillator();C.setPeriodicWave(r(s)),C.frequency.value=j(y.midi),M=C,v.gain.setValueAtTime(0,b),v.gain.linearRampToValueAtTime(0.35*x||0.0001,b+0.005),v.gain.exponentialRampToValueAtTime(0.02*x||0.0001,Math.max(b+0.01,T))}return v.gain.linearRampToValueAtTime(0,T+0.08),M.connect(v),M.start(b),M.stop(T+0.1),M}),c=()=>m.disconnect(),p=!1,k,f=()=>{if(p||!l)return;let y=Number.isFinite(s.outputLatency)?s.outputLatency:0;k=n.setTimeout(()=>{if(!p)l()},Math.max(0,h-s.currentTime+y)*1000)};if(l)Promise.resolve(g).then(f,f);let S=n.setTimeout(()=>{c(),d?.()},(ie(o)+0.15)*1000);return{stop(){p=!0,n.clearTimeout(S),n.clearTimeout(k);for(let y of w)try{y.stop()}catch{}c()}}}}}var ue="pre > code.language-tab, pre > code.language-score",E=new Map,z=null;function de(n){let e=n.defaultView;if(e.alphaTab)return Promise.resolve(e.alphaTab);return z??=new Promise((a,t)=>{let r=n.createElement("script");r.src=L().script,r.onload=()=>e.alphaTab?a(e.alphaTab):t(Error("alphaTab")),r.onerror=()=>{z=null,t(Error("Couldn't load alphaTab"))},n.head.appendChild(r)}),z}function _(n){for(let[a,{result:t,holder:r}]of E)if(!a.isConnected||!t.el.isConnected){if(t.destroy(),r.remove(),E.delete(a),a.isConnected)a.style.removeProperty("display")}let e=[...n.querySelectorAll(ue)].filter((a)=>{let t=a.parentElement,r=E.get(t);if(!r)return t.dataset.mpRendered!=="pending";if(r.source===(a.textContent??""))return!1;return r.result.destroy(),r.holder.remove(),E.delete(t),!0});if(!e.length)return;for(let a of e)a.parentElement.dataset.mpRendered="pending";de(n).then((a)=>{let t=L(),r={scriptFile:null,font:t.font,soundFont:t.soundFont},o=n.defaultView;o.musicNotationSoundfontPlayer??=I(a,r,n,q(o));for(let i of e){let u=i.parentElement;if(!u.parentElement)continue;let d=i.classList.contains("language-score")?"score":"tab",l=i.textContent??"",s=n.createElement("div");s.className="mn-tab-holder",u.insertAdjacentElement("afterend",s);let g=D(d,l,s,{alphaTab:a,assets:r});E.set(u,{result:g,source:l,holder:s}),g.ready.then(({ok:m})=>{if(u.dataset.mpRendered=m?"done":"error",m&&g.el.isConnected)u.style.display="none"})}}).catch(()=>{for(let a of e)a.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0;let n=()=>{B(document),_(document);let e=!1;new MutationObserver(()=>{if(e)return;e=!0,requestAnimationFrame(()=>{e=!1,_(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",n);else n()}})();
@@ -10,13 +10,22 @@ export interface PlayOptions {
10
10
  sound?: Sound;
11
11
  /** 0 to 1, 0.8 by default. */
12
12
  volume?: number;
13
- /** Scales: notes per minute, 90 by default. */
13
+ /** Scales: notes per minute, 90 by default; also strum patterns' tempo when they have none. */
14
14
  bpm?: number;
15
15
  /** Chords: milliseconds between strings, 40 by default. */
16
16
  strum?: number;
17
17
  }
18
+ /** A number within bounds; the fallback when it isn't a number at all. */
19
+ export declare const clamp: (n: number | undefined, lo: number, hi: number, fallback: number) => number;
20
+ /** Small icons, drawn so they look the same in every font. */
21
+ declare const ICONS: Record<'play' | 'stop' | 'loop' | 'volume', string>;
22
+ export declare function icon(doc: Document, name: keyof typeof ICONS): SVGElement;
23
+ export declare function lightFor(win: Window): NotePlayer;
24
+ /** The player apps passed (read at each play), else the light synthesizer. */
25
+ export declare function playerFor(win: Window, options: PlayOptions): NotePlayer;
18
26
  /**
19
27
  * Wraps each playable diagram in `el` (an SVG with notes to play) with its playback bar. Returns
20
28
  * a function that stops whatever plays.
21
29
  */
22
30
  export declare function attachPlayback(el: HTMLElement, options?: PlayOptions): () => void;
31
+ export {};
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Following the notes (#41): while a diagram plays, the element of each note that sounds (a dot,
3
+ * a key, a string's mark) gets the `mn-playing` class for the length of its note, so a learner
4
+ * sees which note sounds where.
5
+ */
6
+ import type { NoteEvent, NotePlayer, PlayKind } from './player.js';
7
+ /** The class a sounding note's element gets. */
8
+ export declare const PLAYING_CLASS = "mn-playing";
9
+ /**
10
+ * How long (ms) the bar waits for a player that doesn't say when its notes start (no
11
+ * `reportsStart`) before it lights notes from the play call.
12
+ */
13
+ export declare const START_WAIT = 300;
14
+ /**
15
+ * True when `player` says when its notes start: it declares `reportsStart`, or it was seen calling
16
+ * `onStart` (a wrapper of the soundfont or light player that doesn't declare it).
17
+ */
18
+ export declare function startsReported(player: NotePlayer): boolean;
19
+ /** Remembers that `player` calls `onStart`, for every bar of the page. */
20
+ export declare function sawStart(player: NotePlayer): void;
21
+ /**
22
+ * The elements each note lights on a drawing: every element of its pitch (a fretboard may show
23
+ * one pitch on two strings). On a strummed chord, strings that share a pitch light one each, low
24
+ * to high, in the order they sound. An element with `data-mn-chroma` (a pitch class, 0-11: a
25
+ * chord of the key on the circle of fifths) lights for every note of that pitch class instead;
26
+ * a chord element (`data-mn-strum`) without one never lights: its `data-midi` is only the note
27
+ * a click plays.
28
+ */
29
+ export declare function noteTargets(drawing: Element, events: readonly NoteEvent[], kind: PlayKind): Element[][];
30
+ export interface Follower {
31
+ /**
32
+ * The notes started sounding now (a player's `onStart`); only the first call counts, also
33
+ * after a run from the play call ended by itself, but not after `stop()`.
34
+ */
35
+ heard(): void;
36
+ /** Unlights every note and cancels the timers. */
37
+ stop(): void;
38
+ }
39
+ /**
40
+ * Lights `targets[i]` while `events[i]` sounds, from the moment `heard()` is called, or `wait` ms
41
+ * after this call when it isn't (Infinity waits for it). One timer at a time, set for the next
42
+ * note's start or end and read against the clock, so it doesn't drift. Stops by itself after the
43
+ * last note, or once `drawing` has left the page.
44
+ */
45
+ export declare function followNotes(win: Window, drawing: Element, targets: readonly (readonly Element[])[], events: readonly NoteEvent[], wait?: number): Follower;
@@ -10,17 +10,29 @@ export interface NoteEvent {
10
10
  time: number;
11
11
  /** Seconds. */
12
12
  duration: number;
13
+ /** How hard the note is played, MIDI style (1–127); 100 when absent. */
14
+ velocity?: number;
13
15
  }
14
16
  export interface PlayHandle {
15
17
  stop(): void;
16
18
  }
17
19
  export interface NotePlayer {
18
- /** Plays the notes; `onEnd` runs once they're over (not after stop). */
20
+ /**
21
+ * Plays the notes; `onEnd` runs once they're over (not after stop). `onStart`, when given,
22
+ * runs once when the notes really start sounding (the events' time 0), after any wait for a
23
+ * soundfont; not after stop. The playback bar lights each note from that moment.
24
+ */
19
25
  play(events: NoteEvent[], options: {
20
26
  sound: Sound;
21
27
  volume: number;
22
28
  onEnd?: () => void;
29
+ onStart?: () => void;
23
30
  }): PlayHandle;
31
+ /**
32
+ * True when `play` calls `onStart`: the bar then waits for it before it lights notes.
33
+ * Without it, the bar lights notes from the first `onStart`, or shortly after the play call.
34
+ */
35
+ readonly reportsStart?: boolean;
24
36
  }
25
37
  /** What a diagram plays: a chord strummed then ringing, or notes one after the other. */
26
38
  export type PlayKind = 'chord' | 'scale';
@@ -0,0 +1,5 @@
1
+ import { type StrumScore } from '../strum/play.js';
2
+ import { type PlayOptions } from './controls.js';
3
+ /** The score of a drawn pattern; null when it has no slots. */
4
+ export declare function scoreFromDrawing(drawing: Element): StrumScore | null;
5
+ export declare function strumBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions): () => void;