@dsebastien/music-notation 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -5
- package/dist/chord/generate.d.ts +34 -9
- package/dist/chord/guitar.d.ts +18 -0
- package/dist/circle/circle.d.ts +8 -2
- package/dist/cli.js +1 -1
- package/dist/convert/text-tab.d.ts +56 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +6599 -4673
- package/dist/index.js.map +32 -30
- package/dist/keyboard/keyboard.d.ts +17 -2
- package/dist/keyboard/piano-chord.d.ts +28 -3
- package/dist/keyboard/play-voicing.d.ts +10 -0
- package/dist/keyboard/scale-fingering.d.ts +41 -0
- package/dist/keyboard/voice-leading.d.ts +55 -4
- package/dist/music-notation.css +68 -5
- package/dist/music-notation.publish.min.js +91 -28
- package/dist/music-notation.tab.min.js +72 -9
- package/dist/playback/controls.d.ts +13 -2
- package/dist/playback/player.d.ts +69 -5
- package/dist/publish/index.js +5306 -3909
- package/dist/publish/index.js.map +31 -29
- package/dist/render/dom.d.ts +25 -1
- package/dist/strum/pattern.d.ts +25 -0
- package/dist/strum/play.d.ts +46 -5
- package/dist/strum/render.d.ts +4 -1
- package/dist/tab/index.d.ts +39 -0
- package/dist/tab/index.js +683 -75
- package/dist/tab/index.js.map +6 -6
- package/dist/theory/detect.d.ts +6 -2
- package/dist/theory/find.d.ts +35 -7
- package/dist/theory/keys.d.ts +8 -2
- package/dist/theory/note-set.d.ts +5 -0
- package/dist/theory/numerals.d.ts +34 -7
- package/dist/voicings/check.d.ts +17 -0
- package/dist/voicings/curated.d.ts +10 -0
- package/dist/voicings/index.d.ts +1 -1
- package/dist/voicings/index.js +429 -109
- package/dist/voicings/index.js.map +10 -8
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @dsebastien/music-notation 0.
|
|
2
|
-
(()=>{var
|
|
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. */
|
|
1
|
+
/*! @dsebastien/music-notation 0.9.0 tab bundle | MIT | loads alphaTab (MPL-2.0) from jsDelivr */
|
|
2
|
+
(()=>{var ce=(e,t)=>{for(let[o,n]of Object.entries(t))if(n!==void 0)e.setAttribute(o,String(n))};function I(e,t,o={},n=[]){let r=e.createElementNS("http://www.w3.org/2000/svg",t);ce(r,o);for(let a of n)if(a)r.appendChild(a);return r}function A(e,t,o,n){let r=e.createElement(t);if(o)r.className=o;if(n!==void 0)r.textContent=n;return r}var He=`mn-name-${Math.random().toString(36).slice(2,8)}-`;var ue="1.8.4",B=(e=ue)=>{let t=`https://cdn.jsdelivr.net/npm/@coderline/alphatab@${e}/dist`;return{script:`${t}/alphaTab.min.js`,font:`${t}/font/Bravura.woff2`,soundFont:`${t}/soundfont/sonivox.sf3`}},de=/^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;function pe(e,t){let o=t.split(/\r?\n/),n={staves:e,stavesWritten:!1,file:null,tracks:null,tex:"",texLine:0},r=0;for(;r<o.length;r++){let a=o[r];if(!a.trim()||/^\s*\/\//.test(a))continue;let m=de.exec(a);if(!m)break;let i=m[1].toLowerCase(),d=m[2].trim();if(i==="staves"){let l=d.toLowerCase();if(l!=="tab"&&l!=="score"&&l!=="both")throw Error(`staves: use tab, score or both, got "${d}"`);n.staves=l,n.stavesWritten=!0}else if(i==="file")n.file=d.replace(/^!?\[\[|\]\]$/g,"").split(/[|#]/)[0].trim()||null;else{let l=d.split(/[\s,]+/).filter(Boolean).map(Number);if(!l.length||l.some((p)=>!Number.isInteger(p)||p<1))throw Error(`tracks: use track numbers from 1, got "${d}"`);n.tracks=l}}while(r<o.length&&!o[r].trim())r++;if(n.texLine=r,n.tex=o.slice(r).join(`
|
|
3
|
+
`).trimEnd(),!n.file&&!n.tex)throw Error("Write the music in alphaTex, or give a file: [[Song.gp]]");return n}function fe(e,t){let o=e?.cause??e;for(let n of["lexerDiagnostics","parserDiagnostics","semanticDiagnostics"]){let r=o?.[n]?.items;if(!Array.isArray(r))continue;let a=r.find((m)=>m.severity===2&&m.message);if(a)return`${a.start?`line ${a.start.line+t}, column ${a.start.col}: `:""}${a.message}`}return e instanceof Error?e.message:String(e)}var he=0;function _(e,t){for(let o of t.tracks)for(let n of o.staves){if(n.isPercussion)for(let a of n.bars??[])a.clef=he;let r=!n.isPercussion&&n.tuning.length>0;if(e==="both"){n.showStandardNotation=!0,n.showTablature=r;continue}n.showSlash=!1,n.showNumbered=!1,n.showTablature=e==="tab"&&r,n.showStandardNotation=!n.showTablature}}var ge=5;function be(e,t){if(t!==null&&/\bdy\b|\\showdynamics/i.test(t))return;if(!e.tracks.some((n)=>n.staves.some((r)=>r.bars.some((a)=>a.voices.some((m)=>m.beats.some((i)=>!i.isRest&&i.dynamics!==ge))))))e.stylesheet.hideDynamics=!0}var ye="rendered by alphaTab";function ve(e,t){e.renderer?.partialRenderFinished?.on((n)=>{for(let r of t.querySelectorAll(".at-surface > div")){if(r.layoutResultId!==n.id)continue;let a=typeof n.renderResult==="string"&&n.renderResult.includes(ye);r.style.visibility=a?"hidden":""}})}function Y(e,t,o=1){let n=e.createElement("canvas");n.width=1,n.height=1;let r=n.getContext("2d",{willReadFrequently:!0});if(!r)return null;r.fillStyle="#000",r.fillStyle=t,r.fillRect(0,0,1,1);let a=r.getImageData(0,0,1,1).data;if(a.length<4)return null;return`rgba(${a[0]}, ${a[1]}, ${a[2]}, ${(a[3]/255*o).toFixed(3)})`}function ke(e){let t=e.ownerDocument,o=t.defaultView?.getComputedStyle(e).color||"",n=o&&Y(t,o)||(/^rgba?\(/.test(o)?o:"rgba(0, 0, 0, 1)"),r=o&&Y(t,o,0.6)||n;return{mainGlyphColor:n,secondaryGlyphColor:r,scoreInfoColor:n,staffLineColor:r,barSeparatorColor:n,barNumberColor:r}}var U=(e)=>{let t=e.defaultView??globalThis;return{map:(o)=>new t.Map(o),bytes:(o)=>{let n=new t.Uint8Array(o.length);return n.set(o),n}}},we={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 z(e,t){let n=I(e,"svg",{class:`mn-play-icon${t==="play"||t==="pause"||t==="stop"?"":" mn-play-icon-loop"}`,viewBox:"0 0 16 16",width:12,height:12,"aria-hidden":"true"});return n.appendChild(I(e,"path",{d:we[t]})),n}var J=(e)=>{let t=Math.max(0,Math.round(e/1000));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`};function xe(e,t,o,n){let r=A(e,"div","mn-play mn-tab-bar");r.addEventListener("mousedown",(c)=>c.stopPropagation()),r.setAttribute("role","group"),r.setAttribute("aria-label","Playback");let a={loop:!1,metronome:!1,countIn:!1,speed:1,volume:1},m=null,i=null,d=()=>(m??=new Promise((c)=>{if(t.playerReady.on(()=>c(!0)),i=()=>c(!1),t.settings.player.playerMode=o.PlayerMode.EnabledSynthesizer,t.settings.player.enableCursor=!0,typeof n.soundFont==="string")t.settings.player.soundFont=n.soundFont;if(t.updateSettings(),n.soundFont instanceof Uint8Array)t.loadSoundFont(U(e).bytes(n.soundFont),!1)}).then((c)=>{if(c)t.isLooping=a.loop,t.metronomeVolume=a.metronome?1:0,t.countInVolume=a.countIn?1:0,t.playbackSpeed=a.speed,t.masterVolume=a.volume;return c}),m),l=(c,u,g)=>{let b=A(e,"button");return b.type="button",b.title=u,b.setAttribute("aria-label",u),b.appendChild(z(e,c)),b.addEventListener("click",g),r.appendChild(b),b},p=(c)=>{if(t.player)c()},f=(c,u,g)=>{let b=l(c,u,()=>{a[g]=!a[g],p(()=>{t.isLooping=a.loop,t.metronomeVolume=a.metronome?1:0,t.countInVolume=a.countIn?1:0}),b.classList.toggle("mn-on",a[g]),b.setAttribute("aria-pressed",String(a[g]))});b.setAttribute("aria-pressed","false")},s=l("play","Play",()=>{d().then((c)=>{if(c)t.playPause()})});l("stop","Stop",()=>p(()=>t.stop())),f("loop","Loop","loop"),f("metronome","Metronome","metronome"),f("countIn","Count-in","countIn");let y=(c,u,g,b,C,P,w="")=>{let F=A(e,"label","mn-play-field"),M=A(e,"span","mn-play-label");M.setAttribute("aria-hidden","true"),M.append(u);let x=A(e,"input");x.type="range",x.min=String(g),x.max=String(b),x.value=String(C),x.setAttribute("aria-label",c),F.title=`${c}: ${C}${w}`,x.addEventListener("input",()=>{P(Number(x.value)),F.title=`${c}: ${x.value}${w}`}),F.append(M,x),r.appendChild(F)};y("Speed","%",25,150,100,(c)=>{a.speed=c/100,p(()=>t.playbackSpeed=a.speed)},"%"),y("Volume",z(e,"volume"),0,100,100,(c)=>{a.volume=c/100,p(()=>t.masterVolume=a.volume)});let v=A(e,"span","mn-tab-time","");return r.appendChild(v),t.playerStateChanged.on((c)=>{let u=Number(c.state)===Number(o.synth.PlayerState.Playing);s.replaceChildren(z(e,u?"pause":"play")),s.title=u?"Pause":"Play",s.setAttribute("aria-label",s.title)}),t.playerPositionChanged.on((c)=>{v.textContent=`${J(c.currentTime)} / ${J(c.endTime)}`}),{bar:r,failed:(c)=>{i?.(),s.disabled=!0,s.title=`Can't play: ${c}`,s.setAttribute("aria-label",s.title)}}}function Ae(e,t){return e.tracks.some((o,n)=>(!t||t.includes(n+1))&&o.staves.some((r)=>!r.isPercussion&&r.tuning.length>0))}var Te=[{staves:"tab",label:"Tab",what:"tablature"},{staves:"score",label:"Score",what:"standard notation"},{staves:"both",label:"Both",what:"standard notation and tablature"}];function Se(e,t,o,n){let r=A(e,"span","mn-tab-views");r.setAttribute("role","group"),r.setAttribute("aria-label","View");let a=t.staves,m=n?A(e,"button","mn-tab-keep","Keep this view"):null,i=Te.map(({staves:l,label:p,what:f})=>{let s=A(e,"button","mn-tab-view",p);s.type="button",s.dataset.staves=l;let y=l!==t.staves?"":t.written?" (this block's staves: line)":" (the default: the block has no staves: line)";return s.title=`Draw as ${f}${y}`,s.addEventListener("click",()=>{if(l===a)return;a=l,d(),o(l)}),r.appendChild(s),s}),d=()=>{for(let l of i){let p=l.dataset.staves===a;l.classList.toggle("mn-on",p),l.setAttribute("aria-pressed",String(p))}if(m)m.hidden=a===t.staves,m.title=`Write staves: ${a} at the top of the block`};if(m&&n)m.type="button",m.addEventListener("click",()=>n(a)),r.appendChild(m);return d(),r}function Q(e,t,o,n){let r=o.ownerDocument,a=A(r,"div",`mn-block mn-block-${e} mn-tab`);o.appendChild(a);let m=null,i=!1,d=!1,l=()=>{},p=new Promise((s)=>{l=(y)=>{if(d)return;d=!0,s(y)}}),f=(s)=>{a.replaceChildren(A(r,"div","mn-error-message",`${e}: ${s}`)),a.classList.add("mn-error"),l({ok:!1,error:s})};if(!t.trim())a.classList.add("mn-empty"),l({ok:!0,error:null});else(async()=>{await Promise.resolve();let s=pe(e,t),y={staves:s.stavesWritten?s.staves:n.defaultStaves??s.staves,written:s.stavesWritten},v=y.staves,c=!1,u=n.alphaTab;if(!u?.AlphaTabApi)throw Error("alphaTab isn't loaded");let g=A(r,"div","mn-tab-surface");a.appendChild(g);let{assets:b}=n,C=U(r),P={core:{useWorkers:Boolean(b.scriptFile),...b.scriptFile?{scriptFile:b.scriptFile}:{},smuflFontSources:C.map([[u.FontFileFormat.Woff2,b.font]]),logLevel:u.LogLevel.Warning,enableLazyLoading:!1},display:{staveProfile:"Default",resources:ke(a)},player:{playerMode:u.PlayerMode.Disabled,enableUserInteraction:!0}},w=new u.AlphaTabApi(g,P);if(m=w,i){w.destroy();return}n.onApi?.(w);let F=[];w.scoreLoaded.on((h)=>{F=h.tracks.flatMap((k)=>k.staves.map((T)=>({showSlash:T.showSlash,showNumbered:T.showNumbered}))),_(v,h),c=Ae(h,s.tracks),be(h,s.file?null:s.tex)}),ve(w,g);let M=null;w.renderFinished.on(()=>{if(d||i)return;if(n.player!==!1){if(M=xe(r,w,u,b),a.appendChild(M.bar),n.views!==!1&&c)M.bar.appendChild(Se(r,y,(h)=>{v=h;let k=w.score;if(i||!k)return;k.tracks.flatMap((S)=>S.staves).forEach((S,R)=>Object.assign(S,F[R])),_(h,k),w.render()},n.onKeepView));a.addEventListener("pointerdown",(h)=>{if(h.pointerType!=="touch"||M?.bar.contains(h.target))return;a.classList.toggle("mn-play-open")})}l({ok:!0,error:null})}),w.error.on((h)=>{let k=fe(h,s.texLine);if(d)M?.failed(k);else f(k)});let x=s.tracks?.map((h)=>h-1);if(s.file){let h;try{h=n.resolveFile?await n.resolveFile(s.file):null}catch(T){throw Error(`Couldn't read "${s.file}": ${T instanceof Error?T.message:String(T)}`)}if(i)return;if(!h)throw Error(`Couldn't find the file "${s.file}"`);if(!w.load(C.bytes(h),x))throw Error(`Couldn't read "${s.file}": not a score file alphaTab knows`)}else w.tex(s.tex,x??"all")})().catch((s)=>{if(!i)f(s instanceof Error?s.message:String(s))});return{el:a,ready:p,get api(){return m},destroy(){i=!0;try{m?.destroy()}catch{}a.remove(),l({ok:!1,error:null})}}}var G={guitar:25,piano:0},D={channel:1,program:28},H={channel:9,key:33},Me=0.5;function Ce(e,t){return{reportsStart:!0,play(o,{sound:n,volume:r,onEnd:a,onStart:m}){let i=t(),d=i?.player;if(!i||!d)throw Error("The soundfont player is not ready");let l=new e.midi.MidiFile,p=new e.midi.AlphaSynthMidiFileHandler(l,!0),f=(u)=>Math.round(u*l.division);if(p.addTempo(0,60),p.addProgramChange(0,0,0,G[n]),n==="guitar"&&o.some((u)=>u.kind==="muted"))p.addProgramChange(0,0,D.channel,D.program);if(o.some((u)=>u.kind==="click"))p.addProgramChange(0,0,H.channel,0);let s=Number.isFinite(r)?Math.min(1,Math.max(0,r)):0.8;i.masterVolume=s;for(let u of o){let g=u.velocity===void 0||!Number.isFinite(u.velocity)?100:Math.round(Math.min(127,Math.max(1,u.velocity))),b=u.kind==="click"?H.channel:u.kind==="muted"&&n==="guitar"?D.channel:0;p.addNote(0,f(u.time),Math.max(1,f(u.duration)),u.kind==="click"?H.key:u.midi,g,b)}let y=Math.max(...o.map((u)=>u.time+u.duration),0);p.addControlChange(0,f(y+Me),0,e.midi.ControllerType.HoldPedal,0),i.playbackSpeed=1,d.playOneTimeMidiFile(l);let v=!1;queueMicrotask(()=>{if(!v)m?.()});let c=setTimeout(()=>a?.(),(y+0.2)*1000);return{stop(){v=!0,clearTimeout(c),d.stop()}}}}}function X(e,t,o,n){let r=null,a=null,m=null,i=()=>{if(m)return m;a=A(o,"div","mn-tab-hidden"),a.setAttribute("aria-hidden","true"),o.body.appendChild(a);let l=U(o);r=new e.AlphaTabApi(a,{core:{useWorkers:Boolean(t.scriptFile),...t.scriptFile?{scriptFile:t.scriptFile}:{},smuflFontSources:l.map([[e.FontFileFormat.Woff2,t.font]])},player:{playerMode:e.PlayerMode.EnabledSynthesizer,...typeof t.soundFont==="string"?{soundFont:t.soundFont}:{}}});let p=r;if(m=new Promise((f)=>{let s=!1,y=!p.playerReady,v=()=>{if(s&&y)f(!0)};p.soundFontLoaded.on(()=>{s=!0,v(),setTimeout(()=>{y=!0,v()},4000)}),p.playerReady?.on(()=>{y=!0,v()}),p.error.on(()=>f(!1))}),t.soundFont instanceof Uint8Array)p.loadSoundFont(l.bytes(t.soundFont),!1);return p.tex(`\\track "Guitar" \\instrument ${G.guitar} r \\track "Piano" \\instrument ${G.piano} r \\track "Muted" \\instrument ${D.program} r`),m},d=Ce(e,()=>r);return{reportsStart:!0,play(l,p){let f=null,s=!1;return i().then((y)=>{if(s)return;try{if(y){f=d.play(l,p);return}}catch{}if(!n)return;if(f=n.play(l,p),!n.reportsStart)p.onStart?.()}),{stop(){s=!0,f?.stop()}}},destroy(){try{r?.destroy()}catch{}a?.remove(),r=null,m=null}}}var Z=`/* 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 {
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
/* Piano keys keep their real colors in every theme. */
|
|
21
21
|
--mn-key-white: #fafafa;
|
|
22
22
|
--mn-key-black: #222;
|
|
23
|
+
/* Faint keys (a compared scale's notes, a chord's notes outside the scale): a pale white key, a
|
|
24
|
+
mid-grey black key, in every theme. */
|
|
25
|
+
--mn-key-white-faint: #d4d4d8;
|
|
26
|
+
--mn-key-black-faint: #8c8c8c;
|
|
23
27
|
font-family: var(--font-interface, system-ui, sans-serif);
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -221,10 +225,19 @@
|
|
|
221
225
|
background: var(--mn-accent);
|
|
222
226
|
}
|
|
223
227
|
|
|
224
|
-
.mn-playable [data-midi]
|
|
228
|
+
.mn-playable [data-midi],
|
|
229
|
+
.mn-playable .mn-hit {
|
|
225
230
|
cursor: pointer;
|
|
226
231
|
}
|
|
227
232
|
|
|
233
|
+
/* A playable mark's hit area: invisible, but it takes clicks and taps (an open string's circle is
|
|
234
|
+
only a ring), centered on the mark. */
|
|
235
|
+
.mn-svg .mn-hit {
|
|
236
|
+
fill: transparent;
|
|
237
|
+
stroke: none;
|
|
238
|
+
pointer-events: all;
|
|
239
|
+
}
|
|
240
|
+
|
|
228
241
|
/* A finger number or note name over a dot or key lets the click reach it. */
|
|
229
242
|
.mn-playable .mn-svg text {
|
|
230
243
|
pointer-events: none;
|
|
@@ -306,6 +319,25 @@
|
|
|
306
319
|
opacity: 0.8;
|
|
307
320
|
}
|
|
308
321
|
|
|
322
|
+
/* The view control (Tab, Score, Both): one segmented group, the view drawn in the accent color. */
|
|
323
|
+
.mn-tab-views {
|
|
324
|
+
display: inline-flex;
|
|
325
|
+
align-items: center;
|
|
326
|
+
gap: 1px;
|
|
327
|
+
padding-left: 6px;
|
|
328
|
+
border-left: 1px solid var(--mn-faint);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.mn-play .mn-tab-views .mn-tab-keep {
|
|
332
|
+
margin-left: 4px;
|
|
333
|
+
text-decoration: underline;
|
|
334
|
+
text-underline-offset: 2px;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.mn-play .mn-tab-views .mn-tab-keep[hidden] {
|
|
338
|
+
display: none;
|
|
339
|
+
}
|
|
340
|
+
|
|
309
341
|
.mn-tab-hidden {
|
|
310
342
|
position: absolute;
|
|
311
343
|
width: 1px;
|
|
@@ -343,9 +375,17 @@
|
|
|
343
375
|
stroke-dasharray: 2 2;
|
|
344
376
|
}
|
|
345
377
|
|
|
346
|
-
|
|
378
|
+
/* Piano keys keep their colors in every theme (the border color would turn a white key dark grey
|
|
379
|
+
and hide a black key in dark themes). */
|
|
380
|
+
.mn-svg .mn-key-white.mn-ghost {
|
|
381
|
+
fill: var(--mn-key-white-faint);
|
|
382
|
+
stroke: #6b6b6b;
|
|
383
|
+
stroke-dasharray: 3 2;
|
|
384
|
+
}
|
|
385
|
+
|
|
347
386
|
.mn-svg .mn-key-black.mn-ghost {
|
|
348
|
-
fill: var(--mn-faint);
|
|
387
|
+
fill: var(--mn-key-black-faint);
|
|
388
|
+
stroke: var(--mn-key-black-faint);
|
|
349
389
|
stroke-dasharray: none;
|
|
350
390
|
}
|
|
351
391
|
|
|
@@ -365,6 +405,14 @@
|
|
|
365
405
|
stroke: var(--mn-root);
|
|
366
406
|
}
|
|
367
407
|
|
|
408
|
+
/* A muted string: an x as big and as dark as an open string's circle. */
|
|
409
|
+
.mn-svg .mn-muted {
|
|
410
|
+
fill: none;
|
|
411
|
+
stroke: var(--mn-fg);
|
|
412
|
+
stroke-width: 1.5;
|
|
413
|
+
stroke-linecap: round;
|
|
414
|
+
}
|
|
415
|
+
|
|
368
416
|
/* A capo: a bar across the strings, in the text color but lighter than the dots. */
|
|
369
417
|
.mn-svg .mn-capo {
|
|
370
418
|
fill: var(--mn-fg);
|
|
@@ -386,7 +434,6 @@
|
|
|
386
434
|
fill: var(--mn-muted);
|
|
387
435
|
}
|
|
388
436
|
|
|
389
|
-
.mn-svg .mn-muted,
|
|
390
437
|
.mn-svg .mn-base-fret,
|
|
391
438
|
.mn-svg .mn-fret-number,
|
|
392
439
|
.mn-svg .mn-string-name {
|
|
@@ -436,7 +483,8 @@
|
|
|
436
483
|
font-weight: 600;
|
|
437
484
|
}
|
|
438
485
|
|
|
439
|
-
/* Which hand plays
|
|
486
|
+
/* Which hand plays the keys of a piano chord (hands: left+right): a bracket under each hand's
|
|
487
|
+
keys, LH or RH under it. */
|
|
440
488
|
.mn-svg .mn-key-hand {
|
|
441
489
|
font-size: 10px;
|
|
442
490
|
font-weight: 600;
|
|
@@ -447,6 +495,15 @@
|
|
|
447
495
|
fill: var(--mn-fg);
|
|
448
496
|
}
|
|
449
497
|
|
|
498
|
+
.mn-svg .mn-hand-bracket {
|
|
499
|
+
stroke: var(--mn-muted);
|
|
500
|
+
stroke-width: 1.2;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.mn-svg .mn-hand-bracket.mn-hand-left {
|
|
504
|
+
stroke: var(--mn-fg);
|
|
505
|
+
}
|
|
506
|
+
|
|
450
507
|
/* Several diagrams in one block: a row that wraps, or a grid of at most \`columns\` columns that
|
|
451
508
|
also wraps on narrow screens rather than shrinking diagrams to nothing. */
|
|
452
509
|
.mn-block .mn-row {
|
|
@@ -688,6 +745,12 @@
|
|
|
688
745
|
font-weight: 600;
|
|
689
746
|
}
|
|
690
747
|
|
|
748
|
+
.mn-svg .mn-strum-feel {
|
|
749
|
+
fill: var(--mn-fg);
|
|
750
|
+
font-size: 12px;
|
|
751
|
+
font-style: italic;
|
|
752
|
+
}
|
|
753
|
+
|
|
691
754
|
.mn-svg .mn-strum-chord {
|
|
692
755
|
fill: var(--mn-accent);
|
|
693
756
|
font-size: 12px;
|
|
@@ -884,4 +947,4 @@
|
|
|
884
947
|
.mn-playable .mn-svg [data-midi].mn-playing + .mn-key-label {
|
|
885
948
|
fill: var(--mn-on-playing);
|
|
886
949
|
}
|
|
887
|
-
`;var
|
|
950
|
+
`;var Fe=Z,ee="music-notation-styles";function te(e){if(e.getElementById(ee))return;let t=e.createElement("style");t.id=ee,t.textContent=Fe,e.head.appendChild(t)}var Ne=(e)=>e.reduce((t,o)=>Math.max(t,o.time+o.duration),0),q=(e)=>440*Math.pow(2,(e-69)/12);function Pe(e,t,o,n=Math.random,r={}){let a=new Float32Array(Math.round(t*o)),m=Math.max(2,Math.round(t/q(e))),i=new Float32Array(m);for(let c=0;c<m;c++)i[c]=n()*2-1;let d=Math.min(1,Math.max(0,r.brightness??1));if(d<1){let c=0.2+0.8*d,u=i[m-1];for(let g=0;g<m;g++)i[g]=u+=c*(i[g]-u)}let l=Math.min(0.5,Math.max(0,r.pick??0)),p=Math.round(l*m);if(p>0){let c=Float32Array.from(i);for(let u=0;u<m;u++)i[u]=c[u]-c[(u-p+m)%m]}if(d<1||p>0){let c=i.reduce((g,b)=>g+b,0)/m,u=i.reduce((g,b)=>Math.max(g,Math.abs(b-c)),0)||1;for(let g=0;g<m;g++)i[g]=(i[g]-c)/u}let f=r.damping!==void 0&&Number.isFinite(r.damping)?r.damping:1,s=(0.004-Math.min(0.0035,0.00004*(90-e)))*f,y=1-Math.min(0.02,Math.max(0.0001,s)),v=0;for(let c=0;c<a.length;c++){let u=(v+1)%m,g=i[v];i[v]=y*0.5*(g+i[u]),a[c]=g*0.5,v=u}return a}var ne=0.07,re=0.03,Le=(e)=>e>=88?2800:e>=84?2100:1400;function Re(e,t,o,n,r,a){let m=n+o.time,i=o.velocity===void 0||!Number.isFinite(o.velocity)?1:Math.min(127,Math.max(0,o.velocity))/100,d=e.createGain();d.connect(t);let l,p;if(o.kind==="click"){let f=e.createOscillator();f.type="triangle",f.frequency.value=Le(o.midi),l=f,p=re,d.gain.setValueAtTime(0,m),d.gain.linearRampToValueAtTime(0.5*i||0.0001,m+0.001),d.gain.exponentialRampToValueAtTime(0.0001,m+re)}else{let f=e.createBiquadFilter();if(f.type="lowpass",f.frequency.value=r==="guitar"?1800:2500,f.connect(d),r==="guitar"){let s=e.createBufferSource();s.buffer=a(e,o.midi),l=s}else{let s=e.createOscillator();s.type="triangle",s.frequency.value=q(o.midi),l=s}p=ne,d.gain.setValueAtTime(1.2*i||0.0001,m),d.gain.exponentialRampToValueAtTime(0.0001,m+ne),l.connect(f)}if(o.kind==="click")l.connect(d);return l.start(m),l.stop(m+p+0.02),l}var oe=new WeakMap;function Ve(e){let t=oe.get(e);if(t)return t;let o=e.AudioContext;if(!o)return null;let n=new o;return oe.set(e,n),n}var De=4,ae=[0,1,0.5,0.3,0.15,0.08,0.04],W=4,$e={guitar:0.15,piano:0.3},se=(e,t)=>Math.min($e[e],Math.max(0.03,t/2)),Oe=(e)=>Math.min(2.5,Math.max(0.35,Math.pow(2,(60-e)/24)));function ie(e,t=Math.random){let o=new Map,n=new WeakMap,r=(i,d)=>i+(d-i)*t(),a=(i,d,l)=>{let p=d*W+l,f=o.get(p);if(!f){let s=Pe(d,i.sampleRate,De,t,{brightness:r(0.55,0.95),pick:r(0.08,0.2),damping:r(0.85,1.15)});f=i.createBuffer(1,s.length,i.sampleRate),f.getChannelData(0).set(s),o.set(p,f)}return f},m=(i)=>{let d=n.get(i);if(!d){let l=new Float32Array(ae.length);d=i.createPeriodicWave(l,Float32Array.from(ae)),n.set(i,d)}return d};return{reportsStart:!0,play(i,{sound:d,volume:l,onEnd:p,onStart:f}){let s=Ve(e);if(!s||!i.length)return{stop(){}};let y=s.resume(),v=i.map(()=>({pluck:Math.min(W-1,Math.floor(t()*W)),cents:r(-4,4),level:r(0.93,1.07),decay:r(0.9,1.1)}));if(d==="guitar")i.forEach((h,k)=>{if(h.kind==="muted")a(s,h.midi,0);else if(!h.kind)a(s,h.midi,v[k].pluck)});let c=s.createGain();c.gain.value=Number.isFinite(l)?Math.min(1,Math.max(0,l)):0.8,c.connect(s.destination);let u=s.currentTime+0.05,g=i.map((h,k)=>{if(h.kind)return Re(s,c,h,u,d,(E,me)=>a(E,me,0));let T=v[k],S=u+h.time,R=S+h.duration,K=se(d,h.duration),N=s.createGain();N.connect(c);let O=(h.velocity===void 0||!Number.isFinite(h.velocity)?1:Math.min(127,Math.max(0,h.velocity))/100)*T.level,L;if(d==="guitar"){let E=s.createBufferSource();E.buffer=a(s,h.midi,T.pluck),E.playbackRate.value=Math.pow(2,T.cents/1200),L=E,N.gain.setValueAtTime(O,S),N.gain.setValueAtTime(O,R)}else{let E=s.createOscillator();E.setPeriodicWave(m(s)),E.frequency.value=q(h.midi),E.detune.value=T.cents,L=E,N.gain.setValueAtTime(0,S),N.gain.linearRampToValueAtTime(0.35*O,S+0.005),N.gain.setTargetAtTime(0,S+0.005,Oe(h.midi)*T.decay)}return N.gain.setTargetAtTime(0,Math.max(S+0.006,R),K/4),L.connect(N),L.start(S),L.stop(Math.max(S+0.006,R)+K),L}),b=()=>c.disconnect(),C=!1,P,w=()=>{if(C||!f)return;let h=Number.isFinite(s.outputLatency)?s.outputLatency:0;P=e.setTimeout(()=>{if(!C)f()},Math.max(0,u-s.currentTime+h)*1000)};if(f)Promise.resolve(y).then(w,w);let F=e.setTimeout(()=>p?.(),(Ne(i)+0.15)*1000),M=i.reduce((h,k)=>Math.max(h,k.time+k.duration+se(d,k.duration)),0),x=e.setTimeout(b,(M+0.15)*1000);return{stop(){if(C)return;C=!0,e.clearTimeout(F),e.clearTimeout(P),e.clearTimeout(x);let h=s.currentTime;c.gain.setTargetAtTime(0,h,0.01);for(let k of g)try{k.stop(h+0.05)}catch{}x=e.setTimeout(b,80)}}}}}var Ie="pre > code.language-tab, pre > code.language-score",V=new Map,j=null;function ze(e){let t=e.defaultView;if(t.alphaTab)return Promise.resolve(t.alphaTab);return j??=new Promise((o,n)=>{let r=e.createElement("script");r.src=B().script,r.onload=()=>t.alphaTab?o(t.alphaTab):n(Error("alphaTab")),r.onerror=()=>{j=null,n(Error("Couldn't load alphaTab"))},e.head.appendChild(r)}),j}function le(e){for(let[o,{result:n,holder:r}]of V)if(!o.isConnected||!n.el.isConnected){if(n.destroy(),r.remove(),V.delete(o),o.isConnected)o.style.removeProperty("display")}let t=[...e.querySelectorAll(Ie)].filter((o)=>{let n=o.parentElement,r=V.get(n);if(!r)return n.dataset.mpRendered!=="pending";if(r.source===(o.textContent??""))return!1;return r.result.destroy(),r.holder.remove(),V.delete(n),!0});if(!t.length)return;for(let o of t)o.parentElement.dataset.mpRendered="pending";ze(e).then((o)=>{let n=B(),r={scriptFile:null,font:n.font,soundFont:n.soundFont},a=e.defaultView;a.musicNotationSoundfontPlayer??=X(o,r,e,ie(a));for(let m of t){let i=m.parentElement;if(!i.parentElement)continue;let d=m.classList.contains("language-score")?"score":"tab",l=m.textContent??"",p=e.createElement("div");p.className="mn-tab-holder",i.insertAdjacentElement("afterend",p);let f=Q(d,l,p,{alphaTab:o,assets:r});V.set(i,{result:f,source:l,holder:p}),f.ready.then(({ok:s})=>{if(i.dataset.mpRendered=s?"done":"error",s&&f.el.isConnected)i.style.display="none"})}}).catch(()=>{for(let o of t)o.parentElement.dataset.mpRendered="error"})}if(!window.musicNotationTabLoaded){window.musicNotationTabLoaded=!0;let e=()=>{te(document),le(document);let t=!1;new MutationObserver(()=>{if(t)return;t=!0,requestAnimationFrame(()=>{t=!1,le(document)})}).observe(document.body,{childList:!0,subtree:!0,characterData:!0})};if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e);else e()}})();
|
|
@@ -12,11 +12,22 @@ export interface PlayOptions {
|
|
|
12
12
|
volume?: number;
|
|
13
13
|
/** Scales: notes per minute, 90 by default; also strum patterns' tempo when they have none. */
|
|
14
14
|
bpm?: number;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Chords: milliseconds between strings; by default 12 on guitar, 0 (a block) on piano. A number
|
|
17
|
+
* is the guitar's (piano chords stay a block); `{ guitar, piano }` sets each instrument's.
|
|
18
|
+
*/
|
|
19
|
+
strum?: number | {
|
|
20
|
+
guitar?: number;
|
|
21
|
+
piano?: number;
|
|
22
|
+
};
|
|
17
23
|
}
|
|
18
24
|
/** A number within bounds; the fallback when it isn't a number at all. */
|
|
19
25
|
export declare const clamp: (n: number | undefined, lo: number, hi: number, fallback: number) => number;
|
|
26
|
+
/**
|
|
27
|
+
* Each instrument's strum from the app's `strum` option, clamped: a plain number is the guitar's,
|
|
28
|
+
* so piano chords stay a block unless `{ piano }` is given.
|
|
29
|
+
*/
|
|
30
|
+
export declare function strumsOf(strum: PlayOptions['strum']): Record<Sound, number>;
|
|
20
31
|
/** Small icons, drawn so they look the same in every font. */
|
|
21
32
|
declare const ICONS: Record<'play' | 'stop' | 'loop' | 'volume', string>;
|
|
22
33
|
export declare function icon(doc: Document, name: keyof typeof ICONS): SVGElement;
|
|
@@ -12,6 +12,12 @@ export interface NoteEvent {
|
|
|
12
12
|
duration: number;
|
|
13
13
|
/** How hard the note is played, MIDI style (1–127); 100 when absent. */
|
|
14
14
|
velocity?: number;
|
|
15
|
+
/**
|
|
16
|
+
* A percussive sound in place of the note: `muted`, a dead (muted) string, as in a muted
|
|
17
|
+
* strum's chuck; `click`, a metronome tick (`midi` higher for a stronger beat). Players that
|
|
18
|
+
* don't know it play the note as written (short).
|
|
19
|
+
*/
|
|
20
|
+
kind?: 'muted' | 'click';
|
|
15
21
|
}
|
|
16
22
|
export interface PlayHandle {
|
|
17
23
|
stop(): void;
|
|
@@ -41,20 +47,78 @@ export interface SequenceOptions {
|
|
|
41
47
|
bpm: number;
|
|
42
48
|
/** Chords: milliseconds between two strings of the strum. */
|
|
43
49
|
strum: number;
|
|
50
|
+
/**
|
|
51
|
+
* Scales: the tonic's pitch class (0–11). The run starts on the lowest tonic drawn, goes up to
|
|
52
|
+
* the highest note, down to the lowest, and back up to that tonic. Without it (or when no
|
|
53
|
+
* tonic is drawn), it runs from the lowest note.
|
|
54
|
+
*/
|
|
55
|
+
root?: number | null;
|
|
56
|
+
/**
|
|
57
|
+
* Scales: the pitch classes of a chord drawn over the scale; its other notes are passing
|
|
58
|
+
* notes, played slightly softer.
|
|
59
|
+
*/
|
|
60
|
+
tones?: readonly number[];
|
|
61
|
+
/** The instrument, for the touch of a chord: guitar (the default) or piano. */
|
|
62
|
+
sound?: Sound;
|
|
63
|
+
/**
|
|
64
|
+
* Scales: play the pitches in the order given, then back (a list of notes as written: G F E
|
|
65
|
+
* D C, then D E F G), instead of the scale run.
|
|
66
|
+
*/
|
|
67
|
+
ordered?: boolean;
|
|
44
68
|
}
|
|
45
69
|
export declare const DEFAULT_SEQUENCE: SequenceOptions;
|
|
46
70
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
71
|
+
* Milliseconds between two notes of a chord, by instrument: a guitar strum (about 12 ms a
|
|
72
|
+
* string, a 6-string chord in 60 ms), a piano chord struck as a block.
|
|
73
|
+
*/
|
|
74
|
+
export declare const DEFAULT_STRUM: Readonly<Record<Sound, number>>;
|
|
75
|
+
/**
|
|
76
|
+
* The order a scale's notes play in, every note drawn at least once: from the lowest tonic up to
|
|
77
|
+
* the highest note, down to the lowest note, and back up to the tonic (the way teachers run a
|
|
78
|
+
* position: root, top, bottom, root). With the tonic at the bottom, that is up and back down;
|
|
79
|
+
* without a tonic, from the lowest note up and back down. The top and bottom notes play once.
|
|
80
|
+
*/
|
|
81
|
+
export declare function scaleRun(pitches: readonly number[], root?: number | null): number[];
|
|
82
|
+
/**
|
|
83
|
+
* The notes a diagram plays: a chord strums low to high and rings; a scale plays every note drawn
|
|
84
|
+
* (see `scaleRun`), each note one beat long, legato.
|
|
49
85
|
*/
|
|
50
86
|
export declare function sequenceOf(kind: PlayKind, pitches: readonly number[], options?: SequenceOptions): NoteEvent[];
|
|
51
87
|
/** The end of a sequence, in seconds. */
|
|
52
88
|
export declare const lengthOf: (events: readonly NoteEvent[]) => number;
|
|
89
|
+
/** How a string is plucked, for a little variety between notes. */
|
|
90
|
+
export interface PluckOptions {
|
|
91
|
+
/** 0 (a soft, dark pluck) to 1 (bright, the default). */
|
|
92
|
+
brightness?: number;
|
|
93
|
+
/** Where the pick hits, as a part of the string's length (0 to 0.5; 0, the default: no effect). */
|
|
94
|
+
pick?: number;
|
|
95
|
+
/** How fast the string loses its energy, times the usual (1 by default). */
|
|
96
|
+
damping?: number;
|
|
97
|
+
}
|
|
53
98
|
/**
|
|
54
99
|
* A plucked string (Karplus-Strong): a burst of noise through a delay line one period long,
|
|
55
|
-
* averaged as it loops, so the tone softens as it decays, like a string.
|
|
100
|
+
* averaged as it loops, so the tone softens as it decays, like a string. The burst can be
|
|
101
|
+
* darker (a softer pluck) and shaped by the pick's position.
|
|
56
102
|
*/
|
|
57
|
-
export declare function pluckedString(midi: number, sampleRate: number, seconds: number, random?: () => number): Float32Array;
|
|
103
|
+
export declare function pluckedString(midi: number, sampleRate: number, seconds: number, random?: () => number, options?: PluckOptions): Float32Array;
|
|
58
104
|
/** A simple piano tone: a few harmonics with a struck attack, the higher ones fading first. */
|
|
59
105
|
export declare function pianoTone(midi: number, sampleRate: number, seconds: number): Float32Array;
|
|
60
|
-
|
|
106
|
+
/**
|
|
107
|
+
* The pitch of a light synthesizer click (a tick, not a note): 2.8 kHz from MIDI 88 (the bar's
|
|
108
|
+
* downbeat), 2.1 kHz from 84 (a counted beat), else 1.4 kHz (the other beats).
|
|
109
|
+
*/
|
|
110
|
+
export declare const clickFrequency: (midi: number) => number;
|
|
111
|
+
/**
|
|
112
|
+
* Seconds a note takes to fade after its end (a finger lifting off a string, a piano's damper),
|
|
113
|
+
* at most half the note (a muted strum stays short).
|
|
114
|
+
*/
|
|
115
|
+
export declare const RELEASE: Readonly<Record<Sound, number>>;
|
|
116
|
+
/** The release of a note of `duration` seconds. */
|
|
117
|
+
export declare const releaseOf: (sound: Sound, duration: number) => number;
|
|
118
|
+
/**
|
|
119
|
+
* The light synthesizer: computed sound, a few KB, no download. No two notes sound quite the
|
|
120
|
+
* same: each guitar note takes one of a few plucks of its string (brightness, pick position,
|
|
121
|
+
* decay), and every note varies a little in pitch (a few cents) and level. `random` (0–1) is
|
|
122
|
+
* for tests.
|
|
123
|
+
*/
|
|
124
|
+
export declare function lightPlayer(win: Window, random?: () => number): NotePlayer;
|