scribbletune 5.1.2 → 5.4.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/dist/browser.cjs +1183 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.js +1135 -1
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +571 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +323 -0
- package/dist/index.d.ts +303 -350
- package/dist/index.js +524 -1
- package/dist/index.js.map +1 -1
- package/dist/scribbletune.global.js +1944 -0
- package/dist/scribbletune.global.js.map +1 -0
- package/package.json +32 -45
- package/dist/scribbletune.es.js +0 -588
- package/dist/scribbletune.js +0 -2
- package/dist/scribbletune.js.map +0 -1
- package/dist/scribbletune.umd.js +0 -1
package/dist/scribbletune.umd.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(v,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(v=typeof globalThis<"u"?globalThis:v||self,T(v.Scribbletune={}))})(this,function(v){"use strict";var T={},D;function J(){return D||(D=1,function(t){(()=>{var r={413:s=>{s.exports=JSON.parse('{"5th":"100000010000","M7#5sus4":"100001001001","7#5sus4":"100001001010","sus4":"100001010000","M7sus4":"100001010001","7sus4":"100001010010","7no5":"100010000010","aug":"100010001000","M7b6":"100010001001","maj7#5":"100010001001","7#5":"100010001010","7b13":"100010001010","M":"100010010000","maj7":"100010010001","7th":"100010010010","6th":"100010010100","7add6":"100010010110","7b6":"100010011010","Mb5":"100010100000","M7b5":"100010100001","7b5":"100010100010","maj#4":"100010110001","7#11":"100010110010","M6#11":"100010110100","7#11b13":"100010111010","m#5":"100100001000","mb6M7":"100100001001","m7#5":"100100001010","m":"100100010000","m/ma7":"100100010001","m7":"100100010010","m6":"100100010100","mMaj7b6":"100100011001","dim":"100100100000","oM7":"100100100001","m7b5":"100100100010","dim7":"100100100100","o7M7":"100100100101","4th":"100101000010","madd4":"100101010000","m7add11":"100101010010","+add#9":"100110001000","7#5#9":"100110001010","7#9":"100110010010","13#9":"100110010110","7#9b13":"100110011010","maj7#9#11":"100110110001","7#9#11":"100110110010","13#9#11":"100110110110","7#9#11b13":"100110111010","sus2":"101000010000","M9#5sus4":"101001001001","sus24":"101001010000","M9sus4":"101001010001","11th":"101001010010","9sus4":"101001010010","13sus4":"101001010110","9no5":"101010000010","13no5":"101010000110","M#5add9":"101010001000","maj9#5":"101010001001","9#5":"101010001010","9b13":"101010001010","Madd9":"101010010000","maj9":"101010010001","9th":"101010010010","6/9":"101010010100","maj13":"101010010101","M7add13":"101010010101","13th":"101010010110","M9b5":"101010100001","9b5":"101010100010","13b5":"101010100110","9#5#11":"101010101010","maj9#11":"101010110001","9#11":"101010110010","69#11":"101010110100","M13#11":"101010110101","13#11":"101010110110","9#11b13":"101010111010","m9#5":"101100001010","madd9":"101100010000","mM9":"101100010001","m9":"101100010010","m69":"101100010100","m13":"101100010110","mMaj9b6":"101100011001","m9b5":"101100100010","m11A":"101101001010","m11":"101101010010","b9sus":"110001010010","11b9":"110001010010","7sus4b9b13":"110001011010","alt7":"110010000010","7#5b9":"110010001010","Maddb9":"110010010000","M7b9":"110010010001","7b9":"110010010010","13b9":"110010010110","7b9b13":"110010011010","7#5b9#11":"110010101010","7b9#11":"110010110010","13b9#11":"110010110110","7b9b13#11":"110010111010","mb6b9":"110100001000","7b9#9":"110110010010"}')},722:s=>{s.exports=JSON.parse(`{"major pentatonic":"101010010100","ionian pentatonic":"100011010001","mixolydian pentatonic":"100011010010","ritusen":"101001010100","egyptian":"101001010010","neopolitan major pentatonic":"100011100010","vietnamese 1":"100101011000","pelog":"110100011000","kumoijoshi":"110001011000","hirajoshi":"101100011000","iwato":"110001100010","in-sen":"110001010010","lydian pentatonic":"100010110001","malkos raga":"100101001010","locrian pentatonic":"100101100010","minor pentatonic":"100101010010","minor six pentatonic":"100101010100","flat three pentatonic":"101100010100","flat six pentatonic":"101010011000","scriabin":"110010010100","whole tone pentatonic":"100010101010","lydian #5P pentatonic":"100010101001","lydian dominant pentatonic":"100010110010","minor #7M pentatonic":"100101010001","super locrian pentatonic":"100110100010","minor hexatonic":"101101010001","augmented":"100110011001","major blues":"101110010100","piongio":"101001010110","prometheus neopolitan":"110010100110","prometheus":"101010100110","mystery #1":"110010101010","six tone symmetric":"110011001100","whole tone":"101010101010","messiaen's mode #5":"110001110001","minor blues":"100101110010","locrian major":"101011101010","double harmonic lydian":"110010111001","harmonic minor":"101101011001","altered":"110110101010","locrian #2":"101101101010","mixolydian b6":"101011011010","lydian dominant":"101010110110","lydian":"101010110101","lydian augmented":"101010101101","dorian b2":"110101010110","melodic minor":"101101010101","locrian":"110101101010","ultralocrian":"110110101100","locrian 6":"110101100110","augmented heptatonic":"100111011001","romanian minor":"101100110110","dorian #4":"101100110110","lydian diminished":"101100110101","phrygian":"110101011010","leading whole tone":"101010101011","lydian minor":"101010111010","phrygian dominant":"110011011010","balinese":"110101011001","neopolitan major":"110101010101","aeolian":"101101011010","harmonic major":"101011011001","double harmonic major":"110011011001","dorian":"101101010110","hungarian minor":"101100111001","hungarian major":"100110110110","oriental":"110011100110","flamenco":"110110110010","todi raga":"110100111001","mixolydian":"101011010110","persian":"110011101001","major":"101011010101","enigmatic":"110010101011","major augmented":"101011001101","lydian #9":"100110110101","messiaen's mode #4":"111001111001","purvi raga":"110011111001","spanish heptatonic":"110111011010","bebop":"101011010111","bebop minor":"101111010110","bebop major":"101011011101","bebop locrian":"110101111010","minor bebop":"101101011011","diminished":"101101101101","ichikosucho":"101011110101","minor six diminished":"101101011101","half-whole diminished":"110110110110","kafi raga":"100111010111","messiaen's mode #6":"101011101011","composite blues":"101111110110","messiaen's mode #3":"101110111011","messiaen's mode #7":"111101111101","chromatic":"111111111111","ionian":"101011010101","minor":"101101011010"}`)}},a={};function d(s){var c=a[s];if(c!==void 0)return c.exports;var u=a[s]={exports:{}};return r[s](u,u.exports,d),u.exports}d.d=(s,c)=>{for(var u in c)d.o(c,u)&&!d.o(s,u)&&Object.defineProperty(s,u,{enumerable:!0,get:c[u]})},d.o=(s,c)=>Object.prototype.hasOwnProperty.call(s,c),d.r=s=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(s,"__esModule",{value:!0})};var o={};(()=>{d.r(o),d.d(o,{chord:()=>h,chords:()=>n,inlineChord:()=>e,scale:()=>m,scales:()=>f});var s=d(722),c=d(413),u=function(p){var g=p.scale,b=p.chord,y=g||b,A=g?"scale":"chord";if(typeof y!="string")throw new Error("".concat(y," is not a valid input for ").concat(A));var M,I,N=y.indexOf(" ");N===-1?(M=y.slice(1),I=y[0],y[1]!=="b"&&y[1]!=="#"||(M=y.slice(2),I+=y[1])):(M=y.slice(N===-1?1:N+1),I=y.slice(0,N));var y0=function(_){return{"C#":"Db","D#":"Eb","F#":"Gb","G#":"Ab","A#":"Bb"}[_.toUpperCase()]||_.charAt(0).toUpperCase()+_.slice(1)}(I.replace(/\d/g,"")),H=I.replace(/\D/g,"")!==""?+I.replace(/\D/g,""):4;if(isNaN(H))throw new Error("".concat(I[0]," does not have a valid octave"));if(!s[M]&&!c[M])throw new Error("".concat(y," is not a valid ").concat(A));for(var v0=function(_,R){var Y=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],b0=Y.map(function(j){return j+R}),g0=Y.map(function(j){return j+(R+1)}),K=b0.concat(g0);return K.slice(K.indexOf(_+R))}(y0,H),z=[],O=0,$=0,G=g?s:c;O<G[M].length;)G[M][O]==="1"&&z.push(v0[$]),O++,$++;return z},e=function(p){var g,b,y="b9sus",A=4;return p.includes(y)?(b=y,g=p.slice(0,p.indexOf(y))):(g=p[0],b=p.slice(1),p[1]!=="b"&&p[1]!=="#"||(g+=p[1],b=p.slice(2))),p.includes("_")&&(A=+p.split("_")[1],b=b.slice(0,b.indexOf("_"))),u({chord:g+A+" "+b})},n=function(){return Object.keys(c)},f=function(){return Object.keys(s)},h=function(p){return u({chord:p})},m=function(p){return u({scale:p})}})();var i=t;for(var l in o)i[l]=o[l];o.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})()}(T)),T}var E=J();const C=t=>/^[a-gA-G](?:#|b)?\d$/.test(t),q=t=>(t=JSON.stringify(t.split("")),t=t.replace(/,"\[",/g,", ["),t=t.replace(/"\[",/g,"["),t=t.replace(/,"\]"/g,"]"),JSON.parse(t)),W=(t,r=!0)=>{const a=t.length-1;return t.forEach((d,o)=>{if(o>=a)return;const i=r?Math.floor(Math.random()*(a-o))+1+o:Math.floor(Math.random()*(a+1-o))+o;t[o]=t[i],t[i]=d}),t},w=t=>t.length>1?t[Math.round(Math.random())]:t[0],F=()=>!!Math.round(Math.random()),Q=t=>typeof t.message=="string",X=t=>{let r,a,d,o;try{r=E.inlineChord(t)}catch(i){d=i}try{a=E.chord(t.replace(/_/g," "))}catch(i){o=i}if(!d&&!o){if(r.toString()!==a.toString())throw new Error(`Chord ${t} cannot decode, guessing ${r} or ${a}`);return r}return d?o?E.chord(t):a:r},S=t=>{if(typeof t=="string"&&C(t))return[t];if(Array.isArray(t))return t.forEach(r=>{if(Array.isArray(r))r.forEach(a=>{if(typeof a!="string"||!C(a))throw new TypeError("array of arrays must comprise valid notes")});else if(typeof r!="string"||!C(r))throw new TypeError("array must comprise valid notes")}),t;if(!Array.isArray(t)){const r=X(t);if(r&&r.length)return r}throw new Error(`Chord ${t} not found`)},k=(t=1)=>Math.round(Math.random()*t),Z=()=>({notes:["C4"],pattern:"x",shuffle:!1,sizzle:!1,sizzleReps:1,arpegiate:!1,subdiv:"4n",amp:100,accentLow:70,randomNotes:null,offlineRendering:!1}),B={"1m":2048,"2m":4096,"3m":6144,"4m":8192,"1n":512,"2n":256,"4n":128,"8n":64,"16n":32},e0=t=>{if(t={...Z(),...t||{}},typeof t.notes=="string"&&(t.notes=t.notes.replace(/\s{2,}/g," "),t.notes=t.notes.split(" ")),t.notes=t.notes?t.notes.map(S):[],/[^x\-_[\]R]/.test(t.pattern))throw new TypeError(`pattern can only comprise x - _ [ ] R, found ${t.pattern}`);t.shuffle&&(t.notes=W(t.notes)),t.randomNotes&&typeof t.randomNotes=="string"&&(t.randomNotes=t.randomNotes.replace(/\s{2,}/g," ").split(/\s/)),t.randomNotes&&(t.randomNotes=t.randomNotes.map(S));const r=[];let a=0;const d=(o,i,l)=>{let s=0;o.forEach((c,u)=>{var e;if(typeof c=="string"){let n=null;if(c==="-"||(c==="R"&&k()&&t.randomNotes&&t.randomNotes.length>0?n=t.randomNotes[k(t.randomNotes.length-1)]:t.notes&&(n=t.notes[a])),(c==="x"||c==="R")&&a++,(c==="x"||c==="-"||c==="R")&&(r.push({note:n,length:i,level:c==="R"&&!t.randomNotes?t.accentLow:t.amp}),s+=i),c==="_"&&r.length&&(r[r.length-1].length+=i,s+=i),l&&s!==l&&u===o.length-1){const f=Math.abs(l-s),h=r[r.length-1];h.length>f?h.length=h.length-f:h.length=h.length+f}a===((e=t.notes)==null?void 0:e.length)&&(a=0)}if(Array.isArray(c)){let n=!1;(c.length%2!==0||i%2!==0)&&(n=!0),d(c,Math.round(i/c.length),n&&i),s+=i}})};if(d(q(t.pattern),B[t.subdiv]||B["4n"],!1),t.sizzle){const o=[],i=t.sizzle===!0?"sin":t.sizzle,l=r.length,s=t.amp,c=t.sizzleReps,u=s/(l/c);if(i==="sin"||i==="cos")for(let e=0;e<l;e++){const n=Math[i](e*Math.PI/(l/c))*s;o.push(Math.round(Math.abs(n)))}if(i==="rampUp"){let e=0;for(let n=0;n<l;n++)n%(l/c)===0?e=0:e=e+u,o.push(Math.round(Math.abs(e)))}if(i==="rampDown"){let e=s;for(let n=0;n<l;n++)n%(l/c)===0?e=s:e=e-u,o.push(Math.round(Math.abs(e)))}for(let e=0;e<o.length;e++)r[e].level=o[e]?o[e]:1}if(t.accent){if(/[^x-]/.test(t.accent))throw new TypeError("Accent can only have x and - characters");let o=0;for(const i of r){let l=t.accent[o]==="x"?t.amp:t.accentLow;t.sizzle&&(l=(i.level+l)/2),i.level=Math.round(l),o=o+1,o===t.accent.length&&(o=0)}}return r},t0=t=>{const r={ionian:["I","ii","iii","IV","V","vi","vii°"],dorian:["i","ii","III","IV","v","vi°","VII"],phrygian:["i","II","III","iv","v°","VI","vii"],lydian:["I","II","iii","iv°","V","vi","vii"],mixolydian:["I","ii","iii°","IV","v","vi","VII"],aeolian:["i","ii°","III","iv","v","VI","VII"],locrian:["i°","II","iii","iv","V","VI","vii"],"melodic minor":["i","ii","III+","IV","V","vi°","vii°"],"harmonic minor":["i","ii°","III+","iv","V","VI","vii°"]};return r.major=r.ionian,r.minor=r.aeolian,r[t]||[]},n0={i:0,ii:1,iii:2,iv:3,v:4,vi:5,vii:6},i0=t=>{const r=t.replace(/\W/g,"");let a="M";return r.toLowerCase()===r&&(a="m"),t.indexOf("°")>-1?a+"7b5":t.indexOf("+")>-1?a+"#5":t.indexOf("7")>-1?a==="M"?"maj7":"m7":a},o0=(t,r)=>{const a=t.split(" ");a[0].match(/\d/)||(a[0]+="4",t=a.join(" "));const d=E.scale(t);return r.replace(/\s*,+\s*/g," ").split(" ").map(l=>{const s=i0(l),c=n0[l.replace(/\W|\d/g,"").toLowerCase()],u=d[c],e=u.replace(/\D+/,"");return u.replace(/\d/,"")+s+"_"+e}).toString().replace(/,/g," ")},U=({T:t,P:r,D:a})=>(d=4)=>{const o=[];o.push(w(t));let i=1;for(i<d-1&&(o.push(w(r)),i++),i<d-1&&F()&&(o.push(w(r)),i++),i<d-1&&(o.push(w(a)),i++),i<d-1&&(o.push(w(r)),i++),i<d-1&&(o.push(w(a)),i++),i<d-1&&F()&&(o.push(w(r)),i++);i<d;)o.push(w(a)),i++;return o},r0=U({T:["I","vi"],P:["ii","IV"],D:["V"]}),s0=U({T:["i","VI"],P:["ii","iv"],D:["V"]}),a0=(t,r=4)=>t==="major"||t==="M"?r0(r):t==="minor"||t==="m"?s0(r):[],c0=4,L=(t,r)=>{const a=l=>{if(!l)throw new Error("Empty element");const s=l.replace(/\d/,""),c=l.replace(/\D/g,"")||c0;if(!s)throw new Error("Incorrect note");return s+(+c+1)},d=t.map(a),o=d.map(a);return[...t,...d,...o].slice(0,r)},l0=t=>{let r=[];const a={count:4,order:"0123",chords:""};if(typeof t=="string")a.chords=t;else{if(t.order&&t.order.match(/\D/g))throw new TypeError("Invalid value for order");if(t.count>8||t.count<2)throw new TypeError("Invalid value for count");t.count&&!t.order&&(a.order=Array.from(Array(t.count).keys()).join("")),Object.assign(a,t)}if(typeof a.chords=="string")a.chords.split(" ").forEach((o,i)=>{try{const l=L(E.inlineChord(o),a.count),s=a.order.split("").map(c=>l[c]);r=[...r,...s]}catch{throw new Error(`Cannot decode chord ${i+1} "${o}" in given "${a.chords}"`)}});else if(Array.isArray(a.chords))a.chords.forEach((d,o)=>{try{const i=L(d,a.count),l=a.order.split("").map(s=>i[s]);r=[...r,...l]}catch(i){throw new Error(`${Q(i)?i.message:i} in chord ${o+1} "${d}"`)}});else throw new TypeError("Invalid value for chords");return r},d0={};var x={exports:{}},f0=x.exports,P;function h0(){return P||(P=1,function(t,r){var a={};(function(d){var o=d.DEFAULT_VOLUME=90;d.DEFAULT_DURATION=128,d.DEFAULT_CHANNEL=0;var i={midi_letter_pitches:{a:21,b:23,c:12,d:14,e:16,f:17,g:19},midiPitchFromNote:function(e){var n=/([a-g])(#+|b+)?([0-9]+)$/i.exec(e),f=n[1].toLowerCase(),h=n[2]||"",m=parseInt(n[3],10);return 12*m+i.midi_letter_pitches[f]+(h.substr(0,1)=="#"?1:-1)*h.length},ensureMidiPitch:function(e){return typeof e=="number"||!/[^0-9]/.test(e)?parseInt(e,10):i.midiPitchFromNote(e)},midi_pitches_letter:{12:"c",13:"c#",14:"d",15:"d#",16:"e",17:"f",18:"f#",19:"g",20:"g#",21:"a",22:"a#",23:"b"},midi_flattened_notes:{"a#":"bb","c#":"db","d#":"eb","f#":"gb","g#":"ab"},noteFromMidiPitch:function(e,p){var f=0,h=e,m,p=p||!1;return e>23&&(f=Math.floor(e/12)-1,h=e-f*12),m=i.midi_pitches_letter[h],p&&m.indexOf("#")>0&&(m=i.midi_flattened_notes[m]),m+f},mpqnFromBpm:function(e){var n=Math.floor(6e7/e),f=[];do f.unshift(n&255),n>>=8;while(n);for(;f.length<3;)f.push(0);return f},bpmFromMpqn:function(e){var n=e;if(typeof e[0]<"u"){n=0;for(var f=0,h=e.length-1;h>=0;++f,--h)n|=e[f]<<h}return Math.floor(6e7/e)},codes2Str:function(e){return String.fromCharCode.apply(null,e)},str2Bytes:function(e,n){if(n)for(;e.length/2<n;)e="0"+e;for(var f=[],h=e.length-1;h>=0;h=h-2){var m=h===0?e[h]:e[h-1]+e[h];f.unshift(parseInt(m,16))}return f},translateTickTime:function(e){for(var n=e&127;e=e>>7;)n<<=8,n|=e&127|128;for(var f=[];f.push(n&255),n&128;)n>>=8;return f}},l=function(e){if(!this)return new l(e);e&&(e.type!==null||e.type!==void 0)&&(e.channel!==null||e.channel!==void 0)&&(e.param1!==null||e.param1!==void 0)&&(this.setTime(e.time),this.setType(e.type),this.setChannel(e.channel),this.setParam1(e.param1),this.setParam2(e.param2))};l.NOTE_OFF=128,l.NOTE_ON=144,l.AFTER_TOUCH=160,l.CONTROLLER=176,l.PROGRAM_CHANGE=192,l.CHANNEL_AFTERTOUCH=208,l.PITCH_BEND=224,l.prototype.setTime=function(e){this.time=i.translateTickTime(e||0)},l.prototype.setType=function(e){if(e<l.NOTE_OFF||e>l.PITCH_BEND)throw new Error("Trying to set an unknown event: "+e);this.type=e},l.prototype.setChannel=function(e){if(e<0||e>15)throw new Error("Channel is out of bounds.");this.channel=e},l.prototype.setParam1=function(e){this.param1=e},l.prototype.setParam2=function(e){this.param2=e},l.prototype.toBytes=function(){var e=[],n=this.type|this.channel&15;return e.push.apply(e,this.time),e.push(n),e.push(this.param1),this.param2!==void 0&&this.param2!==null&&e.push(this.param2),e};var s=function(e){if(!this)return new s(e);this.setTime(e.time),this.setType(e.type),this.setData(e.data)};s.SEQUENCE=0,s.TEXT=1,s.COPYRIGHT=2,s.TRACK_NAME=3,s.INSTRUMENT=4,s.LYRIC=5,s.MARKER=6,s.CUE_POINT=7,s.CHANNEL_PREFIX=32,s.END_OF_TRACK=47,s.TEMPO=81,s.SMPTE=84,s.TIME_SIG=88,s.KEY_SIG=89,s.SEQ_EVENT=127,s.prototype.setTime=function(e){this.time=i.translateTickTime(e||0)},s.prototype.setType=function(e){this.type=e},s.prototype.setData=function(e){this.data=e},s.prototype.toBytes=function(){if(!this.type)throw new Error("Type for meta-event not specified.");var e=[];if(e.push.apply(e,this.time),e.push(255,this.type),Array.isArray(this.data))e.push(this.data.length),e.push.apply(e,this.data);else if(typeof this.data=="number")e.push(1,this.data);else if(this.data!==null&&this.data!==void 0){e.push(this.data.length);var n=this.data.split("").map(function(f){return f.charCodeAt(0)});e.push.apply(e,n)}else e.push(0);return e};var c=function(e){if(!this)return new c(e);var n=e||{};this.events=n.events||[]};c.START_BYTES=[77,84,114,107],c.END_BYTES=[0,255,47,0],c.prototype.addEvent=function(e){return this.events.push(e),this},c.prototype.addNoteOn=c.prototype.noteOn=function(e,n,f,h){return this.events.push(new l({type:l.NOTE_ON,channel:e,param1:i.ensureMidiPitch(n),param2:h||o,time:f||0})),this},c.prototype.addNoteOff=c.prototype.noteOff=function(e,n,f,h){return this.events.push(new l({type:l.NOTE_OFF,channel:e,param1:i.ensureMidiPitch(n),param2:h||o,time:f||0})),this},c.prototype.addNote=c.prototype.note=function(e,n,f,h,m){return this.noteOn(e,n,h,m),f&&this.noteOff(e,n,f,m),this},c.prototype.addChord=c.prototype.chord=function(e,n,f,h){if(!Array.isArray(n)&&!n.length)throw new Error("Chord must be an array of pitches");return n.forEach(function(m){this.noteOn(e,m,0,h)},this),n.forEach(function(m,p){p===0?this.noteOff(e,m,f):this.noteOff(e,m)},this),this},c.prototype.setInstrument=c.prototype.instrument=function(e,n,f){return this.events.push(new l({type:l.PROGRAM_CHANGE,channel:e,param1:n,time:f||0})),this},c.prototype.setTempo=c.prototype.tempo=function(e,n){return this.events.push(new s({type:s.TEMPO,data:i.mpqnFromBpm(e),time:n||0})),this},c.prototype.toBytes=function(){var e=0,n=[],f=c.START_BYTES,h=c.END_BYTES,m=function(g){var b=g.toBytes();e+=b.length,n.push.apply(n,b)};this.events.forEach(m),e+=h.length;var p=i.str2Bytes(e.toString(16),4);return f.concat(p,n,h)};var u=function(e){if(!this)return new u(e);var n=e||{};if(n.ticks){if(typeof n.ticks!="number")throw new Error("Ticks per beat must be a number!");if(n.ticks<=0||n.ticks>=32768||n.ticks%1!==0)throw new Error("Ticks per beat must be an integer between 1 and 32767!")}this.ticks=n.ticks||128,this.tracks=n.tracks||[]};u.HDR_CHUNKID="MThd",u.HDR_CHUNK_SIZE="\0\0\0",u.HDR_TYPE0="\0\0",u.HDR_TYPE1="\0",u.prototype.addTrack=function(e){return e?(this.tracks.push(e),this):(e=new c,this.tracks.push(e),e)},u.prototype.toBytes=function(){var e=this.tracks.length.toString(16),n=u.HDR_CHUNKID+u.HDR_CHUNK_SIZE;return parseInt(e,16)>1?n+=u.HDR_TYPE1:n+=u.HDR_TYPE0,n+=i.codes2Str(i.str2Bytes(e,2)),n+=String.fromCharCode(this.ticks/256,this.ticks%256),this.tracks.forEach(function(f){n+=i.codes2Str(f.toBytes())}),n},d.Util=i,d.File=u,d.Track=c,d.Event=l,d.MetaEvent=s})(a),t!==null?t.exports=a:r!==null?r=a:f0.Midi=a}(x,x.exports)),x.exports}var V=h0();const u0=(t,r="music.mid",a)=>{const o=m0(t,a).toBytes();if(r===null)return o;if(r.endsWith(".mid")||(r=r+".mid"),typeof window<"u"&&window.URL&&window.URL.createObjectURL)return p0(o,r);d0.writeFileSync(r,o,"binary"),console.log(`MIDI file generated: ${r}.`)},p0=(t,r)=>{const a=new Uint8Array(t.length);for(let i=0;i<t.length;i++){const l=t.charCodeAt(i);a[i]=l}const d=new Blob([a],{type:"audio/midi"}),o=document.createElement("a");return o.href=typeof window<"u"&&typeof window.URL<"u"&&typeof window.URL.createObjectURL<"u"&&window.URL.createObjectURL(d)||"",o.download=r,o.innerText="Download MIDI file",o},m0=(t,r)=>{const a=new V.File,d=new V.Track;typeof r=="number"&&d.setTempo(r),a.addTrack(d);for(const o of t){const i=o.level||127;o.note?typeof o.note=="string"?(d.noteOn(0,o.note,o.length,i),d.noteOff(0,o.note,o.length,i)):d.addChord(0,o.note,o.length,i):d.noteOff(0,"",o.length)}return a};v.arp=l0,v.chord=E.chord,v.chords=E.chords,v.clip=e0,v.getChordDegrees=t0,v.getChordsByProgression=o0,v.midi=u0,v.progression=a0,v.scale=E.scale,v.scales=E.scales,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|