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/index.js
CHANGED
|
@@ -1,2 +1,525 @@
|
|
|
1
|
-
(()=>{var e={712(e){"use strict";var t,r=Object.defineProperty,n=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o={};((e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})})(o,{chord:()=>m,chords:()=>l,getIndicesFromScale:()=>y,inlineChord:()=>d,scale:()=>v,scales:()=>f}),e.exports=(t=o,((e,t,o,s)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let o of i(t))a.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"],u={"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"},h={"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 p({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 i=r.trim(),a=i.indexOf(" ");let o,p;-1===a?(o=i.slice(1),p=i[0],"b"!==i[1]&&"#"!==i[1]||(o=i.slice(2),p+=i[1])):(o=i.slice(-1===a?1:a+1),p=i.slice(0,a));const d=function(e){return s[e.toUpperCase()]||e.charAt(0).toUpperCase()+e.slice(1)}(p.replace(/\d/g,"")),l=""!==p.replace(/\D/g,"")?+p.replace(/\D/g,""):4;if(isNaN(l))throw new Error(`${p[0]} does not have a valid octave`);if(!u[o]&&!h[o])throw new Error(`${i} is not a valid ${n}`);const f=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),i=c.map(e=>e+(t+1));return n.concat(i).slice(r)}(d,l),m=[];let v=0,y=0;const g=e?u:h;for(;v<g[o].length;)"1"===g[o][v]&&m.push(f[y]),v++,y++;return m}function d(e){const t="b9sus";let r,n,i=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("_")&&(i=+e.split("_")[1],n=n.slice(0,n.indexOf("_"))),p({chord:r+i+" "+n})}function l(){return Object.keys(h)}function f(){return Object.keys(u)}function m(e){return p({chord:e})}function v(e){return p({scale:e})}function y(e){const t=u[e]||e,r=[];for(let e=0;e<t.length;e++)"1"===t[e]&&r.push(e);return r.push(12),r}},79(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(),i=t[2]||"";return 12*parseInt(t[3],10)+r.midi_letter_pitches[n]+("#"==i.substr(0,1)?1:-1)*i.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,i=0,a=e;return t=t||!1,e>23&&(a=e-12*(i=Math.floor(e/12)-1)),n=r.midi_pitches_letter[a],t&&n.indexOf("#")>0&&(n=r.midi_flattened_notes[n]),n+i},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 i=0===n?e[n]:e[n-1]+e[n];r.unshift(parseInt(i,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 i=function(e){if(!this)return new i(e);this.setTime(e.time),this.setType(e.type),this.setData(e.data)};i.SEQUENCE=0,i.TEXT=1,i.COPYRIGHT=2,i.TRACK_NAME=3,i.INSTRUMENT=4,i.LYRIC=5,i.MARKER=6,i.CUE_POINT=7,i.CHANNEL_PREFIX=32,i.END_OF_TRACK=47,i.TEMPO=81,i.SMPTE=84,i.TIME_SIG=88,i.KEY_SIG=89,i.SEQ_EVENT=127,i.prototype.setTime=function(e){this.time=r.translateTickTime(e||0)},i.prototype.setType=function(e){this.type=e},i.prototype.setData=function(e){this.data=e},i.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 a=function(e){if(!this)return new a(e);var t=e||{};this.events=t.events||[]};a.START_BYTES=[77,84,114,107],a.END_BYTES=[0,255,47,0],a.prototype.addEvent=function(e){return this.events.push(e),this},a.prototype.addNoteOn=a.prototype.noteOn=function(e,i,a,o){return this.events.push(new n({type:n.NOTE_ON,channel:e,param1:r.ensureMidiPitch(i),param2:o||t,time:a||0})),this},a.prototype.addNoteOff=a.prototype.noteOff=function(e,i,a,o){return this.events.push(new n({type:n.NOTE_OFF,channel:e,param1:r.ensureMidiPitch(i),param2:o||t,time:a||0})),this},a.prototype.addNote=a.prototype.note=function(e,t,r,n,i){return this.noteOn(e,t,n,i),r&&this.noteOff(e,t,r,i),this},a.prototype.addChord=a.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},a.prototype.setInstrument=a.prototype.instrument=function(e,t,r){return this.events.push(new n({type:n.PROGRAM_CHANGE,channel:e,param1:t,time:r||0})),this},a.prototype.setTempo=a.prototype.tempo=function(e,t){return this.events.push(new i({type:i.TEMPO,data:r.mpqnFromBpm(e),time:t||0})),this},a.prototype.toBytes=function(){var e=0,t=[],n=a.START_BYTES,i=a.END_BYTES;this.events.forEach(function(r){var n=r.toBytes();e+=n.length,t.push.apply(t,n)}),e+=i.length;var o=r.str2Bytes(e.toString(16),4);return n.concat(o,t,i)};var o=function(e){if(!this)return new o(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||[]};o.HDR_CHUNKID="MThd",o.HDR_CHUNK_SIZE="\0\0\0",o.HDR_TYPE0="\0\0",o.HDR_TYPE1="\0",o.prototype.addTrack=function(e){return e?(this.tracks.push(e),this):(e=new a,this.tracks.push(e),e)},o.prototype.toBytes=function(){var e=this.tracks.length.toString(16),t=o.HDR_CHUNKID+o.HDR_CHUNK_SIZE;return parseInt(e,16)>1?t+=o.HDR_TYPE1:t+=o.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=o,e.Track=a,e.Event=n,e.MetaEvent=i}(n),null!==e?e.exports=n:null!==t?t=n:this.Midi=n},913(e,t,r){"use strict";var n=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.arp=void 0;var i=r(712),a=r(665),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)},i=e.map(r),a=i.map(r);return n(n(n([],e,!0),i,!0),a,!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,a){try{var s=o((0,i.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 "+(a+1)+' "'+e+'" in given "'+r.chords+'"')}});else{if(!Array.isArray(r.chords))throw new TypeError("Invalid value for chords");r.chords.forEach(function(e,i){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(((0,a.errorHasMessage)(t)?t.message:t)+" in chord "+(i+1)+' "'+e+'"')}})}return t}},16(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 i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},n.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.clip=void 0;var i=r(665),a={"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(i.convertChordsToNotes):[],/[^x\-_[\]R]/.test(e.pattern))throw new TypeError("pattern can only comprise x - _ [ ] R, found "+e.pattern);e.shuffle&&(e.notes=(0,i.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(i.convertChordsToNotes));var t=[],r=0,o=function(n,a,s){var c=0;n.forEach(function(u,h){var p;if("string"==typeof u){var d=null;if("-"===u||("R"===u&&(0,i.randomInt)()&&e.randomNotes&&e.randomNotes.length>0?d=e.randomNotes[(0,i.randomInt)(e.randomNotes.length-1)]:e.notes&&(d=e.notes[r])),"x"!==u&&"R"!==u||r++,"x"!==u&&"-"!==u&&"R"!==u||(t.push({note:d,length:a,level:"R"!==u||e.randomNotes?e.amp:e.accentLow}),c+=a),"_"===u&&t.length&&(t[t.length-1].length+=a,c+=a),s&&c!==s&&h===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&&a%2==0||(m=!0),o(u,Math.round(a/u.length),m&&a),c+=a}})};if(o((0,i.expandStr)(e.pattern),a[e.subdiv]||a["4n"],!1),e.sizzle){var s=[],c=!0===e.sizzle?"sin":e.sizzle,u=t.length,h=e.amp,p=e.sizzleReps,d=h/(u/p);if("sin"===c||"cos"===c)for(var l=0;l<u;l++){var f=Math[c](l*Math.PI/(u/p))*h;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+=d,s.push(Math.round(Math.abs(f)));if("rampDown"===c)for(f=h,l=0;l<u;l++)l%(u/p)===0?f=h:f-=d,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}},772(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]}),i=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 a=r(712);Object.defineProperty(t,"scales",{enumerable:!0,get:function(){return a.scales}}),Object.defineProperty(t,"modes",{enumerable:!0,get:function(){return a.scales}}),Object.defineProperty(t,"chords",{enumerable:!0,get:function(){return a.chords}}),Object.defineProperty(t,"scale",{enumerable:!0,get:function(){return a.scale}}),Object.defineProperty(t,"mode",{enumerable:!0,get:function(){return a.scale}}),Object.defineProperty(t,"chord",{enumerable:!0,get:function(){return a.chord}});var o=r(16);Object.defineProperty(t,"clip",{enumerable:!0,get:function(){return o.clip}});var s=r(903);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(913);Object.defineProperty(t,"arp",{enumerable:!0,get:function(){return c.arp}});var u=r(935);Object.defineProperty(t,"midi",{enumerable:!0,get:function(){return u.midi}}),i(r(422),t)},935(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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=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 i(t,e),t},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.midi=void 0;var s=o(r(383)),c=a(r(79));t.midi=function(e,t,r){void 0===t&&(t="music.mid");var n=h(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 i=e.charCodeAt(n);r[n]=i}var a=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(a)||"",o.download=t,o.innerText="Download MIDI file",o},h=function(e,t){var r=new c.File,n=new c.Track;"number"==typeof t&&n.setTempo(t),r.addTrack(n);for(var i=0,a=e;i<a.length;i++){var o=a[i],s=o.level||127;o.note?"string"==typeof o.note?(n.noteOn(0,o.note,o.length,s),n.noteOff(0,o.note,o.length,s)):n.addChord(0,o.note,o.length,s):n.noteOff(0,"",o.length)}return r}},903(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.progression=t.getChordsByProgression=t.getChordDegrees=void 0;var n=r(712),i=r(665);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 a={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 i=(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=a[e.replace(/\W|\d/g,"").toLowerCase()],n=i[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 a=[];a.push((0,i.pickOne)(t));var o=1;for(o<e-1&&(a.push((0,i.pickOne)(r)),o++),o<e-1&&(0,i.dice)()&&(a.push((0,i.pickOne)(r)),o++),o<e-1&&(a.push((0,i.pickOne)(n)),o++),o<e-1&&(a.push((0,i.pickOne)(r)),o++),o<e-1&&(a.push((0,i.pickOne)(n)),o++),o<e-1&&(0,i.dice)()&&(a.push((0,i.pickOne)(r)),o++);o<e;)a.push((0,i.pickOne)(n)),o++;return a}},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):[]}},422(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0})},665(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(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,i){if(!(i>=r)){var a=t?Math.floor(Math.random()*(r-i))+1+i:Math.floor(Math.random()*(r+1-i))+i;e[i]=e[a],e[a]=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,i,a;try{t=(0,n.inlineChord)(e)}catch(e){i=e}try{r=(0,n.chord)(e.replace(/_/g," "))}catch(e){a=e}if(!i&&!a){if(t.toString()!==r.toString())throw new Error("Chord "+e+" cannot decode, guessing "+t+" or "+r);return t}return i?a?(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)}},383(e){"use strict";e.exports=require("fs")}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var a=t[n]={id:n,loaded:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.loaded=!0,a.exports}r.nmd=e=>(e.paths=[],e.children||(e.children=[]),e);var n=r(772),i=exports;for(var a in n)i[a]=n[a];n.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})();
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { chord as chord2, chords, scale as scale2, scales } from "harmonics";
|
|
3
|
+
|
|
4
|
+
// src/arp.ts
|
|
5
|
+
import { inlineChord as inlineChord2 } from "harmonics";
|
|
6
|
+
|
|
7
|
+
// src/utils.ts
|
|
8
|
+
import { chord, inlineChord } from "harmonics";
|
|
9
|
+
var isNote = (str) => /^[a-gA-G](?:#|b)?\d$/.test(str);
|
|
10
|
+
var expandStr = (str) => {
|
|
11
|
+
str = JSON.stringify(str.split(""));
|
|
12
|
+
str = str.replace(/,"\[",/g, ", [");
|
|
13
|
+
str = str.replace(/"\[",/g, "[");
|
|
14
|
+
str = str.replace(/,"\]"/g, "]");
|
|
15
|
+
return JSON.parse(str);
|
|
16
|
+
};
|
|
17
|
+
var shuffle = (arr, fullShuffle = true) => {
|
|
18
|
+
const lastIndex = arr.length - 1;
|
|
19
|
+
arr.forEach((el, idx) => {
|
|
20
|
+
if (idx >= lastIndex) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const rnd = fullShuffle ? (
|
|
24
|
+
// Pick random number from idx+1 to lastIndex (Modified algorithm, (N-1)! combinations)
|
|
25
|
+
// Math.random -> [0, 1) -> [0, lastIndex-idx ) --floor-> [0, lastIndex-idx-1]
|
|
26
|
+
// rnd = [0, lastIndex-idx-1] + 1 + idx = [1 + idx, lastIndex]
|
|
27
|
+
// (Original algorithm would pick rnd = [idx, lastIndex], thus any element could arrive back into its slot)
|
|
28
|
+
Math.floor(Math.random() * (lastIndex - idx)) + 1 + idx
|
|
29
|
+
) : (
|
|
30
|
+
// Pick random number from idx to lastIndex (Unmodified Richard Durstenfeld, N! combinations)
|
|
31
|
+
Math.floor(Math.random() * (lastIndex + 1 - idx)) + idx
|
|
32
|
+
);
|
|
33
|
+
arr[idx] = arr[rnd];
|
|
34
|
+
arr[rnd] = el;
|
|
35
|
+
});
|
|
36
|
+
return arr;
|
|
37
|
+
};
|
|
38
|
+
var pickOne = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
|
39
|
+
var dice = () => !!Math.round(Math.random());
|
|
40
|
+
var errorHasMessage = (x) => {
|
|
41
|
+
return typeof x === "object" && x !== null && "message" in x && typeof x.message === "string";
|
|
42
|
+
};
|
|
43
|
+
var convertChordToNotes = (el) => {
|
|
44
|
+
let c1;
|
|
45
|
+
let c2;
|
|
46
|
+
let e1;
|
|
47
|
+
let e2;
|
|
48
|
+
try {
|
|
49
|
+
c1 = inlineChord(el);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
e1 = e;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
c2 = chord(el.replace(/_/g, " "));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
e2 = e;
|
|
57
|
+
}
|
|
58
|
+
if (!e1 && !e2) {
|
|
59
|
+
if (c1.toString() !== c2.toString()) {
|
|
60
|
+
throw new Error(`Chord ${el} cannot decode, guessing ${c1} or ${c2}`);
|
|
61
|
+
}
|
|
62
|
+
return c1;
|
|
63
|
+
}
|
|
64
|
+
if (!e1) {
|
|
65
|
+
return c1;
|
|
66
|
+
}
|
|
67
|
+
if (!e2) {
|
|
68
|
+
return c2;
|
|
69
|
+
}
|
|
70
|
+
return chord(el);
|
|
71
|
+
};
|
|
72
|
+
var convertChordsToNotes = (el) => {
|
|
73
|
+
if (typeof el === "string" && isNote(el)) {
|
|
74
|
+
return [el];
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(el)) {
|
|
77
|
+
el.forEach((n) => {
|
|
78
|
+
if (Array.isArray(n)) {
|
|
79
|
+
n.forEach((n1) => {
|
|
80
|
+
if (typeof n1 !== "string" || !isNote(n1)) {
|
|
81
|
+
throw new TypeError("array of arrays must comprise valid notes");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
} else if (typeof n !== "string" || !isNote(n)) {
|
|
85
|
+
throw new TypeError("array must comprise valid notes");
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return el;
|
|
89
|
+
}
|
|
90
|
+
if (!Array.isArray(el)) {
|
|
91
|
+
const c = convertChordToNotes(el);
|
|
92
|
+
if (c?.length) {
|
|
93
|
+
return c;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Chord ${el} not found`);
|
|
97
|
+
};
|
|
98
|
+
var randomInt = (num = 1) => Math.round(Math.random() * num);
|
|
99
|
+
|
|
100
|
+
// src/arp.ts
|
|
101
|
+
var DEFAULT_OCTAVE = 4;
|
|
102
|
+
var fillArr = (arr, len) => {
|
|
103
|
+
const bumpOctave = (el) => {
|
|
104
|
+
if (!el) {
|
|
105
|
+
throw new Error("Empty element");
|
|
106
|
+
}
|
|
107
|
+
const note = el.replace(/\d/, "");
|
|
108
|
+
const oct = el.replace(/\D/g, "") || DEFAULT_OCTAVE;
|
|
109
|
+
if (!note) {
|
|
110
|
+
throw new Error("Incorrect note");
|
|
111
|
+
}
|
|
112
|
+
return note + (+oct + 1);
|
|
113
|
+
};
|
|
114
|
+
const arr1 = arr.map(bumpOctave);
|
|
115
|
+
const arr2 = arr1.map(bumpOctave);
|
|
116
|
+
const finalArr = [...arr, ...arr1, ...arr2];
|
|
117
|
+
return finalArr.slice(0, len);
|
|
118
|
+
};
|
|
119
|
+
var arp = (chordsOrParams) => {
|
|
120
|
+
let finalArr = [];
|
|
121
|
+
const params = {
|
|
122
|
+
count: 4,
|
|
123
|
+
order: "0123",
|
|
124
|
+
chords: ""
|
|
125
|
+
};
|
|
126
|
+
if (typeof chordsOrParams === "string") {
|
|
127
|
+
params.chords = chordsOrParams;
|
|
128
|
+
} else {
|
|
129
|
+
if (chordsOrParams.order?.match(/\D/g)) {
|
|
130
|
+
throw new TypeError("Invalid value for order");
|
|
131
|
+
}
|
|
132
|
+
if (chordsOrParams.count > 8 || chordsOrParams.count < 2) {
|
|
133
|
+
throw new TypeError("Invalid value for count");
|
|
134
|
+
}
|
|
135
|
+
if (chordsOrParams.count && !chordsOrParams.order) {
|
|
136
|
+
params.order = Array.from(Array(chordsOrParams.count).keys()).join("");
|
|
137
|
+
}
|
|
138
|
+
Object.assign(params, chordsOrParams);
|
|
139
|
+
}
|
|
140
|
+
if (typeof params.chords === "string") {
|
|
141
|
+
const chordsArr = params.chords.split(" ");
|
|
142
|
+
chordsArr.forEach((c, i) => {
|
|
143
|
+
try {
|
|
144
|
+
const filledArr = fillArr(inlineChord2(c), params.count);
|
|
145
|
+
const reorderedArr = params.order.split("").map((idx) => filledArr[Number(idx)]);
|
|
146
|
+
finalArr = [...finalArr, ...reorderedArr];
|
|
147
|
+
} catch (_e) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Cannot decode chord ${i + 1} "${c}" in given "${params.chords}"`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
} else if (Array.isArray(params.chords)) {
|
|
154
|
+
params.chords.forEach((c, i) => {
|
|
155
|
+
try {
|
|
156
|
+
const filledArr = fillArr(c, params.count);
|
|
157
|
+
const reorderedArr = params.order.split("").map((idx) => filledArr[Number(idx)]);
|
|
158
|
+
finalArr = [...finalArr, ...reorderedArr];
|
|
159
|
+
} catch (e) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
`${errorHasMessage(e) ? e.message : e} in chord ${i + 1} "${c}"`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
throw new TypeError("Invalid value for chords");
|
|
167
|
+
}
|
|
168
|
+
return finalArr;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/clip-utils.ts
|
|
172
|
+
var defaultParams = {
|
|
173
|
+
notes: ["C4"],
|
|
174
|
+
pattern: "x",
|
|
175
|
+
shuffle: false,
|
|
176
|
+
sizzle: false,
|
|
177
|
+
sizzleReps: 1,
|
|
178
|
+
arpegiate: false,
|
|
179
|
+
subdiv: "4n",
|
|
180
|
+
amp: 100,
|
|
181
|
+
accentLow: 70,
|
|
182
|
+
randomNotes: null,
|
|
183
|
+
offlineRendering: false
|
|
184
|
+
};
|
|
185
|
+
var validatePattern = (pattern) => {
|
|
186
|
+
if (/[^x\-_[\]R]/.test(pattern)) {
|
|
187
|
+
throw new TypeError(
|
|
188
|
+
`pattern can only comprise x - _ [ ] R, found ${pattern}`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var preprocessClipParams = (params, extraDefaults) => {
|
|
193
|
+
params = { ...defaultParams, ...extraDefaults, ...params || {} };
|
|
194
|
+
if (typeof params.notes === "string") {
|
|
195
|
+
params.notes = params.notes.replace(/\s{2,}/g, " ").split(" ");
|
|
196
|
+
}
|
|
197
|
+
params.notes = params.notes ? params.notes.map(convertChordsToNotes) : [];
|
|
198
|
+
validatePattern(params.pattern);
|
|
199
|
+
if (params.shuffle) {
|
|
200
|
+
params.notes = shuffle(params.notes);
|
|
201
|
+
}
|
|
202
|
+
if (params.randomNotes && typeof params.randomNotes === "string") {
|
|
203
|
+
params.randomNotes = params.randomNotes.replace(/\s{2,}/g, " ").split(/\s/);
|
|
204
|
+
}
|
|
205
|
+
if (params.randomNotes) {
|
|
206
|
+
params.randomNotes = params.randomNotes.map(
|
|
207
|
+
convertChordsToNotes
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return params;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/clip.ts
|
|
214
|
+
var hdr = {
|
|
215
|
+
"1m": 2048,
|
|
216
|
+
"2m": 4096,
|
|
217
|
+
"3m": 6144,
|
|
218
|
+
"4m": 8192,
|
|
219
|
+
"1n": 512,
|
|
220
|
+
"2n": 256,
|
|
221
|
+
"4n": 128,
|
|
222
|
+
"8n": 64,
|
|
223
|
+
"16n": 32
|
|
224
|
+
};
|
|
225
|
+
var clip = (params) => {
|
|
226
|
+
params = preprocessClipParams(params);
|
|
227
|
+
const clipNotes = [];
|
|
228
|
+
let step = 0;
|
|
229
|
+
const recursivelyApplyPatternToNotes = (patternArr, length, parentNoteLength) => {
|
|
230
|
+
let totalLength = 0;
|
|
231
|
+
patternArr.forEach((char, idx) => {
|
|
232
|
+
if (typeof char === "string") {
|
|
233
|
+
let note = null;
|
|
234
|
+
if (char === "-") {
|
|
235
|
+
} else if (char === "R" && randomInt() && // Use 1/2 probability for R to pick from param.notes
|
|
236
|
+
params.randomNotes && params.randomNotes.length > 0) {
|
|
237
|
+
note = params.randomNotes[randomInt(params.randomNotes.length - 1)];
|
|
238
|
+
} else if (params.notes) {
|
|
239
|
+
note = params.notes[step];
|
|
240
|
+
}
|
|
241
|
+
if (char === "x" || char === "R") {
|
|
242
|
+
step++;
|
|
243
|
+
}
|
|
244
|
+
if (char === "x" || char === "-" || char === "R") {
|
|
245
|
+
clipNotes.push({
|
|
246
|
+
note,
|
|
247
|
+
length,
|
|
248
|
+
level: char === "R" && !params.randomNotes ? params.accentLow : params.amp
|
|
249
|
+
});
|
|
250
|
+
totalLength += length;
|
|
251
|
+
}
|
|
252
|
+
if (char === "_" && clipNotes.length) {
|
|
253
|
+
clipNotes[clipNotes.length - 1].length += length;
|
|
254
|
+
totalLength += length;
|
|
255
|
+
}
|
|
256
|
+
if (parentNoteLength && totalLength !== parentNoteLength && idx === patternArr.length - 1) {
|
|
257
|
+
const diff = Math.abs(
|
|
258
|
+
parentNoteLength - totalLength
|
|
259
|
+
);
|
|
260
|
+
const lastClipNote = clipNotes[clipNotes.length - 1];
|
|
261
|
+
if (lastClipNote.length > diff) {
|
|
262
|
+
lastClipNote.length = lastClipNote.length - diff;
|
|
263
|
+
} else {
|
|
264
|
+
lastClipNote.length = lastClipNote.length + diff;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (step === params.notes?.length) {
|
|
268
|
+
step = 0;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (Array.isArray(char)) {
|
|
272
|
+
let isTriplet = false;
|
|
273
|
+
if (char.length % 2 !== 0 || length % 2 !== 0) {
|
|
274
|
+
isTriplet = true;
|
|
275
|
+
}
|
|
276
|
+
recursivelyApplyPatternToNotes(
|
|
277
|
+
char,
|
|
278
|
+
Math.round(length / char.length),
|
|
279
|
+
isTriplet && length
|
|
280
|
+
);
|
|
281
|
+
totalLength += length;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
recursivelyApplyPatternToNotes(
|
|
286
|
+
expandStr(params.pattern),
|
|
287
|
+
hdr[params.subdiv] || hdr["4n"],
|
|
288
|
+
false
|
|
289
|
+
);
|
|
290
|
+
if (params.sizzle) {
|
|
291
|
+
const volArr = [];
|
|
292
|
+
const style = params.sizzle === true ? "sin" : params.sizzle;
|
|
293
|
+
const beats = clipNotes.length;
|
|
294
|
+
const amp = params.amp;
|
|
295
|
+
const sizzleReps = params.sizzleReps;
|
|
296
|
+
const stepLevel = amp / (beats / sizzleReps);
|
|
297
|
+
if (style === "sin" || style === "cos") {
|
|
298
|
+
for (let i = 0; i < beats; i++) {
|
|
299
|
+
const level = Math[style](i * Math.PI / (beats / sizzleReps)) * amp;
|
|
300
|
+
volArr.push(Math.round(Math.abs(level)));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (style === "rampUp") {
|
|
304
|
+
let level = 0;
|
|
305
|
+
for (let i = 0; i < beats; i++) {
|
|
306
|
+
if (i % (beats / sizzleReps) === 0) {
|
|
307
|
+
level = 0;
|
|
308
|
+
} else {
|
|
309
|
+
level = level + stepLevel;
|
|
310
|
+
}
|
|
311
|
+
volArr.push(Math.round(Math.abs(level)));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (style === "rampDown") {
|
|
315
|
+
let level = amp;
|
|
316
|
+
for (let i = 0; i < beats; i++) {
|
|
317
|
+
if (i % (beats / sizzleReps) === 0) {
|
|
318
|
+
level = amp;
|
|
319
|
+
} else {
|
|
320
|
+
level = level - stepLevel;
|
|
321
|
+
}
|
|
322
|
+
volArr.push(Math.round(Math.abs(level)));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for (let i = 0; i < volArr.length; i++) {
|
|
326
|
+
clipNotes[i].level = volArr[i] ? volArr[i] : 1;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (params.accent) {
|
|
330
|
+
if (/[^x-]/.test(params.accent)) {
|
|
331
|
+
throw new TypeError("Accent can only have x and - characters");
|
|
332
|
+
}
|
|
333
|
+
let a = 0;
|
|
334
|
+
for (const clipNote of clipNotes) {
|
|
335
|
+
let level = params.accent[a] === "x" ? params.amp : params.accentLow;
|
|
336
|
+
if (params.sizzle) {
|
|
337
|
+
level = (clipNote.level + level) / 2;
|
|
338
|
+
}
|
|
339
|
+
clipNote.level = Math.round(level);
|
|
340
|
+
a = a + 1;
|
|
341
|
+
if (a === params.accent.length) {
|
|
342
|
+
a = 0;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return clipNotes;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/midi.ts
|
|
350
|
+
import fs from "fs";
|
|
351
|
+
import { File, Track } from "@scribbletune/midi";
|
|
352
|
+
var midi = (notes, fileName = "music.mid", bpm) => {
|
|
353
|
+
const file = createFileFromNotes(notes, bpm);
|
|
354
|
+
const bytes = file.toBytes();
|
|
355
|
+
if (fileName === null) {
|
|
356
|
+
return bytes;
|
|
357
|
+
}
|
|
358
|
+
if (!fileName.endsWith(".mid")) {
|
|
359
|
+
fileName = `${fileName}.mid`;
|
|
360
|
+
}
|
|
361
|
+
if (typeof window !== "undefined" && window.URL && typeof window.URL.createObjectURL === "function") {
|
|
362
|
+
return createDownloadLink(bytes, fileName);
|
|
363
|
+
}
|
|
364
|
+
fs.writeFileSync(fileName, bytes, "binary");
|
|
365
|
+
console.log(`MIDI file generated: ${fileName}.`);
|
|
366
|
+
};
|
|
367
|
+
var createDownloadLink = (b, fileName) => {
|
|
368
|
+
const bytes = new Uint8Array(b.length);
|
|
369
|
+
for (let i = 0; i < b.length; i++) {
|
|
370
|
+
const ascii = b.charCodeAt(i);
|
|
371
|
+
bytes[i] = ascii;
|
|
372
|
+
}
|
|
373
|
+
const blob = new Blob([bytes], { type: "audio/midi" });
|
|
374
|
+
const link = document.createElement("a");
|
|
375
|
+
link.href = typeof window !== "undefined" && typeof window.URL !== "undefined" && typeof window.URL.createObjectURL !== "undefined" && window.URL.createObjectURL(blob) || "";
|
|
376
|
+
link.download = fileName;
|
|
377
|
+
link.innerText = "Download MIDI file";
|
|
378
|
+
return link;
|
|
379
|
+
};
|
|
380
|
+
var createFileFromNotes = (notes, bpm) => {
|
|
381
|
+
const file = new File();
|
|
382
|
+
const track = new Track();
|
|
383
|
+
if (typeof bpm === "number") {
|
|
384
|
+
track.setTempo(bpm);
|
|
385
|
+
}
|
|
386
|
+
file.addTrack(track);
|
|
387
|
+
for (const noteObj of notes) {
|
|
388
|
+
const level = noteObj.level || 127;
|
|
389
|
+
if (noteObj.note) {
|
|
390
|
+
if (typeof noteObj.note === "string") {
|
|
391
|
+
track.noteOn(0, noteObj.note, noteObj.length, level);
|
|
392
|
+
track.noteOff(0, noteObj.note, noteObj.length, level);
|
|
393
|
+
} else {
|
|
394
|
+
track.addChord(0, noteObj.note, noteObj.length, level);
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
track.noteOff(0, "", noteObj.length);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return file;
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/progression.ts
|
|
404
|
+
import { scale } from "harmonics";
|
|
405
|
+
var getChordDegrees = (mode) => {
|
|
406
|
+
const theRomans = {
|
|
407
|
+
ionian: ["I", "ii", "iii", "IV", "V", "vi", "vii\xB0"],
|
|
408
|
+
dorian: ["i", "ii", "III", "IV", "v", "vi\xB0", "VII"],
|
|
409
|
+
phrygian: ["i", "II", "III", "iv", "v\xB0", "VI", "vii"],
|
|
410
|
+
lydian: ["I", "II", "iii", "iv\xB0", "V", "vi", "vii"],
|
|
411
|
+
mixolydian: ["I", "ii", "iii\xB0", "IV", "v", "vi", "VII"],
|
|
412
|
+
aeolian: ["i", "ii\xB0", "III", "iv", "v", "VI", "VII"],
|
|
413
|
+
locrian: ["i\xB0", "II", "iii", "iv", "V", "VI", "vii"],
|
|
414
|
+
"melodic minor": ["i", "ii", "III+", "IV", "V", "vi\xB0", "vii\xB0"],
|
|
415
|
+
"harmonic minor": ["i", "ii\xB0", "III+", "iv", "V", "VI", "vii\xB0"]
|
|
416
|
+
};
|
|
417
|
+
theRomans.major = theRomans.ionian;
|
|
418
|
+
theRomans.minor = theRomans.aeolian;
|
|
419
|
+
return theRomans[mode] || [];
|
|
420
|
+
};
|
|
421
|
+
var idxByDegree = {
|
|
422
|
+
i: 0,
|
|
423
|
+
ii: 1,
|
|
424
|
+
iii: 2,
|
|
425
|
+
iv: 3,
|
|
426
|
+
v: 4,
|
|
427
|
+
vi: 5,
|
|
428
|
+
vii: 6
|
|
429
|
+
};
|
|
430
|
+
var getChordName = (roman) => {
|
|
431
|
+
const str = roman.replace(/\W/g, "");
|
|
432
|
+
let prefix = "M";
|
|
433
|
+
if (str.toLowerCase() === str) {
|
|
434
|
+
prefix = "m";
|
|
435
|
+
}
|
|
436
|
+
if (roman.indexOf("\xB0") > -1) {
|
|
437
|
+
return `${prefix}7b5`;
|
|
438
|
+
}
|
|
439
|
+
if (roman.indexOf("+") > -1) {
|
|
440
|
+
return `${prefix}#5`;
|
|
441
|
+
}
|
|
442
|
+
if (roman.indexOf("7") > -1) {
|
|
443
|
+
return prefix === "M" ? "maj7" : "m7";
|
|
444
|
+
}
|
|
445
|
+
return prefix;
|
|
446
|
+
};
|
|
447
|
+
var getChordsByProgression = (noteOctaveScale, chordDegress) => {
|
|
448
|
+
const noteOctaveScaleArr = noteOctaveScale.split(" ");
|
|
449
|
+
if (!noteOctaveScaleArr[0].match(/\d/)) {
|
|
450
|
+
noteOctaveScaleArr[0] += "4";
|
|
451
|
+
noteOctaveScale = noteOctaveScaleArr.join(" ");
|
|
452
|
+
}
|
|
453
|
+
const mode = scale(noteOctaveScale);
|
|
454
|
+
const chordDegreesArr = chordDegress.replace(/\s*,+\s*/g, " ").split(" ");
|
|
455
|
+
const chordFamily = chordDegreesArr.map((roman) => {
|
|
456
|
+
const chordName = getChordName(roman);
|
|
457
|
+
const scaleId = idxByDegree[roman.replace(/\W|\d/g, "").toLowerCase()];
|
|
458
|
+
const note = mode[scaleId];
|
|
459
|
+
const oct = note.replace(/\D+/, "");
|
|
460
|
+
return `${note.replace(/\d/, "") + chordName}_${oct}`;
|
|
461
|
+
});
|
|
462
|
+
return chordFamily.toString().replace(/,/g, " ");
|
|
463
|
+
};
|
|
464
|
+
var getProgFactory = ({ T, P, D }) => {
|
|
465
|
+
return (count = 4) => {
|
|
466
|
+
const chords2 = [];
|
|
467
|
+
chords2.push(pickOne(T));
|
|
468
|
+
let i = 1;
|
|
469
|
+
if (i < count - 1) {
|
|
470
|
+
chords2.push(pickOne(P));
|
|
471
|
+
i++;
|
|
472
|
+
}
|
|
473
|
+
if (i < count - 1 && dice()) {
|
|
474
|
+
chords2.push(pickOne(P));
|
|
475
|
+
i++;
|
|
476
|
+
}
|
|
477
|
+
if (i < count - 1) {
|
|
478
|
+
chords2.push(pickOne(D));
|
|
479
|
+
i++;
|
|
480
|
+
}
|
|
481
|
+
if (i < count - 1) {
|
|
482
|
+
chords2.push(pickOne(P));
|
|
483
|
+
i++;
|
|
484
|
+
}
|
|
485
|
+
if (i < count - 1) {
|
|
486
|
+
chords2.push(pickOne(D));
|
|
487
|
+
i++;
|
|
488
|
+
}
|
|
489
|
+
if (i < count - 1 && dice()) {
|
|
490
|
+
chords2.push(pickOne(P));
|
|
491
|
+
i++;
|
|
492
|
+
}
|
|
493
|
+
while (i < count) {
|
|
494
|
+
chords2.push(pickOne(D));
|
|
495
|
+
i++;
|
|
496
|
+
}
|
|
497
|
+
return chords2;
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
var M = getProgFactory({ T: ["I", "vi"], P: ["ii", "IV"], D: ["V"] });
|
|
501
|
+
var m = getProgFactory({ T: ["i", "VI"], P: ["ii", "iv"], D: ["V"] });
|
|
502
|
+
var progression = (scaleType, count = 4) => {
|
|
503
|
+
if (scaleType === "major" || scaleType === "M") {
|
|
504
|
+
return M(count);
|
|
505
|
+
}
|
|
506
|
+
if (scaleType === "minor" || scaleType === "m") {
|
|
507
|
+
return m(count);
|
|
508
|
+
}
|
|
509
|
+
return [];
|
|
510
|
+
};
|
|
511
|
+
export {
|
|
512
|
+
arp,
|
|
513
|
+
chord2 as chord,
|
|
514
|
+
chords,
|
|
515
|
+
clip,
|
|
516
|
+
getChordDegrees,
|
|
517
|
+
getChordsByProgression,
|
|
518
|
+
midi,
|
|
519
|
+
scale2 as mode,
|
|
520
|
+
scales as modes,
|
|
521
|
+
progression,
|
|
522
|
+
scale2 as scale,
|
|
523
|
+
scales
|
|
524
|
+
};
|
|
2
525
|
//# sourceMappingURL=index.js.map
|