@dsebastien/music-notation 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -15
- package/dist/index.js +92 -24
- package/dist/index.js.map +8 -8
- package/dist/music-notation.css +30 -9
- package/dist/music-notation.publish.min.js +47 -26
- package/dist/music-notation.tab.min.js +34 -13
- package/dist/playback/controls.d.ts +3 -2
- package/dist/publish/index.js +62 -15
- package/dist/publish/index.js.map +8 -8
- package/dist/tab/index.js +17 -3
- package/dist/tab/index.js.map +4 -4
- package/dist/theory/scales.d.ts +14 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @dsebastien/music-notation 0.5.
|
|
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
|
|
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((
|
|
1
|
+
/*! @dsebastien/music-notation 0.5.2 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. */
|
|
4
4
|
.mn-block,
|
|
5
5
|
.mn-svg,
|
|
6
6
|
.mn-chart {
|
|
@@ -122,6 +122,13 @@
|
|
|
122
122
|
cursor: pointer;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/* The opened list is a native popup on the page's background, not the bar's: its options take
|
|
126
|
+
the page's colors, not the bar's inherited text color (light text on white in dark themes). */
|
|
127
|
+
.mn-play select option {
|
|
128
|
+
color: var(--text-normal, #222);
|
|
129
|
+
background: var(--background-primary, #fff);
|
|
130
|
+
}
|
|
131
|
+
|
|
125
132
|
.mn-play button:hover,
|
|
126
133
|
.mn-play select:hover,
|
|
127
134
|
.mn-play button:focus-visible,
|
|
@@ -163,16 +170,16 @@
|
|
|
163
170
|
all: unset;
|
|
164
171
|
appearance: none;
|
|
165
172
|
width: 44px;
|
|
166
|
-
/*
|
|
167
|
-
|
|
173
|
+
/* As tall as the thumb, so no host or browser has to center it: the visible 3px track is a
|
|
174
|
+
centered line drawn by the background. */
|
|
175
|
+
height: 9px;
|
|
168
176
|
margin: 0;
|
|
169
|
-
|
|
170
|
-
background: var(--mn-faint);
|
|
177
|
+
background: linear-gradient(var(--mn-faint), var(--mn-faint)) center / 100% 3px no-repeat;
|
|
171
178
|
cursor: pointer;
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
.mn-play input[type='range']::-webkit-slider-runnable-track {
|
|
175
|
-
height:
|
|
182
|
+
height: 9px;
|
|
176
183
|
border: none;
|
|
177
184
|
background: transparent;
|
|
178
185
|
}
|
|
@@ -181,23 +188,31 @@
|
|
|
181
188
|
appearance: none;
|
|
182
189
|
width: 9px;
|
|
183
190
|
height: 9px;
|
|
184
|
-
|
|
191
|
+
/* Hosts may move thumbs (Obsidian: relative, top -6px): the thumb fills the track instead. */
|
|
192
|
+
position: static;
|
|
193
|
+
top: 0;
|
|
194
|
+
margin: 0;
|
|
185
195
|
border: none;
|
|
186
196
|
border-radius: 50%;
|
|
187
197
|
background: var(--mn-accent);
|
|
188
198
|
box-shadow: none;
|
|
189
199
|
}
|
|
190
200
|
|
|
201
|
+
/* Hosts ring a focused thumb (Obsidian): only for keyboard focus here, not after a click. */
|
|
202
|
+
.mn-play input[type='range']:focus:not(:focus-visible)::-webkit-slider-thumb {
|
|
203
|
+
box-shadow: none;
|
|
204
|
+
}
|
|
205
|
+
|
|
191
206
|
.mn-play input[type='range']::-moz-range-track {
|
|
192
|
-
height:
|
|
207
|
+
height: 9px;
|
|
193
208
|
border: none;
|
|
194
|
-
|
|
195
|
-
background: var(--mn-faint);
|
|
209
|
+
background: transparent;
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
.mn-play input[type='range']::-moz-range-thumb {
|
|
199
213
|
width: 9px;
|
|
200
214
|
height: 9px;
|
|
215
|
+
margin: 0;
|
|
201
216
|
border: none;
|
|
202
217
|
border-radius: 50%;
|
|
203
218
|
background: var(--mn-accent);
|
|
@@ -366,6 +381,12 @@
|
|
|
366
381
|
font-weight: 600;
|
|
367
382
|
}
|
|
368
383
|
|
|
384
|
+
.mn-svg .mn-key-finger {
|
|
385
|
+
font-size: 10px;
|
|
386
|
+
fill: var(--mn-fg);
|
|
387
|
+
font-weight: 600;
|
|
388
|
+
}
|
|
389
|
+
|
|
369
390
|
/* Several diagrams in one block: a row that wraps, or a grid of at most \`columns\` columns that
|
|
370
391
|
also wraps on narrow screens rather than shrinking diagrams to nothing. */
|
|
371
392
|
.mn-block .mn-row {
|
|
@@ -524,4 +545,4 @@
|
|
|
524
545
|
color: var(--text-error, #c92a2a);
|
|
525
546
|
font-size: 0.9em;
|
|
526
547
|
}
|
|
527
|
-
`;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))),
|
|
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()}})();
|
|
@@ -2,9 +2,10 @@ import { type NotePlayer, type Sound } from './player.js';
|
|
|
2
2
|
export interface PlayOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Plays the notes: a player, or a function returning one at each play (null for the default),
|
|
5
|
-
* so a soundfont loaded later is used once it's there. The
|
|
5
|
+
* so a soundfont loaded later is used once it's there. The function gets the diagram's window
|
|
6
|
+
* (popouts have their own). The light synthesizer by default.
|
|
6
7
|
*/
|
|
7
|
-
player?: NotePlayer | (() => NotePlayer | null | undefined);
|
|
8
|
+
player?: NotePlayer | ((win: Window) => NotePlayer | null | undefined);
|
|
8
9
|
/** Guitar or piano; by default the diagram's (piano for keyboards and piano chords). */
|
|
9
10
|
sound?: Sound;
|
|
10
11
|
/** 0 to 1, 0.8 by default. */
|
package/dist/publish/index.js
CHANGED
|
@@ -559,7 +559,7 @@ var CANONICAL = new Map([
|
|
|
559
559
|
var canonicalSuffix = (suffix) => CANONICAL.get(suffix) ?? suffix;
|
|
560
560
|
|
|
561
561
|
// src/theory/scales.ts
|
|
562
|
-
import { Scale } from "tonal";
|
|
562
|
+
import { Note, Scale } from "tonal";
|
|
563
563
|
var ALIASES2 = new Map([
|
|
564
564
|
["natural minor", "minor"],
|
|
565
565
|
["blues", "minor blues"],
|
|
@@ -603,6 +603,19 @@ function modesOf(text) {
|
|
|
603
603
|
return null;
|
|
604
604
|
return modes.map(([tonic, mode]) => `${tonic} ${mode}`);
|
|
605
605
|
}
|
|
606
|
+
var DOUBLE_ACCIDENTAL = /^[A-G](##|bb)/;
|
|
607
|
+
var SUPERLOCRIAN = ["1P", "2m", "3m", "4d", "5d", "6m", "7m"];
|
|
608
|
+
function scaleSpelling(scale) {
|
|
609
|
+
const hasDouble = (notes) => notes.some((n) => DOUBLE_ACCIDENTAL.test(n));
|
|
610
|
+
if (!hasDouble(scale.notes))
|
|
611
|
+
return { notes: scale.notes, intervals: scale.intervals };
|
|
612
|
+
if (scale.type === "altered" && scale.tonic) {
|
|
613
|
+
const notes = SUPERLOCRIAN.map((interval) => Note.transpose(scale.tonic, interval));
|
|
614
|
+
if (!hasDouble(notes))
|
|
615
|
+
return { notes, intervals: SUPERLOCRIAN };
|
|
616
|
+
}
|
|
617
|
+
return { notes: scale.notes, intervals: scale.intervals };
|
|
618
|
+
}
|
|
606
619
|
var scaleTypes = () => Scale.names();
|
|
607
620
|
|
|
608
621
|
// src/theory/note-set.ts
|
|
@@ -696,7 +709,8 @@ function scaleNoteSet(name) {
|
|
|
696
709
|
const scale = Scale2.get(scaleName(name));
|
|
697
710
|
if (scale.empty || !scale.tonic)
|
|
698
711
|
return null;
|
|
699
|
-
const
|
|
712
|
+
const { notes, intervals } = scaleSpelling(scale);
|
|
713
|
+
const set = fromNames(name.trim(), notes, intervals);
|
|
700
714
|
if (set)
|
|
701
715
|
set.scaleType = scale.type;
|
|
702
716
|
return set;
|
|
@@ -860,6 +874,7 @@ var WHITE_H = 104;
|
|
|
860
874
|
var BLACK_W = 14;
|
|
861
875
|
var BLACK_H = 64;
|
|
862
876
|
var TITLE3 = 22;
|
|
877
|
+
var FINGER_ROW = 16;
|
|
863
878
|
var isBlack = (midi) => BLACK.has((midi % 12 + 12) % 12);
|
|
864
879
|
function parseKeyRange(text) {
|
|
865
880
|
const parts = text.split(/\s*-\s*(?=[A-Ga-g])/);
|
|
@@ -888,10 +903,13 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
888
903
|
const vertical = options.orientation === "vertical";
|
|
889
904
|
const top = options.title ? TITLE3 : 0;
|
|
890
905
|
const length = whites.length * WHITE_W;
|
|
891
|
-
const
|
|
906
|
+
const label = options.label ?? "notes";
|
|
907
|
+
const fingerRow = label !== "fingers" && [...options.fingers?.keys() ?? []].some((midi) => midi >= from && midi <= to) ? FINGER_ROW : 0;
|
|
908
|
+
const depth = WHITE_H + fingerRow;
|
|
909
|
+
const content = (vertical ? depth : length) + 2;
|
|
892
910
|
const width = Math.max(content, titleWidth(options.title));
|
|
893
911
|
const shift = (width - content) / 2;
|
|
894
|
-
const height = top + (vertical ? length :
|
|
912
|
+
const height = top + (vertical ? length : depth) + 2;
|
|
895
913
|
const at = (along, depth) => vertical ? [shift + 1 + depth, top + 1 + length - along] : [shift + 1 + along, top + 1 + depth];
|
|
896
914
|
const key = (along, size, depth) => {
|
|
897
915
|
const [x1, y1] = at(along, 0);
|
|
@@ -903,7 +921,6 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
903
921
|
height: Math.abs(y2 - y1)
|
|
904
922
|
};
|
|
905
923
|
};
|
|
906
|
-
const label = options.label ?? "notes";
|
|
907
924
|
const root = svgRoot(doc, width, height, "mn-keyboard", `${options.title ?? `Keyboard: ${set.title}`}${describeMarks(set, options.marks)}`);
|
|
908
925
|
if (options.title) {
|
|
909
926
|
root.appendChild(svgText(doc, options.title, {
|
|
@@ -953,6 +970,15 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
953
970
|
}));
|
|
954
971
|
caption(black, at(along + BLACK_W / 2, BLACK_H - 13), true);
|
|
955
972
|
});
|
|
973
|
+
if (fingerRow) {
|
|
974
|
+
for (const [midi, finger] of options.fingers) {
|
|
975
|
+
if (midi < from || midi > to)
|
|
976
|
+
continue;
|
|
977
|
+
const whitesBelow = whites.filter((w) => w < midi).length;
|
|
978
|
+
const along = isBlack(midi) ? whitesBelow * WHITE_W : whitesBelow * WHITE_W + WHITE_W / 2;
|
|
979
|
+
root.appendChild(svgLabel(doc, finger, at(along, WHITE_H + FINGER_ROW / 2 - 1), "mn-key-finger"));
|
|
980
|
+
}
|
|
981
|
+
}
|
|
956
982
|
const played = [];
|
|
957
983
|
for (let midi = from;midi <= to; midi++)
|
|
958
984
|
if (memberOf(set, midi))
|
|
@@ -1167,6 +1193,8 @@ var TONAL_SUFFIXES = new Map([
|
|
|
1167
1193
|
["M9", "maj9"],
|
|
1168
1194
|
["M7", "maj7"],
|
|
1169
1195
|
["M69", "6/9"],
|
|
1196
|
+
["7add6", "13"],
|
|
1197
|
+
["m7add6", "m13"],
|
|
1170
1198
|
["m69", "m6/9"],
|
|
1171
1199
|
["Msus2", "sus2"],
|
|
1172
1200
|
["Msus4", "sus4"],
|
|
@@ -1184,6 +1212,8 @@ function normalize(symbol) {
|
|
|
1184
1212
|
bass = rest.slice(slash + 1);
|
|
1185
1213
|
rest = rest.slice(0, slash);
|
|
1186
1214
|
}
|
|
1215
|
+
if (!TONAL_SUFFIXES.has(rest) && rest.endsWith("no5"))
|
|
1216
|
+
rest = rest.slice(0, -3);
|
|
1187
1217
|
const suffix = canonicalSuffix(TONAL_SUFFIXES.get(rest) ?? rest);
|
|
1188
1218
|
if (!COMMON.includes(suffix) && !EXTENDED.has(suffix))
|
|
1189
1219
|
return null;
|
|
@@ -1191,10 +1221,20 @@ function normalize(symbol) {
|
|
|
1191
1221
|
return parseChord(out) ? out : null;
|
|
1192
1222
|
}
|
|
1193
1223
|
var USUAL_ROOTS = new Set(["C", "C#", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"]);
|
|
1224
|
+
function bassCost(root, quality, bass) {
|
|
1225
|
+
if (!bass)
|
|
1226
|
+
return 0;
|
|
1227
|
+
const chroma = chromaOf(bass);
|
|
1228
|
+
const tone = Chord2.get(`${root}${quality}`).notes.find((note) => chromaOf(note) === chroma);
|
|
1229
|
+
if (tone)
|
|
1230
|
+
return tone === bass ? 0 : 1;
|
|
1231
|
+
const flats = keyPrefersFlats(`${root}${quality.startsWith("m") && !quality.startsWith("maj") ? "m" : ""}`);
|
|
1232
|
+
return bass.includes("b") === flats || !/[#b]/.test(bass) ? 0 : 1;
|
|
1233
|
+
}
|
|
1194
1234
|
var rank = (symbol) => {
|
|
1195
|
-
const m = /^([A-G][#b]*)(.*?)(
|
|
1235
|
+
const m = /^([A-G][#b]*)(.*?)(?:\/([A-G][#b]*))?$/.exec(symbol);
|
|
1196
1236
|
const common = COMMON.indexOf(m[2]);
|
|
1197
|
-
return ((common < 0 ? COMMON.length + 5 : common) + (m[3] ? 10 : 0)) *
|
|
1237
|
+
return ((common < 0 ? COMMON.length + 5 : common) + (m[3] ? 10 : 0)) * 4 + (USUAL_ROOTS.has(m[1]) ? 0 : 2) + bassCost(m[1], m[2], m[3]);
|
|
1198
1238
|
};
|
|
1199
1239
|
function soundOf(symbol) {
|
|
1200
1240
|
const m = /^([A-G][#b]*)(.*?)(?:\/([A-G][#b]*))?$/.exec(symbol);
|
|
@@ -1214,7 +1254,7 @@ function detectChordFromPitches(pitches) {
|
|
|
1214
1254
|
return null;
|
|
1215
1255
|
const readings = new Set;
|
|
1216
1256
|
for (const flats of [false, true]) {
|
|
1217
|
-
for (const symbol of Chord2.detect(namesOf(pitches, flats))) {
|
|
1257
|
+
for (const symbol of Chord2.detect(namesOf(pitches, flats), { assumePerfectFifth: true })) {
|
|
1218
1258
|
const normalized = normalize(symbol);
|
|
1219
1259
|
if (normalized)
|
|
1220
1260
|
readings.add(normalized);
|
|
@@ -1718,21 +1758,28 @@ var renderKeyboardBlock = (doc, block, options) => {
|
|
|
1718
1758
|
const range = field(block, "range");
|
|
1719
1759
|
handOf(block, options);
|
|
1720
1760
|
const fingering = field(block, "fingering");
|
|
1761
|
+
const keys = range ? rangeOf(range) : undefined;
|
|
1721
1762
|
let fingers;
|
|
1722
1763
|
if (fingering && set.root !== null && !set.pitches) {
|
|
1723
|
-
|
|
1724
|
-
|
|
1764
|
+
let start = 60 + set.root;
|
|
1765
|
+
if (keys) {
|
|
1766
|
+
const first = keys[0] + ((set.root - keys[0]) % 12 + 12) % 12;
|
|
1767
|
+
start = first <= keys[1] ? first : keys[0] - ((keys[0] - set.root) % 12 + 12) % 12;
|
|
1768
|
+
}
|
|
1769
|
+
const octave = [
|
|
1725
1770
|
...set.members.map((m) => start + (m.chroma - set.root + 12) % 12),
|
|
1726
1771
|
start + 12
|
|
1727
|
-
];
|
|
1728
|
-
fingers = fingersFor(
|
|
1772
|
+
].sort((a, b) => a - b);
|
|
1773
|
+
fingers = fingersFor(octave, fingering);
|
|
1774
|
+
if (!keys)
|
|
1775
|
+
set.pitches = octave;
|
|
1729
1776
|
}
|
|
1730
1777
|
return renderKeyboard(doc, set, {
|
|
1731
1778
|
playAs: !set.scaleType && set.root !== null ? "chord" : "scale",
|
|
1732
1779
|
title: field(block, "title"),
|
|
1733
1780
|
label: labelField(block, fingers ? "fingers" : "notes", fingers !== undefined),
|
|
1734
1781
|
fingers,
|
|
1735
|
-
range: keyRange(
|
|
1782
|
+
range: keyRange(keys ? keys : fingers && set.pitches ? [set.pitches[0], set.pitches[set.pitches.length - 1]] : keyRangeOf(set)),
|
|
1736
1783
|
orientation: orientationOf(block, options.orientation?.keyboard),
|
|
1737
1784
|
marks: marksOf(block, set)
|
|
1738
1785
|
});
|
|
@@ -1972,7 +2019,7 @@ function lightFor(win) {
|
|
|
1972
2019
|
return player;
|
|
1973
2020
|
}
|
|
1974
2021
|
function playerFor(win, options) {
|
|
1975
|
-
const given = typeof options.player === "function" ? options.player() : options.player;
|
|
2022
|
+
const given = typeof options.player === "function" ? options.player(win) : options.player;
|
|
1976
2023
|
return given ?? lightFor(win);
|
|
1977
2024
|
}
|
|
1978
2025
|
function dataOf(diagram) {
|
|
@@ -3593,5 +3640,5 @@ export {
|
|
|
3593
3640
|
renderAll
|
|
3594
3641
|
};
|
|
3595
3642
|
|
|
3596
|
-
//# debugId=
|
|
3643
|
+
//# debugId=BD9F4C871A0080E264756E2164756E21
|
|
3597
3644
|
//# sourceMappingURL=index.js.map
|