scribbletune 5.2.0 → 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.mjs → index.cjs} +225 -169
- 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 +29 -40
- package/dist/lib/arp.d.ts +0 -10
- package/dist/lib/browser-clip.d.ts +0 -14
- package/dist/lib/browser-index.d.ts +0 -7
- package/dist/lib/channel.d.ts +0 -61
- package/dist/lib/clip.d.ts +0 -2
- package/dist/lib/index.d.ts +0 -7
- package/dist/lib/midi.d.ts +0 -11
- package/dist/lib/progression.d.ts +0 -25
- package/dist/lib/session.d.ts +0 -14
- package/dist/lib/types/arp-params.d.ts +0 -6
- package/dist/lib/types/channel-params.d.ts +0 -92
- package/dist/lib/types/channel-pattern.d.ts +0 -24
- package/dist/lib/types/clip-params.d.ts +0 -104
- package/dist/lib/types/event-fn.d.ts +0 -7
- package/dist/lib/types/index.d.ts +0 -14
- package/dist/lib/types/note-object.d.ts +0 -6
- package/dist/lib/types/nvp.d.ts +0 -4
- package/dist/lib/types/play-params.d.ts +0 -15
- package/dist/lib/types/player-observer-fn.d.ts +0 -6
- package/dist/lib/types/progression-scale.d.ts +0 -2
- package/dist/lib/types/seq-fn.d.ts +0 -2
- package/dist/lib/types/sizzle-style.d.ts +0 -2
- package/dist/lib/types/synth-params.d.ts +0 -20
- package/dist/lib/types/tpd.d.ts +0 -15
- package/dist/lib/utils.d.ts +0 -56
- package/dist/scribbletune.js +0 -2
- package/dist/scribbletune.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,525 @@
|
|
|
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})})();
|
|
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
|