scribbletune 5.1.0 → 5.2.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.js +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +515 -0
- package/dist/lib/arp.d.ts +10 -0
- package/dist/lib/browser-clip.d.ts +14 -0
- package/dist/lib/browser-index.d.ts +7 -0
- package/dist/lib/channel.d.ts +61 -0
- package/dist/lib/clip.d.ts +2 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/midi.d.ts +11 -0
- package/dist/lib/progression.d.ts +25 -0
- package/dist/lib/session.d.ts +14 -0
- package/dist/lib/types/arp-params.d.ts +6 -0
- package/dist/lib/types/channel-params.d.ts +92 -0
- package/dist/lib/types/channel-pattern.d.ts +24 -0
- package/dist/lib/types/clip-params.d.ts +104 -0
- package/dist/lib/types/event-fn.d.ts +7 -0
- package/dist/lib/types/index.d.ts +14 -0
- package/dist/lib/types/note-object.d.ts +6 -0
- package/dist/lib/types/nvp.d.ts +4 -0
- package/dist/lib/types/play-params.d.ts +15 -0
- package/dist/lib/types/player-observer-fn.d.ts +6 -0
- package/dist/lib/types/progression-scale.d.ts +2 -0
- package/dist/lib/types/seq-fn.d.ts +2 -0
- package/dist/lib/types/sizzle-style.d.ts +2 -0
- package/dist/lib/types/synth-params.d.ts +20 -0
- package/dist/lib/types/tpd.d.ts +15 -0
- package/dist/lib/utils.d.ts +56 -0
- package/dist/scribbletune.js +1 -1
- package/dist/scribbletune.js.map +1 -1
- package/package.json +8 -10
- package/dist/max.js +0 -2
- package/dist/max.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export const arp: (chordsOrParams: string | ArpParams) => string[];
|
|
|
52
52
|
* This link will enable the generated MIDI as a downloadable file.
|
|
53
53
|
* @param {Number | null} bpm If a value is provided, the generated midi file will be set to this bpm value.
|
|
54
54
|
*/
|
|
55
|
-
export const midi: (notes: NoteObject[], fileName?: string | null, bpm?: number
|
|
55
|
+
export const midi: (notes: NoteObject[], fileName?: string | null, bpm?: number) => string | HTMLAnchorElement | undefined;
|
|
56
56
|
|
|
57
57
|
interface ArpParams {
|
|
58
58
|
count: number;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var e={397:(e,t)=>{(()=>{"use strict";var e={413:e=>{e.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:e=>{e.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"}')}},r={};function n(t){var o=r[t];if(void 0!==o)return o.exports;var i=r[t]={exports:{}};return e[t](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{n.r(o),n.d(o,{chord:()=>c,chords:()=>a,inlineChord:()=>i,scale:()=>u,scales:()=>s});var e=n(722),t=n(413),r=function(r){var n=r.scale,o=r.chord,i=n||o,a=n?"scale":"chord";if("string"!=typeof i)throw new Error("".concat(i," is not a valid input for ").concat(a));var s,c,u=i.indexOf(" ");-1===u?(s=i.slice(1),c=i[0],"b"!==i[1]&&"#"!==i[1]||(s=i.slice(2),c+=i[1])):(s=i.slice(-1===u?1:u+1),c=i.slice(0,u));var d=function(e){return{"C#":"Db","D#":"Eb","F#":"Gb","G#":"Ab","A#":"Bb"}[e.toUpperCase()]||e.charAt(0).toUpperCase()+e.slice(1)}(c.replace(/\d/g,"")),p=""!==c.replace(/\D/g,"")?+c.replace(/\D/g,""):4;if(isNaN(p))throw new Error("".concat(c[0]," does not have a valid octave"));if(!e[s]&&!t[s])throw new Error("".concat(i," is not a valid ").concat(a));for(var h=function(e,t){var r=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],n=r.map((function(e){return e+t})),o=r.map((function(e){return e+(t+1)})),i=n.concat(o);return i.slice(i.indexOf(e+t))}(d,p),l=[],f=0,m=0,v=n?e:t;f<v[s].length;)"1"===v[s][f]&&l.push(h[m]),f++,m++;return l},i=function(e){var t,n,o="b9sus",i=4;return e.includes(o)?(n=o,t=e.slice(0,e.indexOf(o))):(t=e[0],n=e.slice(1),"b"!==e[1]&&"#"!==e[1]||(t+=e[1],n=e.slice(2))),e.includes("_")&&(i=+e.split("_")[1],n=n.slice(0,n.indexOf("_"))),r({chord:t+i+" "+n})},a=function(){return Object.keys(t)},s=function(){return Object.keys(e)},c=function(e){return r({chord:e})},u=function(e){return r({scale:e})}})();var i=t;for(var a in o)i[a]=o[a];o.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})()},126:function(e,t,r){e=r.nmd(e);var n={};!function(e){var t=e.DEFAULT_VOLUME=90,r=(e.DEFAULT_DURATION=128,e.DEFAULT_CHANNEL=0,{midi_letter_pitches:{a:21,b:23,c:12,d:14,e:16,f:17,g:19},midiPitchFromNote:function(e){var t=/([a-g])(#+|b+)?([0-9]+)$/i.exec(e),n=t[1].toLowerCase(),o=t[2]||"";return 12*parseInt(t[3],10)+r.midi_letter_pitches[n]+("#"==o.substr(0,1)?1:-1)*o.length},ensureMidiPitch:function(e){return"number"!=typeof e&&/[^0-9]/.test(e)?r.midiPitchFromNote(e):parseInt(e,10)},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,t){var n,o=0,i=e;return t=t||!1,e>23&&(i=e-12*(o=Math.floor(e/12)-1)),n=r.midi_pitches_letter[i],t&&n.indexOf("#")>0&&(n=r.midi_flattened_notes[n]),n+o},mpqnFromBpm:function(e){var t=Math.floor(6e7/e),r=[];do{r.unshift(255&t),t>>=8}while(t);for(;r.length<3;)r.push(0);return r},bpmFromMpqn:function(e){if(void 0!==e[0])for(var t=0,r=e.length-1;r>=0;++t,--r)e[t];return Math.floor(6e7/e)},codes2Str:function(e){return String.fromCharCode.apply(null,e)},str2Bytes:function(e,t){if(t)for(;e.length/2<t;)e="0"+e;for(var r=[],n=e.length-1;n>=0;n-=2){var o=0===n?e[n]:e[n-1]+e[n];r.unshift(parseInt(o,16))}return r},translateTickTime:function(e){for(var t=127&e;e>>=7;)t<<=8,t|=127&e|128;for(var r=[];r.push(255&t),128&t;)t>>=8;return r}}),n=function(e){if(!this)return new n(e);!e||null===e.type&&void 0===e.type||null===e.channel&&void 0===e.channel||null===e.param1&&void 0===e.param1||(this.setTime(e.time),this.setType(e.type),this.setChannel(e.channel),this.setParam1(e.param1),this.setParam2(e.param2))};n.NOTE_OFF=128,n.NOTE_ON=144,n.AFTER_TOUCH=160,n.CONTROLLER=176,n.PROGRAM_CHANGE=192,n.CHANNEL_AFTERTOUCH=208,n.PITCH_BEND=224,n.prototype.setTime=function(e){this.time=r.translateTickTime(e||0)},n.prototype.setType=function(e){if(e<n.NOTE_OFF||e>n.PITCH_BEND)throw new Error("Trying to set an unknown event: "+e);this.type=e},n.prototype.setChannel=function(e){if(e<0||e>15)throw new Error("Channel is out of bounds.");this.channel=e},n.prototype.setParam1=function(e){this.param1=e},n.prototype.setParam2=function(e){this.param2=e},n.prototype.toBytes=function(){var e=[],t=this.type|15&this.channel;return e.push.apply(e,this.time),e.push(t),e.push(this.param1),void 0!==this.param2&&null!==this.param2&&e.push(this.param2),e};var o=function(e){if(!this)return new o(e);this.setTime(e.time),this.setType(e.type),this.setData(e.data)};o.SEQUENCE=0,o.TEXT=1,o.COPYRIGHT=2,o.TRACK_NAME=3,o.INSTRUMENT=4,o.LYRIC=5,o.MARKER=6,o.CUE_POINT=7,o.CHANNEL_PREFIX=32,o.END_OF_TRACK=47,o.TEMPO=81,o.SMPTE=84,o.TIME_SIG=88,o.KEY_SIG=89,o.SEQ_EVENT=127,o.prototype.setTime=function(e){this.time=r.translateTickTime(e||0)},o.prototype.setType=function(e){this.type=e},o.prototype.setData=function(e){this.data=e},o.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("number"==typeof this.data)e.push(1,this.data);else if(null!==this.data&&void 0!==this.data){e.push(this.data.length);var t=this.data.split("").map((function(e){return e.charCodeAt(0)}));e.push.apply(e,t)}else e.push(0);return e};var i=function(e){if(!this)return new i(e);var t=e||{};this.events=t.events||[]};i.START_BYTES=[77,84,114,107],i.END_BYTES=[0,255,47,0],i.prototype.addEvent=function(e){return this.events.push(e),this},i.prototype.addNoteOn=i.prototype.noteOn=function(e,o,i,a){return this.events.push(new n({type:n.NOTE_ON,channel:e,param1:r.ensureMidiPitch(o),param2:a||t,time:i||0})),this},i.prototype.addNoteOff=i.prototype.noteOff=function(e,o,i,a){return this.events.push(new n({type:n.NOTE_OFF,channel:e,param1:r.ensureMidiPitch(o),param2:a||t,time:i||0})),this},i.prototype.addNote=i.prototype.note=function(e,t,r,n,o){return this.noteOn(e,t,n,o),r&&this.noteOff(e,t,r,o),this},i.prototype.addChord=i.prototype.chord=function(e,t,r,n){if(!Array.isArray(t)&&!t.length)throw new Error("Chord must be an array of pitches");return t.forEach((function(t){this.noteOn(e,t,0,n)}),this),t.forEach((function(t,n){0===n?this.noteOff(e,t,r):this.noteOff(e,t)}),this),this},i.prototype.setInstrument=i.prototype.instrument=function(e,t,r){return this.events.push(new n({type:n.PROGRAM_CHANGE,channel:e,param1:t,time:r||0})),this},i.prototype.setTempo=i.prototype.tempo=function(e,t){return this.events.push(new o({type:o.TEMPO,data:r.mpqnFromBpm(e),time:t||0})),this},i.prototype.toBytes=function(){var e=0,t=[],n=i.START_BYTES,o=i.END_BYTES;this.events.forEach((function(r){var n=r.toBytes();e+=n.length,t.push.apply(t,n)})),e+=o.length;var a=r.str2Bytes(e.toString(16),4);return n.concat(a,t,o)};var a=function(e){if(!this)return new a(e);var t=e||{};if(t.ticks){if("number"!=typeof t.ticks)throw new Error("Ticks per beat must be a number!");if(t.ticks<=0||t.ticks>=32768||t.ticks%1!=0)throw new Error("Ticks per beat must be an integer between 1 and 32767!")}this.ticks=t.ticks||128,this.tracks=t.tracks||[]};a.HDR_CHUNKID="MThd",a.HDR_CHUNK_SIZE="\0\0\0",a.HDR_TYPE0="\0\0",a.HDR_TYPE1="\0",a.prototype.addTrack=function(e){return e?(this.tracks.push(e),this):(e=new i,this.tracks.push(e),e)},a.prototype.toBytes=function(){var e=this.tracks.length.toString(16),t=a.HDR_CHUNKID+a.HDR_CHUNK_SIZE;return parseInt(e,16)>1?t+=a.HDR_TYPE1:t+=a.HDR_TYPE0,t+=r.codes2Str(r.str2Bytes(e,2)),t+=String.fromCharCode(this.ticks/256,this.ticks%256),this.tracks.forEach((function(e){t+=r.codes2Str(e.toBytes())})),t},e.Util=r,e.File=a,e.Track=i,e.Event=n,e.MetaEvent=o}(n),null!==e?e.exports=n:null!==t?t=n:this.Midi=n},148:function(e,t,r){"use strict";var n=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.arp=void 0;var o=r(397),i=r(604),a=function(e,t){var r=function(e){if(!e)throw new Error("Empty element");var t=e.replace(/\d/,""),r=e.replace(/\D/g,"")||4;if(!t)throw new Error("Incorrect note");return t+(+r+1)},o=e.map(r),i=o.map(r);return n(n(n([],e,!0),o,!0),i,!0).slice(0,t)};t.arp=function(e){var t=[],r={count:4,order:"0123",chords:""};if("string"==typeof e)r.chords=e;else{if(e.order&&e.order.match(/\D/g))throw new TypeError("Invalid value for order");if(e.count>8||e.count<2)throw new TypeError("Invalid value for count");e.count&&!e.order&&(r.order=Array.from(Array(e.count).keys()).join("")),Object.assign(r,e)}if("string"==typeof r.chords)r.chords.split(" ").forEach((function(e,i){try{var s=a((0,o.inlineChord)(e),r.count),c=r.order.split("").map((function(e){return s[e]}));t=n(n([],t,!0),c,!0)}catch(t){throw new Error("Cannot decode chord "+(i+1)+' "'+e+'" in given "'+r.chords+'"')}}));else{if(!Array.isArray(r.chords))throw new TypeError("Invalid value for chords");r.chords.forEach((function(e,o){try{var s=a(e,r.count),c=r.order.split("").map((function(e){return s[e]}));t=n(n([],t,!0),c,!0)}catch(t){throw new Error(((0,i.errorHasMessage)(t)?t.message:t)+" in chord "+(o+1)+' "'+e+'"')}}))}return t}},768:function(e,t,r){"use strict";var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.clip=void 0;var o=r(604),i={"1m":2048,"2m":4096,"3m":6144,"4m":8192,"1n":512,"2n":256,"4n":128,"8n":64,"16n":32};t.clip=function(e){if("string"==typeof(e=n(n({},{notes:["C4"],pattern:"x",shuffle:!1,sizzle:!1,sizzleReps:1,arpegiate:!1,subdiv:"4n",amp:100,accentLow:70,randomNotes:null,offlineRendering:!1}),e||{})).notes&&(e.notes=e.notes.replace(/\s{2,}/g," "),e.notes=e.notes.split(" ")),e.notes=e.notes?e.notes.map(o.convertChordsToNotes):[],/[^x\-_[\]R]/.test(e.pattern))throw new TypeError("pattern can only comprise x - _ [ ] R, found "+e.pattern);e.shuffle&&(e.notes=(0,o.shuffle)(e.notes)),e.randomNotes&&"string"==typeof e.randomNotes&&(e.randomNotes=e.randomNotes.replace(/\s{2,}/g," ").split(/\s/)),e.randomNotes&&(e.randomNotes=e.randomNotes.map(o.convertChordsToNotes));var t=[],r=0,a=function(n,i,s){var c=0;n.forEach((function(u,d){var p;if("string"==typeof u){var h=null;if("-"===u||("R"===u&&(0,o.randomInt)()&&e.randomNotes&&e.randomNotes.length>0?h=e.randomNotes[(0,o.randomInt)(e.randomNotes.length-1)]:e.notes&&(h=e.notes[r])),"x"!==u&&"R"!==u||r++,"x"!==u&&"-"!==u&&"R"!==u||(t.push({note:h,length:i,level:"R"!==u||e.randomNotes?e.amp:e.accentLow}),c+=i),"_"===u&&t.length&&(t[t.length-1].length+=i,c+=i),s&&c!==s&&d===n.length-1){var l=Math.abs(s-c),f=t[t.length-1];f.length>l?f.length=f.length-l:f.length=f.length+l}r===(null===(p=e.notes)||void 0===p?void 0:p.length)&&(r=0)}if(Array.isArray(u)){var m=!1;u.length%2==0&&i%2==0||(m=!0),a(u,Math.round(i/u.length),m&&i),c+=i}}))};if(a((0,o.expandStr)(e.pattern),i[e.subdiv]||i["4n"],!1),e.sizzle){var s=[],c=!0===e.sizzle?"sin":e.sizzle,u=t.length,d=e.amp,p=e.sizzleReps,h=d/(u/p);if("sin"===c||"cos"===c)for(var l=0;l<u;l++){var f=Math[c](l*Math.PI/(u/p))*d;s.push(Math.round(Math.abs(f)))}if("rampUp"===c)for(f=0,l=0;l<u;l++)l%(u/p)==0?f=0:f+=h,s.push(Math.round(Math.abs(f)));if("rampDown"===c)for(f=d,l=0;l<u;l++)l%(u/p)==0?f=d:f-=h,s.push(Math.round(Math.abs(f)));for(l=0;l<s.length;l++)t[l].level=s[l]?s[l]:1}if(e.accent){if(/[^x-]/.test(e.accent))throw new TypeError("Accent can only have x and - characters");for(var m=0,v=0,y=t;v<y.length;v++){var g=y[v];f="x"===e.accent[m]?e.amp:e.accentLow,e.sizzle&&(f=(g.level+f)/2),g.level=Math.round(f),(m+=1)===e.accent.length&&(m=0)}}return t}},136:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.midi=t.arp=t.progression=t.getChordsByProgression=t.getChordDegrees=t.clip=t.chords=t.chord=t.modes=t.scales=t.mode=t.scale=void 0;var i=r(397);Object.defineProperty(t,"scales",{enumerable:!0,get:function(){return i.scales}}),Object.defineProperty(t,"modes",{enumerable:!0,get:function(){return i.scales}}),Object.defineProperty(t,"chords",{enumerable:!0,get:function(){return i.chords}}),Object.defineProperty(t,"scale",{enumerable:!0,get:function(){return i.scale}}),Object.defineProperty(t,"mode",{enumerable:!0,get:function(){return i.scale}}),Object.defineProperty(t,"chord",{enumerable:!0,get:function(){return i.chord}});var a=r(768);Object.defineProperty(t,"clip",{enumerable:!0,get:function(){return a.clip}});var s=r(668);Object.defineProperty(t,"getChordDegrees",{enumerable:!0,get:function(){return s.getChordDegrees}}),Object.defineProperty(t,"getChordsByProgression",{enumerable:!0,get:function(){return s.getChordsByProgression}}),Object.defineProperty(t,"progression",{enumerable:!0,get:function(){return s.progression}});var c=r(148);Object.defineProperty(t,"arp",{enumerable:!0,get:function(){return c.arp}});var u=r(267);Object.defineProperty(t,"midi",{enumerable:!0,get:function(){return u.midi}}),o(r(621),t)},267:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return o(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.midi=void 0;var s=a(r(231)),c=i(r(126));t.midi=function(e,t,r){void 0===t&&(t="music.mid");var n=d(e,r).toBytes();return null===t?n:(t.endsWith(".mid")||(t+=".mid"),"undefined"!=typeof window&&window.URL&&window.URL.createObjectURL?u(n,t):(s.default.writeFileSync(t,n,"binary"),void console.log("MIDI file generated: "+t+".")))};var u=function(e,t){for(var r=new Uint8Array(e.length),n=0;n<e.length;n++){var o=e.charCodeAt(n);r[n]=o}var i=new Blob([r],{type:"audio/midi"}),a=document.createElement("a");return a.href="undefined"!=typeof window&&void 0!==window.URL&&void 0!==window.URL.createObjectURL&&window.URL.createObjectURL(i)||"",a.download=t,a.innerText="Download MIDI file",a},d=function(e,t){var r=new c.File,n=new c.Track;"number"==typeof t&&n.setTempo(t),r.addTrack(n);for(var o=0,i=e;o<i.length;o++){var a=i[o],s=a.level||127;a.note?"string"==typeof a.note?(n.noteOn(0,a.note,a.length,s),n.noteOff(0,a.note,a.length,s)):n.addChord(0,a.note,a.length,s):n.noteOff(0,"",a.length)}return r}},668:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.progression=t.getChordsByProgression=t.getChordDegrees=void 0;var n=r(397),o=r(604);t.getChordDegrees=function(e){var t={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 t.major=t.ionian,t.minor=t.aeolian,t[e]||[]};var i={i:0,ii:1,iii:2,iv:3,v:4,vi:5,vii:6};t.getChordsByProgression=function(e,t){var r=e.split(" ");r[0].match(/\d/)||(r[0]+="4",e=r.join(" "));var o=(0,n.scale)(e);return t.replace(/\s*,+\s*/g," ").split(" ").map((function(e){var t=function(e){var t=e.replace(/\W/g,""),r="M";return t.toLowerCase()===t&&(r="m"),e.indexOf("°")>-1?r+"7b5":e.indexOf("+")>-1?r+"#5":e.indexOf("7")>-1?"M"===r?"maj7":"m7":r}(e),r=i[e.replace(/\W|\d/g,"").toLowerCase()],n=o[r],a=n.replace(/\D+/,"");return n.replace(/\d/,"")+t+"_"+a})).toString().replace(/,/g," ")};var a=function(e){var t=e.T,r=e.P,n=e.D;return function(e){void 0===e&&(e=4);var i=[];i.push((0,o.pickOne)(t));var a=1;for(a<e-1&&(i.push((0,o.pickOne)(r)),a++),a<e-1&&(0,o.dice)()&&(i.push((0,o.pickOne)(r)),a++),a<e-1&&(i.push((0,o.pickOne)(n)),a++),a<e-1&&(i.push((0,o.pickOne)(r)),a++),a<e-1&&(i.push((0,o.pickOne)(n)),a++),a<e-1&&(0,o.dice)()&&(i.push((0,o.pickOne)(r)),a++);a<e;)i.push((0,o.pickOne)(n)),a++;return i}},s=a({T:["I","vi"],P:["ii","IV"],D:["V"]}),c=a({T:["i","VI"],P:["ii","iv"],D:["V"]});t.progression=function(e,t){return void 0===t&&(t=4),"major"===e||"M"===e?s(t):"minor"===e||"m"===e?c(t):[]}},621:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},604:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.randomInt=t.convertChordsToNotes=t.convertChordToNotes=t.errorHasMessage=t.flat=t.dice=t.pickOne=t.sizzleMap=t.shuffle=t.expandStr=t.isNote=void 0;var n=r(397);t.isNote=function(e){return/^[a-gA-G](?:#|b)?\d$/.test(e)},t.expandStr=function(e){return e=(e=(e=(e=JSON.stringify(e.split(""))).replace(/,"\[",/g,", [")).replace(/"\[",/g,"[")).replace(/,"\]"/g,"]"),JSON.parse(e)},t.shuffle=function(e,t){void 0===t&&(t=!0);var r=e.length-1;return e.forEach((function(n,o){if(!(o>=r)){var i=t?Math.floor(Math.random()*(r-o))+1+o:Math.floor(Math.random()*(r+1-o))+o;e[o]=e[i],e[i]=n}})),e},t.sizzleMap=function(e){void 0===e&&(e=127);var t=Math.PI,r=[t/6,t/4,t/3,t/2,2*t/3,3*t/4,5*t/6,t],n=[0,t/6,t/4,t/3,t/2,2*t/3,3*t/4,5*t/6];return n.reverse(),r.concat(n).map((function(t){return Math.round(Math.sin(t)*e)}))},t.pickOne=function(e){return e.length>1?e[Math.round(Math.random())]:e[0]},t.dice=function(){return!!Math.round(Math.random())},t.flat=function(e){return e.reduce((function(e,t){return e.concat(t)}),[])},t.errorHasMessage=function(e){return"string"==typeof e.message},t.convertChordToNotes=function(e){var t,r,o,i;try{t=(0,n.inlineChord)(e)}catch(e){o=e}try{r=(0,n.chord)(e.replace(/_/g," "))}catch(e){i=e}if(!o&&!i){if(t.toString()!==r.toString())throw new Error("Chord "+e+" cannot decode, guessing "+t+" or "+r);return t}return o?i?(0,n.chord)(e):r:t},t.convertChordsToNotes=function(e){if("string"==typeof e&&(0,t.isNote)(e))return[e];if(Array.isArray(e))return e.forEach((function(e){if(Array.isArray(e))e.forEach((function(e){if("string"!=typeof e||!(0,t.isNote)(e))throw new TypeError("array of arrays must comprise valid notes")}));else if("string"!=typeof e||!(0,t.isNote)(e))throw new TypeError("array must comprise valid notes")})),e;if(!Array.isArray(e)){var r=(0,t.convertChordToNotes)(e);if(r&&r.length)return r}throw new Error("Chord "+e+" not found")},t.randomInt=function(e){return void 0===e&&(e=1),Math.round(Math.random()*e)}},231:e=>{"use strict";e.exports=require("fs")}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={id:n,loaded:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}r.nmd=e=>(e.paths=[],e.children||(e.children=[]),e);var n=r(136),o=exports;for(var i in n)o[i]=n[i];n.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
|
|
1
|
+
(()=>{"use strict";var e={712(e){var t,r=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,o={};((e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})})(o,{chord:()=>f,chords:()=>l,getIndicesFromScale:()=>y,inlineChord:()=>p,scale:()=>v,scales:()=>m}),e.exports=(t=o,((e,t,o,s)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let o of a(t))i.call(e,o)||void 0===o||r(e,o,{get:()=>t[o],enumerable:!(s=n(t,o))||s.enumerable});return e})(r({},"__esModule",{value:!0}),t));var s={"C#":"Db","D#":"Eb","F#":"Gb","G#":"Ab","A#":"Bb",CB:"B",FB:"E","E#":"F","B#":"C"},c=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],h={"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",Kanakangi:"111001011100",Ratnangi:"111001011010",Ganamurti:"111001011001",Vanaspati:"111001010110",Manavati:"111001010101",Tanarupi:"111001010011",Senavati:"110101011100",Hanumatodi:"110101011010",Dhenuka:"110101011001",Natakapriya:"110101010110",Kokilapriya:"110101010101",Rupavati:"110101010011",Gayakapriya:"110011011100",Vakulabharanam:"110011011010",Mayamalavagowla:"110011011001",Chakravakam:"110011010110",Suryakantam:"110011010101",Hatakambari:"110011010011",Jhankaradhwani:"101101011100",Natabhairavi:"101101011010",Keeravani:"101101011001",Kharaharapriya:"101101010110",Gourimanohari:"101101010101",Varunapriya:"101101010011",Mararanjani:"101011011100",Charukesi:"101011011010",Sarasangi:"101011011001",Harikambhoji:"101011010110",Dheerasankarabaranam:"101011010101",Naganandini:"101011010011",Yagapriya:"100111011100",Ragavardhini:"100111011010",Gangeyabhushani:"100111011001",Vagadheeswari:"100111010110",Shulini:"100111010101",Chalanata:"100111010011",Salagam:"111000111100",Jalarnavam:"111000111010",Jhalavarali:"111000111001",Navaneetam:"111000110110",Pavani:"111000110101",Raghupriya:"111000110011",Gavambhodi:"110100111100",Bhavapriya:"110100111010",Shubhapantuvarali:"110100111001",Shadvidamargini:"110100110110",Suvarnangi:"110100110101",Divyamani:"110100110011",Dhavalambari:"110010111100",Namanarayani:"110010111010",Kamavardhini:"110010111001",Ramapriya:"110010110110",Gamanashrama:"110010110101",Vishwambari:"110010110011",Shamalangi:"101100111100",Shanmukhapriya:"101100111010",Simhendramadhyamam:"101100111001",Hemavati:"101100110110",Dharmavati:"101100110101",Neetimati:"101100110011",Kantamani:"101010111100",Rishabhapriya:"101010111010",Latangi:"101010111001",Vachaspati:"101010110110",Mechakalyani:"101010110101",Chitrambari:"101010110011",Sucharitra:"100110111100","Jyoti swarupini":"100110111010",Dhatuvardani:"100110111001",Nasikabhushini:"100110110110",Kosalam:"100110110101",Rasikapriya:"100110110011"},d={"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"};function u({scale:e,chord:t}){const r=e||t,n=e?"scale":"chord";if("string"!=typeof r)throw new Error(`${r} is not a valid input for ${n}`);const a=r.trim(),i=a.indexOf(" ");let o,u;-1===i?(o=a.slice(1),u=a[0],"b"!==a[1]&&"#"!==a[1]||(o=a.slice(2),u+=a[1])):(o=a.slice(-1===i?1:i+1),u=a.slice(0,i));const p=function(e){return s[e.toUpperCase()]||e.charAt(0).toUpperCase()+e.slice(1)}(u.replace(/\d/g,"")),l=""!==u.replace(/\D/g,"")?+u.replace(/\D/g,""):4;if(isNaN(l))throw new Error(`${u[0]} does not have a valid octave`);if(!h[o]&&!d[o])throw new Error(`${a} is not a valid ${n}`);const m=function(e,t){const r=c.indexOf(e);if(-1===r)throw new Error(`${e} is not a valid root note`);const n=c.map(e=>e+t),a=c.map(e=>e+(t+1));return n.concat(a).slice(r)}(p,l),f=[];let v=0,y=0;const g=e?h:d;for(;v<g[o].length;)"1"===g[o][v]&&f.push(m[y]),v++,y++;return f}function p(e){const t="b9sus";let r,n,a=4;return e.includes(t)?(n=t,r=e.slice(0,e.indexOf(t))):(r=e[0],n=e.slice(1),"b"!==e[1]&&"#"!==e[1]||(r+=e[1],n=e.slice(2))),e.includes("_")&&(a=+e.split("_")[1],n=n.slice(0,n.indexOf("_"))),u({chord:r+a+" "+n})}function l(){return Object.keys(d)}function m(){return Object.keys(h)}function f(e){return u({chord:e})}function v(e){return u({scale:e})}function y(e){const t=h[e]||e,r=[];for(let e=0;e<t.length;e++)"1"===t[e]&&r.push(e);return r.push(12),r}},716(e,t,r){var n=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,a=0,i=t.length;a<i;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.arp=void 0;var a=r(712),i=r(552),o=function(e,t){var r=function(e){if(!e)throw new Error("Empty element");var t=e.replace(/\d/,""),r=e.replace(/\D/g,"")||4;if(!t)throw new Error("Incorrect note");return t+(+r+1)},a=e.map(r),i=a.map(r);return n(n(n([],e,!0),a,!0),i,!0).slice(0,t)};t.arp=function(e){var t=[],r={count:4,order:"0123",chords:""};if("string"==typeof e)r.chords=e;else{if(e.order&&e.order.match(/\D/g))throw new TypeError("Invalid value for order");if(e.count>8||e.count<2)throw new TypeError("Invalid value for count");e.count&&!e.order&&(r.order=Array.from(Array(e.count).keys()).join("")),Object.assign(r,e)}if("string"==typeof r.chords)r.chords.split(" ").forEach(function(e,i){try{var s=o((0,a.inlineChord)(e),r.count),c=r.order.split("").map(function(e){return s[e]});t=n(n([],t,!0),c,!0)}catch(t){throw new Error("Cannot decode chord ".concat(i+1,' "').concat(e,'" in given "').concat(r.chords,'"'))}});else{if(!Array.isArray(r.chords))throw new TypeError("Invalid value for chords");r.chords.forEach(function(e,a){try{var s=o(e,r.count),c=r.order.split("").map(function(e){return s[e]});t=n(n([],t,!0),c,!0)}catch(t){throw new Error("".concat((0,i.errorHasMessage)(t)?t.message:t," in chord ").concat(a+1,' "').concat(e,'"'))}})}return t}},347(e,t,r){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},n.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.clip=void 0;var a=r(552),i={"1m":2048,"2m":4096,"3m":6144,"4m":8192,"1n":512,"2n":256,"4n":128,"8n":64,"16n":32};t.clip=function(e){if("string"==typeof(e=n(n({},{notes:["C4"],pattern:"x",shuffle:!1,sizzle:!1,sizzleReps:1,arpegiate:!1,subdiv:"4n",amp:100,accentLow:70,randomNotes:null,offlineRendering:!1}),e||{})).notes&&(e.notes=e.notes.replace(/\s{2,}/g," "),e.notes=e.notes.split(" ")),e.notes=e.notes?e.notes.map(a.convertChordsToNotes):[],/[^x\-_[\]R]/.test(e.pattern))throw new TypeError("pattern can only comprise x - _ [ ] R, found ".concat(e.pattern));e.shuffle&&(e.notes=(0,a.shuffle)(e.notes)),e.randomNotes&&"string"==typeof e.randomNotes&&(e.randomNotes=e.randomNotes.replace(/\s{2,}/g," ").split(/\s/)),e.randomNotes&&(e.randomNotes=e.randomNotes.map(a.convertChordsToNotes));var t=[],r=0,o=function(n,i,s){var c=0;n.forEach(function(h,d){var u;if("string"==typeof h){var p=null;if("-"===h||("R"===h&&(0,a.randomInt)()&&e.randomNotes&&e.randomNotes.length>0?p=e.randomNotes[(0,a.randomInt)(e.randomNotes.length-1)]:e.notes&&(p=e.notes[r])),"x"!==h&&"R"!==h||r++,"x"!==h&&"-"!==h&&"R"!==h||(t.push({note:p,length:i,level:"R"!==h||e.randomNotes?e.amp:e.accentLow}),c+=i),"_"===h&&t.length&&(t[t.length-1].length+=i,c+=i),s&&c!==s&&d===n.length-1){var l=Math.abs(s-c),m=t[t.length-1];m.length>l?m.length=m.length-l:m.length=m.length+l}r===(null===(u=e.notes)||void 0===u?void 0:u.length)&&(r=0)}if(Array.isArray(h)){var f=!1;h.length%2==0&&i%2==0||(f=!0),o(h,Math.round(i/h.length),f&&i),c+=i}})};if(o((0,a.expandStr)(e.pattern),i[e.subdiv]||i["4n"],!1),e.sizzle){var s=[],c=!0===e.sizzle?"sin":e.sizzle,h=t.length,d=e.amp,u=e.sizzleReps,p=d/(h/u);if("sin"===c||"cos"===c)for(var l=0;l<h;l++){var m=Math[c](l*Math.PI/(h/u))*d;s.push(Math.round(Math.abs(m)))}if("rampUp"===c)for(m=0,l=0;l<h;l++)l%(h/u)===0?m=0:m+=p,s.push(Math.round(Math.abs(m)));if("rampDown"===c)for(m=d,l=0;l<h;l++)l%(h/u)===0?m=d:m-=p,s.push(Math.round(Math.abs(m)));for(l=0;l<s.length;l++)t[l].level=s[l]?s[l]:1}if(e.accent){if(/[^x-]/.test(e.accent))throw new TypeError("Accent can only have x and - characters");for(var f=0,v=0,y=t;v<y.length;v++){var g=y[v];m="x"===e.accent[f]?e.amp:e.accentLow,e.sizzle&&(m=(g.level+m)/2),g.level=Math.round(m),(f+=1)===e.accent.length&&(f=0)}}return t}},729(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,a)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),a=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.midi=t.arp=t.progression=t.getChordsByProgression=t.getChordDegrees=t.clip=t.chords=t.chord=t.modes=t.scales=t.mode=t.scale=void 0;var i=r(712);Object.defineProperty(t,"scales",{enumerable:!0,get:function(){return i.scales}}),Object.defineProperty(t,"modes",{enumerable:!0,get:function(){return i.scales}}),Object.defineProperty(t,"chords",{enumerable:!0,get:function(){return i.chords}}),Object.defineProperty(t,"scale",{enumerable:!0,get:function(){return i.scale}}),Object.defineProperty(t,"mode",{enumerable:!0,get:function(){return i.scale}}),Object.defineProperty(t,"chord",{enumerable:!0,get:function(){return i.chord}});var o=r(347);Object.defineProperty(t,"clip",{enumerable:!0,get:function(){return o.clip}});var s=r(514);Object.defineProperty(t,"getChordDegrees",{enumerable:!0,get:function(){return s.getChordDegrees}}),Object.defineProperty(t,"getChordsByProgression",{enumerable:!0,get:function(){return s.getChordsByProgression}}),Object.defineProperty(t,"progression",{enumerable:!0,get:function(){return s.progression}});var c=r(716);Object.defineProperty(t,"arp",{enumerable:!0,get:function(){return c.arp}});var h=r(884);Object.defineProperty(t,"midi",{enumerable:!0,get:function(){return h.midi}}),a(r(491),t)},884(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.midi=void 0;var a=n(r(383)),i=r(142);t.midi=function(e,t,r){void 0===t&&(t="music.mid");var n=s(e,r).toBytes();return null===t?n:(t.endsWith(".mid")||(t+=".mid"),"undefined"!=typeof window&&window.URL&&"function"==typeof window.URL.createObjectURL?o(n,t):(a.default.writeFileSync(t,n,"binary"),void console.log("MIDI file generated: ".concat(t,"."))))};var o=function(e,t){for(var r=new Uint8Array(e.length),n=0;n<e.length;n++){var a=e.charCodeAt(n);r[n]=a}var i=new Blob([r],{type:"audio/midi"}),o=document.createElement("a");return o.href="undefined"!=typeof window&&void 0!==window.URL&&void 0!==window.URL.createObjectURL&&window.URL.createObjectURL(i)||"",o.download=t,o.innerText="Download MIDI file",o},s=function(e,t){var r=new i.File,n=new i.Track;"number"==typeof t&&n.setTempo(t),r.addTrack(n);for(var a=0,o=e;a<o.length;a++){var s=o[a],c=s.level||127;s.note?"string"==typeof s.note?(n.noteOn(0,s.note,s.length,c),n.noteOff(0,s.note,s.length,c)):n.addChord(0,s.note,s.length,c):n.noteOff(0,"",s.length)}return r}},514(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.progression=t.getChordsByProgression=t.getChordDegrees=void 0;var n=r(712),a=r(552);t.getChordDegrees=function(e){var t={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 t.major=t.ionian,t.minor=t.aeolian,t[e]||[]};var i={i:0,ii:1,iii:2,iv:3,v:4,vi:5,vii:6};t.getChordsByProgression=function(e,t){var r=e.split(" ");r[0].match(/\d/)||(r[0]+="4",e=r.join(" "));var a=(0,n.scale)(e);return t.replace(/\s*,+\s*/g," ").split(" ").map(function(e){var t=function(e){var t=e.replace(/\W/g,""),r="M";return t.toLowerCase()===t&&(r="m"),e.indexOf("°")>-1?r+"7b5":e.indexOf("+")>-1?r+"#5":e.indexOf("7")>-1?"M"===r?"maj7":"m7":r}(e),r=i[e.replace(/\W|\d/g,"").toLowerCase()],n=a[r],o=n.replace(/\D+/,"");return n.replace(/\d/,"")+t+"_"+o}).toString().replace(/,/g," ")};var o=function(e){var t=e.T,r=e.P,n=e.D;return function(e){void 0===e&&(e=4);var i=[];i.push((0,a.pickOne)(t));var o=1;for(o<e-1&&(i.push((0,a.pickOne)(r)),o++),o<e-1&&(0,a.dice)()&&(i.push((0,a.pickOne)(r)),o++),o<e-1&&(i.push((0,a.pickOne)(n)),o++),o<e-1&&(i.push((0,a.pickOne)(r)),o++),o<e-1&&(i.push((0,a.pickOne)(n)),o++),o<e-1&&(0,a.dice)()&&(i.push((0,a.pickOne)(r)),o++);o<e;)i.push((0,a.pickOne)(n)),o++;return i}},s=o({T:["I","vi"],P:["ii","IV"],D:["V"]}),c=o({T:["i","VI"],P:["ii","iv"],D:["V"]});t.progression=function(e,t){return void 0===t&&(t=4),"major"===e||"M"===e?s(t):"minor"===e||"m"===e?c(t):[]}},491(e,t){Object.defineProperty(t,"__esModule",{value:!0})},552(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.randomInt=t.convertChordsToNotes=t.convertChordToNotes=t.errorHasMessage=t.flat=t.dice=t.pickOne=t.sizzleMap=t.shuffle=t.expandStr=t.isNote=void 0;var n=r(712);t.isNote=function(e){return/^[a-gA-G](?:#|b)?\d$/.test(e)},t.expandStr=function(e){return e=(e=(e=(e=JSON.stringify(e.split(""))).replace(/,"\[",/g,", [")).replace(/"\[",/g,"[")).replace(/,"\]"/g,"]"),JSON.parse(e)},t.shuffle=function(e,t){void 0===t&&(t=!0);var r=e.length-1;return e.forEach(function(n,a){if(!(a>=r)){var i=t?Math.floor(Math.random()*(r-a))+1+a:Math.floor(Math.random()*(r+1-a))+a;e[a]=e[i],e[i]=n}}),e},t.sizzleMap=function(e){void 0===e&&(e=127);var t=Math.PI,r=[t/6,t/4,t/3,t/2,2*t/3,3*t/4,5*t/6,t],n=[0,t/6,t/4,t/3,t/2,2*t/3,3*t/4,5*t/6];return n.reverse(),r.concat(n).map(function(t){return Math.round(Math.sin(t)*e)})},t.pickOne=function(e){return e.length>1?e[Math.round(Math.random())]:e[0]},t.dice=function(){return!!Math.round(Math.random())},t.flat=function(e){return e.reduce(function(e,t){return e.concat(t)},[])},t.errorHasMessage=function(e){return"string"==typeof e.message},t.convertChordToNotes=function(e){var t,r,a,i;try{t=(0,n.inlineChord)(e)}catch(e){a=e}try{r=(0,n.chord)(e.replace(/_/g," "))}catch(e){i=e}if(!a&&!i){if(t.toString()!==r.toString())throw new Error("Chord ".concat(e," cannot decode, guessing ").concat(t," or ").concat(r));return t}return a?i?(0,n.chord)(e):r:t},t.convertChordsToNotes=function(e){if("string"==typeof e&&(0,t.isNote)(e))return[e];if(Array.isArray(e))return e.forEach(function(e){if(Array.isArray(e))e.forEach(function(e){if("string"!=typeof e||!(0,t.isNote)(e))throw new TypeError("array of arrays must comprise valid notes")});else if("string"!=typeof e||!(0,t.isNote)(e))throw new TypeError("array must comprise valid notes")}),e;if(!Array.isArray(e)){var r=(0,t.convertChordToNotes)(e);if(r&&r.length)return r}throw new Error("Chord ".concat(e," not found"))},t.randomInt=function(e){return void 0===e&&(e=1),Math.round(Math.random()*e)}},383(e){e.exports=require("fs")},142(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r={a:21,b:23,c:12,d:14,e:16,f:17,g:19},n={12:"c",13:"c#",14:"d",15:"d#",16:"e",17:"f",18:"f#",19:"g",20:"g#",21:"a",22:"a#",23:"b"},a={"a#":"bb","c#":"db","d#":"eb","f#":"gb","g#":"ab"};function i(e){const t=/([a-g])(#+|b+)?([0-9]+)$/i.exec(e);if(!t)throw new Error(`Invalid note name: ${e}`);const n=t[1].toLowerCase(),a=t[2]||"";return 12*parseInt(t[3],10)+r[n]+("#"===a.substring(0,1)?1:-1)*a.length}function o(e){return"number"!=typeof e&&/[^0-9]/.test(e)?i(e):parseInt(String(e),10)}function s(e){let t=Math.floor(6e7/e);const r=[];do{r.unshift(255&t),t>>=8}while(t);for(;r.length<3;)r.push(0);return r}function c(e){return String.fromCharCode(...e)}function h(e,t){let r=e;if(t)for(;r.length/2<t;)r="0"+r;const n=[];for(let e=r.length-1;e>=0;e-=2){const t=0===e?r[e]:r[e-1]+r[e];n.unshift(parseInt(t,16))}return n}function d(e){let t=127&e,r=e>>7;for(;r;)t<<=8,t|=127&r|128,r>>=7;const n=[];for(;n.push(255&t),128&t;)t>>=8;return n}var u={midi_letter_pitches:r,midi_pitches_letter:n,midi_flattened_notes:a,midiPitchFromNote:i,ensureMidiPitch:o,noteFromMidiPitch:function(e,t){let r=0,i=e;e>23&&(r=Math.floor(e/12)-1,i=e-12*r);let o=n[String(i)];if(!o)throw new Error(`Invalid MIDI pitch: ${e}`);return t&&o.indexOf("#")>0&&(o=a[o]),o+r},mpqnFromBpm:s,bpmFromMpqn:function(e){let t;if(Array.isArray(e)){t=0;for(let r=0,n=e.length-1;n>=0;++r,--n)t|=e[r]<<8*n}else t=e;return Math.floor(6e7/t)},codes2Str:c,str2Bytes:h,translateTickTime:d},p={NOTE_OFF:128,NOTE_ON:144,AFTER_TOUCH:160,CONTROLLER:176,PROGRAM_CHANGE:192,CHANNEL_AFTERTOUCH:208,PITCH_BEND:224},l={SEQUENCE:0,TEXT:1,COPYRIGHT:2,TRACK_NAME:3,INSTRUMENT:4,LYRIC:5,MARKER:6,CUE_POINT:7,CHANNEL_PREFIX:32,END_OF_TRACK:47,TEMPO:81,SMPTE:84,TIME_SIG:88,KEY_SIG:89,SEQ_EVENT:127},m=class e{static NOTE_OFF=p.NOTE_OFF;static NOTE_ON=p.NOTE_ON;static AFTER_TOUCH=p.AFTER_TOUCH;static CONTROLLER=p.CONTROLLER;static PROGRAM_CHANGE=p.PROGRAM_CHANGE;static CHANNEL_AFTERTOUCH=p.CHANNEL_AFTERTOUCH;static PITCH_BEND=p.PITCH_BEND;time;type;channel;param1;param2;constructor(e){this.setTime(e.time),this.setType(e.type),this.setChannel(e.channel),this.setParam1(e.param1),void 0!==e.param2&&this.setParam2(e.param2)}setTime(e){this.time=d(e||0)}setType(t){if(t<e.NOTE_OFF||t>e.PITCH_BEND)throw new Error("Trying to set an unknown event: "+t);this.type=t}setChannel(e){if(e<0||e>15)throw new Error("Channel is out of bounds.");this.channel=e}setParam1(e){this.param1=e}setParam2(e){this.param2=e}toBytes(){const e=[],t=this.type|15&this.channel;return e.push(...this.time),e.push(t),e.push(this.param1),void 0!==this.param2&&null!==this.param2&&e.push(this.param2),e}},f=class{static SEQUENCE=l.SEQUENCE;static TEXT=l.TEXT;static COPYRIGHT=l.COPYRIGHT;static TRACK_NAME=l.TRACK_NAME;static INSTRUMENT=l.INSTRUMENT;static LYRIC=l.LYRIC;static MARKER=l.MARKER;static CUE_POINT=l.CUE_POINT;static CHANNEL_PREFIX=l.CHANNEL_PREFIX;static END_OF_TRACK=l.END_OF_TRACK;static TEMPO=l.TEMPO;static SMPTE=l.SMPTE;static TIME_SIG=l.TIME_SIG;static KEY_SIG=l.KEY_SIG;static SEQ_EVENT=l.SEQ_EVENT;time;type;data;constructor(e){this.time=d(0),this.type=0,this.setTime(e.time),this.setType(e.type),this.setData(e.data)}setTime(e){this.time=d(e||0)}setType(e){this.type=e}setData(e){this.data=e}toBytes(){if(!this.type)throw new Error("Type for meta-event not specified.");const e=[];if(e.push(...this.time),e.push(255,this.type),Array.isArray(this.data))e.push(this.data.length),e.push(...this.data);else if("number"==typeof this.data)e.push(1,this.data);else if(null!==this.data&&void 0!==this.data){e.push(this.data.length);const t=this.data.split("").map(e=>e.charCodeAt(0));e.push(...t)}else e.push(0);return e}},v=class e{static START_BYTES=[77,84,114,107];static END_BYTES=[0,255,47,0];events;constructor(e){this.events=e?.events??[]}addEvent(e){return this.events.push(e),this}addNoteOn(e,t,r,n){return this.events.push(new m({type:m.NOTE_ON,channel:e,param1:o(t),param2:n||90,time:r||0})),this}addNoteOff(e,t,r,n){return this.events.push(new m({type:m.NOTE_OFF,channel:e,param1:o(t),param2:n||90,time:r||0})),this}addNote(e,t,r,n,a){return this.addNoteOn(e,t,n,a),r&&this.addNoteOff(e,t,r,a),this}addChord(e,t,r,n){if(!Array.isArray(t)||0===t.length)throw new Error("Chord must be a non-empty array of pitches");return t.forEach(t=>{this.addNoteOn(e,t,0,n)}),t.forEach((t,n)=>{0===n?this.addNoteOff(e,t,r):this.addNoteOff(e,t)}),this}setInstrument(e,t,r){return this.events.push(new m({type:m.PROGRAM_CHANGE,channel:e,param1:t,time:r||0})),this}setTempo(e,t){return this.events.push(new f({type:f.TEMPO,data:s(e),time:t||0})),this}setTimeSignature(e,t,r){const n=Math.log2(t);if(n!==Math.floor(n))throw new Error("Time signature denominator must be an exact power of 2!");return this.events.push(new f({type:f.TIME_SIG,data:[255&e,255&Math.floor(n),24,8],time:r||0})),this}setKeySignature(e,t,r){return this.events.push(new f({type:f.KEY_SIG,data:[255&e,t?1:0],time:r||0})),this}toBytes(){let t=0;const r=[],n=e.START_BYTES,a=e.END_BYTES;this.events.forEach(e=>{const n=e.toBytes();t+=n.length,r.push(...n)}),t+=a.length;const i=h(t.toString(16),4);return n.concat(i,r,a)}};v.prototype.noteOn=v.prototype.addNoteOn,v.prototype.noteOff=v.prototype.addNoteOff,v.prototype.note=v.prototype.addNote,v.prototype.chord=v.prototype.addChord,v.prototype.instrument=v.prototype.setInstrument,v.prototype.tempo=v.prototype.setTempo,v.prototype.timeSignature=v.prototype.setTimeSignature,v.prototype.keySignature=v.prototype.setKeySignature;var y=class e{static HDR_CHUNKID="MThd";static HDR_CHUNK_SIZE="\0\0\0";static HDR_TYPE0="\0\0";static HDR_TYPE1="\0";ticks;tracks;constructor(e){const t=e||{};if(void 0!==t.ticks){if("number"!=typeof t.ticks)throw new Error("Ticks per beat must be a number!");if(t.ticks<=0||t.ticks>=32768||t.ticks%1!=0)throw new Error("Ticks per beat must be an integer between 1 and 32767!")}this.ticks=t.ticks||128,this.tracks=[]}addTrack(e){if(e)return this.tracks.push(e),this;{const e=new v;return this.tracks.push(e),e}}toBytes(){const t=this.tracks.length.toString(16);let r=e.HDR_CHUNKID+e.HDR_CHUNK_SIZE;return parseInt(t,16)>1?r+=e.HDR_TYPE1:r+=e.HDR_TYPE0,r+=c(h(t,2)),r+=String.fromCharCode(this.ticks/256,this.ticks%256),this.tracks.forEach(e=>{r+=c(e.toBytes())}),r}toUint8Array(){const e=this.toBytes(),t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}toBlob(e){return new Blob([this.toUint8Array()],{type:e?"application/octet-stream":"audio/x-midi"})}},g={Util:u,File:y,Track:v,Event:m,MetaEvent:f,DEFAULT_VOLUME:90,DEFAULT_DURATION:128,DEFAULT_CHANNEL:0};t.DEFAULT_CHANNEL=0,t.DEFAULT_DURATION=128,t.DEFAULT_VOLUME=90,t.Event=m,t.File=y,t.MetaEvent=f,t.MetaEventType=l,t.MidiEvent=m,t.MidiEventType=p,t.Track=v,t.Util=u,t.default=g}},t={},r=function r(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}(729),n=exports;for(var a in r)n[a]=r[a];r.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})();
|
|
2
2
|
//# sourceMappingURL=index.js.map
|