@dsebastien/music-notation 0.6.0 → 0.7.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.
@@ -1,6 +1,6 @@
1
- /*! @dsebastien/music-notation 0.6.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
2
- (()=>{var j=(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);j(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 q="1.8.4",F=(t=q)=>{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`}},_=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function K(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=_.exec(n);if(!s)break;let c=s[1].toLowerCase(),d=s[2].trim();if(c==="staves"){let i=d.toLowerCase();if(i!=="tab"&&i!=="score"&&i!=="both")throw Error(`staves: use tab, score or both, got "${d}"`);r.staves=i}else if(c==="file")r.file=d.replace(/^!?\[\[|\]\]$/g,"").split(/[|#]/)[0].trim()||null;else{let i=d.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 "${d}"`);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 Y(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 J={tab:"Tab",score:"Score",both:"ScoreTab"};function L(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 Q(t){let e=t.ownerDocument,a=e.defaultView?.getComputedStyle(t).color||"",r=a&&L(e,a)||(/^rgba?\(/.test(a)?a:"rgba(0, 0, 0, 1)"),o=a&&L(e,a,0.6)||r;return{mainGlyphColor:r,secondaryGlyphColor:o,scoreInfoColor:r,staffLineColor:o,barSeparatorColor:r,barNumberColor:o}}var P=(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}}},X={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:X[e]})),r}var V=(t)=>{let e=Math.max(0,Math.round(t/1000));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`};function Z(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,d=()=>(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(P(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,h,y)=>{let p=w(t,"button");return p.type="button",p.title=h,p.setAttribute("aria-label",h),p.appendChild(E(t,l)),p.addEventListener("click",y),o.appendChild(p),p},u=(l)=>{if(e.player)l()},f=(l,h,y)=>{let p=i(l,h,()=>{n[y]=!n[y],u(()=>{e.isLooping=n.loop,e.metronomeVolume=n.metronome?1:0,e.countInVolume=n.countIn?1:0}),p.classList.toggle("mn-on",n[y]),p.setAttribute("aria-pressed",String(n[y]))});p.setAttribute("aria-pressed","false")},m=i("play","Play",()=>{d().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,h,y,p,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(h);let A=w(t,"input");A.type="range",A.min=String(y),A.max=String(p),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 g=w(t,"span","mn-tab-time","");return o.appendChild(g),e.playerStateChanged.on((l)=>{let h=Number(l.state)===Number(a.synth.PlayerState.Playing);m.replaceChildren(E(t,h?"pause":"play")),m.title=h?"Pause":"Play",m.setAttribute("aria-label",m.title)}),e.playerPositionChanged.on((l)=>{g.textContent=`${V(l.currentTime)} / ${V(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,d=!1,i=()=>{},u=new Promise((m)=>{i=(b)=>{if(d)return;d=!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=K(t,e),b=r.alphaTab;if(!b?.AlphaTabApi)throw Error("alphaTab isn't loaded");let g=w(o,"div","mn-tab-surface");n.appendChild(g);let{assets:l}=r,h=P(o),y={core:{useWorkers:Boolean(l.scriptFile),...l.scriptFile?{scriptFile:l.scriptFile}:{},smuflFontSources:h.map([[b.FontFileFormat.Woff2,l.font]]),logLevel:b.LogLevel.Warning},display:{staveProfile:J[m.staves],resources:Q(n)},player:{playerMode:b.PlayerMode.Disabled,enableUserInteraction:!0}},p=new b.AlphaTabApi(g,y);if(s=p,c){p.destroy();return}r.onApi?.(p);let v=null;p.renderFinished.on(()=>{if(d||c)return;if(r.player!==!1)v=Z(o,p,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})}),p.error.on((x)=>{let T=Y(x,m.texLine);if(d)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(!p.load(h.bytes(x),k))throw Error(`Couldn't read "${m.file}": not a score file alphaTab knows`)}else p.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 ee={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 d=new t.midi.MidiFile,i=new t.midi.AlphaSynthMidiFileHandler(d,!0),u=(g)=>Math.round(g*d.division);i.addTempo(0,60),i.addProgramChange(0,0,0,ee[r]);let f=Number.isFinite(o)?Math.min(1,Math.max(0,o)):0.8;s.masterVolume=f;for(let g of a)i.addNote(0,u(g.time),Math.max(1,u(g.duration)),g.midi,100,0);let m=Math.max(...a.map((g)=>g.time+g.duration),0);s.playbackSpeed=1,c.playOneTimeMidiFile(d);let b=setTimeout(()=>n?.(),(m+0.2)*1000);return{stop(){clearTimeout(b),c.stop()}}}}}function R(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=P(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)=>{u.soundFontLoaded.on(()=>f(!0)),u.error.on(()=>f(!1))}),e.soundFont instanceof Uint8Array)u.loadSoundFont(i.bytes(e.soundFont),!1);return u.tex("r"),s},d=te(t,()=>o);return{play(i,u){let f=null,m=!1;return c().then((b)=>{if(m)return;try{if(b){f=d.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 I=`/* Music notation. Colors follow Obsidian's theme variables when present, with fallbacks for any page. */
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. */
4
4
  .mn-block,
5
5
  .mn-svg,
6
6
  .mn-chart {
@@ -545,4 +545,4 @@
545
545
  color: var(--text-error, #c92a2a);
546
546
  font-size: 0.9em;
547
547
  }
548
- `;var oe=I,D="music-notation-styles";function G(t){if(t.getElementById(D))return;let e=t.createElement("style");e.id=D,e.textContent=oe,t.head.appendChild(e)}var re=(t)=>t.reduce((e,a)=>Math.max(e,a.time+a.duration),0),B=(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/B(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)),d=0;for(let i=0;i<o.length;i++){let u=(d+1)%n,f=s[d];s[d]=c*0.5*(f+s[u]),o[i]=f*0.5,d=u}return o}var z=new WeakMap;function ie(t){let e=z.get(t);if(e)return e;let a=t.AudioContext;if(!a)return null;let r=new a;return z.set(t,r),r}var se=4,H=[0,1,0.5,0.3,0.15,0.08,0.04];function U(t){let e=new Map,a=new WeakMap,r=(n,s)=>{let c=e.get(s);if(!c){let d=ae(s,n.sampleRate,se);c=n.createBuffer(1,d.length,n.sampleRate),c.getChannelData(0).set(d),e.set(s,c)}return c},o=(n)=>{let s=a.get(n);if(!s){let c=new Float32Array(H.length);s=n.createPeriodicWave(c,Float32Array.from(H)),a.set(n,s)}return s};return{play(n,{sound:s,volume:c,onEnd:d}){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 h=f+l.time,y=h+l.duration,p=i.createGain();p.connect(u);let v;if(s==="guitar"){let k=i.createBufferSource();k.buffer=r(i,l.midi),v=k,p.gain.setValueAtTime(1,y)}else{let k=i.createOscillator();k.setPeriodicWave(o(i)),k.frequency.value=B(l.midi),v=k,p.gain.setValueAtTime(0,h),p.gain.linearRampToValueAtTime(0.35,h+0.005),p.gain.exponentialRampToValueAtTime(0.02,Math.max(h+0.01,y))}return p.gain.linearRampToValueAtTime(0,y+0.08),v.connect(p),v.start(h),v.stop(y+0.1),v}),b=()=>u.disconnect(),g=t.setTimeout(()=>{b(),d?.()},(re(n)+0.15)*1000);return{stop(){t.clearTimeout(g);for(let l of m)try{l.stop()}catch{}b()}}}}}var le="pre > code.language-tab, pre > code.language-score",M=new Map,N=null;function me(t){let e=t.defaultView;if(e.alphaTab)return Promise.resolve(e.alphaTab);return N??=new Promise((a,r)=>{let o=t.createElement("script");o.src=F().script,o.onload=()=>e.alphaTab?a(e.alphaTab):r(Error("alphaTab")),o.onerror=()=>{N=null,r(Error("Couldn't load alphaTab"))},t.head.appendChild(o)}),N}function W(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=F(),o={scriptFile:null,font:r.font,soundFont:r.soundFont},n=t.defaultView;n.musicNotationSoundfontPlayer??=R(a,o,t,U(n));for(let s of e){let c=s.parentElement;if(!c.parentElement)continue;let d=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(d,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=()=>{G(document),W(document);let e=!1;new MutationObserver(()=>{if(e)return;e=!0,requestAnimationFrame(()=>{e=!1,W(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",t);else t()}})();
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()}})();
@@ -32,12 +32,10 @@ export interface SequenceOptions {
32
32
  }
33
33
  export declare const DEFAULT_SEQUENCE: SequenceOptions;
34
34
  /**
35
- * The notes a diagram plays: a chord strums low to high and rings; a scale goes up and back down
36
- * (the top note once), each note one beat long.
35
+ * The notes a diagram plays: a chord strums low to high and rings; a scale plays every note drawn,
36
+ * up and back down (the top note once), each note one beat long.
37
37
  */
38
- export declare function sequenceOf(kind: PlayKind, pitches: readonly number[], options?: SequenceOptions,
39
- /** A scale's root (chroma): the run goes from the lowest root to the highest one. */
40
- root?: number | null): NoteEvent[];
38
+ export declare function sequenceOf(kind: PlayKind, pitches: readonly number[], options?: SequenceOptions): NoteEvent[];
41
39
  /** The end of a sequence, in seconds. */
42
40
  export declare const lengthOf: (events: readonly NoteEvent[]) => number;
43
41
  /**
@@ -900,9 +900,9 @@ function renderFretboard(doc, set, options = {}) {
900
900
  root.setAttribute("data-mn-play", "scale");
901
901
  root.setAttribute("data-mn-sound", "guitar");
902
902
  root.setAttribute("data-mn-set", set.title);
903
+ root.setAttribute("data-mn-labels", label);
904
+ root.setAttribute("data-mn-orientation", orientation);
903
905
  root.setAttribute("data-mn-frets", `${from}-${to}`);
904
- if (set.root !== null && !set.list)
905
- root.setAttribute("data-mn-root", String(set.root));
906
906
  return root;
907
907
  }
908
908
 
@@ -1073,8 +1073,8 @@ function renderKeyboard(doc, set, options = {}) {
1073
1073
  root.setAttribute("data-mn-play", options.playAs ?? "scale");
1074
1074
  root.setAttribute("data-mn-sound", "piano");
1075
1075
  root.setAttribute("data-mn-set", set.title);
1076
- if (set.root !== null && !set.list)
1077
- root.setAttribute("data-mn-root", String(set.root));
1076
+ root.setAttribute("data-mn-labels", label);
1077
+ root.setAttribute("data-mn-orientation", vertical ? "vertical" : "horizontal");
1078
1078
  return root;
1079
1079
  }
1080
1080
 
@@ -1347,8 +1347,16 @@ function namesOf(pitches, flats) {
1347
1347
  }
1348
1348
  return names;
1349
1349
  }
1350
+ function isStepwiseRun(pitches) {
1351
+ let sorted = [...new Set(pitches)].sort((a, b) => a - b);
1352
+ if (sorted.length > 1 && sorted[sorted.length - 1] - sorted[0] === 12)
1353
+ sorted = sorted.slice(0, -1);
1354
+ if (sorted.length < 5 || sorted[sorted.length - 1] - sorted[0] >= 12)
1355
+ return false;
1356
+ return sorted.every((pitch, i) => i === 0 || pitch - sorted[i - 1] <= 2);
1357
+ }
1350
1358
  function detectChordFromPitches(pitches) {
1351
- if (pitches.length < 2)
1359
+ if (pitches.length < 2 || isStepwiseRun(pitches))
1352
1360
  return null;
1353
1361
  const readings = new Set;
1354
1362
  for (const flats of [false, true]) {
@@ -1764,7 +1772,10 @@ function pianoPitches(symbol) {
1764
1772
  pitches.unshift(48 + bass);
1765
1773
  return { ...set, pitches };
1766
1774
  }
1775
+ var ROOT_FOR_LISTS_ONLY = "root only applies to lists of notes on fretboards and keyboards (notes: C E G with root: C): a chord has its own root";
1767
1776
  var renderChord = (doc, block, options) => {
1777
+ if (block.fields.get("root")?.trim())
1778
+ throw new Error(ROOT_FOR_LISTS_ONLY);
1768
1779
  const short = shorthand(block.head);
1769
1780
  const name = field(block, "name");
1770
1781
  const written = field(block, "symbol", "chord") ?? short.symbol;
@@ -1940,13 +1951,40 @@ var renderKeyboardBlock = (doc, block, options) => {
1940
1951
  fingers = fingersFor(octave, fingering);
1941
1952
  if (!keys)
1942
1953
  set.pitches = octave;
1954
+ } else if (fingering && set.list) {
1955
+ const fingerList = fingering.split(/[\s,-]+/).filter(Boolean);
1956
+ let pitches = set.pitches;
1957
+ if (!pitches) {
1958
+ const chromas = set.title.split(/[\s,]+/).filter(Boolean).map((name) => chromaOf(name) ?? 0);
1959
+ const first = chromas[0] ?? 0;
1960
+ let at = keys ? keys[0] + ((first - keys[0]) % 12 + 12) % 12 : 60 + first;
1961
+ pitches = chromas.map((chroma, i) => {
1962
+ if (i > 0) {
1963
+ const up = ((chroma - at) % 12 + 12) % 12;
1964
+ at += up === 0 ? 12 : up <= 6 ? up : up - 12;
1965
+ }
1966
+ return at;
1967
+ });
1968
+ if (!keys)
1969
+ set.pitches = pitches;
1970
+ }
1971
+ if (fingerList.length !== pitches.length) {
1972
+ throw new Error(`fingering has ${fingerList.length} fingers for ${pitches.length} notes: one finger per note, in the order written`);
1973
+ }
1974
+ if (new Set(pitches).size !== pitches.length) {
1975
+ throw new Error("A key is listed twice: one finger per key");
1976
+ }
1977
+ if (keys && pitches.some((midi) => midi < keys[0] || midi > keys[1])) {
1978
+ throw new Error("The fingered notes go past the range: widen range: or leave it out");
1979
+ }
1980
+ fingers = new Map(pitches.map((midi, i) => [midi, fingerList[i]]));
1943
1981
  }
1944
1982
  return renderKeyboard(doc, set, {
1945
1983
  playAs: !set.scaleType && !set.list && set.root !== null ? "chord" : "scale",
1946
1984
  title: field(block, "title"),
1947
1985
  label: labelField(block, fingers ? "fingers" : "notes", fingers !== undefined),
1948
1986
  fingers,
1949
- range: keyRange(keys ? keys : fingers && set.pitches ? [set.pitches[0], set.pitches[set.pitches.length - 1]] : keyRangeOf(set)),
1987
+ range: keyRange(keys ? keys : fingers && set.pitches ? [Math.min(...set.pitches), Math.max(...set.pitches)] : keyRangeOf(set)),
1950
1988
  orientation: orientationOf(block, options.orientation?.keyboard),
1951
1989
  marks: marksOf(block, set)
1952
1990
  });
@@ -2013,7 +2051,7 @@ var RENDERERS = {
2013
2051
  // src/playback/player.ts
2014
2052
  var DEFAULT_SEQUENCE = { bpm: 90, strum: 40 };
2015
2053
  var RING = 2.5;
2016
- function sequenceOf(kind, pitches, options = DEFAULT_SEQUENCE, root = null) {
2054
+ function sequenceOf(kind, pitches, options = DEFAULT_SEQUENCE) {
2017
2055
  if (!pitches.length)
2018
2056
  return [];
2019
2057
  if (kind === "chord") {
@@ -2027,12 +2065,7 @@ function sequenceOf(kind, pitches, options = DEFAULT_SEQUENCE, root = null) {
2027
2065
  }
2028
2066
  const bpm = Number.isFinite(options.bpm) ? options.bpm : DEFAULT_SEQUENCE.bpm;
2029
2067
  const beat = 60 / Math.min(240, Math.max(20, bpm));
2030
- let up = [...pitches].sort((a, b) => a - b);
2031
- if (root !== null) {
2032
- const roots = up.filter((p) => (p % 12 + 12) % 12 === root);
2033
- if (roots.length >= 2)
2034
- up = up.filter((p) => p >= roots[0] && p <= roots[roots.length - 1]);
2035
- }
2068
+ const up = [...pitches].sort((a, b) => a - b);
2036
2069
  const order = [...up, ...up.slice(0, -1).reverse()];
2037
2070
  return order.map((midi, i) => ({ midi, time: i * beat, duration: beat * 0.95 }));
2038
2071
  }
@@ -2207,10 +2240,60 @@ function dataOf(diagram) {
2207
2240
  return {
2208
2241
  kind: diagram.getAttribute("data-mn-play") === "chord" ? "chord" : "scale",
2209
2242
  pitches,
2210
- sound: diagram.getAttribute("data-mn-sound") === "piano" ? "piano" : "guitar",
2211
- root: Number.isInteger(Number(diagram.getAttribute("data-mn-root") ?? "x")) ? Number(diagram.getAttribute("data-mn-root")) : null
2243
+ sound: diagram.getAttribute("data-mn-sound") === "piano" ? "piano" : "guitar"
2212
2244
  };
2213
2245
  }
2246
+ var LABELS2 = new Set(["notes", "degrees", "intervals", "none"]);
2247
+ function spelledNote(name, midi) {
2248
+ const octave = Math.floor(midi / 12) - 1;
2249
+ for (const o of [octave, octave + 1, octave - 1])
2250
+ if (midiOf(`${name}${o}`) === midi)
2251
+ return `${name}${o}`;
2252
+ return `${nameOf(midi)}${octave}`;
2253
+ }
2254
+ function redrawFor(doc, diagram, data) {
2255
+ const toGuitar = data.sound === "piano";
2256
+ const pitches = [...new Set(data.pitches)].sort((a, b) => a - b).filter((midi) => !toGuitar || midi >= 40 && midi <= 88);
2257
+ if (!pitches.length)
2258
+ return null;
2259
+ const chord = diagram.getAttribute("data-mn-chord");
2260
+ const named = diagram.getAttribute("data-mn-set");
2261
+ let set = chord && chordNoteSet(chord) || named && (scaleNoteSet(named) ?? (named.includes(" ") ? null : chordNoteSet(named))) || null;
2262
+ if (set && !pitches.every((midi) => set.members.some((m) => m.chroma === midi % 12)))
2263
+ set = null;
2264
+ if (set)
2265
+ set.pitches = pitches;
2266
+ else {
2267
+ const flats = [...diagram.querySelectorAll("[data-mn-note]")].some((el) => /^[A-G]b/.test(el.getAttribute("data-mn-note") ?? ""));
2268
+ const nameAt = (midi) => diagram.querySelector(`[data-midi="${midi}"][data-mn-note]`)?.getAttribute("data-mn-note") ?? nameOf(midi, flats);
2269
+ const rootEl = diagram.querySelector(".mn-root[data-midi]");
2270
+ const rootMidi = rootEl ? Number(rootEl.getAttribute("data-midi")) : null;
2271
+ set = listNoteSet(pitches.map((midi) => spelledNote(nameAt(midi), midi)).join(" "), rootMidi === null ? undefined : nameAt(rootMidi));
2272
+ if (!set)
2273
+ return null;
2274
+ }
2275
+ const written = diagram.getAttribute("data-mn-labels");
2276
+ const label = written && LABELS2.has(written) && (set.root !== null || written === "notes" || written === "none") ? written : "notes";
2277
+ const title = diagram.querySelector(".mn-title")?.textContent ?? undefined;
2278
+ const orientation = diagram.getAttribute("data-mn-orientation") === "vertical" ? "vertical" : undefined;
2279
+ const drawn = toGuitar ? renderFretboard(doc, set, {
2280
+ label,
2281
+ ...title ? { title } : {},
2282
+ ...orientation ? { orientation } : {},
2283
+ frets: [0, Math.max(12, Math.min(24, pitches[pitches.length - 1] - 64))]
2284
+ }) : renderKeyboard(doc, set, {
2285
+ label,
2286
+ ...title ? { title } : {},
2287
+ ...orientation ? { orientation } : {},
2288
+ range: keyRangeOf(set),
2289
+ playAs: data.kind
2290
+ });
2291
+ const name = diagram.getAttribute("aria-label");
2292
+ if (name)
2293
+ drawn.setAttribute("aria-label", `${name}, drawn for ${toGuitar ? "guitar" : "piano"}`);
2294
+ drawn.classList.add("mn-redrawn");
2295
+ return drawn;
2296
+ }
2214
2297
  function attachPlayback(el, options = {}) {
2215
2298
  const doc = el.ownerDocument;
2216
2299
  const win = doc.defaultView;
@@ -2242,6 +2325,8 @@ function barFor(doc, win, diagram, data, options) {
2242
2325
  loop: false
2243
2326
  };
2244
2327
  let playing = null;
2328
+ let shown = diagram;
2329
+ const pitchesShown = () => shown === diagram ? data.pitches : dataOf(shown)?.pitches ?? data.pitches;
2245
2330
  const toggle = html(doc, "button", "mn-play-toggle");
2246
2331
  toggle.type = "button";
2247
2332
  const show = () => {
@@ -2267,7 +2352,7 @@ function barFor(doc, win, diagram, data, options) {
2267
2352
  stop();
2268
2353
  if (!wrap.isConnected)
2269
2354
  return;
2270
- playing = play(sequenceOf(data.kind, data.pitches, settings, data.root), () => {
2355
+ playing = play(sequenceOf(data.kind, pitchesShown(), settings), () => {
2271
2356
  playing = null;
2272
2357
  if (settings.loop && wrap.isConnected)
2273
2358
  start();
@@ -2325,11 +2410,24 @@ function barFor(doc, win, diagram, data, options) {
2325
2410
  option.selected = value === settings.sound;
2326
2411
  sound.appendChild(option);
2327
2412
  }
2413
+ let other;
2414
+ const drawFor = () => {
2415
+ if (settings.sound !== data.sound)
2416
+ other ??= redrawFor(doc, diagram, data);
2417
+ const next = settings.sound === data.sound ? diagram : other ?? diagram;
2418
+ if (next !== shown && shown.parentNode === wrap) {
2419
+ wrap.replaceChild(next, shown);
2420
+ shown = next;
2421
+ }
2422
+ };
2328
2423
  sound.addEventListener("change", () => {
2424
+ stop();
2329
2425
  settings.sound = sound.value === "piano" ? "piano" : "guitar";
2426
+ drawFor();
2330
2427
  });
2428
+ drawFor();
2331
2429
  bar.appendChild(sound);
2332
- diagram.addEventListener("click", (event) => {
2430
+ wrap.addEventListener("click", (event) => {
2333
2431
  const node = event.target;
2334
2432
  const target = typeof node?.closest === "function" ? node.closest("[data-midi]") : null;
2335
2433
  const midi = Number(target?.getAttribute("data-midi"));
@@ -3281,6 +3379,8 @@ function voicingParts(language, source) {
3281
3379
  if (instrument === "piano" || instrument === "keyboard" || fields.has("pitches") || fields.has("notes")) {
3282
3380
  throw new Error("voicings are for guitar and other fretted instruments");
3283
3381
  }
3382
+ if (fields.get("root")?.trim())
3383
+ throw new Error(ROOT_FOR_LISTS_ONLY);
3284
3384
  const refused = NOT_WITH_VOICINGS.find((key) => fields.has(key));
3285
3385
  if (refused)
3286
3386
  throw new Error(`voicings finds the frets itself: remove "${refused}"`);
@@ -3398,6 +3498,8 @@ function triadParts(language, source) {
3398
3498
  const fields = block.fields;
3399
3499
  if (fields.has("voicings"))
3400
3500
  throw new Error("Use triads or voicings, not both");
3501
+ if (fields.get("root")?.trim())
3502
+ throw new Error(ROOT_FOR_LISTS_ONLY);
3401
3503
  const refused = NOT_WITH_VOICINGS.find((key) => fields.has(key));
3402
3504
  if (refused)
3403
3505
  throw new Error(`triads finds the frets itself: remove "${refused}"`);
@@ -3522,6 +3624,8 @@ function transitionParts(language, source) {
3522
3624
  if (fromText !== undefined && progressionText !== undefined) {
3523
3625
  throw new Error("Use from and to, or progression, not both");
3524
3626
  }
3627
+ if (fields.get("root")?.trim())
3628
+ throw new Error(ROOT_FOR_LISTS_ONLY);
3525
3629
  const refused = [...NOT_WITH_VOICINGS, "voicings", "triads"].find((key) => fields.has(key));
3526
3630
  if (refused)
3527
3631
  throw new Error(`"${refused}" can't be used with ${fromText ? "from" : "progression"}`);
@@ -3831,5 +3935,5 @@ export {
3831
3935
  renderAll
3832
3936
  };
3833
3937
 
3834
- //# debugId=4DA24EFA15D7239964756E2164756E21
3938
+ //# debugId=D4DF2B374CD0BDA864756E2164756E21
3835
3939
  //# sourceMappingURL=index.js.map