*/class e{}function i(t){let e=0;for(let i=0;i>1;1==(t+e&1)&&(e+=16384),t=e}}else if(1==t)for(let t=0;t>1;1==(t+e&1)&&(e+=32768),t=e}}else if(3==t){let t=1;for(let i=0;i>1;1==(t+e&1)&&(e+=40),t=e}}else if(4==t)h(n,10,11,1,1,0),h(n,11,14,.6578,.6578,0),i(n,e.chipNoiseLength),s(n,1/Math.sqrt(e.chipNoiseLength));else if(5==t)for(var o=1,r=0;r>1)&1)&&(a+=40),o=a}else if(6==t)h(n,1,10,1,1,0),h(n,20,14,-2,-2,0),i(n,e.chipNoiseLength),s(n,1/Math.sqrt(e.chipNoiseLength));else if(7==t)for(o=1,r=0;r>1)&1)&&(a+=60),o=a}else{if(8!=t)throw new Error("Unrecognized drum index: "+t);for(o=1,r=0;r<32768;r++){var a;n[r]=(1&o)/2+.5,1==(o+(a=o>>1)&1)&&(a-=40),o=a}}n[e.chipNoiseLength]=n[0]}return n}function h(t,i,s,h,o,r){const a=0|Math.pow(2,i),l=Math.min(e.chipNoiseLength>>1,0|Math.pow(2,s)),c=n(0);let d=0;for(let n=a;n>6,i=63&t;return c.presetCategories[e].presets[i]}static midiProgramToPresetValue(t){for(let e=0;e=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},u=t&&t.i||function(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var s,n,h=i.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(s=h.next()).done;)o.push(s.value)}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}return o},f=t&&t.h||function(){for(var t=[],e=0;e=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},k=function(){for(var t=[],e=0;e'+t.join()+"","image/svg+xml").documentElement;null!==s.firstChild;)document.importNode(s.firstChild,!0),i.appendChild(s.firstChild);return i},M=function(t){k[t]=function(){for(var e=[],i=0;i=2;s--){const i=1<>1,h=i<<1,o=2*Math.PI/h,r=Math.cos(o),a=Math.sin(o),l=2*r;for(let s=0;s16)throw new Error("FFT array length must not be greater than 2^16.");const s=16-i;for(let i=0;i>1|(21845&i)<<1,e=(52428&e)>>2|(13107&e)<<2,e=(61680&e)>>4|(3855&e)<<4,e=(e>>8|(255&e)<<8)>>s,e>i){let s=t[i];t[i]=t[e],t[e]=s}}}(t,e)}B.firstChild.clientWidth<30&&document.documentElement.classList.add("obtrusive-scrollbars"),document.body.removeChild(B),document.head.appendChild(k.style({type:"text/css"},`\n\n/* Note: "#" symbols need to be encoded as "%23" in SVG data urls, otherwise they are interpreted as fragment identifiers! */\n:root {\n\t--play-symbol: url('data:image/svg+xml,');\n\t--pause-symbol: url('data:image/svg+xml,');\n\t--prev-bar-symbol: url('data:image/svg+xml,');\n\t--next-bar-symbol: url('data:image/svg+xml,');\n\t--volume-symbol: url('data:image/svg+xml,');\n\t--unmuted-symbol: url('data:image/svg+xml,');\n\t--muted-symbol: url('data:image/svg+xml,');\n\t--menu-down-symbol: url('data:image/svg+xml,');\n\t--select-arrows-symbol: url('data:image/svg+xml,');\n\t--file-page-symbol: url('data:image/svg+xml,');\n\t--edit-pencil-symbol: url('data:image/svg+xml,');\n\t--preferences-gear-symbol: url('data:image/svg+xml,');\n\t--customize-dial-symbol: url('data:image/svg+xml, \t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t\t \t\t');\n\t--export-symbol: url('data:image/svg+xml,');\n\t--close-symbol: url('data:image/svg+xml,');\n\t--checkmark-symbol: url('data:image/svg+xml,');\n\t--drum-symbol: url('data:image/svg+xml, \t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t');\n\t--piano-key-symbol: url('data:image/svg+xml, \t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t');\n --mod-key-symbol: url('data:image/svg+xml, \t\t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t\t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t');\n}\n\n\n.obtrusive-scrollbars, .obtrusive-scrollbars * {\n\tscrollbar-width: thin;\n\tscrollbar-color: ${T.uiWidgetBackground} ${T.editorBackground};\n}\n.obtrusive-scrollbars::-webkit-scrollbar, .obtrusive-scrollbars *::-webkit-scrollbar {\n\twidth: 12px;\n}\n.obtrusive-scrollbars::-webkit-scrollbar-track, .obtrusive-scrollbars *::-webkit-scrollbar-track {\n\tbackground: ${T.editorBackground};\n}\n.obtrusive-scrollbars::-webkit-scrollbar-thumb, .obtrusive-scrollbars *::-webkit-scrollbar-thumb {\n\tbackground-color: ${T.uiWidgetBackground};\n\tborder: 3px solid ${T.editorBackground};\n}\n\n@-moz-document url-prefix() {\n\t.muteButtonText {\n\t\ttransform: translate(3px, 1px) !important;\n\t}\n}\n\n.beepboxEditor {\n\tdisplay: grid;\n grid-template-columns: minmax(0, 1fr) max-content;\n grid-template-rows: max-content 1fr; /* max-content minmax(0, 1fr); Chrome 80 grid layout regression. https://bugs.chromium.org/p/chromium/issues/detail?id=1050307 */\n grid-template-areas: "pattern-area settings-area" "track-area settings-area";\n\tgrid-column-gap: 6px;\n\tgrid-row-gap: 6px;\n\tposition: relative;\n\ttouch-action: manipulation;\n\tcursor: default;\n\tfont-size: small;\n\toverflow: hidden;\n\tcolor: ${T.primaryText};\n\tbackground: ${T.editorBackground};\n opacity: 0;\n -webkit-transition: opacity 0.2s ease-in;\n -moz-transition: opacity 0.2s ease-in;\n -o-transition: opacity 0.2s ease-in;\n -ms-transition: opacity 0.2s ease-in;\n transition: opacity 0.2s ease-in;\n transition-delay: 0s;\n}\n\n.pattern-area {\n opacity: 0;\n -webkit-transition: opacity 0.5s ease-in;\n -moz-transition: opacity 0.5s ease-in;\n -o-transition: opacity 0.5s ease-in;\n -ms-transition: opacity 0.5s ease-in;\n transition: opacity 0.5s ease-in;\n transition-delay: 0s;\n}\n\n.settings-area {\n opacity: 0;\n -webkit-transition: opacity 0.5s ease-in;\n -moz-transition: opacity 0.5s ease-in;\n -o-transition: opacity 0.5s ease-in;\n -ms-transition: opacity 0.5s ease-in;\n transition: opacity 0.5s ease-in;\n transition-delay: 0.15s;\n}\n\n.editor-song-settings {\n opacity: 0;\n -webkit-transition: opacity 0.5s ease-in;\n -moz-transition: opacity 0.5s ease-in;\n -o-transition: opacity 0.5s ease-in;\n -ms-transition: opacity 0.5s ease-in;\n transition: opacity 0.5s ease-in;\n transition-delay: 0.35s;\n}\n\n.instrument-settings-area {\n opacity: 0;\n -webkit-transition: opacity 0.5s ease-in;\n -moz-transition: opacity 0.5s ease-in;\n -o-transition: opacity 0.5s ease-in;\n -ms-transition: opacity 0.5s ease-in;\n transition: opacity 0.5s ease-in;\n transition-delay: 0.45s;\n}\n\n.trackAndMuteContainer {\n opacity: 0;\n -webkit-transition: opacity 0.5s ease-in;\n -moz-transition: opacity 0.5s ease-in;\n -o-transition: opacity 0.5s ease-in;\n -ms-transition: opacity 0.5s ease-in;\n transition: opacity 0.5s ease-in;\n transition-delay: 0.4s;\n}\n\n.barScrollBar {\n opacity: 0;\n -webkit-transition: opacity 0.5s ease-in;\n -moz-transition: opacity 0.5s ease-in;\n -o-transition: opacity 0.5s ease-in;\n -ms-transition: opacity 0.5s ease-in;\n transition: opacity 0.5s ease-in;\n transition-delay: 0.5s;\n}\n\n\n\n.load {\n opacity: 1;\n}\n\n.beepboxEditor .noSelection {\n\t-webkit-touch-callout: none;\n\t-webkit-user-select: none;\n\t-moz-user-select: none;\n\t-ms-user-select: none;\n\tuser-select: none;\n}\n\n.beepboxEditor div {\n\tmargin: 0;\n\tpadding: 0;\n}\n\n.beepboxEditor .pattern-area {\n\tgrid-area: pattern-area;\n\theight: 481px;\n\tdisplay: flex;\n\tflex-direction: row;\n}\n\n.beepboxEditor .track-area {\n\tgrid-area: track-area;\n}\n\n.beepboxEditor .settings-area {\n\tgrid-area: settings-area;\n\tdisplay: grid;\n grid-template-columns: auto;\n grid-template-rows: min-content min-content min-content min-content min-content;\n grid-template-areas: "version-area" "play-pause-area" "menu-area" "song-settings-area" "instrument-settings-area";\n\tgrid-column-gap: 6px;\n}\n\n.beepboxEditor .version-area{ grid-area: version-area; }\n.beepboxEditor .play-pause-area{ grid-area: play-pause-area; }\n.beepboxEditor .menu-area{ grid-area: menu-area; }\n.beepboxEditor .song-settings-area{ grid-area: song-settings-area; }\n.beepboxEditor .instrument-settings-area{ grid-area: instrument-settings-area; }\n\n.beepboxEditor .tip {\n\tcursor: help;\n}\n\n.beepboxEditor .tip:hover {\n\tcolor: ${T.linkAccent};\n\ttext-decoration: underline;\n}\n.beepboxEditor .tip:active {\n\tcolor: ${T.primaryText};\n}\n\n.beepboxEditor .volume-speaker {\n\tflex-shrink: 0;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: ${T.secondaryText};\n\t-webkit-mask-image: var(--volume-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--volume-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor .drum-button {\n\tflex: 1;\n\tbackground-color: transparent;\n\tbackground-image: var(--drum-symbol);\n\tbackground-repeat: no-repeat;\n\tbackground-position: center;\n}\n\n.beepboxEditor .modulator-button {\n\tflex: 1;\n\tposition: relative;\n\tdisplay: flex;\n\talign-items: center;\n}\n.beepboxEditor .modulator-button::before {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 0;\n\ttop: 0;\n\twidth: 100%;\n\theight: 100%;\n\tpointer-events: none;\n\tbackground-image: var(--mod-key-symbol);\n\tbackground-repeat: no-repeat;\n\tbackground-position: center;\n\tbackground-size: 100% 102%;\n}\n\n.beepboxEditor .piano-button {\n\tflex: 1;\n\tposition: relative;\n\tdisplay: flex;\n\talign-items: center;\n}\n.beepboxEditor .piano-button::before {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 0;\n\ttop: 0;\n\twidth: 100%;\n\theight: 100%;\n\tpointer-events: none;\n\tbackground-image: var(--piano-key-symbol);\n\tbackground-repeat: no-repeat;\n\tbackground-position: center;\n\tbackground-size: 100% 115.38%;\n}\n.beepboxEditor .piano-button.disabled::after {\n\tcontent: "";\n\tposition: absolute;\n\tright: 0;\n\ttop: 0;\n\twidth: 70%;\n\theight: 100%;\n\tpointer-events: none;\n\tbackground: ${T.editorBackground};\n\t-webkit-mask-image: linear-gradient(90deg, transparent 0%, gray 70%, gray 100%);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: linear-gradient(90deg, transparent 0%, gray 70%, gray 100%);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor .customize-instrument {\n\tmargin: 2px 0;\n}\n.beepboxEditor .customize-instrument::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--customize-dial-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--customize-dial-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor .menu.file::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--file-page-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--file-page-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor .menu.edit::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--edit-pencil-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--edit-pencil-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor .menu.preferences::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--preferences-gear-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--preferences-gear-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor .mute-button {\n\tbackground: transparent;\n\tborder: none;\n padding-right: 0px;\n padding-left: 0px;\n box-shadow: none;\n}\n\n.beepboxEditor .mute-button:focus {\n background: transparent;\n\tborder: none;\n}\n\n.beepboxEditor .mute-button::before {\n\tcontent: "";\n\tpointer-events: none;\n\twidth: 100%;\n\theight: 100%;\n\tdisplay: inline-block;\n background: var(--mute-button-normal);\n\t-webkit-mask-image: var(--unmuted-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\t-webkit-mask-size: cover;\n mask-repeat: no-repeat;\n\tmask-position: center;\n\tmask-size: cover;\n mask-image: var(--unmuted-symbol);\n}\n\n.beepboxEditor .mute-button.muted::before {\n background: var(--ui-widget-background);\n\t-webkit-mask-image: var(--muted-symbol);\n mask-image: var(--muted-symbol);\n}\n\n.beepboxEditor .mute-button.modMute.muted::before {\n background: var(--ui-widget-background);\n\t-webkit-mask-image: var(--muted-symbol);\n mask-image: var(--muted-symbol);\n}\n\n.beepboxEditor .mute-button.modMute::before {\n background: var(--mute-button-mod);\n}\n\n\n.beepboxEditor .promptContainer {\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n\twidth: 100%;\n\theight: 100%;\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n}\n\n.beepboxEditor .promptContainer::before {\n\tcontent: "";\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n\twidth: 100%;\n\theight: 100%;\n\tbackground: ${T.editorBackground};\n\topacity: 0.5;\n\tdisplay: flex;\n}\n\n.beepboxEditor .prompt {\n\tmargin: auto;\n\ttext-align: center;\n\tbackground: ${T.editorBackground};\n\tborder-radius: 15px;\n\tborder: 4px solid ${T.uiWidgetBackground};\n\tcolor: ${T.primaryText};\n\tpadding: 20px;\n\tdisplay: flex;\n\tflex-direction: column;\n\tposition: relative;\n\tbox-shadow: 5px 5px 20px 10px rgba(0,0,0,0.5);\n}\n\n.beepboxEditor .prompt > *:not(:first-child):not(.cancelButton) {\n\tmargin-top: 1.5em;\n}\n\n.beepboxEditor .prompt h2 {\n\tfont-size: 2em;\n\tmargin: 0 16px;\n\tfont-weight: normal;\n}\n\n.beepboxEditor .prompt p {\n\ttext-align: left;\n\tmargin: 1em 0;\n}\n\n.beepboxEditor .selectContainer {\n\tposition: relative;\n}\n.beepboxEditor .selectContainer:not(.menu)::after {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tright: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 1.1em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--select-arrows-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--select-arrows-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n.beepboxEditor .selectContainer.menu::after {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tright: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--menu-down-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--menu-down-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n.beepboxEditor select {\n\tmargin: 0;\n\tpadding: 0 0.3em;\n\tdisplay: block;\n\theight: 2em;\n\tborder: none;\n\tborder-radius: 0.4em;\n\tbackground: ${T.uiWidgetBackground};\n\tcolor: inherit;\n\tfont-size: inherit;\n\tcursor: pointer;\n\tfont-family: inherit;\n\tfont-weight: inherit;\n\n\t-webkit-appearance:none;\n\t-moz-appearance: none;\n\tappearance: none;\n}\n\n.select2-container .select2-selection--single {\n height: auto;\n}\n\n.select2-container {\n width: -moz-available !important;\n width: -webkit-fill-available !important;\n}\n\n.select2-container--default .select2-selection--single{\n border-radius: 0px;\n border: 0px;\n background-color: transparent;\n outline: none;\n}\n\n.select2-selection__rendered:not(.menu)::before {\n\tcontent: "";\n\tposition: absolute;\n\tright: 0.3em;\n\ttop: 0.4em;\n\tborder-bottom: 0.4em solid currentColor;\n\tborder-left: 0.3em solid transparent;\n\tborder-right: 0.3em solid transparent;\n\tpointer-events: none;\n}\n.select2-selection__rendered:not(.menu)::after {\n\tcontent: "";\n\tposition: absolute;\n\tright: 0.3em;\n\tbottom: 0.4em;\n\tborder-top: 0.4em solid currentColor;\n\tborder-left: 0.3em solid transparent;\n\tborder-right: 0.3em solid transparent;\n\tpointer-events: none;\n}\n.select2-selection__rendered {\n\tmargin: 0;\n\tpadding: 0 0.3em;\n\tdisplay: block;\n\theight: 2em;\n\tborder: none;\n\tborder-radius: 0.4em;\n\tbackground: ${T.uiWidgetBackground};\n\tcolor: inherit !important;\n\tfont-size: inherit;\n\tcursor: pointer;\n\tfont-family: inherit;\n\t-webkit-appearance:none;\n\t-moz-appearance: none;\n\tappearance: none;\n}\n.select2-selection__arrow b{\n display:none !important;\n}\n\n.select2-selection__rendered--focus {\n\tbackground: ${T.uiWidgetFocus};\n\toutline: none;\n}\n.select2-search__field {\n background: ${T.uiWidgetBackground};\n color: inherit !important;\n font-size: small;\n font-family: inherit;\n border: 0px !important;\n padding: 1px !important;\n}\n.select2-dropdown {\n box-sizing: border-box;\n display: inline-block;\n margin: 0;\n font-size: small;\n position: relative;\n vertical-align: middle;\n background-color: ${T.uiWidgetFocus};\n}\n\n.select2-container--default .select2-results>.select2-results__options {\n max-height: 430px;\n overflow-x: hidden;\n}\n.select2-container--default .select2-results__group {\n cursor: default;\n display: block;\n padding: 1px;\n background: ${T.select2OptGroup};\n}\n.select2-results__option {\n padding: 2px;\n user-select: none;\n -webkit-user-select: none;\n}\n.select2-container--default .select2-results__option .select2-results__option {\n padding-left: 0.1em;\n}\n.select2-container--default .select2-results__option[aria-selected=true] {\n background-color: transparent !important;\n}\n\n.beepboxEditor .menu select {\n\tpadding: 0 2em;\n}\n.beepboxEditor select:focus {\n\tbackground: ${T.uiWidgetFocus};\n\toutline: none;\n}\n.beepboxEditor .menu select {\n\ttext-align: center;\n\ttext-align-last: center;\n}\n.beepboxEditor .settings-area select {\n width: 100%;\n}\n\n/* This makes it look better in firefox on my computer... What about others?\n@-moz-document url-prefix() {\n\t.beepboxEditor select { padding: 0 2px; }\n}\n*/\n.beepboxEditor button {\n\tmargin: 0;\n\tposition: relative;\n\theight: 2em;\n\tborder: none;\n\tborder-radius: 0.4em;\n\tbackground: ${T.uiWidgetBackground};\n\tcolor: inherit;\n\tfont-size: inherit;\n\tfont-family: inherit;\n\tfont-weight: inherit;\n\tcursor: pointer;\n}\n.beepboxEditor button:focus {\n\tbackground: ${T.uiWidgetFocus};\n\toutline: none;\n}\n\n.beepboxEditor button.cancelButton {\n\tfloat: right;\n\twidth: 2em;\n\tposition: absolute;\n\ttop: 8px;\n\tright: 8px;\n}\n\n.beepboxEditor button.playButton, .beepboxEditor button.pauseButton, .beepboxEditor button.okayButton, .beepboxEditor button.exportButton {\n\tpadding-left: 2em;\n}\n.beepboxEditor button.playButton::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--play-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--play-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n.beepboxEditor button.pauseButton::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 0;\n\ttop: 50%;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--pause-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--pause-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor button.prevBarButton::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 50%;\n\ttop: 50%;\n\tmargin-left: -1em;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--prev-bar-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--prev-bar-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor button.nextBarButton::before {\n\tcontent: "";\n\tflex-shrink: 0;\n\tposition: absolute;\n\tleft: 50%;\n\ttop: 50%;\n\tmargin-left: -1em;\n\tmargin-top: -1em;\n\tpointer-events: none;\n\twidth: 2em;\n\theight: 2em;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--next-bar-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--next-bar-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor button.cancelButton::before {\n\tcontent: "";\n\tposition: absolute;\n\twidth: 2em;\n\theight: 2em;\n\tleft: 0;\n\ttop: 0;\n\tpointer-events: none;\n\tbackground: currentColor;\n\tmask-image: var(--close-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n\t-webkit-mask-image: var(--close-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n}\n\n.beepboxEditor button.okayButton::before {\n\tcontent: "";\n\tposition: absolute;\n\twidth: 2em;\n\theight: 2em;\n\tleft: 0;\n\ttop: 0;\n\tpointer-events: none;\n\tbackground: currentColor;\n\t-webkit-mask-image: var(--checkmark-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n\tmask-image: var(--checkmark-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n}\n\n.beepboxEditor button.exportButton::before {\n\tcontent: "";\n\tposition: absolute;\n\twidth: 2em;\n\theight: 2em;\n\tleft: 0;\n\ttop: 0;\n\tpointer-events: none;\n\tbackground: currentColor;\n\tmask-image: var(--export-symbol);\n\tmask-repeat: no-repeat;\n\tmask-position: center;\n\t-webkit-mask-image: var(--export-symbol);\n\t-webkit-mask-repeat: no-repeat;\n\t-webkit-mask-position: center;\n}\n\n.beepboxEditor canvas {\n\toverflow: hidden;\n\tposition: absolute;\n\tdisplay: block;\n cursor: crosshair;\n}\n\n@keyframes dash-animation {\n to {\n stroke-dashoffset: -100;\n }\n}\n\n.beepboxEditor .dash-move {\n animation: dash-animation 20s infinite linear;\n}\n\n.beepboxEditor .trackContainer {\n\toverflow-x: hidden;\n\tflex-grow: 1;\n}\n\n.beepboxEditor .trackAndMuteContainer {\n\tdisplay: flex;\n\talign-items: flex-start;\n}\n\n.beepboxEditor .muteEditor {\n\theight: 128px;\n\twidth: 32px;\n\tflex-shrink: 0;\n\tdisplay: flex;\n\tflex-direction: column;\n\talign-items: stretch;\n}\n\n.beepboxEditor .selectRow {\n\tmargin: 2px 0;\n\theight: 2em;\n\tdisplay: flex;\n\tflex-direction: row;\n\talign-items: center;\n\tjustify-content: space-between;\n}\n\n.beepboxEditor .tip {\n\tcolor: ${T.secondaryText};\n}\n\n.beepboxEditor .selectRow > :nth-child(2) {\n\twidth: 61.5%;\n}\n\n.beepboxEditor .operatorRow {\n\tmargin: 2px 0;\n\theight: 2em;\n\tdisplay: flex;\n\tflex-direction: row;\n\talign-items: center;\n}\n\n.beepboxEditor .operatorRow > * {\n\tflex-grow: 1;\n\tflex-shrink: 1;\n}\n\n.beepboxEditor .menu-area {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n.beepboxEditor .menu-area > * {\n\tmargin: 2px 0;\n}\n.beepboxEditor .menu-area > button {\n\tpadding: 0 2em;\n\twhite-space: nowrap;\n}\n\n.beepboxEditor .song-settings-area {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-controls {\n\tflex-shrink: 0;\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .instrument-settings-area {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-right-side-top > *, .beepboxEditor .editor-right-side-bottom > * {\n\tflex-shrink: 0;\n}\n\n.beepboxEditor input[type=text], .beepboxEditor input[type=number] {\n\tfont-size: inherit;\n\tfont-weight: inherit;\n\tfont-family: inherit;\n\tbackground: transparent;\n\ttext-align: center;\n\tborder: 1px solid ${T.inputBoxOutline};\n\tcolor: ${T.primaryText};\n}\n\n.beepboxEditor input[type=text]::selection, .beepboxEditor input[type=number]::selection {\n\tbackground-color: ${T.textSelection};\n\tcolor: ${T.primaryText};\n}\n\n.beepboxEditor input[type=checkbox] {\n transform: scale(1.5);\n}\n\n.beepboxEditor input[type=range] {\n\t-webkit-appearance: none;\n\tcolor: inherit;\n\twidth: 100%;\n\theight: 2em;\n\tfont-size: inherit;\n\tmargin: 0;\n\tcursor: pointer;\n\tbackground-color: ${T.editorBackground};\n\ttouch-action: pan-y;\n position: relative;\n}\n.beepboxEditor input[type=range]:focus {\n\toutline: none;\n}\n.beepboxEditor input[type=range]::-webkit-slider-runnable-track {\n\twidth: 100%;\n\theight: 0.5em;\n\tcursor: pointer;\n\tbackground: ${T.uiWidgetBackground};\n}\n\n.beepboxEditor span.midTick:after {\n content: "";\n display:inline-block;\n position: absolute;\n background: currentColor;\n width: 2%;\n left: 49%;\n height: 0.5em;\n top: 32%;\n z-index: 1;\n\t\tpointer-events: none;\n}\n.beepboxEditor span.modSlider {\n\t--mod-position: 20%;\n\t--mod-color: ${T.overwritingModSlider};\n --mod-border-radius: 0%;\n}\n.beepboxEditor span.modSlider:before {\n\tcontent: "";\n display:inline-block;\n position: absolute;\n background: var(--mod-color);\n width: 4%;\n left: var(--mod-position);\n height: 0.8em;\n top: 28%;\n z-index: 2;\n\t\ttransform: translate(-50%, 0%);\n\t\tpointer-events: none;\n\t\tborder: 40%;\n\t\tborder-radius: var(--mod-border-radius);\n}\n.beepboxEditor input[type=range]::-webkit-slider-thumb {\n\theight: 2em;\n\twidth: 0.5em;\n\tborder-radius: 0.25em;\n\tbackground: currentColor;\n\tcursor: pointer;\n\t-webkit-appearance: none;\n\tmargin-top: -0.75em;\n}\n.beepboxEditor input[type=range]:focus::-webkit-slider-runnable-track {\n\tbackground: ${T.uiWidgetFocus};\n}\n.beepboxEditor input[type=range]::-moz-range-track {\n\twidth: 100%;\n\theight: 0.5em;\n\tcursor: pointer;\n\tbackground: ${T.uiWidgetBackground};\n}\n.beepboxEditor input[type=range]:focus::-moz-range-track {\n\tbackground: ${T.uiWidgetFocus};\n}\n.beepboxEditor input[type=range]::-moz-range-thumb {\n\theight: 2em;\n\twidth: 0.5em;\n\tborder-radius: 0.25em;\n\tborder: none;\n\tbackground: currentColor;\n\tcursor: pointer;\n}\n.beepboxEditor input[type=range]::-ms-track {\n\twidth: 100%;\n\theight: 0.5em;\n\tcursor: pointer;\n\tbackground: ${T.uiWidgetBackground};\n\tborder-color: transparent;\n}\n.beepboxEditor input[type=range]:focus::-ms-track {\n\tbackground: ${T.uiWidgetFocus};\n}\n.beepboxEditor input[type=range]::-ms-thumb {\n\theight: 2em;\n\twidth: 0.5em;\n\tborder-radius: 0.25em;\n\tbackground: currentColor;\n\tcursor: pointer;\n}\n.beepboxEditor .hintButton {\n\tborder: 1px solid currentColor;\n\tborder-radius: 50%;\n\ttext-decoration: none;\n\twidth: 1em;\n\theight: 1em;\n\ttext-align: center;\n\tmargin-left: auto;\n\tmargin-right: .4em;\n\tcursor: pointer;\n}\n\nli.select2-results__option[role=group] > strong:hover {\n background-color: #516fbb;\n}\n\n/* wide screen */\n@media (min-width: 701px) {\n\t#beepboxEditorContainer {\n\t\tdisplay: table;\n\t}\n\t.beepboxEditor {\n\t\tflex-direction: row;\n\t}\n\t.beepboxEditor:focus-within {\n\t\toutline: 3px solid ${T.uiWidgetBackground};\n\t}\n\t.beepboxEditor .trackAndMuteContainer {\n\t\twidth: 512px;\n\t}\n\t.beepboxEditor .trackSelectBox {\n\t\tdisplay: none;\n\t}\n .beepboxEditor .muteButtonSelectBox {\n\t\tdisplay: none;\n\t}\n\t.beepboxEditor .play-pause-area {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t}\n\t.beepboxEditor .playback-bar-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tmargin: 2px 0;\n\t}\n\t.beepboxEditor .playback-volume-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tmargin: 2px 0;\n\t\talign-items: center;\n\t}\n\t.beepboxEditor .pauseButton, .beepboxEditor .playButton,\n .beepboxEditor .copyButton, .beepboxEditor .pasteButton\n {\n\t\tflex-grow: 1;\n\t}\n\t.beepboxEditor .nextBarButton, .beepboxEditor .prevBarButton {\n\t\tflex-grow: 1;\n\t\tmargin-left: 10px;\n\t}\n\t.beepboxEditor .settings-area {\n\t\twidth: 14em;\n\t}\n}\n\n/* narrow screen */\n@media (max-width: 700px) {\n\t.beepboxEditor {\n\t\tgrid-template-columns: minmax(0, 1fr);\n\t\tgrid-template-rows: min-content 6px min-content min-content;\n\t\tgrid-template-areas: "pattern-area" "." "track-area" "settings-area";\n\t\tgrid-row-gap: 0;\n\t}\n\t.beepboxEditor .settings-area {\n\t\tgrid-template-columns: minmax(0, 1fr) minmax(0, 1fr);\n\t\tgrid-template-rows: min-content min-content 1fr min-content;\n\t\tgrid-template-areas:\n\t\t\t"play-pause-area play-pause-area"\n\t\t\t"menu-area instrument-settings-area"\n\t\t\t"song-settings-area instrument-settings-area"\n\t\t\t"version-area version-area";\n\t\tgrid-column-gap: 8px;\n\t\tmargin: 0 4px;\n\t}\n\t.beepboxEditor:focus-within {\n\t\toutline: none;\n\t}\n\t.beepboxEditor .pattern-area {\n\t\tmax-height: 75vh;\n\t}\n\t.beepboxEditor .trackContainer {\n\t\toverflow-x: auto;\n\t}\n\t.beepboxEditor .barScrollBar {\n\t\tdisplay: none;\n\t}\n\t.beepboxEditor .play-pause-area {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tmargin: 2px 0;\n\t}\n\t.beepboxEditor .playback-bar-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tflex-grow: 1;\n\t}\n\t.beepboxEditor .playback-volume-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\talign-items: center;\n\t\tflex-grow: 1;\n\t\tmargin: 0 2px;\n\t}\n\t.beepboxEditor .pauseButton, .beepboxEditor .playButton,\n\t.beepboxEditor .nextBarButton, .beepboxEditor .prevBarButton,\n .beepboxEditor .copyButton, .beepboxEditor .pasteButton\n {\n\t\tflex-grow: 1;\n\t\tmargin: 0 2px;\n\t}\n\t\n\t.beepboxEditor .soundIcon {\n\t background: ${T.editorBackground};\n\t display: inline-block;\n\t height: 10px;\n\t margin-left: 0px;\n\t margin-top: 8px;\n\t\tposition: relative;\n\t\twidth: 10px;\n\t}\n\t.beepboxEditor .soundIcon:before {\n\t border-bottom: 6px solid transparent;\n\t border-top: 6px solid transparent;\n\t border-right: 10px solid ${T.editorBackground};\n\t content: "";\n\t height: 10px;\n\t left: 6px;\n\t position: absolute;\n\t top: -6px;\n\t width: 0;\n\t}\n}\n\n`));class F{constructor(){this.l=1,this.u=[void 0],this.m=0,this.v=0,this.k=0}pushFront(t){this.k>=this.l&&this.M(),this.v=this.v-1&this.m,this.u[this.v]=t,this.k++}pushBack(t){this.k>=this.l&&this.M(),this.u[this.v+this.k&this.m]=t,this.k++}popFront(){if(this.k<=0)throw new Error("No elements left to pop.");const t=this.u[this.v];return this.u[this.v]=void 0,this.v=this.v+1&this.m,this.k--,t}popBack(){if(this.k<=0)throw new Error("No elements left to pop.");this.k--;const t=this.v+this.k&this.m,e=this.u[t];return this.u[t]=void 0,e}peakFront(){if(this.k<=0)throw new Error("No elements left to pop.");return this.u[this.v]}peakBack(){if(this.k<=0)throw new Error("No elements left to pop.");return this.u[this.v+this.k-1&this.m]}count(){return this.k}set(t,e){if(t<0||t>=this.k)throw new Error("Invalid index");this.u[this.v+t&this.m]=e}get(t){if(t<0||t>=this.k)throw new Error("Invalid index");return this.u[this.v+t&this.m]}remove(t){if(t<0||t>=this.k)throw new Error("Invalid index");if(t<=this.k>>1){for(;t>0;)this.set(t,this.get(t-1)),t--;this.popFront()}else{for(t++;t=1073741824)throw new Error("Capacity too big.");this.l=this.l<<1;const t=this.u,e=new Array(this.l),i=0|this.k,s=0|this.v;for(let n=0;n>5&1),this.S.push(e>>4&1),this.S.push(e>>3&1),this.S.push(e>>2&1),this.S.push(e>>1&1),this.S.push(1&e)}}read(t){let e=0;for(;t>0;)e<<=1,e+=this.S[this.q++],t--;return e}readLongTail(t,e){let i=t,s=e;for(;this.S[this.q++];)i+=1<0;)s--,this.S[this.q++]&&(i+=1<=0;)this.S[this.P++]=e>>>t&1,t--}writeLongTail(t,e,i){if(i=1<0;)s--,this.S[this.P++]=i>>>s&1}writePartDuration(t){this.writeLongTail(1,3,t)}writePinCount(t){this.writeLongTail(1,0,t)}writePitchInterval(t){t<0?(this.write(1,1),this.writeLongTail(1,3,-t)):(this.write(1,0),this.writeLongTail(1,3,t))}concat(t){for(let e=0;e=t?i:t:e}function O(t,e,i){if(t<=i&&i<=e)return i;throw new Error(`Value ${i} not in range [${t}, ${e}]`)}class U{constructor(t,e,i,s,n=!1){this.pitches=[t],this.pins=[I(0,0,s),I(0,i-e,n?0:s)],this.start=e,this.end=i}pickMainInterval(){let t=0,e=0;for(let i=1;i=25;this.spectrum[i]=t?Math.max(0,Math.round(e.spectrumMax*(1-i/30))):0}this.R=!1}markCustomWaveDirty(){this.R=!1}getCustomWave(t){if(!this.R||null==this.T){let s=e.chipNoiseLength;null!=this.T&&this.T.length==s+1||(this.T=new Float32Array(s+1));const n=this.T;for(let t=0;t=e.spectrumControlPoints?this.spectrum[e.spectrumControlPoints-1]:this.spectrum[t],c=i(t-1);let d=i(t);t>=e.spectrumControlPoints&&(d=o+(d-o)*r),0==s&&0==a||(l+=.02*h(n,c,d,s/e.spectrumMax,a/e.spectrumMax,-.5))}this.spectrum[e.spectrumControlPoints-1]>0&&(l+=.02*h(n,o+(i(e.spectrumControlPoints)-o)*r,o,this.spectrum[e.spectrumControlPoints-1]/e.spectrumMax,0,-.5)),N(n,s),z(n,5/(Math.sqrt(s)*Math.pow(l,.75))),n[s]=n[0],this.R=!0}return this.T}}class G{constructor(){this.harmonics=[],this.T=null,this.R=!1,this.reset()}reset(){for(let t=0;t=e.harmonicsControlPoints&&(a*=1-(n-e.harmonicsControlPoints)/(e.harmonicsRendered-e.harmonicsControlPoints));const l=a/e.harmonicsMax;let c=Math.pow(2,a-e.harmonicsMax+1)*Math.sqrt(l);n>>0),null!=t.volume?this.volume=_(-e.volumeRange/2,e.volumeRange/2,0|t.volume):this.volume=0,null!=t.pan?this.pan=_(0,e.panMax+1,Math.round(e.panCenter+(0|t.pan)*e.panCenter/100)):this.pan=e.panCenter,null!=t.panDelay?this.panDelay=0|t.panDelay:this.panDelay=10,null!=t.detune?this.detune=_(e.detuneMin,e.detuneMax+1,0|t.detune):this.detune=0;const r={binary:0,sudden:1,smooth:2},a=t.transition||t.envelope;if(this.transition=null!=r[a]?r[a]:e.transitions.findIndex((t=>t.name==a)),-1==this.transition&&(this.transition=1),this.effects=e.effectsNames.indexOf(t.effects),-1==this.effects&&(this.effects=2==this.type?0:1),null!=t.filterCutoffHz?this.filterCutoff=_(0,e.filterCutoffRange,Math.round(e.filterCutoffRange-1+2*Math.log((0|t.filterCutoffHz)/e.filterCutoffMaxHz)/Math.LN2)):this.filterCutoff=0==this.type?6:10,null!=t.filterResonance?this.filterResonance=_(0,e.filterResonanceRange,Math.round((e.filterResonanceRange-1)*(0|t.filterResonance)/100)):this.filterResonance=0,this.filterEnvelope=e.envelopes.findIndex((e=>e.name==t.filterEnvelope)),-1==this.filterEnvelope&&(this.filterEnvelope=e.envelopes.dictionary.steady.index),null!=t.filter){const e=[20,12,6,0,16,10,4],i=[1,1,1,1,18,19,20],s=["none","bright","medium","soft","decay bright","decay medium","decay soft"],n={"sustain sharp":1,"sustain medium":2,"sustain soft":3,"decay sharp":4};let h=null!=n[t.filter]?n[t.filter]:s.indexOf(t.filter);-1==h&&(h=0),this.filterCutoff=e[h],this.filterEnvelope=i[h],this.filterResonance=0}const l=["none","vibrato light","vibrato delayed","vibrato heavy"];if(2==this.type)this.chipNoise=e.chipNoises.findIndex((e=>e.name==t.wave)),-1==this.chipNoise&&(this.chipNoise=1),this.chord=e.chords.findIndex((e=>e.name==t.chord)),-1==this.chord&&(this.chord=2),2==this.chord&&null!=t.arpeggioSpeed?this.arpeggioSpeed=t.arpeggioSpeed:this.arpeggioSpeed=n?9:12,null!=t.fastTwoNoteArp?this.fastTwoNoteArp=t.fastTwoNoteArp:this.fastTwoNoteArp=h;else if(3==this.type){if(null!=t.spectrum)for(let i=0;ie.name==t.chord)),-1==this.chord&&(this.chord=0)}else if(4==this.type){if(null!=t.drums)for(let i=0;it.name==s.filterEnvelope)),-1==this.drumsetEnvelopes[i]&&(this.drumsetEnvelopes[i]=e.envelopes.dictionary["twang 2"].index)),null!=s.spectrum))for(let t=0;te.name==t.interval)),-1==this.interval&&(this.interval=0)),null!=t.vibrato&&(this.vibrato=e.vibratos.findIndex((e=>e.name==t.vibrato)),-1==this.vibrato&&(this.vibrato=e.vibratos.length),this.vibrato==e.vibratos.length?(this.vibratoDepth=t.vibratoDepth,this.vibratoSpeed=t.vibratoSpeed,this.vibratoDelay=t.vibratoDelay,this.vibratoType=t.vibratoType):(this.vibratoDepth=e.vibratos[this.vibrato].amplitude,this.vibratoDelay=e.vibratos[this.vibrato].delayParts,this.vibratoSpeed=10,this.vibratoType=e.vibratos[this.vibrato].type)),this.chord=e.chords.findIndex((e=>e.name==t.chord)),-1==this.chord&&(this.chord=0)}else if(6==this.type)null!=t.pulseWidth?this.pulseWidth=_(0,e.pulseWidthRange+1,t.pulseWidth):this.pulseWidth=e.pulseWidthRange,null!=t.pulseEnvelope&&(this.pulseEnvelope=e.envelopes.findIndex((e=>e.name==t.pulseEnvelope)),-1==this.pulseEnvelope&&(this.pulseEnvelope=e.envelopes.dictionary.steady.index)),null!=t.vibrato&&(this.vibrato=e.vibratos.findIndex((e=>e.name==t.vibrato)),-1==this.vibrato&&(this.vibrato=e.vibratos.length),this.vibrato==e.vibratos.length?(this.vibratoDepth=t.vibratoDepth,this.vibratoSpeed=t.vibratoSpeed,this.vibratoDelay=t.vibratoDelay,this.vibratoType=t.vibratoType):(this.vibratoDepth=e.vibratos[this.vibrato].amplitude,this.vibratoDelay=e.vibratos[this.vibrato].delayParts,this.vibratoSpeed=10,this.vibratoType=e.vibratos[this.vibrato].type)),this.chord=e.chords.findIndex((e=>e.name==t.chord)),-1==this.chord&&(this.chord=0);else if(0==this.type){const i={triangle:1,square:2,"pulse wide":3,"pulse narrow":4,sawtooth:5,"double saw":6,"double pulse":7,spiky:8,plateau:0};if(this.chipWave=null!=i[t.wave]?i[t.wave]:e.chipWaves.findIndex((e=>e.name==t.wave)),-1==this.chipWave&&(this.chipWave=1),null!=t.interval)this.interval=e.intervals.findIndex((e=>e.name==t.interval)),-1==this.interval&&(this.interval=0);else if(null!=t.chorus){const i={fifths:5,octaves:6};this.interval=null!=i[t.chorus]?i[t.chorus]:e.intervals.findIndex((e=>e.name==t.chorus)),-1==this.interval&&(this.interval=0)}null!=t.vibrato?(this.vibrato=e.vibratos.findIndex((e=>e.name==t.vibrato)),-1==this.vibrato&&(this.vibrato=e.vibratos.length),this.vibrato==e.vibratos.length?(this.vibratoDepth=t.vibratoDepth,this.vibratoSpeed=t.vibratoSpeed,this.vibratoDelay=t.vibratoDelay,this.vibratoType=t.vibratoType):(this.vibratoDepth=e.vibratos[this.vibrato].amplitude,this.vibratoDelay=e.vibratos[this.vibrato].delayParts,this.vibratoSpeed=10,this.vibratoType=e.vibratos[this.vibrato].type)):null!=t.effect&&(this.vibrato=l.indexOf(t.effect),-1==this.vibrato&&(this.vibrato=0)),this.chord=e.chords.findIndex((e=>e.name==t.chord)),-1==this.chord&&(this.chord=2),2==this.chord&&null!=t.arpeggioSpeed?this.arpeggioSpeed=t.arpeggioSpeed:this.arpeggioSpeed=n?9:12,null!=t.fastTwoNoteArp?this.fastTwoNoteArp=t.fastTwoNoteArp:this.fastTwoNoteArp=h,"custom harmony"==t.chorus&&(this.interval=2,this.chord=3)}else if(1==this.type){null!=t.vibrato?(this.vibrato=e.vibratos.findIndex((e=>e.name==t.vibrato)),-1==this.vibrato&&(this.vibrato=e.vibratos.length),this.vibrato==e.vibratos.length?(this.vibratoDepth=t.vibratoDepth,this.vibratoSpeed=t.vibratoSpeed,this.vibratoDelay=t.vibratoDelay,this.vibratoType=t.vibratoType):(this.vibratoDepth=e.vibratos[this.vibrato].amplitude,this.vibratoDelay=e.vibratos[this.vibrato].delayParts,this.vibratoSpeed=10,this.vibratoType=e.vibratos[this.vibrato].type)):null!=t.effect&&(this.vibrato=l.indexOf(t.effect),-1==this.vibrato&&(this.vibrato=0)),this.chord=e.chords.findIndex((e=>e.name==t.chord)),-1==this.chord&&(this.chord=3),2==this.chord&&null!=t.arpeggioSpeed?this.arpeggioSpeed=t.arpeggioSpeed:this.arpeggioSpeed=n?9:12,null!=t.fastTwoNoteArp?this.fastTwoNoteArp=t.fastTwoNoteArp:this.fastTwoNoteArp=h,this.algorithm=e.algorithms.findIndex((e=>e.name==t.algorithm)),-1==this.algorithm&&(this.algorithm=0),this.feedbackType=e.feedbacks.findIndex((e=>e.name==t.feedbackType)),-1==this.feedbackType&&(this.feedbackType=0),null!=t.feedbackAmplitude?this.feedbackAmplitude=_(0,e.operatorAmplitudeMax+1,0|t.feedbackAmplitude):this.feedbackAmplitude=0;const i={"pluck 1":6,"pluck 2":7,"pluck 3":8};this.feedbackEnvelope=null!=i[t.feedbackEnvelope]?i[t.feedbackEnvelope]:e.envelopes.findIndex((e=>e.name==t.feedbackEnvelope)),-1==this.feedbackEnvelope&&(this.feedbackEnvelope=0);for(let s=0;st.name==h.frequency)),-1==n.frequency&&(n.frequency=0),null!=h.amplitude?n.amplitude=_(0,e.operatorAmplitudeMax+1,0|h.amplitude):n.amplitude=0,n.envelope=null!=i[h.envelope]?i[h.envelope]:e.envelopes.findIndex((t=>t.name==h.envelope)),-1==n.envelope&&(n.envelope=0)}}else if(7==this.type){if(null!=t.interval)this.interval=e.intervals.findIndex((e=>e.name==t.interval)),-1==this.interval&&(this.interval=0);else if(null!=t.chorus){const i={fifths:5,octaves:6};this.interval=null!=i[t.chorus]?i[t.chorus]:e.intervals.findIndex((e=>e.name==t.chorus)),-1==this.interval&&(this.interval=0)}if(null!=t.vibrato?(this.vibrato=e.vibratos.findIndex((e=>e.name==t.vibrato)),-1==this.vibrato&&(this.vibrato=e.vibratos.length),this.vibrato==e.vibratos.length?(this.vibratoDepth=t.vibratoDepth,this.vibratoSpeed=t.vibratoSpeed,this.vibratoDelay=t.vibratoDelay,this.vibratoType=t.vibratoType):(this.vibratoDepth=e.vibratos[this.vibrato].amplitude,this.vibratoDelay=e.vibratos[this.vibrato].delayParts,this.vibratoSpeed=10,this.vibratoType=e.vibratos[this.vibrato].type)):null!=t.effect&&(this.vibrato=l.indexOf(t.effect),-1==this.vibrato&&(this.vibrato=0)),this.chord=e.chords.findIndex((e=>e.name==t.chord)),-1==this.chord&&(this.chord=2),2==this.chord&&null!=t.arpeggioSpeed?this.arpeggioSpeed=t.arpeggioSpeed:this.arpeggioSpeed=n?9:12,null!=t.fastTwoNoteArp?this.fastTwoNoteArp=t.fastTwoNoteArp:this.fastTwoNoteArp=h,"custom harmony"==t.chorus&&(this.interval=2,this.chord=3),t.customChipWave){for(let e=0;e<64;e++)this.customChipWave[e]=t.customChipWave[e];let e=0;for(let t=0;t{if(t&&null!=i&&null!=s&&null!=n){n=e.modCount-n-1;let t=this.mstMaxVols.get(this.channels[i].instruments[s].modSettings[n]);return null!=t?t:6}return 6},this.getVolumeCapForSetting=(t,e)=>{if(t){let t=this.mstMaxVols.get(e);return null!=t?t:6}return 6},null!=t?this.fromBase64String(t):this.initToDefault(!0)}modValueToReal(t,i){switch(i){case Y.mstTempo:t+=e.tempoMin;break;case Y.mstInsVolume:t-=e.volumeRange/2;break;case Y.mstDetune:t+=e.detuneMin;break;case Y.mstSongDetune:t+=e.songDetuneMin;break;case Y.mstFilterCut:case Y.mstFilterPeak:case Y.mstSongVolume:case Y.mstPan:case Y.mstReverb:case Y.mstNextBar:case Y.mstFMSlider1:case Y.mstFMSlider2:case Y.mstFMSlider3:case Y.mstFMSlider4:case Y.mstFMFeedback:case Y.mstPulseWidth:case Y.mstVibratoDepth:case Y.mstVibratoSpeed:case Y.mstVibratoDelay:case Y.mstArpeggioSpeed:case Y.mstPanDelay:case Y.mstResetArpeggio:case Y.mstNone:}return t}isSettingForSong(t){switch(t){case Y.mstTempo:case Y.mstReverb:case Y.mstSongVolume:case Y.mstNextBar:return!0;default:return!1}}realToModValue(t,i){switch(i){case Y.mstTempo:t-=e.tempoMin;break;case Y.mstInsVolume:t+=e.volumeRange/2;break;case Y.mstDetune:t-=e.detuneMin;break;case Y.mstSongDetune:t-=e.songDetuneMin;break;case Y.mstFilterCut:case Y.mstFilterPeak:case Y.mstSongVolume:case Y.mstPan:case Y.mstReverb:case Y.mstNextBar:case Y.mstFMSlider1:case Y.mstFMSlider2:case Y.mstFMSlider3:case Y.mstFMSlider4:case Y.mstFMFeedback:case Y.mstPulseWidth:case Y.mstVibratoDepth:case Y.mstVibratoSpeed:case Y.mstVibratoDelay:case Y.mstArpeggioSpeed:case Y.mstPanDelay:case Y.mstResetArpeggio:case Y.mstNone:}return t}getChannelCount(){return this.pitchChannelCount+this.noiseChannelCount+this.modChannelCount}getChannelIsNoise(t){return t>=this.pitchChannelCount&&t=this.pitchChannelCount+this.noiseChannelCount}initToDefault(t=!0){if(this.scale=0,this.key=0,this.loopStart=0,this.loopLength=4,this.tempo=150,this.reverb=0,this.beatsPerBar=8,this.barCount=16,this.patternsPerChannel=8,this.rhythm=1,this.instrumentsPerChannel=1,this.title="Unnamed",document.title=c.versionDisplayName,t){this.pitchChannelCount=3,this.noiseChannelCount=1,this.modChannelCount=0;for(let t=0;t=this.pitchChannelCount&&t=this.pitchChannelCount+this.noiseChannelCount;for(let t=0;t>6],L[63&s.length]);for(let t=0;t>6],L[63&this.loopStart]),i.push(101,L[this.loopLength-1>>6],L[this.loopLength-1&63]),i.push(116,L[this.tempo>>6],L[63&this.tempo]),i.push(109,L[this.reverb]),i.push(97,L[this.beatsPerBar-1]),i.push(103,L[this.barCount-1>>6],L[this.barCount-1&63]),i.push(106,L[this.patternsPerChannel-1>>6],L[this.patternsPerChannel-1&63]),i.push(105,L[this.instrumentsPerChannel-1]),i.push(114,L[this.rhythm]),i.push(79),1!=this.compressionRatio||1!=this.limitRatio||4e3!=this.limitRise||4!=this.limitDecay||1!=this.limitThreshold||1!=this.compressionThreshold||1!=this.masterGain?(i.push(L[Math.round(this.compressionRatio<1?10*this.compressionRatio:10+60*(this.compressionRatio-1))]),i.push(L[Math.round(this.limitRatio<1?10*this.limitRatio:9+this.limitRatio)]),i.push(L[this.limitDecay]),i.push(L[Math.round((this.limitRise-2e3)/250)]),i.push(L[Math.round(20*this.compressionThreshold)]),i.push(L[Math.round(20*this.limitThreshold)]),i.push(L[Math.round(50*this.masterGain)>>6],L[63&Math.round(50*this.masterGain)])):i.push(L[63]),i.push(85);for(let t=0;t>6],L[n.volume+e.volumeRange/2&63]),i.push(76,L[n.pan>>6],L[63&n.pan]),i.push(L[n.panDelay]),i.push(68,L[n.detune-e.detuneMin>>6],L[n.detune-e.detuneMin&63]),i.push(117,L[n.preset>>6],L[63&n.preset]),i.push(113,L[n.effects]),4!=n.type&&(i.push(100,L[n.transition]),i.push(102,L[n.filterCutoff]),i.push(121,L[n.filterResonance]),i.push(122,L[n.filterEnvelope]),i.push(67,L[n.chord])),0==n.type)i.push(119,L[n.chipWave]),i.push(99,L[n.vibrato]),n.vibrato==e.vibratos.length&&(i.push(L[Math.round(25*n.vibratoDepth)]),i.push(L[n.vibratoSpeed]),i.push(L[n.vibratoDelay]),i.push(L[n.vibratoType])),2==n.chord&&(i.push(71,L[n.arpeggioSpeed]),i.push(L[+n.fastTwoNoteArp])),i.push(104,L[n.interval]);else if(1==n.type){i.push(99,L[n.vibrato]),n.vibrato==e.vibratos.length&&(i.push(L[Math.round(25*n.vibratoDepth)]),i.push(L[n.vibratoSpeed]),i.push(L[n.vibratoDelay]),i.push(L[n.vibratoType])),2==n.chord&&(i.push(71,L[n.arpeggioSpeed]),i.push(L[+n.fastTwoNoteArp])),i.push(104,L[n.interval]),i.push(65,L[n.algorithm]),i.push(70,L[n.feedbackType]),i.push(66,L[n.feedbackAmplitude]),i.push(86,L[n.feedbackEnvelope]),i.push(81);for(let t=0;t0){t.write(1,1);let i=0;for(const h of s.notes){h.starti&&(t.write(2,0),n&&t.write(1,0),t.writePartDuration(h.start-i)),o.clear();for(let t=1;t10&&c.pop();const p=h.pitches.concat(u);for(let e=0;e8&&l.pop(),a=e==h.pitches.length-1?h.pitches[0]:i}i=h.end}i0;)l.unshift(L[63&a]),a>>=6;i.push(L[l.length]),Array.prototype.push.apply(i,l),t.encodeBase64(i);const c=64e3;if(i.lengthQ.$||nQ.H||n=this.pitchChannelCount&&t=this.pitchChannelCount+this.noiseChannelCount;for(let s=this.channels[t].instruments.length;s=2&&(v=!0));break;case 111:if(o&&"beepbox"==s)m=A[t.charCodeAt(i++)],this.channels[m].octave=_(0,e.maxScrollableOctaves+1,A[t.charCodeAt(i++)]),g[m]=_(0,e.maxScrollableOctaves-+(window.localStorage.getItem("extraOctaves")||"0")+1,this.channels[m].octave);else for(m=0;m=this.instrumentsPerChannel&&(p++,y=0),O(0,this.channels.length-1,p);const e=this.channels[p].instruments[y],s=_(0,9,A[t.charCodeAt(i++)]);e.setTypeAndReset(s,p>=this.pitchChannelCount&&p=this.pitchChannelCount+this.noiseChannelCount),b&&(e.arpeggioSpeed=9),v&&(e.fastTwoNoteArp=!0)}break;case 117:{const e=A[t.charCodeAt(i++)]<<6|A[t.charCodeAt(i++)];this.channels[p].instruments[y].preset=e}break;case 119:if(o&&"beepbox"==s){const s=[1,2,3,4,5,6,7,8,0],n=A[t.charCodeAt(i++)];this.channels[n].instruments[0].chipWave=_(0,e.chipWaves.length,0|s[A[t.charCodeAt(i++)]])}else if(l&&"beepbox"==s){const s=[1,2,3,4,5,6,7,8,0];for(let n=0;n=this.pitchChannelCount?this.channels[n].instruments[h].chipNoise=_(0,e.chipNoises.length,A[t.charCodeAt(i++)]):this.channels[n].instruments[h].chipWave=_(0,e.chipWaves.length,0|s[A[t.charCodeAt(i++)]])}else if(d&&"beepbox"==s){const s=[1,2,3,4,5,6,7,8,0];p>=this.pitchChannelCount?this.channels[p].instruments[y].chipNoise=_(0,e.chipNoises.length,A[t.charCodeAt(i++)]):this.channels[p].instruments[y].chipWave=_(0,e.chipWaves.length,0|s[A[t.charCodeAt(i++)]])}else p>=this.pitchChannelCount?this.channels[p].instruments[y].chipNoise=_(0,e.chipNoises.length,A[t.charCodeAt(i++)]):this.channels[p].instruments[y].chipWave=_(0,e.chipWaves.length,A[t.charCodeAt(i++)]);break;case 102:if(d&&"beepbox"==s){const e=[10,6,3,0,8,5,2],n=[1,1,1,1,18,19,20],h=["none","bright","medium","soft","decay bright","decay medium","decay soft"];if(o&&"beepbox"==s){m=A[t.charCodeAt(i++)];const s=this.channels[m].instruments[0],o=[1,3,4,5][_(0,h.length,A[t.charCodeAt(i++)])];s.filterCutoff=e[o],s.filterEnvelope=n[o],s.filterResonance=0}else if(l&&"beepbox"==s)for(m=0;m0;)h<<=6,h+=A[t.charCodeAt(i++)],e--}const r=new H(t,i,i+h);i+=h;let a=0;for(;1<10&&m.pop(),l=new U(0,p,p+n.length,n.initialVolume),l.pitches=[],l.pins.length=1;const g=[];for(let t=0;t0;){for(a++;-1!=f.indexOf(a);)a++;e--}for(;e<0;){for(a--;-1!=f.indexOf(a);)a--;e++}}f.unshift(a),f.length>8&&f.pop(),t=this.getChannelCount())break}}break;default:throw new Error("Unrecognized song tag code "+String.fromCharCode(f)+" at index "+(i-1))}for(let t=0;tt.name==s));-1!=n&&(this.scale=n)}if(null!=t.key)if("number"==typeof t.key)this.key=(t.key+1200>>>0)%e.keys.length;else if("string"==typeof t.key){const e=t.key,i=e.charAt(0).toUpperCase(),s=e.charAt(1).toLowerCase();let n={C:0,D:2,E:4,F:5,G:7,A:9,B:11}[i];const h={"#":1,"♯":1,b:-1,"♭":-1}[s];null!=n&&(null!=h&&(n+=h),n<0&&(n+=12),n%=12,this.key=n)}null!=t.beatsPerMinute&&(this.tempo=_(e.tempoMin,e.tempoMax+1,0|t.beatsPerMinute)),null!=t.reverb&&(this.reverb=_(0,e.reverbRange,0|t.reverb)),null!=t.beatsPerBar&&(this.beatsPerBar=Math.max(e.beatsPerBarMin,Math.min(e.beatsPerBarMax,0|t.beatsPerBar)));let i=4;null!=t.ticksPerBeat&&(i=0|t.ticksPerBeat||4,this.rhythm=e.rhythms.findIndex((t=>t.stepsPerBeat==i)),-1==this.rhythm&&(this.rhythm=1));let s=1,n=1,h=1;if(t.channels)for(const e of t.channels)e.instruments&&(s=Math.max(s,0|e.instruments.length)),e.patterns&&(n=Math.max(n,0|e.patterns.length)),e.sequence&&(h=Math.max(h,0|e.sequence.length));this.instrumentsPerChannel=Math.min(s,e.instrumentsPerChannelMax),this.patternsPerChannel=Math.min(n,e.barCountMax),this.barCount=Math.min(h,e.barCountMax),null!=t.introBars&&(this.loopStart=_(0,this.barCount,0|t.introBars)),null!=t.loopBars&&(this.loopLength=_(1,this.barCount-this.loopStart+1,0|t.loopBars));const o=[],r=[],a=[];if(t.channels)for(let s=0;s=3,l?r.push(h):c?a.push(h):o.push(h),null!=n.octaveScrollBar&&(h.octave=_(0,e.maxScrollableOctaves-+(window.localStorage.getItem("extraOctaves")||"0")+1,0|n.octaveScrollBar));for(let t=h.instruments.length;t=2)}for(let t=0;t0)){const t=Math.min(this.beatsPerBar*e.partsPerBeat,o.notes.length>>>0);for(let n=0;n=t);n++){const t=o.notes[n];if(!(t&&t.pitches&&t.pitches.length>=1&&t.points&&t.points.length>=2))continue;const r=new U(0,0,0,0);r.pitches=[],r.pins=[];for(let i=0;i=e.maxChordSize))break}if(r.pitches.length<1)continue;let a=0;for(let n=0;n0?Math.round(0|o.volume):Math.max(0,Math.min(f,Math.round((0|o.volume)*f/100))),d>this.beatsPerBar*e.partsPerBeat||(0==r.pins.length&&(r.start=d,a=l),r.pins.push(I(l-a,d-r.start,u)))}if(r.pins.length<2)continue;r.end=r.pins[r.pins.length-1].time+r.start;const d=l?e.drumCount-1:e.maxPitch;let u=d,f=0;for(let t=0;td)&&(r.pitches.splice(t,1),t--),r.pitches[t]f&&(f=r.pitches[t]);if(!(r.pitches.length<1)){for(let t=0;td&&(e.interval=d-f),t>=2&&e.interval==r.pins[t-1].interval&&e.interval==r.pins[t-2].interval&&e.volume==r.pins[t-1].volume&&e.volume==r.pins[t-2].volume&&(r.pins.splice(t-1,1),t--)}s.notes.push(r)}}}}for(let t=0;t>>0):0}o.length>e.pitchChannelCountMax&&(o.length=e.pitchChannelCountMax),r.length>e.noiseChannelCountMax&&(r.length=e.noiseChannelCountMax),a.length>e.modChannelCountMax&&(a.length=e.modChannelCountMax),this.pitchChannelCount=o.length,this.noiseChannelCount=r.length,this.modChannelCount=a.length,this.channels.length=0,Array.prototype.push.apply(this.channels,o),Array.prototype.push.apply(this.channels,r),Array.prototype.push.apply(this.channels,a)}getPattern(t,e){if(e<0||e>=this.barCount)return null;const i=this.channels[t].bars[e];return 0==i?null:this.channels[t].patterns[i-1]}getPatternInstrument(t,e){const i=this.getPattern(t,e);return null==i?0:i.instrument}getBeatsPerMinute(){return this.tempo}}Q.O="BeepBox",Q.I=2,Q.$=8,Q._=1,Q.H=3,Q.L=106;class X{constructor(){this.pitches=[0,0,0,0],this.pitchCount=0,this.chordSize=0,this.drumsetPitch=0,this.note=null,this.prevNote=null,this.nextNote=null,this.prevNotePitchIndex=0,this.nextNotePitchIndex=0,this.active=!1,this.noteStart=0,this.noteEnd=0,this.noteLengthTicks=0,this.ticksSinceReleased=0,this.liveInputSamplesHeld=0,this.lastInterval=0,this.lastVolume=0,this.stereoVolume1=0,this.stereoVolume2=0,this.stereoOffset=0,this.stereoDelay=0,this.sample=0,this.phases=[],this.phaseDeltas=[],this.volumeStarts=[],this.volumeDeltas=[],this.volumeStart=0,this.volumeDelta=0,this.phaseDeltaScale=0,this.pulseWidth=0,this.pulseWidthDelta=0,this.filter=0,this.filterScale=0,this.filterSample0=0,this.filterSample1=0,this.vibratoScale=0,this.intervalMult=0,this.intervalVolumeMult=1,this.feedbackOutputs=[],this.feedbackMult=0,this.feedbackDelta=0,this.stereoVolumeLStart=0,this.stereoVolumeRStart=0,this.stereoVolumeLDelta=0,this.stereoVolumeRDelta=0,this.stereoDelayStart=0,this.stereoDelayEnd=0,this.stereoDelayDelta=0,this.customVolumeStart=0,this.customVolumeEnd=0,this.filterResonanceStart=0,this.filterResonanceDelta=0,this.isFirstOrder=!1,this.reset()}reset(){for(let t=0;t{const e=t.outputBuffer,i=e.getChannelData(0),s=e.getChannelData(1);if(performance.now()0){let t=[],i=[];this.modValues=[],this.nextModValues=[],this.modInsValues=[],this.nextModInsValues=[];for(let t=0;t=0;o--)if(h=this.song.getPattern(n,o),null!=h){let r=this.song.getPatternInstrument(n,o),a=this.song.channels[n].instruments[r],l=[],c=[],d=o==this.bar?s:this.findPartsInBar(o);for(const t of h.notes)if(t.startl[e.modCount-1-t.pitches[0]]))if(t.end<=d)l[e.modCount-1-t.pitches[0]]=t.end,c[e.modCount-1-t.pitches[0]]=t.pins[t.pins.length-1].volume;else{l[e.modCount-1-t.pitches[0]]=d;for(let i=0;id){const s=t.pins[i].time-t.pins[i-1].time,n=d-t.start-t.pins[i-1].time,h=t.pins[i].volume-t.pins[i-1].volume;c[e.modCount-1-t.pitches[0]]=Math.round(t.pins[i-1].volume+h*n/s),i=t.pins.length}}for(let s=0;st[a.modSettings[s]])&&(this.setModValue(c[s],c[s],s,a,a.modSettings[s]),t[a.modSettings[s]]=o*e.partsPerBeat*this.song.beatsPerBar+l[s]):(null==i[a.modChannels[s]][a.modInstruments[s]][a.modSettings[s]]||o*e.partsPerBeat*this.song.beatsPerBar+l[s]>i[a.modChannels[s]][a.modInstruments[s]][a.modSettings[s]])&&(this.setModValue(c[s],c[s],s,a,a.modSettings[s]),i[a.modChannels[s]][a.modInstruments[s]][a.modSettings[s]]=o*e.partsPerBeat*this.song.beatsPerBar+l[s]))}}}}static operatorAmplitudeCurve(t){return(Math.pow(16,t/15)-1)/15}get playing(){return this.isPlayingSong}get playhead(){return this.playheadInternal}set playhead(t){if(null!=this.song){this.playheadInternal=Math.max(0,Math.min(this.song.barCount,t));let i=this.playheadInternal;this.bar=Math.floor(i),i=this.song.beatsPerBar*(i-this.bar),this.beat=Math.floor(i),i=e.partsPerBeat*(i-this.beat),this.part=Math.floor(i),i=e.ticksPerPart*(i-this.part),this.tick=Math.floor(i);const s=this.getSamplesPerTick();i=s*(i-this.tick),this.tickSampleCountdown=s-i}}getSamplesPerBar(){if(null==this.song)throw new Error;return this.getSamplesPerTick()*e.ticksPerPart*e.partsPerBeat*this.song.beatsPerBar}findPartsInBar(t){if(null==this.song)return 0;let i=e.partsPerBeat*this.song.beatsPerBar;for(let s=this.song.pitchChannelCount+this.song.noiseChannelCount;st.start&&(i=t.start)}}return i}getTotalSamples(t,i,s){if(null==this.song)return-1;let n=t?0:this.song.loopStart,h=i?this.song.barCount:this.song.loopStart+this.song.loopLength,o=!1,r=!1;for(let t=this.song.pitchChannelCount+this.song.noiseChannelCount;tt.pitches[0]==e.modCount-1-s))){i=!0,h.notes.sort((function(t,e){return t.start==e.start?t.pitches[0]-e.pitches[0]:t.start-e.start}));for(const t of h.notes)if(t.pitches[0]==e.modCount-1-s&&(l+=Math.min(n-c,t.start-c)*e.ticksPerPart*this.getSamplesPerTickSpecificBPM(a),t.startn&&(o=this.song.modValueToReal(t.pins[i-1].volume+(t.pins[i].volume-t.pins[i-1].volume)*(n-(t.start+t.pins[i-1].time))/(t.pins[i].time-t.pins[i-1].time),Y.mstTempo));let r=e.partsPerBeat*e.ticksPerPart/60;l+=o!=h?-this.samplesPerSecond*s*(Math.log(r*o*s)-Math.log(r*h*s))/(r*(h-o)):s*this.getSamplesPerTickSpecificBPM(o),a=o}c=Math.min(t.start+t.pins[i].time,n)}}}}}l+=(n-c)*e.ticksPerPart*this.getSamplesPerTickSpecificBPM(a),t++,0!=s&&t==this.song.loopStart+this.song.loopLength&&(t=this.song.loopStart,s>0&&s--),t>=h&&(i=!0)}return Math.ceil(l)}return this.getSamplesPerBar()*this.getTotalBars(t,i,s)}getTotalBars(t,e,i=this.loopRepeatCount){if(null==this.song)throw new Error;let s=this.song.loopLength*(i+1);return t&&(s+=this.song.loopStart),e&&(s+=this.song.barCount-(this.song.loopStart+this.song.loopLength)),s}setSong(t){"string"==typeof t?this.song=new Q(t):t instanceof Q&&(this.song=t)}setModValue(t,e,i,s,n){let h,o;switch(n){case Y.mstSongVolume:case Y.mstReverb:case Y.mstTempo:case Y.mstSongDetune:h=this.song.modValueToReal(t,n),o=this.song.modValueToReal(e,n),null!=this.modValues[n]&&this.modValues[n]==h&&this.nextModValues[n]==o||(this.modValues[n]=h,this.nextModValues[n]=o);break;case Y.mstInsVolume:case Y.mstPan:case Y.mstPulseWidth:case Y.mstFilterCut:case Y.mstFilterPeak:case Y.mstFMSlider1:case Y.mstFMSlider2:case Y.mstFMSlider3:case Y.mstFMSlider4:case Y.mstFMFeedback:case Y.mstVibratoDepth:case Y.mstVibratoSpeed:case Y.mstVibratoDelay:case Y.mstArpeggioSpeed:case Y.mstPanDelay:case Y.mstResetArpeggio:case Y.mstDetune:h=this.song.modValueToReal(t,n),o=this.song.modValueToReal(e,n);let r=s.modChannels[i]+(s.modStatuses[i]==K.msForNoise?this.song.pitchChannelCount:0);null!=this.modInsValues[r][s.modInstruments[i]][n]&&this.modInsValues[r][s.modInstruments[i]][n]==h&&this.nextModInsValues[r][s.modInstruments[i]][n]==o||(this.modInsValues[r][s.modInstruments[i]][n]=h,this.nextModInsValues[r][s.modInstruments[i]][n]=o);break;case Y.mstNextBar:h=this.song.modValueToReal(t,n);break;case Y.mstNone:default:h=-1}return h}getModValue(t,e,i,s,n){if(e){if(null!=this.modValues[t]&&null!=this.nextModValues[t])return n?this.nextModValues[t]:this.modValues[t]}else if(null!=i&&null!=s&&null!=this.modInsValues[i][s][t]&&null!=this.nextModInsValues[i][s][t])return n?this.nextModInsValues[i][s][t]:this.modInsValues[i][s][t];return-1}isAnyModActive(t,e){for(let i=0;i=this.song.loopStart+this.song.loopLength)){const t=this.bar;this.bar=this.song.loopStart,this.playheadInternal+=this.bar-t,this.playing&&this.computeLatestModValues()}}nextBar(){if(!this.song)return;const t=this.bar;this.bar++,this.bar>=this.song.barCount&&(this.bar=0),this.playheadInternal+=this.bar-t,this.playing&&this.computeLatestModValues()}skipBar(){if(!this.song)return;const t=this.getSamplesPerTick();this.bar++,this.beat=0,this.part=0,this.tick=0,this.tickSampleCountdown=t,0!=this.loopRepeatCount&&this.bar==this.song.loopStart+this.song.loopLength&&(this.bar=this.song.loopStart,this.loopRepeatCount>0&&this.loopRepeatCount--)}firstBar(){this.song&&(this.bar=0,this.playheadInternal=0,this.beat=0,this.part=0,this.playing&&this.computeLatestModValues())}jumpToEditingBar(t){this.song&&(this.bar=t,this.playheadInternal=t,this.beat=0,this.part=0,this.playing&&this.computeLatestModValues())}prevBar(){if(!this.song)return;const t=this.bar;this.bar--,(this.bar<0||this.bar>=this.song.barCount)&&(this.bar=this.song.barCount-1),this.playheadInternal+=this.bar-t,this.playing&&this.computeLatestModValues()}synthesize(t,i,s,n=!0){if(null==this.song){for(let e=0;eo&&(this.tickSampleCountdown=o),n&&(this.beat>=this.song.beatsPerBar&&(this.bar++,this.beat=0,this.part=0,this.tick=0,this.tickSampleCountdown=o,0!=this.loopRepeatCount&&this.bar==this.song.loopStart+this.song.loopLength&&(this.bar=this.song.loopStart,this.loopRepeatCount>0&&this.loopRepeatCount--)),this.bar>=this.song.barCount&&(this.bar=0,-1!=this.loopRepeatCount&&(a=!0,this.pause())));const l=4*s;null!=this.samplesForNone&&this.samplesForNone.length==l&&null!=this.samplesForReverb&&this.samplesForReverb.length==l&&null!=this.samplesForChorus&&this.samplesForChorus.length==l&&null!=this.samplesForChorusReverb&&this.samplesForChorusReverb.length==l||(this.samplesForNone=new Float32Array(l),this.samplesForReverb=new Float32Array(l),this.samplesForChorus=new Float32Array(l),this.samplesForChorusReverb=new Float32Array(l),this.stereoBufferIndex=0);let c=this.stereoBufferIndex;const d=this.samplesForNone,u=this.samplesForReverb,f=this.samplesForChorus,m=this.samplesForChorusReverb,p=+this.volume,y=this.chorusDelayLine,g=this.reverbDelayLine,b=2*Math.PI/(2*this.samplesPerSecond),v=150*this.samplesPerSecond/44100,w=2048-1.51*v,k=2048-2.1*v,x=2048-3.35*v,M=2048-1.47*v,E=2048-2.15*v,C=2048-3.25*v;let S=this.chorusPhase%(2*Math.PI),q=2047&this.chorusDelayPos,P=16383&this.reverbDelayPos,T=+this.reverbFeedback0,B=+this.reverbFeedback1,z=+this.reverbFeedback2,R=+this.reverbFeedback3,N=this.song.reverb;this.isModActive(Y.mstReverb,!0)&&(N=this.getModValue(Y.mstReverb,!0));let L=.425*Math.pow(N/e.reverbRange,.667);const A=1-Math.pow(.5,this.song.limitDecay/this.samplesPerSecond),H=1-Math.pow(.5,this.song.limitRise/this.samplesPerSecond),D=this.song.compressionThreshold,$=this.song.limitThreshold,I=this.song.compressionRatio,_=this.song.limitRatio,O=this.song.masterGain;let U=+this.limit;for(;r=s.instrument.getTransition().releaseTicks){this.freeReleasedTone(t,i),i--;continue}const n=i+this.activeTones[t].count()>=e.maximumTonesPerChannel;this.playTone(this.song,c,l,t,o,F,s,!0,n)}}let X=q+w-v*Math.sin(S+0),tt=q+k-v*Math.sin(S+2.1),et=q+x-v*Math.sin(S+4.2),it=q+1024+M-v*Math.sin(S+3.2),st=q+1024+E-v*Math.sin(S+5.3),nt=q+1024+C-v*Math.sin(S+1);S+=b*F;const ht=(q+F+w-v*Math.sin(S+0)-X)/F,ot=(q+F+k-v*Math.sin(S+2.1)-tt)/F,rt=(q+F+x-v*Math.sin(S+4.2)-et)/F,at=(q+F+1024+M-v*Math.sin(S+3.2)-it)/F,lt=(q+F+1024+E-v*Math.sin(S+5.3)-st)/F,ct=(q+F+1024+C-v*Math.sin(S+1)-nt)/F,dt=r+F;for(let e=r;eTt?Pt:Tt;this.song.inVolumeCap=this.song.inVolumeCap>Bt?this.song.inVolumeCap:Bt;const zt=+(Bt>D)+ +(Bt>$),Rt=+(0==zt)*((.8*(Bt+1-D)+.25)*I+1.05*(1-I))+1.05*+(1==zt)+1.05*((Bt+1-$)*_+(1-$))*+(2==zt);U+=(Rt-U)*(U=1?1.05*U:.8*U+.25);t[e]=St*Nt,i[e]=qt*Nt,this.song.outVolumeCap=this.song.outVolumeCap>Bt*Nt?this.song.outVolumeCap:Bt*Nt}if(r+=F,this.tickSampleCountdown-=F,this.tickSampleCountdown<=0){for(let t=0;t=e.maximumTonesPerChannel&&(this.freeReleasedTone(t,i),i--)}for(let t=0;t0&&this.loopRepeatCount--),this.bar>=this.song.barCount&&(this.bar=0,-1!=this.loopRepeatCount&&(a=!0,this.resetEffects(),this.pause())))))}}for(let t=0;t0){const t=this.tonePool.popBack();return t.reset(),t.active=!1,t}return new X}releaseTone(t,e){null!=this.song&&this.song.getChannelIsMod(t)||this.releasedTones[t].pushFront(e)}freeReleasedTone(t,e){null!=this.song&&this.song.getChannelIsMod(t)||(this.freeTone(this.releasedTones[t].get(e)),this.releasedTones[t].remove(e))}freeAllTones(){for(;this.liveInputTones.count()>0;)this.freeTone(this.liveInputTones.popBack());for(let t=0;t0;)this.freeTone(this.activeTones[t].popBack());for(let t=0;t0;)this.freeTone(this.releasedTones[t].popBack());for(let t=0;t0;)this.freeTone(this.activeModTones[t][e].popBack())}determineLiveInputTones(t){const e=this.liveInputTones,i=this.liveInputPitches;let s=0;if(this.liveInputDuration>0){const n=t.channels[this.liveInputChannel].instruments[t.getPatternInstrument(this.liveInputChannel,this.bar)];if(n.getChord().arpeggiates){let t;0==e.count()?(t=this.newTone(),e.pushBack(t)):!n.getTransition().isSeamless&&this.liveInputStarted?(this.releaseTone(this.liveInputChannel,e.popFront()),t=this.newTone(),e.pushBack(t)):t=e.get(0),s=1;for(let e=0;es;)this.releaseTone(this.liveInputChannel,e.popBack());this.liveInputStarted=!1}determineCurrentActiveTones(t,i,s){const n=t.channels[i].instruments[t.getPatternInstrument(i,this.bar)],h=t.getPattern(i,this.bar),o=this.part+this.beat*e.partsPerBeat;if(s&&t.getChannelIsMod(i)&&!t.channels[i].muted){let s=i-(t.pitchChannelCount+t.noiseChannelCount),r=[],a=[],l=[],c=e.modCount;for(;c--;)r.push(null),a.push(null),l.push(null);if(null!=h)for(let t=0;ta[h.notes[t].pitches[0]].start)&&(a[h.notes[t].pitches[0]]=h.notes[t]):h.notes[t].start<=o&&h.notes[t].end>o?r[h.notes[t].pitches[0]]=h.notes[t]:h.notes[t].start>o&&(null==l[h.notes[t].pitches[0]]||h.notes[t].start0;)e.peakBack().instrument.getTransition().releases?this.releaseTone(i,e.popBack()):this.freeTone(e.popBack())}}else if(!t.getChannelIsMod(i)){let e=null,r=null,a=null;if(s&&null!=h&&!t.channels[i].muted)for(let t=0;to)e=h.notes[t];else if(h.notes[t].start>o){a=h.notes[t];break}const l=this.activeTones[i];if(null!=e)null!=r&&r.end!=e.start&&(r=null),null!=a&&a.start!=e.end&&(a=null),this.syncTones(i,l,n,e.pitches,e,r,a,o);else for(;l.count()>0;)l.peakBack().instrument.getTransition().releases?this.releaseTone(i,l.popBack()):this.freeTone(l.popBack())}}syncTones(t,i,s,n,h,o,r,a){let l=0;if(s.getChord().arpeggiates){let t;0==i.count()?(t=this.newTone(),i.pushBack(t)):t=i.get(0),l=1;for(let e=0;ec?o:null,u=h,f=r&&r.pitches.length>c?r:null,m=u.start+n;if(m>a){if(!(i.count()>c&&t.isSeamless&&null!=d))break;f=u,u=d,d=null,m=u.start+n}let p,y=u.end;t.isSeamless&&null!=f&&(y=Math.min(e.partsPerBeat*this.song.beatsPerBar,y+n)),i.count()<=c?(p=this.newTone(),i.pushBack(p)):p=i.get(c),l++,p.pitches[0]=u.pitches[c],p.pitchCount=1,p.chordSize=u.pitches.length,p.instrument=s,p.note=u,p.noteStart=m,p.noteEnd=y,p.prevNote=d,p.nextNote=f,p.prevNotePitchIndex=c,p.nextNotePitchIndex=c}}for(;i.count()>l;)i.peakBack().instrument.getTransition().releases?this.releaseTone(t,i.popBack()):this.freeTone(i.popBack())}playTone(t,e,i,s,n,h,o,r,a){let l;switch(tt.computeTone(this,t,s,n,h,o,r,a),o.instrument.effects){case 0:l=this.samplesForNone;break;case 1:l=this.samplesForReverb;break;case 2:l=this.samplesForChorus;break;case 3:l=this.samplesForChorusReverb;break;default:throw new Error}tt.getInstrumentSynthFunction(o.instrument)(this,l,e,i,2*h,o,o.instrument)}static computeEnvelope(t,e,i,s){switch(t.type){case 0:return s;case 1:return 1;case 4:return 1/(1+e*t.speed);case 5:return 1-1/(1+e*t.speed);case 6:return.5-.5*Math.cos(2*i*Math.PI*t.speed);case 7:return.75-.25*Math.cos(2*i*Math.PI*t.speed);case 2:return Math.max(1,2-10*e);case 3:const n=t.speed,h=.25/Math.sqrt(n);return et==c));r.phaseDeltaScale=0,r.filter=1,r.filterScale=1,r.vibratoScale=0,r.intervalMult=1,r.intervalVolumeMult=1,r.active=!1;let P=c.pan,T=c.pan;t.isModActive(Y.mstPan,!1,s,q)&&(P=t.getModValue(Y.mstPan,!1,s,q,!1),T=t.getModValue(Y.mstPan,!1,s,q,!0));let B=c.panDelay,z=c.panDelay;t.isModActive(Y.mstPanDelay,!1,s,q)&&(B=t.getModValue(Y.mstPanDelay,!1,s,q,!1),z=t.getModValue(Y.mstPanDelay,!1,s,q,!0));const R=(P-e.panCenter)/e.panCenter,N=(T-e.panCenter)/e.panCenter,F=13e-5*B*t.samplesPerSecond,L=13e-5*z*t.samplesPerSecond;r.stereoDelayStart=-R*F;const A=-N*L;r.stereoDelayDelta=(A-r.stereoDelayStart)/h,r.stereoVolumeLStart=1.414*Math.cos((1+R)*Math.PI*.25),r.stereoVolumeRStart=1.414*Math.cos((1-R)*Math.PI*.25);const H=1.414*Math.cos((1+N)*Math.PI*.25),D=1.414*Math.cos((1-N)*Math.PI*.25);r.stereoVolumeLDelta=(H-r.stereoVolumeLStart)/h,r.stereoVolumeRDelta=(D-r.stereoVolumeRStart)/h;let $,I,_,O,U=!0,V=0,j=0,W=0,G=1,K=1,Z=f,Q=f,X=0,et=0,it=0,st=0;if(3==c.type)m?(I=e.spectrumBasePitch,_=.6):(I=e.keys[i.key].basePitch,_=.3),$=e.spectrumBasePitch,O=28;else if(4==c.type)I=e.spectrumBasePitch,_=.45,$=I,O=48;else if(2==c.type)I=e.chipNoises[c.chipNoise].basePitch,_=.19,$=I,O=e.chipNoises[c.chipNoise].isSoft?24:60;else if(1==c.type)I=e.keys[i.key].basePitch,_=.03,$=16,O=48;else if(0==c.type||7==c.type)I=e.keys[i.key].basePitch,_=.03375,$=16,O=48;else if(5==c.type)I=e.keys[i.key].basePitch,_=.025,$=16,O=48;else if(6==c.type)I=e.keys[i.key].basePitch,_=.04725,$=16,O=48;else{if(8!=c.type)throw new Error("Unknown instrument type in computeTone.");_=1,$=0,O=1,I=0}for(let t=0;to);p++);const y=s.pins[p-1],g=s.pins[p],v=l*e.ticksPerPart,x=m*e.ticksPerPart-v,C=(s.start+y.time)*e.ticksPerPart,S=(s.start+g.time)*e.ticksPerPart;r.lastInterval=s.pins[s.pins.length-1].interval,r.lastVolume=s.pins[s.pins.length-1].volume,r.ticksSinceReleased=0,r.noteLengthTicks=x;const q=o*e.ticksPerPart+t.tick,P=o*e.ticksPerPart+t.tick+1,T=q-v,B=P-v,z=Math.min(1,(q-C)/(S-C)),R=Math.min(1,(P-C)/(S-C));let N=y.volume+(g.volume-y.volume)*z,F=y.volume+(g.volume-y.volume)*R,L=1,A=1,H=f,D=f,$=y.interval+(g.interval-y.interval)*z,I=y.interval+(g.interval-y.interval)*R,_=M-l,O=E-l;U=q+w-v==0||!b;const J=.5*x;if(d.isSeamless&&!d.slides&&0==s.start)U=!b;else if(d.isSeamless&&null!=n&&(U=!b,d.slides)){const t=Math.min(J,d.slideTicks),e=Math.max(0,1-T/t),i=Math.max(0,1-B/t),h=.5*(n.pitches[r.prevNotePitchIndex]+n.pins[n.pins.length-1].interval-r.pitches[0]),o=.5*(n.pins[n.pins.length-1].volume-s.pins[0].volume),a=.5*(n.end-n.start);if($+=e*h,I+=i*h,N+=e*o,F+=i*o,_+=e*a,O+=i*a,!u.arpeggiates){const t=.5*(n.pitches.length-r.chordSize);H=tt.computeChordVolume(r.chordSize+e*t),D=tt.computeChordVolume(r.chordSize+i*t)}}if(d.isSeamless&&!d.slides&&s.end==a);else if(d.isSeamless&&null!=h){if(d.slides){const t=Math.min(J,d.slideTicks),e=Math.max(0,1-(x-T)/t),i=Math.max(0,1-(x-B)/t),n=.5*(h.pitches[r.nextNotePitchIndex]-(r.pitches[0]+s.pins[s.pins.length-1].interval)),o=.5*(h.pins[0].volume-s.pins[s.pins.length-1].volume),a=.5*-(m-l);if($+=e*n,I+=i*n,N+=e*o,F+=i*o,_+=e*a,O+=i*a,!u.arpeggiates){const t=.5*(h.pitches.length-r.chordSize);H=tt.computeChordVolume(r.chordSize+e*t),D=tt.computeChordVolume(r.chordSize+i*t)}}}else if(!d.releases){const t=d.releaseTicks;t>0&&(L*=Math.min(1,(x-T)/t),A*=Math.min(1,(x-B)/t))}j=$+(I-$)*w,W=$+(I-$)*k,8!=c.type?(X=tt.expressionToVolumeMult(N+(F-N)*w),et=tt.expressionToVolumeMult(N+(F-N)*k)):(X=N+(F-N)*Math.max(0,w),et=N+(F-N)*Math.min(1,k),r.customVolumeStart=X,r.customVolumeEnd=et),G=L+(A-L)*w,K=L+(A-L)*k,Z=H+(D-H)*w,Q=H+(D-H)*k,it=_+(O-_)*w,st=_+(O-_)*k}const nt=1/t.samplesPerSecond;if(r.active=!0,0==c.type||1==c.type||5==c.type||6==c.type||7==c.type||3==c.type){const i=tt.getLFOAmplitude(c,y*c.LFOtime),n=tt.getLFOAmplitude(c,y*c.nextLFOtime);let h,o,r=c.vibratoDepth,a=c.vibratoDepth;t.isModActive(Y.mstVibratoDepth,!1,s,q)&&(r=t.getModValue(Y.mstVibratoDepth,!1,s,q,!1)/25,a=t.getModValue(Y.mstVibratoDepth,!1,s,q,!0)/25);const l=t.isModActive(Y.mstVibratoDelay,!1,s,q);if(c.vibrato==e.vibratos.length||l){let e=c.vibratoDelay,i=c.vibratoDelay;l&&(e=t.getModValue(Y.mstVibratoDelay,!1,s,q,!1),i=t.getModValue(Y.mstVibratoDelay,!1,s,q,!0),e==t.song.mstMaxVols.get(Y.mstVibratoDelay)&&(e=Number.MAX_VALUE),i==t.song.mstMaxVols.get(Y.mstVibratoDelay)&&(i=Number.MAX_VALUE)),h=e,o=i}else h=e.vibratos[c.vibrato].delayParts,o=e.vibratos[c.vibrato].delayParts;j+=(V0&&(G*=Math.min(1,y*it/t),K*=Math.min(1,y*st/t))}const ht=tt.instrumentVolumeToVolumeMult(c.volume);4==c.type&&(r.drumsetPitch=r.pitches[0],null!=r.note&&(r.drumsetPitch+=r.note.pickMainInterval()),r.drumsetPitch=Math.max(0,Math.min(e.drumCount-1,r.drumsetPitch)));let ot,rt,at=c.filterCutoff,lt=c.filterCutoff;t.isModActive(Y.mstFilterCut,!1,s,q)&&(at=i.modValueToReal(t.getModValue(Y.mstFilterCut,!1,s,q,!1),Y.mstFilterCut),lt=i.modValueToReal(t.getModValue(Y.mstFilterCut,!1,s,q,!0),Y.mstFilterCut)),4==c.type?(ot=0,rt=0):(ot=.5*(at-(e.filterCutoffRange-1)),rt=.5*(lt-(e.filterCutoffRange-1)));const ct=4==c.type?c.getDrumsetEnvelope(r.drumsetPitch):c.getFilterEnvelope(),dt=e.filterCutoffMaxHz*Math.pow(2,ot),ut=e.filterCutoffMaxHz*Math.pow(2,rt),ft=2*Math.sin(Math.PI*dt/t.samplesPerSecond),mt=2*Math.sin(Math.PI*ut/t.samplesPerSecond),pt=2*Math.sin(Math.PI*e.filterCutoffMinHz/t.samplesPerSecond);r.filter=ft*tt.computeEnvelope(ct,y*it,g*C,X);let yt=mt*tt.computeEnvelope(ct,y*st,g*S,et);r.filter=Math.min(e.filterMax,Math.max(pt,r.filter)),yt=Math.min(e.filterMax,Math.max(pt,yt)),r.filterScale=Math.pow(yt/r.filter,1/h);let gt=Math.pow(.5,.35*ot),bt=Math.pow(.5,.35*rt);r.filterResonanceStart=c.getFilterResonance(),r.filterResonanceDelta=0;let vt=c.filterResonance,wt=c.filterResonance;if(r.isFirstOrder=4!=c.type&&0==vt,t.isModActive(Y.mstFilterPeak,!1,s,q)){r.isFirstOrder=!1,vt=i.modValueToReal(t.getModValue(Y.mstFilterPeak,!1,s,q,!1),Y.mstFilterPeak),wt=i.modValueToReal(t.getModValue(Y.mstFilterPeak,!1,s,q,!0),Y.mstFilterPeak),r.filterResonanceStart=e.filterMaxResonance*Math.pow(Math.max(0,vt-1)/(e.filterResonanceRange-2),.5);const n=e.filterMaxResonance*Math.pow(Math.max(0,wt-1)/(e.filterResonanceRange-2),.5);r.filterResonanceDelta=(n-r.filterResonanceStart)/h}else r.filterResonanceStart=e.filterMaxResonance*Math.pow(Math.max(0,vt-1)/(e.filterResonanceRange-2),.5);if(0==r.isFirstOrder&&(gt=Math.pow(gt,1.7)*Math.pow(.5,.125*(vt-1)),bt=Math.pow(bt,1.7)*Math.pow(.5,.125*(wt-1))),8==ct.type?(gt*=1.25+.025*ct.speed,bt*=1.25+.025*ct.speed):4==ct.type&&(gt*=1+.02*ct.speed,bt*=1+.02*ct.speed),U&&r.reset(),1==c.type){let i=1,n=1,a=0,l=0,d=0;if(r.pitchCount>1&&!u.harmonizes){const t=Math.floor(c.arpTime/e.ticksPerArpeggio);d=r.pitches[o(r.pitchCount,c.fastTwoNoteArp,t)]-r.pitches[0]}let f=c.detune/25,m=c.detune/25;t.isModActive(Y.mstDetune,!1,s,q)&&(f=t.getModValue(Y.mstDetune,!1,s,q,!1)/25,m=t.getModValue(Y.mstDetune,!1,s,q,!0)/25),t.isModActive(Y.mstSongDetune,!0)&&(f+=t.getModValue(Y.mstSongDetune,!0,null,null,!1)/25,m+=t.getModValue(Y.mstSongDetune,!0,null,null,!0)/25);const b=e.algorithms[c.algorithm].carrierCount;for(let o=0;o1){const t=Math.floor(c.arpTime/e.ticksPerArpeggio);if(u.harmonizes){const e=r.pitches[1+o(r.pitchCount-1,c.fastTwoNoteArp,t)]-r.pitches[0];r.intervalMult=Math.pow(2,e/12),r.intervalVolumeMult=Math.pow(2,-e/O)}else a=r.pitches[o(r.pitchCount,c.fastTwoNoteArp,t)]}const l=I+(a+j+i)*p,d=I+(a+W+n)*p,f=J.frequencyFromPitch(l),m=Math.pow(2,-(l-$)/O),b=Math.pow(2,-(d-$)/O);let v=_*gt,w=_*bt;if(2==c.type&&(v*=e.chipNoises[c.chipNoise].volume,w*=e.chipNoises[c.chipNoise].volume),0!=c.type&&7!=c.type||(v*=e.chipWaves[c.chipWave].volume,w*=e.chipWaves[c.chipWave].volume),0!=c.type&&5!=c.type&&7!=c.type||(v*=e.intervals[c.interval].volume,w*=e.intervals[c.interval].volume),6==c.type){let i=c.pulseWidth/(2*e.pulseWidthRange),n=c.pulseWidth/(2*e.pulseWidthRange);t.isModActive(Y.mstPulseWidth,!1,s,q)&&(i=t.getModValue(Y.mstPulseWidth,!1,s,q,!1)/(2*e.pulseWidthRange),n=t.getModValue(Y.mstPulseWidth,!1,s,q,!0)/(2*e.pulseWidthRange));const o=e.envelopes[c.pulseEnvelope],a=i*tt.computeEnvelope(o,y*it,g*C,X),l=n*tt.computeEnvelope(o,y*st,g*S,et);r.pulseWidth=a,r.pulseWidthDelta=(l-a)/h}r.phaseDeltas[0]=f*nt,r.volumeStart=G*Z*m*v*ht;let k=K*Q*b*w*ht;if(0==ct.type||6==c.type&&0==e.envelopes[c.pulseEnvelope].type||(r.volumeStart*=X,k*=et),t.isModActive(Y.mstInsVolume,!1,s,q)){const i=t.getModValue(Y.mstInsVolume,!1,s,q,!1),n=t.getModValue(Y.mstInsVolume,!1,s,q,!0);r.volumeStart*=i<=0?(i+e.volumeRange/2)/(e.volumeRange/2):this.instrumentVolumeToVolumeMult(i),k*=n<=0?(n+e.volumeRange/2)/(e.volumeRange/2):this.instrumentVolumeToVolumeMult(n)}t.isModActive(Y.mstSongVolume,!0)&&(r.volumeStart*=t.getModValue(Y.mstSongVolume,!0,void 0,void 0,!1)/100,k*=t.getModValue(Y.mstSongVolume,!0,void 0,void 0,!0)/100),r.volumeDelta=(k-r.volumeStart)/h}r.phaseDeltaScale=Math.pow(2,(W-j)*p/12/h)}static getLFOAmplitude(t,i){let s=0;for(const n of e.vibratoTypes[t.vibratoType].periodsSeconds)s+=Math.sin(2*Math.PI*i/n);return s}static getInstrumentSynthFunction(t){if(1==t.type){const i=t.algorithm+"_"+t.feedbackType;if(null==tt.fmSynthFunctionCache[i]){const s=[];for(const i of tt.fmSourceTemplate)if(-1!=i.indexOf("// CARRIER OUTPUTS")){const n=[];for(let i=0;i=0;i--)for(const n of tt.operatorSourceTemplate)if(-1!=n.indexOf("/* + operator@Scaled*/")){let h="";for(const s of e.algorithms[t.algorithm].modulatedBy[i])h+=" + operator"+(s-1)+"Scaled";const o=e.feedbacks[t.feedbackType].indices[i];if(o.length>0){h+=" + feedbackMult * (";const t=[];for(const e of o)t.push("operator"+(e-1)+"Output");h+=t.join(" + ")+")"}s.push(n.replace(/\#/g,i+"").replace("/* + operator@Scaled*/",h))}else s.push(n.replace(/\#/g,i+""));else if(-1!=i.indexOf("#"))for(let t=0;t1-r){h+=.5*((z=(t-1)/r)+z+z*z+1)}if(n1-r){var z;h-=.5*((z=(n-1)/r)+z+z*z+1)}k+=p*(h-k+(v+v/(1-p))*(k-x)),x+=y*(k-x),p*=g,y*=b,d+=r,r*=a,u+=f,v+=w;const o=x*l;l+=c,E=T<0?[0,0,2*(0|-T),-T%1]:[2*(0|T),T%1,0,0],e[(i+E[0])%s]+=o*C*(1-E[1]),e[(i+E[0]+2)%s]+=o*C*E[1],e[(i+E[2]+1)%s]+=o*q*(1-E[3]),e[(i+E[2]+3)%s]+=o*q*E[3],C+=S,q+=P,T+=B,i+=2}h.phases[0]=d;const R=1e-24;-1e-240;h--){const h=s+16&32767,o=t[h];if(n*o<=0){for(let h=0;h<16;h++){const h=s+1&32767,o=t[h];if(n*o<=0){const t=o-n;i=s,Math.abs(t)>1e-8&&(i+=-n/t),i=Math.max(0,i)%e.chipNoiseLength;break}s=h,n=o}break}s=h,n=o}return i}static instrumentVolumeToVolumeMult(t){return t==-e.volumeRange/2?0:Math.pow(2,e.volumeLogScale*t)}static volumeMultToInstrumentVolume(t){return t<=0?-e.volumeRange/2:Math.min(e.volumeRange,Math.log(t)/Math.LN2/e.volumeLogScale)}static expressionToVolumeMult(t){return Math.pow(Math.max(0,t)/6,1.5)}static volumeMultToExpression(t){return 6*Math.pow(Math.max(0,t),1/1.5)}getSamplesPerTick(){if(null==this.song)return 0;let t=this.song.getBeatsPerMinute();return this.isModActive(Y.mstTempo,!0)&&(t=this.getModValue(Y.mstTempo,!0)),this.getSamplesPerTickSpecificBPM(t)}getSamplesPerTickSpecificBPM(t){const i=t/60,s=e.partsPerBeat*i,n=e.ticksPerPart*s;return this.samplesPerSecond/n}}tt.fmSynthFunctionCache={},tt.fmSourceTemplate=("\nconst sineWave = beepbox.Config.sineWave;\n\nlet phaseDeltaScale = +tone.phaseDeltaScale;\n// I'm adding 1000 to the phase to ensure that it's never negative even when modulated by other waves because negative numbers don't work with the modulus operator very well.\nlet operator#Phase = +((tone.phases[#] % 1) + 1000) * beepbox.Config.sineWaveLength;\nlet operator#PhaseDelta = +tone.phaseDeltas[#];\nlet operator#OutputMult = +tone.volumeStarts[#];\nconst operator#OutputDelta = +tone.volumeDeltas[#];\nlet operator#Output = +tone.feedbackOutputs[#];\nlet feedbackMult = +tone.feedbackMult;\nconst feedbackDelta = +tone.feedbackDelta;\nlet volume = +tone.volumeStart;\nconst volumeDelta = +tone.volumeDelta;\n\nconst isFirstOrder = tone.isFirstOrder;\nlet filter1 = +tone.filter;\nlet filter2 = isFirstOrder ? 1.0 : filter1;\nconst filterScale1 = +tone.filterScale;\nconst filterScale2 = isFirstOrder ? 1.0 : filterScale1;\nlet filterResonance = tone.filterResonanceStart;\nlet filterResonanceDelta = tone.filterResonanceDelta;\nlet filterSample0 = +tone.filterSample0;\nlet filterSample1 = +tone.filterSample1;\n\nconst stopIndex = stereoBufferIndex + runLength;\nstereoBufferIndex += tone.stereoOffset;\nlet stereoVolumeL = tone.stereoVolumeLStart;\nlet stereoVolumeLDelta = tone.stereoVolumeLDelta;\nlet stereoVolumeR = tone.stereoVolumeRStart;\nlet stereoVolumeRDelta = tone.stereoVolumeRDelta;\nlet stereoDelay = tone.stereoDelayStart;\nlet stereoDelayDelta = tone.stereoDelayDelta;\nlet delays = [];\nwhile (stereoBufferIndex < stopIndex) {\n// INSERT OPERATOR COMPUTATION HERE\nconst fmOutput = (/*operator#Scaled*/); // CARRIER OUTPUTS\n\nconst feedback = filterResonance + filterResonance / (1.0 - filter1);\nfilterSample0 += filter1 * (fmOutput - filterSample0 + feedback * (filterSample0 - filterSample1));\nfilterSample1 += filter2 * (filterSample0 - filterSample1);\n\nfeedbackMult += feedbackDelta;\noperator#OutputMult += operator#OutputDelta;\noperator#Phase += operator#PhaseDelta;\noperator#PhaseDelta *= phaseDeltaScale;\nfilter1 *= filterScale1;\nfilter2 *= filterScale2;\nfilterResonance += filterResonanceDelta;\n\nconst output = filterSample1 * volume;\nvolume += volumeDelta;\n\n//const absStereoDelay: number = Math.abs(stereoDelay);\n//const fracStereoDelay: number = absStereoDelay % 1;\n//const floorStereoDelay: number = absStereoDelay | 0;\n\n//delays = stereoDelay < 0 ? [0, 0, floorStereoDelay * 2, fracStereoDelay] : [floorStereoDelay * 2, fracStereoDelay, 0, 0];\n\n// Optimized ver: can remove the above three declarations, but muddier conceptually. Still has that conditional, too...\ndelays = stereoDelay < 0 ? [0, 0, ((-stereoDelay) | 0) * 2, (-stereoDelay) % 1] : [(stereoDelay | 0) * 2, stereoDelay % 1, 0, 0];\n\ndata[(stereoBufferIndex + delays[0]) % stereoBufferLength] += output * stereoVolumeL * (1 - delays[1]);\ndata[(stereoBufferIndex + delays[0] + 2) % stereoBufferLength] += output * stereoVolumeL * delays[1];\ndata[(stereoBufferIndex + delays[2] + 1) % stereoBufferLength] += output * stereoVolumeR * (1 - delays[3]);\ndata[(stereoBufferIndex + delays[2] + 3) % stereoBufferLength] += output * stereoVolumeR * delays[3];\n\nstereoVolumeL += stereoVolumeLDelta;\nstereoVolumeR += stereoVolumeRDelta;\nstereoDelay += stereoDelayDelta;\n\nstereoBufferIndex += 2;\n}\n\ntone.phases[#] = operator#Phase / "+e.sineWaveLength+";\ntone.feedbackOutputs[#] = operator#Output;\n\nconst epsilon = (1.0e-24);\nif (-epsilon < filterSample0 && filterSample0 < epsilon) filterSample0 = 0.0;\nif (-epsilon < filterSample1 && filterSample1 < epsilon) filterSample1 = 0.0;\ntone.filterSample0 = filterSample0;\ntone.filterSample1 = filterSample1;\n").split("\n"),tt.operatorSourceTemplate=("\nconst operator#PhaseMix = operator#Phase/* + operator@Scaled*/;\nconst operator#PhaseInt = operator#PhaseMix|0;\nconst operator#Index = operator#PhaseInt & "+e.sineWaveMask+";\nconst operator#Sample = sineWave[operator#Index];\noperator#Output = operator#Sample + (sineWave[operator#Index + 1] - operator#Sample) * (operator#PhaseMix - operator#PhaseInt);\nconst operator#Scaled = operator#OutputMult * operator#Output;\n").split("\n");class et{constructor(t,e){this.U=t,this.V=e,this.j=512,this.W=20,this.J=x.rect("rect",{fill:T.playhead,x:0,y:0,width:2,height:this.W}),this.K=x.svg({"pointer-events":"none"}),this.Y=x.rect({fill:T.uiWidgetBackground,x:0,y:2,width:10,height:this.W-4}),this.Z=x.rect({fill:"none",stroke:T.hoverPreview,"stroke-width":2,"pointer-events":"none",x:0,y:1,width:10,height:this.W-2}),this.X=x.path({fill:T.hoverPreview,"pointer-events":"none"}),this.tt=x.path({fill:T.hoverPreview,"pointer-events":"none"}),this.et=-1,this.it=x.svg({style:`background-color: ${T.editorBackground}; touch-action: pan-y; position: absolute;`,width:this.j,height:this.W},this.K,this.Y,this.Z,this.X,this.tt,this.J),this.container=k.div({class:"barScrollBar",style:"width: 512px; height: 20px; overflow: hidden; position: relative;"},this.it),this.st=0,this.nt=!1,this.ht=!1,this.ot=!1,this.rt=-1,this.at=-1,this.animatePlayhead=()=>{const t=Math.min(512,Math.max(0,this.lt*this.U.synth.playhead-2));this.et!=t&&(this.et=t,this.J.setAttribute("x",""+t))},this.ct=t=>{this.U.barScrollPos=this.V.scrollLeft/this.U.getBarWidth()},this.dt=t=>{this.ht||(this.ht=!0,this.ut())},this.ft=t=>{this.ht&&(this.ht=!1,this.ut())},this.yt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=(t.clientX||t.pageX)-e.left,this.ut(),this.st>=this.U.barScrollPos*this.lt&&this.st<=(this.U.barScrollPos+this.U.trackVisibleBars)*this.lt&&(this.ot=!0,this.gt=this.st)},this.bt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=t.touches[0].clientX-e.left,this.ut(),this.st>=this.U.barScrollPos*this.lt&&this.st<=(this.U.barScrollPos+this.U.trackVisibleBars)*this.lt&&(this.ot=!0,this.gt=this.st)},this.vt=t=>{const e=this.it.getBoundingClientRect();this.st=(t.clientX||t.pageX)-e.left,this.wt()},this.kt=t=>{if(!this.nt)return;t.preventDefault();const e=this.it.getBoundingClientRect();this.st=t.touches[0].clientX-e.left,this.wt()},this.xt=t=>{!this.ot&&this.nt&&(this.st<(this.U.barScrollPos+8)*this.lt?(this.U.barScrollPos>0&&this.U.barScrollPos--,this.U.notifier.changed()):(this.U.barScrollPos0;)this.U.barScrollPos--,this.gt-=this.lt,this.U.notifier.changed();for(;this.st-this.gt>.5*this.lt&&this.U.barScrollPos=1;)t<0?this.U.barScrollPos>0&&(this.U.barScrollPos--,this.gt+=this.lt,this.U.notifier.changed()):this.U.barScrollPos0?-1:1}ut(){let t=!1,e=!1,i=!1;this.ht&&!this.nt&&(this.st(this.U.barScrollPos+this.U.trackVisibleBars)*this.lt?e=!0:i=!0),this.X.style.visibility=t?"visible":"hidden",this.tt.style.visibility=e?"visible":"hidden",this.Z.style.visibility=i?"visible":"hidden"}render(){this.lt=(this.j-1)/Math.max(this.U.trackVisibleBars,this.U.song.barCount);const t=this.rt!=this.U.song.barCount;if(t){for(this.rt=this.U.song.barCount;this.K.firstChild;)this.K.removeChild(this.K.firstChild);for(let t=0;t<=this.U.song.barCount;t++){const e=t%16==0?0:t%4==0?this.W/8:this.W/3;this.K.appendChild(x.rect({fill:T.uiWidgetBackground,x:t*this.lt-1,y:e,width:2,height:this.W-2*e}))}}(t||this.at!=this.U.barScrollPos)&&(this.at=this.U.barScrollPos,this.Y.setAttribute("x",""+this.lt*this.U.barScrollPos),this.Y.setAttribute("width",""+this.lt*this.U.trackVisibleBars),this.Z.setAttribute("x",""+this.lt*this.U.barScrollPos),this.Z.setAttribute("width",""+this.lt*this.U.trackVisibleBars)),this.ut(),this.V.scrollLeft=this.U.barScrollPos*this.U.getBarWidth()}}class it{constructor(){this.Mt=!0}Et(){this.Mt=!1}isNoop(){return this.Mt}commit(){}}class st extends it{constructor(t){super(),this.Ct=t,this.St=!t}undo(){this.Ct?(this.qt(),this.St=!0):(this.Pt(),this.St=!1)}redo(){this.Ct?(this.Pt(),this.St=!1):(this.qt(),this.St=!0)}Tt(){return this.St}qt(){throw new Error("Change.doForwards(): Override me.")}Pt(){throw new Error("Change.doBackwards(): Override me.")}}class nt extends it{constructor(){super()}append(t){t.isNoop()||this.Et()}}class ht extends st{constructor(t){super(!1),this.Bt=null==t?[]:t.concat()}append(t){t.isNoop()||(this.Bt[this.Bt.length]=t,this.Et())}qt(){for(let t=0;t=0;t--)this.Bt[t].undo()}}function ot(t,e){for(const i of t.notes)for(const t of i.pitches)for(const s of i.pins){const i=(t+s.interval)%12;e[i]||(e[i]=!0)}}function rt(t,e,i,s,n){const h=new U(-1,i,s,3,!1);n.push(h),h.pins.length=0,h.pitches.length=0;const o=s-i;for(const e of t.pitches)h.pitches.push(e);for(let i=0;i=t.pins.length)throw new Error("Error converting pins in note overflow.");const o=t.pins[i+1],r=o.time+e;if(r>0){const t=-n/(r-n);h.pins.push(I(Math.round(s.interval+t*(o.interval-s.interval)),0,Math.round(s.volume+t*(o.volume-s.volume))))}}else if(n<=o)h.pins.push(I(s.interval,n,s.volume));else{if(i<1)throw new Error("Error converting pins in note overflow.");const r=t.pins[i-1],a=r.time+e;if(a=this.Ht[t+1].time?this.Ht.splice(t,1):t++;for(let t=1;t=2),s.volume=e,s.pan=i,s.panDelay=h}s.preset=i,t.notifier.changed(),this.Et()}}}class ut extends it{constructor(t){function i(t){let e=0;for(const i of t)e+=i.weight;let i=Math.random()*e;for(const e of t)if(i-=e.weight,i<=0)return e.item;return t[Math.random()*t.length|0].item}function s(t,e,s,n){const h=[];for(let i=t;i<=e;i++)h.push({item:i,weight:1/(Math.pow((i-s)/n,2)+1)});return i(h)}super();const n=t.song.getChannelIsNoise(t.channel),h=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];if(n){const t=i([{item:2,weight:1},{item:3,weight:3}]);function o(t){let i=0;for(const e of t)e>i&&(i=e);for(let s=0;s{const t=[];for(let i=0;i{let t=1;const i=[t];for(let s=1;s{let t=1;const i=[t];for(let s=1;si&&(i=e);for(let s=0;s{const t=[];for(let i=0;i{let t=1;const i=[t];for(let s=1;s{let t=1;const i=[t];for(let s=1;st.song.patternsPerChannel)throw new Error("invalid pattern");for(let o=i;oe&&s.bars.splice(0,t.song.barCount-e)}else{for(;s.bars.length0)&&(t.barScrollPos=Math.max(0,t.barScrollPos+i)),t.song.loopStart=Math.max(0,t.song.loopStart+i)}t.bar=Math.min(t.bar,e-1),t.barScrollPos=Math.max(0,Math.min(e-t.trackVisibleBars,t.barScrollPos)),t.song.loopLength=Math.min(e,t.song.loopLength),t.song.loopStart=Math.min(e-t.song.loopLength,t.song.loopStart),t.song.barCount=e,t.notifier.changed(),this.Et()}}}class gt extends it{constructor(t,i,s){super();const n=Math.min(e.barCountMax,t.song.barCount+s);if(0!=(s=n-t.song.barCount)){for(const e of t.song.channels)for(;e.bars.length=i?t.song.loopStart+=s:t.song.loopStart+t.song.loopLength>=i&&(t.song.loopLength+=s),t.notifier.changed(),this.Et()}}}class bt extends it{constructor(t,e,i){super();for(const s of t.song.channels)s.bars.splice(e,i),0==s.bars.length&&s.bars.push(0);t.song.barCount=Math.max(1,t.song.barCount-i),t.bar=Math.max(0,t.bar-i),t.barScrollPos=Math.max(0,t.barScrollPos-i),t.song.loopStart>=e?t.song.loopStart=Math.max(0,t.song.loopStart-i):t.song.loopStart+t.song.loopLength>e&&(t.song.loopLength-=i),t.song.loopLength=Math.max(1,Math.min(t.song.barCount-t.song.loopStart,t.song.loopLength)),t.notifier.changed(),this.Et()}}class vt extends it{constructor(t,e,i,s,n,h,o,r){super(),t.song.limitRatio=e,t.song.compressionRatio=i,t.song.limitThreshold=s,t.song.compressionThreshold=n,t.song.limitRise=h,t.song.limitDecay=o,t.song.masterGain=r,t.notifier.changed(),this.Et()}}class wt extends it{constructor(t,i,s){super();let n=t.song.channels[i];t.song.channels[i]=t.song.channels[s],t.song.channels[s]=n;for(let n=t.song.pitchChannelCount+t.song.noiseChannelCount;n=2),s.preset=n,o[e].instruments[i]=s}for(let i=0;i=t.song.pitchChannelCount&&h==K.msForPitch&&(h=K.msNone,e.modStatuses[n]=K.msNone,e.modSettings[n]=Y.mstNone),o>=t.song.pitchChannelCount+t.song.noiseChannelCount&&h==K.msForNoise&&(e.modStatuses[n]=K.msNone,e.modSettings[n]=Y.mstNone)}t.notifier.changed(),T.resetColors(),this.Et()}}}class xt extends it{constructor(t,e,i,s=!1){super();const n=t.channel,h=t.bar;t.channel=e,t.bar=i,s||(t.barScrollPos=Math.min(t.bar,Math.max(t.bar-(t.trackVisibleBars-1),t.barScrollPos))),t.notifier.changed(),n==e&&h==i||this.Et()}}class Mt extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.interval!=e&&(this.Et(),i.interval=e,i.preset=i.type,t.notifier.changed())}}class Et extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.chord!=e&&(this.Et(),i.chord=e,i.preset=i.type,t.notifier.changed())}}class Ct extends it{constructor(t,i){super();const s=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];s.vibrato!=i&&(s.vibrato=i,s.vibratoDepth=e.vibratos[s.vibrato].amplitude,s.vibratoDelay=e.vibratos[s.vibrato].delayParts,s.vibratoSpeed=10,s.vibratoType=e.vibratos[s.vibrato].type,s.preset=s.type,t.notifier.changed(),this.Et())}}class St extends it{constructor(t,i,s){super();const n=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];let h=n.vibrato;t.synth.unsetMod(Y.mstVibratoDepth,t.channel,t.getCurrentInstrument()),t.notifier.changed(),i==s&&h==e.vibratos.length||(n.vibratoDepth=s/25,n.vibrato=e.vibratos.length,t.notifier.changed(),this.Et())}}class qt extends it{constructor(t,i,s){super();const n=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];let h=n.vibrato;t.synth.unsetMod(Y.mstVibratoSpeed,t.channel,t.getCurrentInstrument()),t.notifier.changed(),i==s&&h==e.vibratos.length||(n.vibratoSpeed=s,n.vibrato=e.vibratos.length,t.notifier.changed(),this.Et())}}class Pt extends it{constructor(t,i,s){super();const n=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];let h=n.vibrato;t.synth.unsetMod(Y.mstVibratoDelay,t.channel,t.getCurrentInstrument()),t.notifier.changed(),i==s&&h==e.vibratos.length||(n.vibratoDelay=s,n.vibrato=e.vibratos.length,t.notifier.changed(),this.Et())}}class Tt extends it{constructor(t,i){super();const s=t.song.channels[t.channel].instruments[t.getCurrentInstrument()],n=s.vibratoType;let h=s.vibrato;t.notifier.changed(),n==i&&h==e.vibratos.length||(s.vibratoType=i,s.vibrato=e.vibratos.length,t.notifier.changed(),this.Et())}}class Bt extends it{constructor(t,e,i){super();t.song.channels[t.channel].instruments[t.getCurrentInstrument()].arpeggioSpeed=i,t.synth.unsetMod(Y.mstArpeggioSpeed,t.channel,t.getCurrentInstrument()),t.notifier.changed(),e!=i&&this.Et()}}class zt extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()],s=i.fastTwoNoteArp;t.notifier.changed(),s!=e&&(i.fastTwoNoteArp=e,this.Et())}}class Rt extends it{constructor(t,e,i){super(),i.markCustomWaveDirty(),e.preset=e.type,t.notifier.changed(),this.Et()}}class Nt extends it{constructor(t,e,i){super(),i.markCustomWaveDirty(),e.preset=e.type,t.notifier.changed(),this.Et()}}class Ft extends it{constructor(t,e,i){super();const s=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];s.drumsetEnvelopes[e]!=i&&(s.drumsetEnvelopes[e]=i,s.preset=s.type,t.notifier.changed(),this.Et())}}class Lt extends it{constructor(t){super(),this.U=t,this._t=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()]}commit(){this.isNoop()||(this._t.preset=this._t.type,this.U.notifier.changed())}}class At extends Lt{constructor(t,e,i){super(t),this._t.pulseWidth=i,t.synth.unsetMod(Y.mstPulseWidth,t.channel,t.getCurrentInstrument()),t.notifier.changed(),e!=i&&this.Et()}}class Ht extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.pulseEnvelope!=e&&(i.pulseEnvelope=e,i.preset=i.type,t.notifier.changed(),this.Et())}}class Dt extends Lt{constructor(t,e,i){super(t),this._t.filterCutoff=i,t.synth.unsetMod(Y.mstFilterCut,t.channel,t.getCurrentInstrument()),t.notifier.changed(),e!=i&&this.Et()}}class $t extends Lt{constructor(t,e,i){super(t),this._t.filterResonance=i,t.synth.unsetMod(Y.mstFilterPeak,t.channel,t.getCurrentInstrument()),t.notifier.changed(),e!=i&&this.Et()}}class It extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.filterEnvelope!=e&&(i.filterEnvelope=e,i.preset=i.type,t.notifier.changed(),this.Et())}}class _t extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.algorithm!=e&&(i.algorithm=e,i.preset=i.type,t.notifier.changed(),this.Et())}}class Ot extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.feedbackType!=e&&(i.feedbackType=e,i.preset=i.type,t.notifier.changed(),this.Et())}}class Ut extends it{constructor(t,e){super();const i=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];i.feedbackEnvelope!=e&&(i.feedbackEnvelope=e,i.preset=i.type,t.notifier.changed(),this.Et())}}class Vt extends it{constructor(t,e,i){super();const s=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];s.operators[e].envelope!=i&&(s.operators[e].envelope=i,s.preset=s.type,t.notifier.changed(),this.Et())}}class jt extends it{constructor(t,e,i){super();const s=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];s.operators[e].frequency!=i&&(s.operators[e].frequency=i,s.preset=s.type,t.notifier.changed(),this.Et())}}class Wt extends Lt{constructor(t,e,i,s){super(t),this._t.operators[e].amplitude=s,t.notifier.changed(),i!=s&&this.Et()}}class Gt extends Lt{constructor(t,e,i){super(t),this._t.feedbackAmplitude=i,t.notifier.changed(),e!=i&&this.Et()}}class Jt extends it{constructor(t,i){if(super(),t.song.instrumentsPerChannel!=i){for(let e=0;e=2),t.song.channels[e].instruments[h]=i}t.song.channels[e].instruments.length=i;for(let s=0;s=i&&(t.song.channels[e].patterns[s].instrument=0)}t.song.instrumentsPerChannel=i;for(let i=t.song.pitchChannelCount+t.song.noiseChannelCount;i=t.song.instrumentsPerChannel&&(e.modInstruments[n]=0,e.modSettings[n]=0)}t.notifier.changed(),this.Et()}}}class Kt extends it{constructor(t,e){super(),t.song.key!=e&&(t.song.key=e,t.notifier.changed(),this.Et())}}class Yt extends it{constructor(t,e,i,s,n){super(),this.U=t,this.oldStart=e,this.oldLength=i,this.newStart=s,this.newLength=n,this.U.song.loopStart=this.newStart,this.U.song.loopLength=this.newLength,this.U.notifier.changed(),this.oldStart==this.newStart&&this.oldLength==this.newLength||this.Et()}}class Zt extends st{constructor(t,e,i,s,n=!1){super(n),this.U=t,this.zt=e,this.Ot=i,this.P=s,this.Et(),this.redo()}qt(){this.zt.pitches.splice(this.P,0,this.Ot),this.U.notifier.changed()}Pt(){this.zt.pitches.splice(this.P,1),this.U.notifier.changed()}}class Qt extends it{constructor(t,e,i){super(),this.oldValue=e,t.song.channels[t.channel].octave=i,t.notifier.changed(),e!=i&&this.Et()}}class Xt extends nt{constructor(t,e){super(),t.song.rhythm!=e&&(t.song.rhythm=e,t.notifier.changed(),this.Et())}}class te extends nt{constructor(t,e,i,s,n,h){super(),this.append(new qe(t,e,s,n,null,!0));let o=0;if(t.song.getChannelIsMod(t.channel))o=e.notes.length;else for(let t=0;ts)throw new Error;o=t+1}else if(e.notes[t].start=n)break;const a=new U(h.pitches[0],i,r,h.pins[0].volume,!1);a.pitches.length=0;for(const t of h.pitches)a.pitches.push(t);a.pins.length=0;for(const t of h.pins)a.pins.push(I(t.interval,t.time,t.volume));e.notes.splice(o++,0,a),a.end>n&&this.append(new Se(t,a,a.start,n))}s+=h}t.notifier.changed(),this.Et()}}class ee extends nt{constructor(t,e,i){super(),e.fromJsonObject(i,i.isDrum,i.isMod,!1,!1),t.notifier.changed(),this.Et()}}class ie extends it{constructor(t,e,i){super(),i.instrument!=e&&(i.instrument=e,t.notifier.changed(),this.Et())}}class se extends it{constructor(t,e,i){super();let s=K.msNone,n=0,h=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];1==i?s=K.msForSong:0==i?s=K.msNone:i<2+t.song.pitchChannelCount?(s=K.msForPitch,n=i-2):(s=K.msForNoise,n=i-t.song.pitchChannelCount-2),h.modStatuses[e]==s&&h.modChannels[e]==n||(h.modStatuses[e]=s,h.modChannels[e]=n,t.notifier.changed(),this.Et())}}class ne extends it{constructor(t,e,i){super();let s=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];s.modInstruments[e]!=i&&(s.modInstruments[e]=i,t.notifier.changed(),this.Et())}}class he extends it{constructor(t,i,s){super();let n=Y.mstNone,h=t.song.channels[t.channel].instruments[t.getCurrentInstrument()];switch(s){case"song volume":n=Y.mstSongVolume;break;case"tempo":n=Y.mstTempo;break;case"reverb":n=Y.mstReverb;break;case"next bar":n=Y.mstNextBar;break;case"volume":n=Y.mstInsVolume;break;case"pan":n=Y.mstPan;break;case"filter cut":n=Y.mstFilterCut;break;case"filter peak":n=Y.mstFilterPeak;break;case"fm slider 1":n=Y.mstFMSlider1;break;case"fm slider 2":n=Y.mstFMSlider2;break;case"fm slider 3":n=Y.mstFMSlider3;break;case"fm slider 4":n=Y.mstFMSlider4;break;case"fm feedback":n=Y.mstFMFeedback;break;case"pulse width":n=Y.mstPulseWidth;break;case"detune":n=Y.mstDetune;break;case"vibrato depth":n=Y.mstVibratoDepth;break;case"vibrato speed":n=Y.mstVibratoSpeed;break;case"vibrato delay":n=Y.mstVibratoDelay;break;case"pan delay":n=Y.mstPanDelay;break;case"arpeggio speed":n=Y.mstArpeggioSpeed;break;case"reset arpeggio":n=Y.mstResetArpeggio;break;case"song detune":n=Y.mstSongDetune}if(h.modSettings[i]!=n){h.modSettings[i]=n;let s=t.song.mstMaxVols.get(n);for(let n=0;ns&&(e.volume=s)}}}t.notifier.changed(),this.Et()}}}class oe extends it{constructor(t,e){if(super(),t.song.patternsPerChannel!=e){for(let i=0;ie&&(s[t]=0);for(let t=n.length;to&&(r||(this.Ht.push(I(this.At[i].interval,s,this.At[i].volume)),r=!0),this.Ht.push(I(n.interval,a,n.volume)))}r||this.Ht.push(I(this.At[i].interval,s,this.At[i].volume)),this.It()}}class le extends lt{constructor(t,e,i,s,n,h){super(t,e),i-=this.Rt,s-=this.Rt,n-=e.pitches[h];let o,r,a,l,c=!1,d=!1,u=0,f=3,m=!0;for(s>i?(o=0,r=1,a=e.pins.length,l=t=>{this.Ht.push(t)}):(o=e.pins.length-1,r=-1,a=-1,l=t=>{this.Ht.unshift(t)});o!=a;o+=r){const t=e.pins[o],h=t.time;for(;;)if(c){if(d){if(h*r==s*r)break;t.interval!=u&&(m=!1),l(I(m?n:t.interval,h,t.volume));break}if(h*r<=s*r&&(u=t.interval,f=t.volume),h*r=t))break;o+=s}return o}return Math.round(i/s)*s};let h=0;for(;h=n(e.end)?this.append(new Ce(t,i,e,h,!0)):(this.append(new de(t,e,n)),h++)}}}class de extends lt{constructor(t,e,i){super(t,e);for(const t of this.At)this.Ht.push(I(t.interval,i(t.time+this.Rt)-this.Rt,t.volume));this.It()}}class ue extends nt{constructor(t,i,s){super();let n=Math.round(i%t.song.beatsPerBar*e.partsPerBeat);if(n<0&&(n+=t.song.beatsPerBar*e.partsPerBeat),0!=n){switch(s){case"wrapAround":{const i=e.partsPerBeat*t.song.beatsPerBar;for(const e of t.song.channels)for(const t of e.patterns){const e=[];for(let s=1;s>=0;s--){const h=s*i;for(const s of t.notes){const t=s.start+n,o=s.end+n,r=Math.max(0,t-h),a=Math.min(i,o-h);ri){const s=new ht;for(let n=0;n=e(i.end)?this.append(new Ce(t,n,i,h,!0)):(this.append(new de(t,i,e)),h++)}}this.append(new Me(t,t.song.tempo,t.song.tempo*i/t.song.beatsPerBar))}break;case"overflow":this.append(new at(t,i,0)),t.song.loopStart=0,t.song.loopLength=t.song.barCount;break;default:throw new Error("Unrecognized beats-per-bar conversion strategy.")}t.song.beatsPerBar=i,t.notifier.changed(),this.Et()}}}class me extends nt{constructor(t,e){super(),t.song.scale!=e&&(t.song.scale=e,t.notifier.changed(),this.Et())}}class pe extends nt{constructor(t){super();const i=t.song,s=e.keys[i.key].basePitch,n=[0,0,0,0,0,0,0,0,0,0,0,0];for(let t=0;t0,!0));i.key=h,t.notifier.changed(),this.Et()}}}function ye(t){const e=[];for(let i=0;i.5?"chip noise":"standard drumset"):ye(s),o=c.valueToPreset(h);i.fromJsonObject(o.settings,s,n,0==t.rhythm||2==t.rhythm,t.rhythm>=2),i.preset=h}}class be extends nt{constructor(t,e){super();let i=t.song.pitchChannelCount,s=t.song.noiseChannelCount,n=t.song.modChannelCount;t.song.fromBase64String(e),i==t.song.pitchChannelCount&&s==t.song.noiseChannelCount&&n==t.song.modChannelCount||T.resetColors(),""==e?(this.append(new Re(t,0,0)),t.selection.resetBoxSelection(),ge(t.song)):this.append(new ve(t)),t.notifier.changed(),this.Et()}}class ve extends it{constructor(t){super();const e=Math.min(t.channel,t.song.getChannelCount()-1),i=Math.max(0,Math.min(t.song.barCount-1,t.bar)),s=Math.min(t.bar,Math.max(t.bar-(t.trackVisibleBars-1),Math.max(0,Math.min(t.song.barCount-t.trackVisibleBars,t.barScrollPos))));t.channel==e&&t.bar==i&&t.barScrollPos==s||(t.channel=e,t.bar=i,t.barScrollPos=s,t.notifier.changed(),this.Et())}}class we extends nt{constructor(t,i,s,n){super();const h=t.song;function o(t,e){for(;t.length>e;){let e=t.length-1,i=0;for(let s=0;s=i&&(e=s,i=n)}t.splice(e,1)}}for(o(i,e.pitchChannelCountMax),o(s,e.noiseChannelCountMax),o(n,e.modChannelCountMax);i.lengthh.patternsPerChannel||i.bars[t]<0)&&(i.bars[t]=0);for(const t of i.patterns)(t.instrument>=h.instrumentsPerChannel||t.instrument<0)&&(t.instrument=0);for(;i.bars.lengthi&&!h&&this.Ht.push(I(r,i,o)),this.Ht.push(I(t.interval,t.time,t.volume)),h=!0,t.time==s){a=!1;break}}}a&&this.Ht.push(I(this.At[n].interval,s,this.At[n].volume)),this.It()}}class qe extends ht{constructor(t,e,i,s,n=null,h=!1){super();let o=0;for(;o=s){if(!t.song.getChannelIsMod(t.channel))break;o++}else if(r.starts){if(!t.song.getChannelIsMod(t.channel)||h||null!=n&&r.pitches[0]==n.pitches[0]){const n=r.clone();this.append(new Se(t,r,r.start,i)),o++,this.append(new Ce(t,e,n,o,!1)),this.append(new Se(t,n,s,n.end))}o++}else r.starts?((!t.song.getChannelIsMod(t.channel)||h||null!=n&&r.pitches[0]==n.pitches[0])&&this.append(new Se(t,r,s,r.end)),o++):!t.song.getChannelIsMod(t.channel)||h||null!=n&&r.pitches[0]==n.pitches[0]?this.append(new Ce(t,e,r,o,!0)):o++}}}class Pe extends ht{constructor(t,e){super();let i=0;for(;i=0;i--)if(r||h||e.scales[t.song.scale].flags[i%12]){s=i;break}let l=!1;for(let t=0;te+a&&(c=e+a)}for(const i of this.At){let s=i.interval+this.Dt[0];if(sc&&(s=c),o&&!r)s=n?Math.min(c,s+12):Math.max(l,s-12);else if(n){for(let i=s+1;i<=c;i++)if(r||h||e.scales[t.song.scale].flags[i%12]){s=i;break}}else for(let i=s-1;i>=l;i--)if(r||h||e.scales[t.song.scale].flags[i%12]){s=i;break}s-=this.$t[0],this.Ht.push(I(s,i.time,i.volume))}if(0!=this.Ht[0].interval)throw new Error("wrong pin start interval");for(let t=1;t=t.selection.patternSelectionEnd)||this.append(new Te(t,e,o,s,n,h))}}class ze extends it{constructor(t,e,i,s,n){super(),t.selection.boxSelectionX0=e,t.selection.boxSelectionX1=i,t.selection.boxSelectionY0=s,t.selection.boxSelectionY1=n,t.notifier.changed(),this.Et()}}class Re extends st{constructor(t,e,i){super(!1),this.U=t,this.Rt=t.selection.patternSelectionStart,this.Nt=t.selection.patternSelectionEnd,this.Yt=t.selection.patternSelectionActive,this.Ft=e,this.Lt=i,this.Zt=et.song.beatsPerBar*e.partsPerBeat-n&&this.append(new qe(t,s,t.song.beatsPerBar*e.partsPerBeat-n,r,null,!0))),this.append(new Re(t,a,l));const c=[];let d=0,u=0;for(;u=r?(u++,e.end<=a&&(d=u)):(c.push(e.clone()),this.append(new Ce(t,s,e,u,!0)))}for(const e of c){e.start+=n,e.end+=n;for(let s=0;s0));this.append(new Ce(t,s,e,d++,!1))}}}class Fe extends nt{constructor(t,i,s,n,h){super();for(let o=n;o=i+s)&&t.song.channels[o].bars[e]==r){a=!0;break}if(a){const i=t.song.getPattern(o,h);this.append(new pt(t,0,h,o,1,1)),this.append(new re(t,o,h));const s=t.song.getPattern(o,h);if(null==s)throw new Error;this.append(new te(t,s,i.notes,0,e.partsPerBeat*t.song.beatsPerBar,e.partsPerBeat*t.song.beatsPerBar)),this.append(new ie(t,i.instrument,s)),n[String(r)]=t.song.channels[o].bars[h]}else n[String(r)]=r}this.append(new pt(t,n[String(r)],h,o,1,1))}}}}}class Le extends it{constructor(t,i,s){super(),t.selection.patternSelectionActive&&new Pe(t,i);const n=e.maxPitch;for(const e of i.notes){if(t.selection.patternSelectionActive&&(e.end<=t.selection.patternSelectionStart||e.start>=t.selection.patternSelectionEnd))continue;const i=[],h=[];for(let t=0;te+n&&(r=e+n)}for(const t of e.pins){let n=t.interval+e.pitches[0];nr&&(n=r);const a=s[n%12]+(n-n%12);h.push(I(a-i[0],t.time,t.volume))}if(0!=h[0].interval)throw new Error("wrong pin start interval");for(let t=1;t30&&(i=i.substring(0,30)),t.song.title=i,document.title=i+" - "+c.versionDisplayName,t.notifier.changed(),e!=i&&this.Et()}}class De extends it{constructor(t,e,i){super(),i.length>15&&(i=i.substring(0,15)),t.song.channels[t.muteEditorChannel].name=i,t.recalcChannelNames=!0,t.notifier.changed(),e!=i&&this.Et()}}class $e extends it{constructor(t,e,i){super(),t.song.channels[t.channel].instruments[t.getCurrentInstrument()].pan=i,t.synth.unsetMod(Y.mstPan,t.channel,t.getCurrentInstrument()),t.notifier.changed(),e!=i&&this.Et()}}class Ie extends it{constructor(t,e,i){super(),t.song.channels[t.channel].instruments[t.getCurrentInstrument()].panDelay=i,t.notifier.changed(),e!=i&&this.Et()}}class _e extends it{constructor(t,e,i){super(),t.song.channels[t.channel].instruments[t.getCurrentInstrument()].detune=i,t.synth.unsetMod(Y.mstDetune,t.channel,t.getCurrentInstrument()),t.notifier.changed(),e!=i&&this.Et()}}class Oe extends st{constructor(t,e,i,s,n,h){super(!1),this.U=t,this.zt=e,this.At=e.pins,this.Ht=[];let o=!1;for(const t of e.pins)t.time{this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.Qt.removeEventListener("keypress",Xe.ne),this.Qt.removeEventListener("blur",Xe.he),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se()},this.se=()=>{window.localStorage.setItem("beatCountStrategy",this.Xt.value),this.U.prompt=null,this.U.record(new fe(this.U,Xe.re(this.Qt),this.Xt.value),!0)},this.Qt.value=this.U.song.beatsPerBar+"",this.Qt.min=e.beatsPerBarMin+"",this.Qt.max=e.beatsPerBarMax+"";const i=window.localStorage.getItem("beatCountStrategy");null!=i&&(this.Xt.value=i),this.Qt.select(),setTimeout((()=>this.Qt.focus())),this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.Qt.addEventListener("keypress",Xe.ne),this.Qt.addEventListener("blur",Xe.he),this.container.addEventListener("keydown",this.oe)}static ne(t){const e=t.which?t.which:t.keyCode;return 46!=e&&e>31&&(e<48||e>57)&&(t.preventDefault(),!0)}static he(t){const e=t.target;e.value=String(Xe.re(e))}static re(t){return Math.floor(Math.max(Number(t.min),Math.min(Number(t.max),Number(t.value))))}}const{button:ti,div:ei,h2:ii,input:si}=k;class ni{constructor(t){this.U=t,this.ae=si({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.le=si({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.ce=si({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.de=si({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.ue=si({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.te=ti({class:"cancelButton"}),this.ee=ti({class:"okayButton",style:"width:45%;"},"Okay"),this.container=ei({class:"prompt noSelection",style:"width: 250px;"},ii("Channel Settings"),ei({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},"Pitch channels:",this.ce),ei({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},"Drum channels:",this.de),ei({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},"Mod channels:",this.ue),ei({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},"Patterns per channel:",this.ae),ei({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},"Instruments per channel:",this.le),ei({style:"display: flex; flex-direction: row-reverse; justify-content: space-between;"},this.ee),this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.ae.removeEventListener("keypress",ni.ne),this.le.removeEventListener("keypress",ni.ne),this.ce.removeEventListener("keypress",ni.ne),this.de.removeEventListener("keypress",ni.ne),this.ue.removeEventListener("keypress",ni.ne),this.ae.removeEventListener("blur",ni.he),this.le.removeEventListener("blur",ni.he),this.ce.removeEventListener("blur",ni.he),this.de.removeEventListener("blur",ni.he),this.ue.removeEventListener("blur",ni.he),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se()},this.se=()=>{const t=new nt;t.append(new oe(this.U,ni.re(this.ae))),t.append(new Jt(this.U,ni.re(this.le))),t.append(new kt(this.U,ni.re(this.ce),ni.re(this.de),ni.re(this.ue))),this.U.prompt=null,this.U.record(t,!0)},this.ae.value=this.U.song.patternsPerChannel+"",this.ae.min="1",this.ae.max=e.barCountMax+"",this.le.value=this.U.song.instrumentsPerChannel+"",this.le.min=e.instrumentsPerChannelMin+"",this.le.max=e.instrumentsPerChannelMax+"",this.ce.value=this.U.song.pitchChannelCount+"",this.ce.min=e.pitchChannelCountMin+"",this.ce.max=e.pitchChannelCountMax+"",this.de.value=this.U.song.noiseChannelCount+"",this.de.min=e.noiseChannelCountMin+"",this.de.max=e.noiseChannelCountMax+"",this.ue.value=this.U.song.modChannelCount+"",this.ue.min=e.modChannelCountMin+"",this.ue.max=e.modChannelCountMax+"",this.ce.select(),setTimeout((()=>this.ce.focus())),this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.ae.addEventListener("keypress",ni.ne),this.le.addEventListener("keypress",ni.ne),this.ce.addEventListener("keypress",ni.ne),this.de.addEventListener("keypress",ni.ne),this.ue.addEventListener("keypress",ni.ne),this.ae.addEventListener("blur",ni.he),this.le.addEventListener("blur",ni.he),this.ce.addEventListener("blur",ni.he),this.de.addEventListener("blur",ni.he),this.ue.addEventListener("blur",ni.he),this.container.addEventListener("keydown",this.oe)}static ne(t){const e=t.which?t.which:t.keyCode;return 46!=e&&e>31&&(e<48||e>57)&&(t.preventDefault(),!0)}static he(t){const e=t.target;e.value=String(ni.re(e))}static re(t){return Math.floor(Math.max(Number(t.min),Math.min(Number(t.max),Number(t.value))))}}const{button:hi,div:oi,h2:ri}=k;class ai{constructor(t){this.st=0,this.fe=0,this.me=0,this.pe=0,this.nt=!1,this.chipData=new Float64Array(64),this.startingChipData=new Float64Array(64),this.ye=0,this.ge=[],this.j=768,this.W=294,this.be=x.path({fill:T.uiWidgetBackground,"pointer-events":"none"}),this.ve=x.svg({"pointer-events":"none"}),this.we=x.svg({"pointer-events":"none"}),this.ke=x.svg({"pointer-events":"none"}),this.it=x.svg({style:`background-color: ${T.editorBackground}; touch-action: none; overflow: visible;`,width:"100%",height:"100%",viewBox:"0 0 "+this.j+" "+this.W,preserveAspectRatio:"none"},this.be,this.ve,this.we,this.ke),this.container=k.div({class:"",style:"height: 294px; width: 768px; padding-bottom: 1.5em;"},this.it),this.xe=()=>{var t=!0;if(this.ge.length>0)for(var e=0;e<64;e++)this.ge[this.ye][e]!=this.chipData[e]&&(t=!1,e=64);0!=t&&0!=this.ge.length||(this.ge.splice(0,this.ye),this.ye=0,this.ge.unshift(this.chipData.slice()),this.ge.length>32&&this.ge.pop())},this.undo=()=>{this.ye{this.ye>0&&(this.ye--,this.chipData=this.ge[this.ye].slice(),new ct(this.U,this.chipData),this.render())},this.oe=t=>{90==t.keyCode&&(this.undo(),t.stopPropagation()),89==t.keyCode&&(this.redo(),t.stopPropagation())},this.yt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.me=-1,this.wt()},this.bt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.me=-1,this.wt()},this.vt=t=>{if(null==this.container.offsetParent)return;const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.kt=t=>{if(null==this.container.offsetParent)return;if(!this.nt)return;t.preventDefault();const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.xt=t=>{this.xe(),this.nt=!1},this.U=t;for(let t=0;t<=4;t+=2)this.ve.appendChild(x.rect({fill:T.tonic,x:t*this.j/4-1,y:0,width:2,height:this.W}));for(let t=1;t<=8;t++)this.we.appendChild(x.rect({fill:T.fifthNote,x:t*this.j/8-1,y:0,width:1,height:this.W}));this.ve.appendChild(x.rect({fill:T.tonic,x:0,y:this.W/2-1,width:this.j,height:2}));for(let t=0;t<3;t++)this.we.appendChild(x.rect({fill:T.fifthNote,x:0,y:8*t*(this.W/49),width:this.j,height:1})),this.we.appendChild(x.rect({fill:T.fifthNote,x:0,y:this.W-1-8*t*(this.W/49),width:this.j,height:1}));let e=T.getChannelColor(this.U.song,this.U.channel).primaryNote;for(let t=0;t<=64;t++){let i=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].customChipWave[t];this.chipData[t]=i,this.startingChipData[t]=i,this.ke.appendChild(x.rect({fill:e,x:t*this.j/64,y:(i+24)*(this.W/49),width:this.j/64,height:this.W/49}))}this.xe(),this.container.addEventListener("mousedown",this.yt),document.addEventListener("mousemove",this.vt),document.addEventListener("mouseup",this.xt),this.container.addEventListener("touchstart",this.bt),this.container.addEventListener("touchmove",this.kt),this.container.addEventListener("touchend",this.xt),this.container.addEventListener("touchcancel",this.xt),this.it.addEventListener("keydown",this.oe),this.container.addEventListener("keydown",this.oe)}wt(){if(this.nt){const h=Math.min(63,Math.max(0,Math.floor(64*this.st/this.j))),o=Math.min(48,Math.max(0,Math.floor(49*this.fe/this.W)));if(-1!=this.me&&this.me!=h){var t=h,e=this.me,i=o,s=this.pe;this.me{this.U.synth.playing?(this.Me.Se(),this.updatePlayButton()):(this.U.synth.snapToBar(),this.Me.qe(),this.updatePlayButton())},this.ie=()=>{this.U.prompt=null,this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.container.removeEventListener("keydown",this.whenKeyPressed),this.Ee.removeEventListener("click",this.Ce)},this.whenKeyPressed=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se(),32==t.keyCode&&(this.Ce(),t.preventDefault()),90==t.keyCode&&(this.customChipCanvas.undo(),t.stopPropagation()),89==t.keyCode&&(this.customChipCanvas.redo(),t.stopPropagation())},this.se=()=>{this.U.prompt=null,new ct(this.U,this.customChipCanvas.startingChipData),this.U.record(new ct(this.U,this.customChipCanvas.chipData),!0)},this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.container.addEventListener("keydown",this.whenKeyPressed),this.Ee.addEventListener("click",this.Ce),this.updatePlayButton(),setTimeout((()=>this.Ee.focus())),this.customChipCanvas.render()}updatePlayButton(){this.U.synth.playing?(this.Ee.classList.remove("playButton"),this.Ee.classList.add("pauseButton"),this.Ee.title="Pause (Space)",this.Ee.innerText="Pause"):(this.Ee.classList.remove("pauseButton"),this.Ee.classList.add("playButton"),this.Ee.title="Play (Space)",this.Ee.innerText="Play")}}function ci(t,e){const i=new ArrayBuffer(e);let s=0,n=Math.min(t.byteLength,i.byteLength);const h=[8,4,2,1];for(const e of h)if(n>=e){const h=o(e,t,i,s,n);s=h.nextOffset,n=h.leftBytes}return i;function o(t,e,i,s,n){let h=Uint8Array;switch(t){case 8:h=Float64Array;break;case 4:h=Float32Array;break;case 2:h=Uint16Array;break;case 1:default:h=Uint8Array}const o=new h(e,s,n/t|0),r=new h(i,s,n/t|0);for(let t=0;tthis.Be.byteLength&&(this.Be=ci(this.Be,Math.max(2*this.Be.byteLength,this.Te)),this.ze=new DataView(this.Be))}getWriteIndex(){return this.Pe}rewriteUint32(t,e){this.ze.setUint32(t,e>>>0,!1)}writeUint32(t){t>>>=0,this.Re(4),this.ze.setUint32(this.Pe,t,!1),this.Pe=this.Te}writeUint24(t){t>>>=0,this.Re(3),this.ze.setUint8(this.Pe,t>>16&255),this.ze.setUint8(this.Pe+1,t>>8&255),this.ze.setUint8(this.Pe+2,255&t),this.Pe=this.Te}writeUint16(t){t>>>=0,this.Re(2),this.ze.setUint16(this.Pe,t,!1),this.Pe=this.Te}writeUint8(t){t>>>=0,this.Re(1),this.ze.setUint8(this.Pe,t),this.Pe=this.Te}writeInt8(t){t|=0,this.Re(1),this.ze.setInt8(this.Pe,t),this.Pe=this.Te}writeMidi7Bits(t){if((t>>>=0)>=128)throw new Error("7 bit value contained 8th bit!");this.Re(1),this.ze.setUint8(this.Pe,t),this.Pe=this.Te}writeMidiVariableLength(t){if((t>>>=0)>268435455)throw new Error("writeVariableLength value too big.");let e=!1;for(let i=0;i<4;i++){const s=t>>>21-7*i&127;0==s&&3!=i||(e=!0),e&&this.writeUint8((3==i?0:128)|s)}}writeMidiAscii(t){this.writeMidiVariableLength(t.length);for(let e=0;e127)throw new Error("Trying to write unicode character as ascii.");this.writeUint8(i)}}toCompactArrayBuffer(){return ci(this.Be,this.Te)}}const ui=8192,fi={35:{frequency:0,duration:2,volume:3},36:{frequency:0,duration:2,volume:3},37:{frequency:5,duration:1,volume:3},38:{frequency:4,duration:2,volume:3},39:{frequency:5,duration:2,volume:3},40:{frequency:4,duration:2,volume:3},41:{frequency:1,duration:2,volume:3},42:{frequency:8,duration:1,volume:3},43:{frequency:1,duration:2,volume:3},44:{frequency:8,duration:1,volume:2},45:{frequency:2,duration:2,volume:3},46:{frequency:8,duration:4,volume:3},47:{frequency:2,duration:2,volume:3},48:{frequency:3,duration:2,volume:3},49:{frequency:7,duration:4,volume:3},50:{frequency:3,duration:2,volume:3},51:{frequency:6,duration:4,volume:2},52:{frequency:7,duration:4,volume:3},53:{frequency:6,duration:2,volume:3},54:{frequency:11,duration:2,volume:3},55:{frequency:9,duration:4,volume:3},56:{frequency:7,duration:1,volume:2},57:{frequency:7,duration:4,volume:3},58:{frequency:10,duration:2,volume:2},59:{frequency:6,duration:4,volume:3},69:{frequency:10,duration:2,volume:3},70:{frequency:10,duration:2,volume:3},73:{frequency:10,duration:1,volume:2},74:{frequency:10,duration:2,volume:2}};function mi(t){return Math.pow(t/127,4)/.3844015376046128}const{button:pi,div:yi,h2:gi,input:bi,select:vi,option:wi}=k;function ki(t,e,i){return t+i*(e-t)}function xi(t,e){if(navigator.msSaveOrOpenBlob)return void navigator.msSaveOrOpenBlob(t,e);const i=document.createElement("a");if(null!=i.download){const s=URL.createObjectURL(t);setTimeout((function(){URL.revokeObjectURL(s)}),6e4),i.href=s,i.download=e,setTimeout((function(){i.dispatchEvent(new MouseEvent("click"))}),0)}else{const e=URL.createObjectURL(t);setTimeout((function(){URL.revokeObjectURL(e)}),6e4),window.open(e,"_blank")||(window.location.href=e)}}class Mi{constructor(t){this.U=t,this.Ne=bi({type:"text",style:"width: 10em;",value:"BeepBox-Song",maxlength:250,autofocus:"autofocus"}),this.Fe=yi({style:"width: 10em;"},new Text("0:00")),this.Le=bi({type:"checkbox"}),this.Ae=bi({style:"width: 2em;",type:"number",min:"1",max:"4",step:"1"}),this.He=bi({type:"checkbox"}),this.De=vi({style:"width: 100%;"},wi({value:"wav"},"Export to .wav file."),wi({value:"mp3"},"Export to .mp3 file."),wi({value:"midi"},"Export to .mid file."),wi({value:"json"},"Export to .json file.")),this.te=pi({class:"cancelButton"}),this.$e=pi({class:"exportButton",style:"width:45%;"},"Export"),this.container=yi({class:"prompt noSelection",style:"width: 200px;"},gi("Export Options"),yi({style:"display: flex; flex-direction: row; align-items: center; justify-content: space-between;"},"File name:",this.Ne),yi({style:"display: flex; flex-direction: row; align-items: center; justify-content: space-between;"},"Length:",this.Fe),yi({style:"display: table; width: 100%;"},yi({style:"display: table-row;"},yi({style:"display: table-cell;"},"Intro:"),yi({style:"display: table-cell;"},"Loop Count:"),yi({style:"display: table-cell;"},"Outro:")),yi({style:"display: table-row;"},yi({style:"display: table-cell; vertical-align: middle;"},this.Le),yi({style:"display: table-cell; vertical-align: middle;"},this.Ae),yi({style:"display: table-cell; vertical-align: middle;"},this.He))),yi({class:"selectContainer",style:"width: 100%;"},this.De),yi({style:"text-align: left;"},"(Be patient, exporting may take some time...)"),yi({style:"display: flex; flex-direction: row-reverse; justify-content: space-between;"},this.$e),this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.Ne.removeEventListener("input",Mi.Ie),this.Ae.removeEventListener("blur",Mi.he),this.$e.removeEventListener("click",this._e),this.te.removeEventListener("click",this.ie),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this._e()},this._e=()=>{switch(window.localStorage.setItem("exportFormat",this.De.value),this.De.value){case"wav":this.Oe();break;case"mp3":this.Ue();break;case"midi":this.Ve();break;case"json":this.je();break;default:throw new Error("Unhandled file export type.")}},this.Ae.value="1",0==this.U.song.loopStart?(this.Le.checked=!1,this.Le.disabled=!0):(this.Le.checked=!0,this.Le.disabled=!1),this.U.song.loopStart+this.U.song.loopLength==this.U.song.barCount?(this.He.checked=!1,this.He.disabled=!0):(this.He.checked=!0,this.He.disabled=!1);const e=window.localStorage.getItem("exportFormat");null!=e&&(this.De.value=e),this.Ne.select(),setTimeout((()=>this.Ne.focus())),this.Ne.addEventListener("input",Mi.Ie),this.Ae.addEventListener("blur",Mi.he),this.$e.addEventListener("click",this._e),this.te.addEventListener("click",this.ie),this.He.addEventListener("click",(()=>{this.Fe.firstChild.textContent=this.samplesToTime(this.U.synth.getTotalSamples(this.Le.checked,this.He.checked,+this.Ae.value-1))})),this.Le.addEventListener("click",(()=>{this.Fe.firstChild.textContent=this.samplesToTime(this.U.synth.getTotalSamples(this.Le.checked,this.He.checked,+this.Ae.value-1))})),this.Ae.addEventListener("change",(()=>{this.Fe.firstChild.textContent=this.samplesToTime(this.U.synth.getTotalSamples(this.Le.checked,this.He.checked,+this.Ae.value-1))})),this.container.addEventListener("keydown",this.oe),this.Ne.value=t.song.title,Mi.Ie(null,this.Ne),this.Fe.firstChild.textContent=this.samplesToTime(this.U.synth.getTotalSamples(this.Le.checked,this.He.checked,+this.Ae.value-1))}samplesToTime(t){const e=Math.round(t/this.U.synth.samplesPerSecond),i=e%60;return Math.floor(e/60)+":"+(i<10?"0":"")+i}changeFileName(t){this.Ne.value=t}static Ie(t,e){let i;if(null!=t)i=t.target;else{if(null==e)return;i=e}const s=/[\+\*\$\?\|\{\}\\\/<>#%!`&'"=:@]/gi;if(s.test(i.value)){let t=i.selectionStart;i.value=i.value.replace(s,""),t--,i.setSelectionRange(t,t)}}static he(t){const e=t.target;e.value=Math.floor(Math.max(Number(e.min),Math.min(Number(e.max),Number(e.value))))+""}We(t){const e=new tt(this.U.song);if(e.samplesPerSecond=t,e.loopRepeatCount=Number(this.Ae.value)-1,!this.Le.checked)for(let t=0;t{const{recordedSamplesL:t,recordedSamplesR:e}=this.We(44100),i=1152,s=new window.lamejs.Mp3Encoder(2,44100,192),n=[],h=new Int16Array(t.length),o=new Int16Array(e.length);for(let i=0;i0&&n.push(a)}const r=s.flush();r.length>0&&n.push(r);xi(new Blob(n,{type:"audio/mp3"}),this.Ne.value.trim()+".mp3"),this.ie()};if("lamejs"in window)t();else{var e=document.createElement("script");e.src="https://cdn.jsdelivr.net/npm/lamejs@1.2.0/lame.min.js",e.onload=t,document.head.appendChild(e)}}Ve(){const t=this.U.song,i=2*e.ticksPerPart*e.partsPerBeat,s=2*e.ticksPerPart,n=t.getBeatsPerMinute(),h=Math.round(6e7/n),r=i*t.beatsPerBar,a=24,l=[];if(this.Le.checked)for(let e=0;e=16)continue;d.push({isMeta:!1,channel:t,midiChannel:u++,isNoise:this.U.song.getChannelIsNoise(t),isDrumset:!1}),9==u&&u++}else d.push({isMeta:!1,channel:t,midiChannel:9,isNoise:!0,isDrumset:!0}),f=!0;const m=new di(1024);m.writeUint32(1297377380),m.writeUint32(6),m.writeUint16(1),m.writeUint16(d.length),m.writeUint16(i);for(const n of d){m.writeUint32(1297379947);const{isMeta:d,channel:u,midiChannel:f,isNoise:g,isDrumset:b}=n,v=m.getWriteIndex();m.writeUint32(0);let w=0,k=0;const x=function(t){if(t=0&&e<=127))throw new Error("Midi control event value out of range: "+e);m.writeUint8(176|f),m.writeMidi7Bits(t),m.writeMidi7Bits(0|e)};if(d){x(0),m.writeUint8(255),m.writeMidi7Bits(1),m.writeMidiAscii("Composed with jummbus.bitbucket.io"),x(0),m.writeUint8(255),m.writeMidi7Bits(81),m.writeMidiVariableLength(3),m.writeUint24(h),x(0),m.writeUint8(255),m.writeMidi7Bits(88),m.writeMidiVariableLength(4),m.writeUint8(t.beatsPerBar),m.writeUint8(2),m.writeUint8(24),m.writeUint8(8);const i=e.scales[t.scale].flags[3]&&!e.scales[t.scale].flags[4],s=t.key;let n=s;for(1==(1&s)&&(n+=6),i&&(n+=9);n>6;)n-=12;x(0),m.writeUint8(255),m.writeMidi7Bits(89),m.writeMidiVariableLength(2),m.writeInt8(n),m.writeUint8(i?1:0),this.Le.checked&&(k+=r*t.loopStart),x(k),m.writeUint8(255),m.writeMidi7Bits(6),m.writeMidiAscii("Loop Start");for(let e=0;es.chipWave&&(t=e[s.chipWave])}else if(6==s.type)t=i?25:81;else if(1==s.type||5==s.type)t=i?2:81;else{if(7!=s.type)throw new Error("Unrecognized instrument type.");t=i?25:81}}x(k),m.writeUint8(192|f),m.writeMidi7Bits(t)}x(k);let t=(o=tt.instrumentVolumeToVolumeMult(s.volume),127*Math.pow(.3844015376046128*o,.25));M(7,Math.min(127,Math.round(t))),x(k);let r=63*(s.pan/e.panCenter-1)+64;M(10,Math.min(127,Math.round(r)))}var o}null==t.getPattern(u,0)&&p(0);let d=ui,v=127,w=!1;const E=g?e.spectrumBasePitch:e.keys[t.key].basePitch,C=g?e.noiseInterval:1;for(const n of l){const h=t.getPattern(u,n);if(null!=h){const n=h.instrument,r=t.channels[u].instruments[n],l=c.valueToPreset(r.preset);p(n);let S=!1,q=!0,P=1;S=r.getChord().harmonizes,q=r.getChord().arpeggiates,q?S&&(0==r.type?P=2:1==r.type?P=e.operatorCount:console.error("Unrecognized instrument type for harmonizing arpeggio: "+r.type)):P=e.maxChordSize;for(let t=0;t>7&127),d=$),I==v||b||(x(h),M(11,I),v=I);const _=h==u;for(let t=0;t=t.length)throw new Error("Could not find corresponding drumset pitch. "+a);a=t[a]}else{if(q&&n.pitches.length>t+1&&t==R-1){const l=(h-k)%i,c=e.ticksPerArpeggio*s/e.ticksPerPart,d=Math.floor(l/c);a=n.pitches[t+o(n.pitches.length-t,r.fastTwoNoteArp,d)]}a=E+a*C+L,null!=l&&null!=l.midiSubharmonicOctaves?a+=12*l.midiSubharmonicOctaves:g&&(a+=12*+c.presetCategories.dictionary["Drum Presets"].presets.dictionary["taiko drum"].midiSubharmonicOctaves),g&&(a*=2)}a=Math.max(0,Math.min(127,a)),z[t]=a,_||B[t]==z[t]||(x(h),m.writeUint8(128|f),m.writeMidi7Bits(B[t]),m.writeMidi7Bits(N))}for(let t=0;t>7&127)));k+=r}}x(k),m.writeUint8(255),m.writeMidi7Bits(47),m.writeMidiVariableLength(0),m.rewriteUint32(v,m.getWriteIndex()-v-4)}var y;xi(new Blob([m.toCompactArrayBuffer()],{type:"audio/midi"}),this.Ne.value.trim()+".mid"),this.ie()}je(){const t=this.U.song.toJsonObject(this.Le.checked,Number(this.Ae.value),this.He.checked),e=JSON.stringify(t,null,"\t");xi(new Blob([e],{type:"application/json"}),this.Ne.value.trim()+".json"),this.ie()}}Mi.midiSustainInstruments=[74,71,80,70,70,68,68,81,81,81,81,81,81],Mi.midiDecayInstruments=[33,46,46,6,6,24,24,25,25,25,25,106,106];class Ei{constructor(t){this.U=t,this.j=112,this.W=26,this.Ge=x.svg({"pointer-events":"none"}),this.Je=x.svg({"pointer-events":"none"}),this.Ke=x.path({fill:"none",stroke:"currentColor","stroke-width":2,"pointer-events":"none"}),this.Ye=[],this.Ze=x.svg({"pointer-events":"none"}),this.it=x.svg({style:"background-color: ${ColorConfig.editorBackground}; touch-action: none; cursor: crosshair;",width:"100%",height:"100%",viewBox:"0 0 "+this.j+" "+this.W,preserveAspectRatio:"none"},this.Ge,this.Je,this.Ke,this.Ze),this.container=k.div({class:"harmonics",style:"height: 2em;"},this.it),this.st=0,this.fe=0,this.Qe=0,this.Xe=0,this.nt=!1,this.ti=null,this.ei="",this.ii=!0,this.yt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.Qe=this.si(this.st),this.Xe=this.ni(this.fe),this.wt()},this.bt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.Qe=this.si(this.st),this.Xe=this.ni(this.fe),this.wt()},this.vt=t=>{if(null==this.container.offsetParent)return;const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.kt=t=>{if(null==this.container.offsetParent)return;if(!this.nt)return;t.preventDefault();const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.xt=t=>{this.nt&&(this.U.record(this.ti),this.ti=null),this.nt=!1};for(let t=1;t<=e.harmonicsControlPoints;t*=2)this.Ge.appendChild(x.rect({fill:T.tonic,x:(t-.5)*(this.j-8)/(e.harmonicsControlPoints-1)-1,y:0,width:2,height:this.W}));for(let t=3;t<=e.harmonicsControlPoints;t*=2)this.Je.appendChild(x.rect({fill:T.fifthNote,x:(t-.5)*(this.j-8)/(e.harmonicsControlPoints-1)-1,y:0,width:2,height:this.W}));for(let t=0;t<4;t++){const e=x.rect({fill:"currentColor",x:this.j-2*t-1,y:0,width:1,height:this.W});this.Ye.push(e),this.Ze.appendChild(e)}this.container.addEventListener("mousedown",this.yt),document.addEventListener("mousemove",this.vt),document.addEventListener("mouseup",this.xt),this.container.addEventListener("touchstart",this.bt),this.container.addEventListener("touchmove",this.kt),this.container.addEventListener("touchend",this.xt),this.container.addEventListener("touchcancel",this.xt)}si(t){return(e.harmonicsControlPoints-1)*t/(this.j-8)-.5}ni(t){return e.harmonicsMax*(1-t/this.W)}wt(){if(this.nt){const t=this.si(this.st),i=this.ni(this.fe),s=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()],n=s.harmonicsWave;if(t!=this.Qe){const s=(i-this.Xe)/(t-this.Qe),h=this.Xe-this.Qe*s,o=Math.ceil(Math.min(this.Qe,t)),r=Math.floor(Math.max(this.Qe,t));for(let t=o;t<=r;t++)t<0||t>=e.harmonicsControlPoints||(n.harmonics[t]=Math.max(0,Math.min(e.harmonicsMax,Math.round(t*s+h))))}n.harmonics[Math.max(0,Math.min(e.harmonicsControlPoints-1,Math.round(t)))]=Math.max(0,Math.min(e.harmonicsMax,Math.round(i))),this.Qe=t,this.Xe=i,this.ti=new Nt(this.U,s,n),this.U.setProspectiveChange(this.ti)}}render(){const t=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].harmonicsWave,i=t=>(1-t/e.harmonicsMax)*this.W;let s=l(this.W),n="";for(let h=0;h{this.U.lastChangeWas(this.ti)||(this.ri=this.oi),this.ti=this.hi(this.ri,this.input.value),this.U.setProspectiveChange(this.ti)},this.li=()=>{this.U.record(this.ti),this.ti=null},t.addEventListener("input",this.ai),t.addEventListener("change",this.li)}updateValue(t){this.oi=t,this.input.value=String(t)}}class qi{constructor(t,e,i,s){this.input=t,this.U=e,this.hi=i,this.ti=null,this.oi=0,this.ri=0,this.ai=()=>{this.U.lastChangeWas(this.ti)||(this.ri=this.oi),null!=this.hi&&(this.ti=this.hi(this.ri,parseInt(this.input.value)),this.U.setProspectiveChange(this.ti))},this.li=()=>{null!=this.hi&&(this.U.record(this.ti),this.ti=null)},this.container=Ci(s?{class:"midTick",style:"position: sticky; width: 61.5%;"}:{style:"position: sticky;"},t),t.addEventListener("input",this.ai),t.addEventListener("change",this.li)}updateValue(t){this.oi=t,this.input.value=String(t)}}class Pi{constructor(t){this.q=0,this.ze=t}getReadIndex(){return this.q}readUint32(){if(this.q+4>this.ze.byteLength)throw new Error("Reading past the end of the buffer.");const t=this.ze.getUint32(this.q,!1);return this.q+=4,t}readUint24(){return this.readUint8()<<16|this.readUint8()<<8|this.readUint8()}readUint16(){if(this.q+2>this.ze.byteLength)throw new Error("Reading past the end of the buffer.");const t=this.ze.getUint16(this.q,!1);return this.q+=2,t}readUint8(){if(this.q+1>this.ze.byteLength)throw new Error("Reading past the end of the buffer.");const t=this.ze.getUint8(this.q);return this.q++,t}readInt8(){if(this.q+1>this.ze.byteLength)throw new Error("Reading past the end of the buffer.");const t=this.ze.getInt8(this.q);return this.q++,t}peakUint8(){if(this.q+1>this.ze.byteLength)throw new Error("Reading past the end of the buffer.");return this.ze.getUint8(this.q)}readMidi7Bits(){const t=this.readUint8();return t>=128&&console.log("7 bit value contained 8th bit! value "+t+", index "+this.q),127&t}readMidiVariableLength(){let t=0;for(let e=0;e<4;e++){const e=this.readUint8();if(t+=127&e,!(128&e))break;t<<=7}return t}skipBytes(t){this.q+=t}hasMore(){return this.ze.byteLength>this.q}getReaderForNextBytes(t){if(this.q+t>this.ze.byteLength)throw new Error("Reading past the end of the buffer.");const e=new Pi(new DataView(this.ze.buffer,this.ze.byteOffset+this.q,t));return this.skipBytes(t),e}}const{button:Ti,p:Bi,div:zi,h2:Ri,input:Ni}=k;class Fi{constructor(t){this.U=t,this.ci=Ni({type:"file",accept:".json,application/json,.mid,.midi,audio/midi,audio/x-midi"}),this.te=Ti({class:"cancelButton"}),this.container=zi({class:"prompt noSelection",style:"width: 300px;"},Ri("Import"),Bi({style:"text-align: left; margin: 0.5em 0;"},"BeepBox songs can be exported and re-imported as .json files. You could also use other means to make .json files for BeepBox as long as they follow the same structure."),Bi({style:"text-align: left; margin: 0.5em 0;"},"BeepBox can also (crudely) import .mid files. There are many tools available for creating .mid files. Shorter and simpler songs are more likely to work well."),this.ci,this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.ci.removeEventListener("change",this.di),this.te.removeEventListener("click",this.ie)},this.di=()=>{const t=this.ci.files[0];if(!t)return;const e=t.name.slice(2+(t.name.lastIndexOf(".")-1>>>0));if("json"==e){const e=new FileReader;e.addEventListener("load",(t=>{this.U.prompt=null,this.U.goBackToStart(),this.U.record(new be(this.U,e.result),!0,!0)})),e.readAsText(t)}else if("midi"==e||"mid"==e){const e=new FileReader;e.addEventListener("load",(t=>{this.U.prompt=null,this.U.goBackToStart(),this.ui(e.result)})),e.readAsArrayBuffer(t)}else console.error("Unrecognized file extension."),this.ie()},this.ci.select(),setTimeout((()=>this.ci.focus())),this.ci.addEventListener("change",this.di),this.te.addEventListener("click",this.ie)}ui(t){const i=new Pi(new DataView(t));let s=null;const n=[];for(;i.hasMore();){const t=i.readUint32(),e=i.readUint32();if(1297377380==t)null==s?s=i.getReaderForNextBytes(e):console.error("This MIDI file has more than one header chunk.");else if(1297379947==t){const t=i.getReaderForNextBytes(e);t.hasMore()&&n.push({reader:t,nextEventMidiTick:t.readMidiVariableLength(),ended:!1,runningStatus:-1})}else i.skipBytes(e)}if(null==s)return console.error("No header chunk found in this MIDI file."),void this.ie();const h=s.readUint16();s.readUint16();const o=s.readUint16();let r=0;const a=[],l=2==h;if(l)a.push(r);else for(let t=0;t0||x>e.beatsPerBarMax)&&x>=2*e.beatsPerBarMin;)x>>=1,s-=1;x=Math.max(e.beatsPerBarMin,Math.min(e.beatsPerBarMax,x))}else 89==t?(M=h.reader.readInt8(),E=1==h.reader.readUint8(),h.reader.skipBytes(i-2)):h.reader.skipBytes(i)}else{if(240!=s&&247!=s)return console.error("Unrecognized event status: "+s),void this.ie();{const t=h.reader.readMidiVariableLength();h.reader.skipBytes(t)}}break;default:return console.error("Unrecognized event type: "+o),void this.ie()}!q&&h.reader.hasMore()?h.nextEventMidiTick=C+h.reader.readMidiVariableLength():(h.ended=!0,l&&(r++,r0&&c>o&&(null==l||l.on)){const t=Math.floor(o/T),a=t*T;if(n!=t||null==h){for(n++;ny)&&(d.volume=y,d.pan=g,d.panDelay=0,r=!0);const l=[];let u=f,p=0,b=1;for(const t of s){const e=fi[t];-1==l.indexOf(e.frequency)&&l.push(e.frequency),b=Math.max(b,Math.round(e.volume*m)),u=Math.min(u,e.duration),p=Math.max(p,e.duration)}const v=Math.min(p,Math.max(u,2)),w=o-a,k=Math.min(T,Math.min(c-a,w+6*v)),x=new U(-1,w,k,b,!0);x.pitches.length=0;for(let t=0;t0&&b>B){const h=Math.floor(B/T),v=Math.ceil(b/T);for(let w=h;w=1:Math.floor(r)!=Math.floor($),f=c||u,p=Math.round(a),y=Math.abs(a-p)<.01,g=Math.abs(_-Math.round(_))?Math.abs(a-_)>=1:Math.floor(a)!=Math.floor(_),w=y||g;if($=r,_=a,f||w||o){const t={part:i,pitch:l,volume:p,keyPitch:f||o,keyVolume:w||o},e=T[B];let s=!1,n=Number.MAX_VALUE;if(t.keyPitch){const i=(t.pitch-e.pitch)/(t.part-e.part);let h=Math.abs(i),o=!1,r=Number.MAX_VALUE;for(let t=B+1;te;){let e=t.length-2,i=t.length-1,s=Number.MAX_VALUE,n=Number.MAX_VALUE;for(let h=0;h .editor-controls {\n\t\t\t\t\tposition: absolute;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .song-settings-area {\n\t\t\t\t\toverflow-y: auto;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t.beepboxEditor .settings-area {\n\t\t\t\t\twidth: 30em;\n\t\t\t\t\tgrid-template-columns: minmax(0, 1fr) minmax(0, 1fr);\n\t\t\t\t\tgrid-template-rows: auto auto auto minmax(0, 1fr);\n\t\t\t\t\tgrid-template-areas:\n\t\t\t\t\t\t"instrument-settings-area version-area"\n\t\t\t\t\t\t"instrument-settings-area play-pause-area"\n\t\t\t\t\t\t"instrument-settings-area menu-area"\n\t\t\t\t\t\t"instrument-settings-area song-settings-area";\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .trackAndMuteContainer {\n\t\t\t\t\tmax-height: calc( 100vh - 20px );\n\t\t\t\t}\n\n\t\t\t\t.beepboxEditor .barScrollBar {\n\t\t\t\t\tposition: absolute !important;\n\t\t\t\t}\n\n\t\t\t}\n\t\t',Li.mi=`\n\t\t\t/* full screen (beepbox) */\n\t\t\t@media (min-width: 701px) {\n\t\t\t\t#beepboxEditorContainer {\n\t\t\t\t\tmax-width: initial;\n\t\t\t\t\theight: 100vh;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor {\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\tmin-height: 100vh;\n\t\t\t\t\tgrid-template-columns: minmax(0, 1fr) 30em; /* minmax(0, 1fr) min-content; Chrome 80 grid layout regression. https://bugs.chromium.org/p/chromium/issues/detail?id=1050307 */\n\t\t\t\t\tgrid-template-rows: minmax(481px, 1fr) min-content;\n\t\t\t\t\tgrid-template-areas: "pattern-area settings-area" "track-area track-area";\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .pattern-area {\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\theight: 100%;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .track-area {\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\toverflow-y: auto;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .editor-widget-column {\n\t\t\t\t\tflex: 0;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .trackAndMuteContainer {\n\t\t\t\t\twidth: 100%;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .instrument-settings-area {\n\t\t\t\t\toverflow-y: auto;\n\t\t\t\t\tposition: relative;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .instrument-settings-area > .editor-controls {\n\t\t\t\t\tposition: absolute;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .song-settings-area {\n\t\t\t\t\toverflow-y: auto;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t.beepboxEditor .settings-area {\n\t\t\t\t\twidth: 30em;\n\t\t\t\t\tgrid-template-columns: minmax(0, 1fr) minmax(0, 1fr);\n\t\t\t\t\tgrid-template-rows: auto auto auto minmax(0, 1fr);\n\t\t\t\t\tgrid-template-areas:\n\t\t\t\t\t\t"instrument-settings-area version-area"\n\t\t\t\t\t\t"instrument-settings-area play-pause-area"\n\t\t\t\t\t\t"instrument-settings-area menu-area"\n\t\t\t\t\t\t"instrument-settings-area song-settings-area";\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t.beepboxEditor .barScrollBar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor.selectRow {\n\t\t\t\t\theight: 2em;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .operatorRow {\n\t\t\t\t\theiht: 2em;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .trackAndMuteContainer {\n\t\t\t\t\tmax-height: 446px;\n\t\t\t\t}\n\n\t\t\t\t.beepboxEditor .trackContainer {\n\t\t\t\t\toverflow-x: auto;\n\t\t\t\t\tscrollbar-width: auto;\n\t\t\t\t\tscrollbar-color: ${T.uiWidgetBackground} ${T.editorBackground};\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .trackContainer::-webkit-scrollbar {\n\t\t\t\t\twidth: 20px;\n\t\t\t\t\theight: 20px;\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .trackContainer::-webkit-scrollbar-track {\n\t\t\t\t\tbackground: ${T.editorBackground};\n\t\t\t\t}\n\t\t\t\t.beepboxEditor .trackContainer::-webkit-scrollbar-thumb {\n\t\t\t\t\tbackground-color: ${T.uiWidgetBackground};\n\t\t\t\t\tborder: 3px solid ${T.editorBackground};\n\t\t\t\t}\n\t\t\t}\n\t\t`,Li.o=document.head.appendChild(k.style({type:"text/css"}));const{button:Ai,div:Hi,h2:Di,input:$i,select:Ii,option:_i}=k;class Oi{constructor(t){this.U=t,this.yi=$i({style:"width: 3em; margin-left: 1em;",type:"number",step:"1",value:"0"}),this.gi=Ii({style:"width: 100%;"},_i({value:"normal"},"Normal Layout"),_i({value:"fullscreen"},"Full-screen Layout"),_i({value:"widefullscreen"},"Wide Full-screen Layout")),this.te=Ai({class:"cancelButton"}),this.ee=Ai({class:"okayButton",style:"width:45%;"},"Okay"),this.container=Hi({class:"prompt noSelection",style:"width: 250px;"},Di("Set Layout"),Hi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},Hi({style:"text-align: right;"},"Extra View Octaves:"),this.yi),Hi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},Hi({class:"selectContainer",style:"width: 100%;"},this.gi)),Hi({style:"display: flex; flex-direction: row-reverse; justify-content: space-between;"},this.ee),this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.yi.removeEventListener("blur",Oi.he),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se()},this.se=()=>{window.localStorage.setItem("fullScreen",this.gi.value),window.localStorage.setItem("extraOctaves",this.yi.value),this.U.prompt=null,this.U.fullScreen=this.gi.value,Li.setFullScreen(this.U.fullScreen),this.U.windowOctaves=+(window.localStorage.getItem("extraOctaves")||"0")+3,this.U.scrollableOctaves=e.pitchOctaves-this.U.windowOctaves,this.U.windowPitchCount=this.U.windowOctaves*e.pitchesPerOctave+1,this.U.undo()},this.yi.min="0",this.yi.max="2";const i=window.localStorage.getItem("extraOctaves");null!=i&&(this.yi.value=i);const s=window.localStorage.getItem("fullScreen");null!=s&&(this.gi.value=s),this.yi.select(),setTimeout((()=>this.yi.focus())),this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.yi.addEventListener("blur",Oi.he),this.container.addEventListener("keydown",this.oe)}static he(t){const e=t.target;let i=+e.value;e.value=Math.max(+e.min,Math.min(+e.max,i))+""}}const{button:Ui,div:Vi,h2:ji,input:Wi}=k;class Gi{constructor(t){this.j=200,this.W=52,this.be=x.path({fill:T.uiWidgetBackground,"pointer-events":"none"}),this.ve=x.svg({"pointer-events":"none"}),this.we=x.svg({"pointer-events":"none"}),this.bi=x.path({fill:"none",stroke:T.textSelection,"stroke-width":2,"pointer-events":"none"}),this.vi=x.circle({fill:T.textSelection,stroke:"none",r:"3"}),this.wi=x.path({fill:"none",stroke:T.primaryText,"stroke-width":2,"pointer-events":"none"}),this.ki=x.path({fill:"none",stroke:T.linkAccent,"stroke-width":2,"pointer-events":"none"}),this.xi=x.circle({fill:T.linkAccent,stroke:"none",r:"3"}),this.Mi=x.text({x:"-1.5%",y:"148.5%","pointer-events":"none","font-size":"7pt",fill:"var(--secondary-text)"},"0"),this.Ei=x.text({x:"48.2%",y:"148.5%","pointer-events":"none","font-size":"7pt",fill:"var(--secondary-text)"},"1"),this.Ci=x.text({x:"98.2%",y:"148.5%","pointer-events":"none","font-size":"7pt",fill:"var(--secondary-text)"},"2"),this.Si=x.text({x:"-5%",y:"113.5%","pointer-events":"none","font-size":"6pt",fill:"var(--secondary-text)"},"In"),this.qi=x.text({x:"-9%",y:"131%","pointer-events":"none","font-size":"6pt",fill:"var(--secondary-text)"},"Out"),this.Pi=x.text({x:"42%",y:"172%","pointer-events":"none","font-size":"7pt",fill:"var(--primary-text)"},"Volume"),this.Ti=x.text({x:"55.2%",y:"160%","pointer-events":"none","font-size":"7pt",transform:"rotate(-90 30,120)",fill:"var(--primary-text)"},"Gain"),this.Bi=x.rect({"pointer-events":"none",width:"100%",height:"6px",x:"0%",y:"105%",fill:T.uiWidgetBackground}),this.zi=x.rect({"pointer-events":"none",width:"100%",height:"6px",x:"0%",y:"120%",fill:T.uiWidgetBackground}),this.Ri=x.rect({"pointer-events":"none",height:"6px",x:"0%",y:"105%",fill:"url('#volumeGrad')"}),this.Ni=x.rect({"pointer-events":"none",width:"2px",height:"6px",y:"105%",fill:T.uiWidgetFocus}),this.Fi=x.rect({"pointer-events":"none",height:"6px",x:"0%",y:"120%",fill:"url('#volumeGrad')"}),this.Li=x.rect({"pointer-events":"none",width:"2px",height:"6px",y:"120%",fill:T.uiWidgetFocus}),this.Ai=x.stop({"stop-color":"lime",offset:"30%"}),this.Hi=x.stop({"stop-color":"orange",offset:"45%"}),this.Di=x.stop({"stop-color":"red",offset:"50%"}),this.$i=x.linearGradient({id:"volumeGrad",gradientUnits:"userSpaceOnUse"},this.Ai,this.Hi,this.Di),this.Ii=x.defs({},this.$i),this.it=x.svg({style:`background-color: ${T.editorBackground}; touch-action: none; overflow: visible;`,width:"100%",height:"100%",viewBox:"0 0 "+this.j+" "+this.W,preserveAspectRatio:"none"},this.Ii,this.be,this.ve,this.we,this.bi,this.wi,this.ki,this.vi,this.xi,this.Mi,this.Ei,this.Ci,this.Si,this.qi,this.Pi,this.Ti,this.Bi,this.zi,this.Ri,this.Fi,this.Ni,this.Li),this.container=k.div({class:"",style:"height: 4em; width: 80%; padding-bottom: 1.5em;"},this.it);for(let t=0;t<=2;t++)this.ve.appendChild(x.rect({fill:T.tonic,x:t*this.j/2-1,y:0,width:2,height:this.W}));for(let t=1;t<=3;t+=2)this.we.appendChild(x.rect({fill:T.fifthNote,x:t*this.j/4-1,y:0,width:1,height:this.W}));this._i=t}animateVolume(t,e,i,s){this.Ri.setAttribute("width",""+Math.min(this.j,t*(this.j/2))),this.Ni.setAttribute("x",""+Math.min(this.j,e*(this.j/2))),this.Fi.setAttribute("width",""+Math.min(this.j,i*(this.j/2))),this.Li.setAttribute("x",""+Math.min(this.j,s*(this.j/2)))}render(){const t=t=>Math.max(0,(1-t/5)*(this.W-1)+1);let e=0,i=0,s=-1,n="",h=["","",""];for(let o=0;o<64;o++){let r=+this._i.limitRatioSlider.value;r=r<10?r/10:r-9;let a=+this._i.compressionRatioSlider.value;a=a<10?a/10:1+(a-10)/60;let c=+this._i.limitThresholdSlider.value,d=+this._i.compressionThresholdSlider.value,u=2*o/64,f=1/1.05;u>=c?f=1/(1.05*(u+1-c)*r+(1-r)):us&&(s>=0&&(h[s]+="L "+l(o*this.j/64)+" "+l(t(f))+" "),h[i]+="M "+l(o*this.j/64)+" "+l(t(f))+" ",(1==i||0==s&&2==i)&&(this.vi.setAttribute("cx",l(o*this.j/64)),this.vi.setAttribute("cy",l(t(f)))),2==i&&(this.xi.setAttribute("cx",l(o*this.j/64)),this.xi.setAttribute("cy",l(t(f)))),s=i),0!=e||0!=f?(n+="L ",h[i]+="L "):(n+="M ",h[i]+="M "),n+=l(o*this.j/64)+" "+l(t(f))+" ",h[i]+=l(o*this.j/64)+" "+l(t(f))+" ",e=f,0==i&&o>=32*d-2&&i++,1==i&&o>=32*c-2&&i++}const o=t(e);e>0&&(n+="L "+(this.j-1)+" "+l(o)+" ",h[i]+="L "+(this.j-1)+" "+l(o)+" "),this.bi.setAttribute("d",h[0]),this.wi.setAttribute("d",h[1]),this.ki.setAttribute("d",h[2]),this.be.setAttribute("d",n+"L "+this.j+" "+l(o)+" L "+this.j+" "+l(this.W)+" L 0 "+l(this.W)+" z ")}}class Ji{constructor(t,e){this.U=t,this.Me=e,this.limiterCanvas=new Gi(this),this.Ee=Ui({style:"width: 55%;",type:"button"}),this.limitDecaySlider=Wi({title:"limit decay",style:"width: 5em; flex-grow: 1; margin: 0;",type:"range",min:"1",max:"30",value:"4",step:"1"}),this.limitRiseSlider=Wi({title:"limit rise",style:"width: 5em; flex-grow: 1; margin: 0;",type:"range",min:"2000",max:"10000",value:"4000",step:"250"}),this.compressionThresholdSlider=Wi({title:"compressor threshold",style:"width: 100%; flex-grow: 1; margin: 0;",type:"range",min:"0",max:"1.1",value:"1",step:"0.05"}),this.limitThresholdSlider=Wi({title:"limiter threshold",style:"width: 100%; flex-grow: 1; margin: 0;",type:"range",min:"0",max:"2",value:"1",step:"0.05"}),this.compressionRatioSlider=Wi({title:"compressor ratio",style:"width: 100%; flex-grow: 1; margin: 0;",type:"range",min:"0",max:"20",value:"10",step:"1"}),this.limitRatioSlider=Wi({title:"limiter ratio",style:"width: 100%; flex-grow: 1; margin: 0;",type:"range",min:"0",max:"20",value:"10",step:"1"}),this.masterGainSlider=Wi({title:"master gain",style:"width: 5em; flex-grow: 1; margin: 0;",type:"range",min:"0",max:"5",value:"1",step:"0.02"}),this.inVolumeHistoricTimer=0,this.inVolumeHistoricCap=0,this.outVolumeHistoricTimer=0,this.outVolumeHistoricCap=0,this.te=Ui({class:"cancelButton"}),this.ee=Ui({class:"okayButton",style:"width:45%;"},"Okay"),this.Oi=Ui({style:"width:45%;"},"Reset"),this.container=Vi({class:"prompt noSelection",style:"width: 250px;"},ji("Limiter Options"),Vi({style:"display: flex; width: 55%; align-self: center; flex-direction: row; align-items: center; justify-content: center;"},this.Ee),Vi({style:"display: flex; flex-direction: row; align-items: center; justify-content: center;"},this.limiterCanvas.container),Vi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; margin-top: 1.5em; justify-content: flex-end;"},Vi({style:`text-align: right; width: 25%; margin-right: 4.5%; color: ${T.primaryText};`},""),Vi({style:`text-align: center; width: 33%; margin-right: 4.5%; color: ${T.textSelection};`},"Boost"),Vi({style:`text-align: center; width: 33%; margin-right: 0%; color: ${T.linkAccent};`},"Cutoff")),Vi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; margin-top: 0.5em; justify-content: flex-end;"},Vi({style:`text-align: right; width: 25%; margin-right: 4.5%; color: ${T.primaryText};`},"Threshold:"),Vi({style:"width: 33%; margin-right: 4.5%;"},this.compressionThresholdSlider),Vi({style:"width: 33%; margin-right: 0%;"},this.limitThresholdSlider)),Vi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},Vi({style:`text-align: right; width: 25%; margin-right: 4.5%; color: ${T.primaryText};`},"Ratio:"),Vi({style:"width: 33%; margin-right: 4.5%;"},this.compressionRatioSlider),Vi({style:"width: 33%; margin-right: 0%;"},this.limitRatioSlider)),Vi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},Vi({style:`text-align: right; width: 8.5em; margin-right: 1em; color: ${T.primaryText};`},"Limit Decay:"),this.limitDecaySlider),Vi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},Vi({style:`text-align: right; width: 8.5em; margin-right: 1em; color: ${T.primaryText};`},"Limit Rise:"),this.limitRiseSlider),Vi({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},Vi({style:`text-align: right; width: 8.5em; margin-right: 1em; color: ${T.primaryText};`},"Master Gain:"),this.masterGainSlider),Vi({style:"display: flex; flex-direction: row-reverse; justify-content: space-between;"},this.ee,this.Oi),this.te),this.Ui=()=>{this.inVolumeHistoricTimer--,this.inVolumeHistoricTimer<=0&&(this.inVolumeHistoricCap-=.03),this.U.song.inVolumeCap>this.inVolumeHistoricCap&&(this.inVolumeHistoricCap=this.U.song.inVolumeCap,this.inVolumeHistoricTimer=50),this.outVolumeHistoricTimer--,this.outVolumeHistoricTimer<=0&&(this.outVolumeHistoricCap-=.03),this.U.song.outVolumeCap>this.outVolumeHistoricCap&&(this.outVolumeHistoricCap=this.U.song.outVolumeCap,this.outVolumeHistoricTimer=50),this.limiterCanvas.animateVolume(this.U.song.inVolumeCap,this.inVolumeHistoricCap,this.U.song.outVolumeCap,this.outVolumeHistoricCap),window.requestAnimationFrame(this.Ui)},this.Ce=()=>{this.U.synth.playing?(this.Me.Se(),this.updatePlayButton()):(this.U.synth.snapToBar(),this.Me.qe(),this.updatePlayButton())},this.ai=()=>{+this.limitThresholdSlider.value<+this.compressionThresholdSlider.value&&(this.limitThresholdSlider.removeEventListener("input",this.Vi),this.limitThresholdSlider.value=this.compressionThresholdSlider.value,this.limitThresholdSlider.addEventListener("input",this.Vi)),this.limiterCanvas.render(),this.ji()},this.Vi=()=>{+this.limitThresholdSlider.value<+this.compressionThresholdSlider.value&&(this.compressionThresholdSlider.removeEventListener("input",this.ai),this.compressionThresholdSlider.value=this.limitThresholdSlider.value,this.compressionThresholdSlider.addEventListener("input",this.ai)),this.limiterCanvas.render(),this.ji()},this.ie=()=>{this.limitRatioSlider.value=""+this.startingLimitRatio,this.compressionRatioSlider.value=""+this.startingCompressionRatio,this.limitThresholdSlider.value=""+this.startingLimitThreshold,this.compressionThresholdSlider.value=""+this.startingCompressionThreshold,this.limitDecaySlider.value=""+this.startingLimitDecay,this.limitRiseSlider.value=""+this.startingLimitRise,this.masterGainSlider.value=""+this.startingMasterGain,this.ji(),this.U.prompt=null},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.Oi.removeEventListener("click",this.Wi),this.te.removeEventListener("click",this.ie),this.container.removeEventListener("keydown",this.whenKeyPressed),this.limitDecaySlider.removeEventListener("input",this.ai),this.limitRiseSlider.removeEventListener("input",this.ai),this.limitThresholdSlider.removeEventListener("input",this.Vi),this.limitRatioSlider.removeEventListener("input",this.ai),this.compressionRatioSlider.removeEventListener("input",this.ai),this.compressionThresholdSlider.removeEventListener("input",this.ai),this.masterGainSlider.removeEventListener("input",this.ai),this.Ee.removeEventListener("click",this.Ce)},this.whenKeyPressed=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se(),32==t.keyCode&&(this.Ce(),t.preventDefault())},this.Wi=()=>{"10"==this.limitRatioSlider.value&&"4000"==this.limitRiseSlider.value&&"4"==this.limitDecaySlider.value&&"1"==this.limitThresholdSlider.value&&"10"==this.compressionRatioSlider.value&&"1"==this.compressionThresholdSlider.value&&"1"==this.masterGainSlider.value||(this.limitRatioSlider.value="10",this.limitRiseSlider.value="4000",this.limitDecaySlider.value="4",this.limitThresholdSlider.value="1",this.compressionRatioSlider.value="10",this.compressionThresholdSlider.value="1",this.masterGainSlider.value="1",this.ai())},this.ji=()=>{this.U.record(new vt(this.U,+this.limitRatioSlider.value<10?+this.limitRatioSlider.value/10:+this.limitRatioSlider.value-9,+this.compressionRatioSlider.value<10?+this.compressionRatioSlider.value/10:1+(+this.compressionRatioSlider.value-10)/60,+this.limitThresholdSlider.value,+this.compressionThresholdSlider.value,+this.limitRiseSlider.value,+this.limitDecaySlider.value,+this.masterGainSlider.value),!0)},this.se=()=>{this.ji(),this.U.prompt=null},this.ee.addEventListener("click",this.se),this.Oi.addEventListener("click",this.Wi),this.te.addEventListener("click",this.ie),this.container.addEventListener("keydown",this.whenKeyPressed),this.limitRatioSlider.value=""+(this.U.song.limitRatio<1?10*this.U.song.limitRatio:9+this.U.song.limitRatio),this.compressionRatioSlider.value=""+(this.U.song.compressionRatio<1?10*this.U.song.compressionRatio:10+60*(this.U.song.compressionRatio-1)),this.limitThresholdSlider.value=""+this.U.song.limitThreshold,this.compressionThresholdSlider.value=""+this.U.song.compressionThreshold,this.limitDecaySlider.value=""+this.U.song.limitDecay,this.limitRiseSlider.value=""+this.U.song.limitRise,this.masterGainSlider.value=""+this.U.song.masterGain,this.startingLimitRatio=+this.limitRatioSlider.value,this.startingCompressionRatio=+this.compressionRatioSlider.value,this.startingLimitThreshold=+this.limitThresholdSlider.value,this.startingCompressionThreshold=+this.compressionThresholdSlider.value,this.startingLimitDecay=+this.limitDecaySlider.value,this.startingLimitRise=+this.limitRiseSlider.value,this.startingMasterGain=+this.masterGainSlider.value,this.limitDecaySlider.addEventListener("input",this.ai),this.limitRiseSlider.addEventListener("input",this.ai),this.limitRatioSlider.addEventListener("input",this.ai),this.limitThresholdSlider.addEventListener("input",this.Vi),this.compressionRatioSlider.addEventListener("input",this.ai),this.compressionThresholdSlider.addEventListener("input",this.ai),this.masterGainSlider.addEventListener("input",this.ai),this.Ee.addEventListener("click",this.Ce),window.requestAnimationFrame(this.Ui),this.updatePlayButton(),this.limiterCanvas.render()}updatePlayButton(){this.U.synth.playing?(this.Ee.classList.remove("playButton"),this.Ee.classList.add("pauseButton"),this.Ee.title="Pause (Space)",this.Ee.innerText="Pause"):(this.Ee.classList.remove("pauseButton"),this.Ee.classList.add("playButton"),this.Ee.title="Play (Space)",this.Ee.innerText="Play")}}class Ki{constructor(t){this.U=t,this.W=20,this.Gi=0,this.Ji=1,this.Ki=2,this.Yi=x.path({fill:"none",stroke:T.loopAccent,"stroke-width":4}),this.Zi=x.path({fill:T.hoverPreview,"pointer-events":"none"}),this.it=x.svg({style:`background-color: ${T.editorBackground}; touch-action: pan-y; position: absolute;`,height:this.W},this.Yi,this.Zi),this.container=k.div({style:"height: 20px; position: relative; margin: 5px 0;"},this.it),this.Qi=32,this.ti=null,this.Xi={startBar:-1,mode:-1},this.st=0,this.ts=0,this.es=0,this.ss=!1,this.ns=!1,this.nt=!1,this.ht=!1,this.hs=-1,this.os=-1,this.rs=0,this.ls=-1,this.dt=t=>{this.ht||(this.ht=!0,this.ut())},this.ft=t=>{this.ht&&(this.ht=!1,this.ut())},this.yt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=(t.clientX||t.pageX)-e.left,this.cs(),this.ut(),this.vt(t)},this.bt=t=>{this.nt=!0;const e=this.it.getBoundingClientRect();this.st=t.touches[0].clientX-e.left,this.cs(),this.ut(),this.ts=t.touches[0].clientX,this.es=t.touches[0].clientY,this.ns=!1,this.ss=!1},this.vt=t=>{const e=this.it.getBoundingClientRect();this.st=(t.clientX||t.pageX)-e.left,this.wt()},this.kt=t=>{if(!this.nt)return;const e=this.it.getBoundingClientRect();this.st=t.touches[0].clientX-e.left,this.ns||this.ss||(Math.abs(t.touches[0].clientY-this.es)>10?this.ss=!0:Math.abs(t.touches[0].clientX-this.ts)>10&&(this.ns=!0)),this.ns&&(this.wt(),t.preventDefault())},this.ds=t=>{t.preventDefault(),this.ss||(this.wt(),this.ht=!1,this.xt(t),this.ut()),this.nt=!1},this.xt=t=>{null!=this.ti&&this.U.record(this.ti),this.ti=null,this.nt=!1,this.cs(),this.us()},this.fs=()=>{this.us()},this.cs(),this.us(),this.U.notifier.watch(this.fs),this.container.addEventListener("mousedown",this.yt),document.addEventListener("mousemove",this.vt),document.addEventListener("mouseup",this.xt),this.container.addEventListener("mouseover",this.dt),this.container.addEventListener("mouseout",this.ft),this.container.addEventListener("touchstart",this.bt),this.container.addEventListener("touchmove",this.kt),this.container.addEventListener("touchend",this.ds),this.container.addEventListener("touchcancel",this.ds)}cs(){const t=this.st/this.Qi;this.Xi.startBar=t,t>this.U.song.loopStart-.25&&tthis.U.song.barCount&&(e-=i-this.U.song.barCount,i=this.U.song.barCount),{start:e,length:i-e}}wt(){if(this.nt){let t=this.U.song.loopStart,e=this.U.song.loopStart+this.U.song.loopLength;null!=this.ti&&this.U.lastChangeWas(this.ti)&&(t=this.ti.oldStart,e=t+this.ti.oldLength);const i=this.st/this.Qi;let s,n,h;if(this.Xi.mode==this.Gi)s=t+Math.round(i-this.Xi.startBar),n=e,s<0&&(s=0),s>=this.U.song.barCount&&(s=this.U.song.barCount),s==n?s=n-1:s>n&&(h=s,s=n,n=h),this.ti=new Yt(this.U,t,e-t,s,n-s);else if(this.Xi.mode==this.Ji)s=t,n=e+Math.round(i-this.Xi.startBar),n<0&&(n=0),n>=this.U.song.barCount&&(n=this.U.song.barCount),n==s?n=s+1:n{this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.Qt.removeEventListener("blur",ns.he),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se()},this.se=()=>{window.localStorage.setItem("moveNotesSidewaysStrategy",this.Xt.value),this.U.prompt=null,this.U.record(new ue(this.U,+this.Qt.value,this.Xt.value),!0)},this.Qt.min=-this.U.song.beatsPerBar+"",this.Qt.max=this.U.song.beatsPerBar+"";const e=window.localStorage.getItem("moveNotesSidewaysStrategy");null!=e&&(this.Xt.value=e),this.Qt.select(),setTimeout((()=>this.Qt.focus()),100),this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.Qt.addEventListener("blur",ns.he),this.container.addEventListener("keydown",this.oe)}static he(t){const i=t.target;let s=+i.value;s=Math.round(s*e.partsPerBeat)/e.partsPerBeat,s=Math.round(100*s)/100,i.value=Math.max(+i.min,Math.min(+i.max,s))+""}}class hs{constructor(t,i){this.U=t,this.ys=i,this.gs=[],this.bs=[],this.vs=k.div({style:`background-color: ${T.uiWidgetFocus}; white-space:nowrap; display: none; transform:translate(20px); width: auto; pointer-events: none; position: absolute; border-radius: 0.2em; z-index: 2;`,color:T.primaryText},""),this.ws=new Si(k.input({style:`color: ${T.primaryText}; background-color: ${T.uiWidgetFocus}; margin-top: -2px; display: none; width: 6em; position: absolute; border-radius: 0.2em; z-index: 2;`,color:T.primaryText},""),this.U,((t,e)=>new De(this.U,t,e))),this.ks=k.select({style:"width: 0px; left: 19px; height: 19px; position:absolute; opacity:0"},k.option({value:"rename"},"Rename..."),k.option({value:"chnUp"},"Move Channel Up"),k.option({value:"chnDown"},"Move Channel Down"),k.option({value:"chnMute"},"Mute Channel"),k.option({value:"chnSolo"},"Solo Channel"),k.option({value:"chnInsert"},"Insert Channel Below"),k.option({value:"chnDelete"},"Delete This Channel")),this.container=k.div({class:"muteEditor",style:"position: relative; margin-top: "+e.barEditorHeight+"px;"},this.vs,this.ws.input,this.ks),this.W=128,this.xs=0,this.Ms=0,this.Es=0,this.Cs=0,this.Ss=-1,this.qs=0,this.Ps=!1,this.Ts=!1,this.Bs=()=>{let t=this.ws.input.value;t.length>15&&(this.ws.input.value=t.substring(0,15))},this.zs=t=>{t.stopPropagation()},this.Rs=()=>{this.ws.input.style.setProperty("display","none"),this.vs.style.setProperty("display","none")},this.Ns=t=>{this.Ps=!this.Ts,this.Fs(t)},this.Ls=()=>{this.Ps=!1,this.vs.style.setProperty("display","none")},this.Fs=t=>{this.Ts=this.Ps,this.qs=Math.floor(Math.min(this.xs,Math.max(0,parseInt(this.ks.style.getPropertyValue("top"))/this.Ss))),this.U.muteEditorChannel=this.qs,this.vs.style.setProperty("display",""),this.qs=this.U.song.pitchChannelCount&&this.qs=this.U.song.pitchChannelCount+this.U.song.noiseChannelCount&&this.U.song.modChannelCount==e.modChannelCountMax?this.ks.options[5].disabled=!0:this.ks.options[5].disabled=!1,0==this.qs||this.qs==this.U.song.pitchChannelCount||this.qs==this.U.song.pitchChannelCount+this.U.song.noiseChannelCount?this.ks.options[1].disabled=!0:this.ks.options[1].disabled=!1,this.qs==this.U.song.pitchChannelCount-1||this.qs==this.U.song.pitchChannelCount+this.U.song.noiseChannelCount-1||this.qs==this.U.song.getChannelCount()-1?this.ks.options[2].disabled=!0:this.ks.options[2].disabled=!1,1==this.U.song.pitchChannelCount&&0==this.qs?this.ks.options[6].disabled=!0:this.ks.options[6].disabled=!1},this.As=t=>{switch(this.vs.style.setProperty("display","none"),this.ks.style.setProperty("display","none"),this.Ps=!1,t.stopPropagation(),this.ks.value){case"rename":this.ws.input.style.setProperty("display",""),this.ws.input.style.setProperty("transform",this.vs.style.getPropertyValue("transform")),null!=this.vs.textContent?this.ws.input.value=this.vs.textContent:this.ws.input.value="",this.ws.input.select();break;case"chnUp":this.U.record(new wt(this.U,this.qs,this.qs-1));break;case"chnDown":this.U.record(new wt(this.U,this.qs,this.qs+1));break;case"chnMute":this.U.song.channels[this.qs].muted=!this.U.song.channels[this.qs].muted,this.render();break;case"chnSolo":{let t=!1;for(let e=0;ethis.qs+1;e--)this.U.record(new wt(this.U,e-1,e),!0);break}case"chnDelete":{let t=this.U.song.pitchChannelCount,e=this.U.song.noiseChannelCount,i=this.U.song.modChannelCount;if(this.qs=this.U.song.pitchChannelCount&&this.qs{const e=this.gs.indexOf(t.target);if(-1==e)return;t.clientX-this.gs[0].getBoundingClientRect().left<21&&(this.U.song.channels[e].muted=!this.U.song.channels[e].muted),this.U.notifier.changed()},this.Ds=t=>{const i=this.gs.indexOf(t.target);if(-1==i)return void(this.Ps||t.target==this.vs||t.target==this.ks||(this.vs.style.setProperty("display","none"),this.ks.style.setProperty("display","none"),this.ks.style.setProperty("width","0px")));if(t.clientX-this.gs[0].getBoundingClientRect().left>=21){if(!this.Ps){this.ks.style.setProperty("display","");var s=this.U.getChannelHeight();this.vs.style.setProperty("transform","translate(20px, "+(s/4+s*i)+"px)"),""!=this.U.song.channels[i].name?(this.vs.textContent=this.U.song.channels[i].name,this.vs.style.setProperty("display","")):(i{this.Ps||(this.vs.style.setProperty("display","none"),this.ks.style.setProperty("width","0px"))},this.container.addEventListener("click",this.Hs),this.container.addEventListener("mousemove",this.Ds),this.container.addEventListener("mouseleave",this.$s),this.ks.selectedIndex=-1,this.ks.addEventListener("change",this.As),this.ks.addEventListener("mousedown",this.Fs),this.ks.addEventListener("blur",this.Ls),this.ks.addEventListener("click",this.Ns),this.ws.input.addEventListener("change",this.Rs),this.ws.input.addEventListener("blur",this.Rs),this.ws.input.addEventListener("mousedown",this.zs),this.ws.input.addEventListener("input",this.Bs)}onKeyUp(t){switch(t.keyCode){case 27:case 13:this.Ps=!1,this.vs.style.setProperty("display","none")}}render(){if(!this.U.enableChannelMuting)return;const t=this.U.getChannelHeight();if(this.xs!=this.U.song.getChannelCount()){for(let t=this.xs;t=10?"xx-small":"inherit"}else if(t=10?"xx-small":"inherit"}else{let e=t-this.U.song.pitchChannelCount-this.U.song.noiseChannelCount+1;this.bs[t].textContent=e+"",this.bs[t].style.fontSize=e>=10?"xx-small":"inherit"}this.Ms=this.U.song.pitchChannelCount,this.Es=this.U.song.noiseChannelCount,this.Cs=this.U.song.modChannelCount}this.Ss==t&&this.xs==this.U.song.getChannelCount()||(this.Ss=t,this.xs=this.U.song.getChannelCount(),this.W=e.barEditorHeight+this.U.song.getChannelCount()*t,this.vs.style.setProperty("display","none"),this.container.style.height=this.W+"px",this.Ss<27?(this.vs.style.setProperty("margin-top","-2px"),this.ks.style.setProperty("margin-top","-4px"),this.ws.input.style.setProperty("margin-top","-4px")):this.Ss<30?(this.vs.style.setProperty("margin-top","-1px"),this.ks.style.setProperty("margin-top","-3px"),this.ws.input.style.setProperty("margin-top","-3px")):(this.vs.style.setProperty("margin-top","0px"),this.ks.style.setProperty("margin-top","0px"),this.ws.input.style.setProperty("margin-top","-2px")))}}class os{constructor(t,i){this.U=t,this.Is=i,this.j=20,this.W=481,this._s=4,this.Os=e.pitchOctaves,this.Us=(this.W-this._s)/this.Os,this.Vs=this.Us*this.U.windowOctaves+this._s,this.Y=x.rect({fill:T.uiWidgetBackground,x:2,y:0,width:this.j-4,height:this.Vs}),this.Z=x.rect({fill:"none",stroke:T.hoverPreview,"stroke-width":2,"pointer-events":"none",x:1,y:0,width:this.j-2,height:this.Vs}),this.js=x.path({fill:T.hoverPreview,"pointer-events":"none"}),this.Ws=x.path({fill:T.hoverPreview,"pointer-events":"none"}),this.it=x.svg({style:"background-color: ${ColorConfig.editorBackground}; touch-action: pan-x; position: absolute;",width:this.j,height:"100%",viewBox:"0 0 20 "+this.W,preserveAspectRatio:"none"}),this.container=k.div({id:"octaveScrollBarContainer",style:"width: 20px; height: 100%; overflow: hidden; position: relative; flex-shrink: 0;"},this.it),this.fe=0,this.nt=!1,this.ht=!1,this.ot=!1,this.Gs=-1,this.Js=-1,this.ti=null,this.dt=t=>{this.ht||(this.ht=!0,this.ut())},this.ft=t=>{this.ht&&(this.ht=!1,this.ut())},this.yt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.U.song.getChannelIsNoise(this.U.channel)||this.U.song.getChannelIsMod(this.U.channel)||(this.ut(),this.fe>=this.Ks-this.Vs&&this.fe<=this.Ks&&(this.ot=!0,this.ti=null,this.gt=this.fe))},this.bt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.U.song.getChannelIsNoise(this.U.channel)||this.U.song.getChannelIsMod(this.U.channel)||(this.ut(),this.fe>=this.Ks-this.Vs&&this.fe<=this.Ks&&(this.ot=!0,this.ti=null,this.gt=this.fe))},this.vt=t=>{const e=this.it.getBoundingClientRect();this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.wt()},this.kt=t=>{if(!this.nt)return;t.preventDefault();const e=this.it.getBoundingClientRect();this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.wt()},this.xt=t=>{if(!this.U.song.getChannelIsNoise(this.U.channel)&&!this.U.song.getChannelIsMod(this.U.channel)&&this.nt)if(this.ot)null!=this.ti&&this.U.record(this.ti);else{const t=this.U.lastChangeWas(this.ti),e=t?this.ti.oldValue:this.U.song.channels[this.U.channel].octave,i=this.U.song.channels[this.U.channel].octave;this.fe0&&(this.ti=new Qt(this.U,e,i-1),this.U.record(this.ti,t))}this.nt=!1,this.ot=!1,this.ut()},this.fs=()=>{this.Ks=this.W-this.Us*this.U.song.channels[this.U.channel].octave,this.us()},this.U.notifier.watch(this.fs),this.fs(),this.it.appendChild(this.Y);for(let t=0;t<=this.Os;t++)this.it.appendChild(x.rect({fill:T.tonic,x:0,y:t*this.Us,width:this.j,height:this._s}));this.it.appendChild(this.Z),this.it.appendChild(this.js),this.it.appendChild(this.Ws);const s=.5*this.j;this.js.setAttribute("d",`M ${s} 9 L ${s+6} 20 L ${s-6} 20 z`),this.Ws.setAttribute("d",`M ${s} ${this.W-9} L ${s+6} ${this.W-20} L ${s-6} ${this.W-20} z`),this.container.addEventListener("mousedown",this.yt),document.addEventListener("mousemove",this.vt),document.addEventListener("mouseup",this.xt),this.container.addEventListener("mouseover",this.dt),this.container.addEventListener("mouseout",this.ft),this.container.addEventListener("touchstart",this.bt),this.container.addEventListener("touchmove",this.kt),this.container.addEventListener("touchend",this.xt),this.container.addEventListener("touchcancel",this.xt)}wt(){if(!this.U.song.getChannelIsNoise(this.U.channel)&&!this.U.song.getChannelIsMod(this.U.channel)){if(this.ot){const t=this.U.song.channels[this.U.channel].octave,e=this.U.lastChangeWas(this.ti)?this.ti.oldValue:t;let i=t;for(;this.fe-this.gt<.5*-this.Us&&i.5*this.Us&&i>0;)i--,this.gt+=this.Us;this.ti=new Qt(this.U,e,i),this.U.setProspectiveChange(this.ti)}this.ht&&this.ut()}}ut(){let t=!1,e=!1,i=!1;this.ht&&!this.nt&&(this.fethis.Ks?e=!0:i=!0),this.js.style.visibility=t?"inherit":"hidden",this.Ws.style.visibility=e?"inherit":"hidden",this.Z.style.visibility=i?"inherit":"hidden"}us(){this.Vs=this.Us*this.U.windowOctaves+this._s,this.it.style.visibility=this.U.song.getChannelIsNoise(this.U.channel)||this.U.song.getChannelIsMod(this.U.channel)?"hidden":"visible",this.Gs==this.Ks&&this.Js==this.Vs||(this.Gs=this.Ks,this.Js=this.Vs,this.Y.setAttribute("height",""+this.Vs),this.Z.setAttribute("height",""+this.Vs),this.Y.setAttribute("y",""+(this.Ks-this.Vs)),this.Z.setAttribute("y",""+(this.Ks-this.Vs)),this.Is.forceRender()),this.ut()}}class rs{constructor(){this.valid=!1,this.prevNote=null,this.curNote=null,this.nextNote=null,this.pitch=0,this.pitchIndex=-1,this.curIndex=0,this.start=0,this.end=0,this.part=0,this.exactPart=0,this.nearPinIndex=0,this.pins=[]}}class as{constructor(t,i,s){this.U=t,this.Ys=i,this.Zs=s,this.controlMode=!1,this.shiftMode=!1,this.Qs=x.pattern({id:"patternEditorNoteBackground"+this.Zs,x:"0",y:"0",patternUnits:"userSpaceOnUse"}),this.Xs=x.pattern({id:"patternEditorDrumBackground"+this.Zs,x:"0",y:"0",patternUnits:"userSpaceOnUse"}),this.tn=x.pattern({id:"patternEditorModBackground"+this.Zs,x:"0",y:"0",patternUnits:"userSpaceOnUse"}),this.en=x.rect({x:"0",y:"0","pointer-events":"none",fill:"url(#patternEditorNoteBackground"+this.Zs+")"}),this.sn=x.svg(),this.nn=x.rect({x:"0",y:"0",width:"4",fill:T.playhead,"pointer-events":"none"}),this.hn=x.rect({class:"dashed-line dash-move",fill:T.boxSelectionFill,stroke:T.hoverPreview,"stroke-width":2,"stroke-dasharray":"5, 3","fill-opacity":"0.4","pointer-events":"none",visibility:"hidden"}),this.rn=x.path({fill:"none",stroke:T.hoverPreview,"stroke-width":"2","pointer-events":"none"}),this.modDragValueLabel=k.div({width:"90","text-anchor":"start",contenteditable:"true",style:"display: flex, justify-content: center; align-items:center; position:absolute; pointer-events: none;","dominant-baseline":"central"}),this.it=x.svg({style:`background-color: ${T.editorBackground}; touch-action: none; position: absolute;`,width:"100%",height:"100%"},x.defs(this.Qs,this.Xs,this.tn),this.en,this.hn,this.sn,this.rn,this.nn),this.container=k.div({style:"height: 100%; overflow:hidden; position: relative; flex-grow: 1;"},this.it,this.modDragValueLabel),this.an=34,this.ln=[],this.cn=x.rect(),this.dn=x.rect(),this.un=0,this.fn=0,this.mn=0,this.editingModLabel=!1,this.pn=0,this.yn=0,this.gn=6,this.bn=-1,this.st=0,this.fe=0,this.nt=!1,this.ht=!1,this.vn=!1,this.wn=!1,this.kn=!1,this.xn=[],this.Mn=0,this.En=0,this.Cn=0,this.Sn=!1,this.qn=!1,this.Pn=!1,this.Tn=!1,this.Bn=!1,this.zn=0,this.Rn=0,this.Nn=0,this.Fn=!1,this.Ln=null,this.An=null,this.Hn=!1,this.Xi=new rs,this.Dn=[],this.Kt=null,this.$n=0,this.In=0,this._n=-1,this.On=-1,this.Un=-1,this.Vn=-1,this.ii=!1,this.jn=!1,this.Wn=!1,this.Gn=-1,this.Jn=-1,this.Kn=-1,this.Yn=-1,this.Zn=-1,this.Qn=t=>{const e=t.target;let i=Number(e.innerText);if(!(!isNaN(i)&&i>=0&&i=10)+ +(t>=100)+ +(t<0)+ +(t<=-10);this.un=+l(Math.max(Math.min(this.j-10-8*s,this.Xn*(this.th.start+this.eh.time)-4-4*s),2)),this.modDragValueLabel.style.setProperty("left",this.un+"px");const n=new ht;this.Ln=n,this.U.setProspectiveChange(this.Ln),n.append(new Oe(this.U,this.th,this.eh.time,this.U.song.realToModValue(t,this.ih),this.eh.interval,this.shiftMode))}},this.resetCopiedPins=()=>{const t=this.sh();let e=this.U.song.getVolumeCap(!1);this.xn.length=this.U.song.getChannelCount(),this.Dn.length=this.U.song.getChannelCount();for(let i=0;i{this.kn&&!this.shiftMode&&!this.vn&&this.nt&&performance.now()>this.Cn+1e3&&this.Xi.valid&&this.U.lastChangeWas(this.Ln)&&(this.Ln.undo(),this.Sn=!0,this.qn=!1,this.hh(),this.U.notifier.notifyWatchers());const e=Math.floor(this.U.synth.playhead);if(this.U.synth.playing&&(null!=this.Kt&&this.U.song.getPattern(this.U.channel,Math.floor(this.U.synth.playhead))==this.Kt||Math.floor(this.U.synth.playhead)==this.U.bar+this.Zs)){this.nn.setAttribute("visibility","visible");const t=this.U.synth.playhead-e;Math.abs(t-this.$n)>.1?this.$n=t:this.$n+=.2*(t-this.$n),this.nn.setAttribute("x",""+l(this.$n*this.j-2))}else this.nn.setAttribute("visibility","hidden");this.U.synth.playing&&this.U.autoFollow&&this.Zn!=e&&(new xt(this.U,this.U.channel,e),this.U.notifier.notifyWatchers()),this.Zn=e,window.requestAnimationFrame(this.nh)},this.dt=t=>{this.ht||(this.ht=!0,this.kn=!1)},this.ft=t=>{this.ht&&(this.ht=!1)},this.yt=t=>{t.preventDefault();const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.kn=!1,this.Sn=t.shiftKey,this.qn=!1,this.hh()},this.bt=t=>{t.preventDefault();const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.kn=!0,this.Sn=t.shiftKey,this.qn=!1,this.Cn=performance.now(),this.hh()},this.vt=t=>{const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.kn=!1,this.wt()},this.kt=t=>{if(!this.nt)return;t.preventDefault();const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.xt=t=>{if(!this.Xi.valid)return;const i=this.U.lastChangeWas(this.Ln);if(this.nt&&i&&null!=this.Ln)if(this.Bn)this.U.record(this.Ln),this.Ln=null,null!=this.Kt&&this.U.song.getChannelIsMod(this.U.channel)&&this.Kt.notes.sort((function(t,e){return t.start==e.start?t.pitches[0]-e.pitches[0]:t.start-e.start}));else if(this.Pn||this.Tn||this.Sn)this.oh(this.Ln),this.Ln=null;else if(this.vn||null==this.Xi.curNote||!this.Ln.isNoop()||this.Pn||this.Tn||this.Bn||this.Sn)this.U.record(this.Ln),this.Ln=null,null!=this.Kt&&this.U.song.getChannelIsMod(this.U.channel)&&this.Kt.notes.sort((function(t,e){return t.start==e.start?t.pitches[0]-e.pitches[0]:t.start-e.start}));else{if(null==this.Kt)throw new Error;const t=new ht;if(t.append(new Re(this.U,0,0)),-1==this.Xi.pitchIndex){if(this.Xi.curNote.pitches.length==e.maxChordSize&&t.append(new Zt(this.U,this.Xi.curNote,this.Xi.curNote.pitches[0],0,!0)),t.append(new Zt(this.U,this.Xi.curNote,this.Xi.pitch,this.Xi.curNote.pitches.length)),this.rh(this.Xi.curNote),this.U.enableNotePreview&&!this.U.synth.playing){const t=Math.min(e.partsPerBeat,this.Xi.end-this.Xi.start);this.U.synth.liveInputDuration=t,this.U.synth.liveInputPitches=this.Xi.curNote.pitches.concat(),this.U.synth.liveInputStarted=!0}}else 1==this.Xi.curNote.pitches.length?t.append(new Ce(this.U,this.Kt,this.Xi.curNote,this.Xi.curIndex,!0)):t.append(new Zt(this.U,this.Xi.curNote,this.Xi.pitch,this.Xi.curNote.pitches.indexOf(this.Xi.pitch),!0));this.U.record(t)}this.nt=!1,this.vn=!1,this.Pn=!1,this.Tn=!1,this.Bn=!1,this.Hn=!1,this.modDragValueLabel.setAttribute("fill",T.secondaryText),this.cs(),this.ut()};for(let t=0;tthis.j||this.fe<0||this.fe>this.W||this.bn<=0)return;const t=this.ah();this.Xi.exactPart=this.st/this.Xn,this.Xi.part=Math.floor(Math.max(0,Math.min(this.U.song.beatsPerBar*e.partsPerBeat-t,this.Xi.exactPart))/t)*t;let i=!1;if(null!=this.Kt){for(const t of this.Kt.notes)if(t.end<=this.Xi.exactPart)this.U.song.getChannelIsMod(this.U.channel)?(t.pitches[0]==Math.floor(this.dh(this.fe))&&(this.Xi.prevNote=t),i||this.Xi.curIndex++):(this.Xi.prevNote=t,this.Xi.curIndex++);else if(t.start<=this.Xi.exactPart&&t.end>this.Xi.exactPart)this.U.song.getChannelIsMod(this.U.channel)?t.pitches[0]==Math.floor(this.dh(this.fe))?(this.Xi.curNote=t,i=!0):(!i||null!=this.Xi.curNote&&t.startthis.Xi.exactPart){if(!this.U.song.getChannelIsMod(this.U.channel)){this.Xi.nextNote=t;break}if(t.pitches[0]==Math.floor(this.dh(this.fe))){this.Xi.nextNote=t;break}}if(this.U.song.getChannelIsMod(this.U.channel)&&!this.editingModLabel)if(null!=this.Kt.notes[this.Xi.curIndex]&&null!=this.Xi.curNote){let t=0;for(;this.Xi.curNote.start+this.Xi.curNote.pins[t].time0&&this.Xi.curNote.start+this.Xi.curNote.pins[t].time-this.Xi.exactPart>this.Xi.exactPart-(this.Xi.curNote.start+this.Xi.curNote.pins[t-1].time)&&t--,this.modDragValueLabel.style.setProperty("color","#666688"),this.modDragValueLabel.style.setProperty("display","");let i=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument(this.Zs)].modSettings[e.modCount-1-this.Xi.curNote.pitches[0]],s=this.U.song.modValueToReal(this.Xi.curNote.pins[t].volume,i),n=+(s>=10)+ +(s>=100)+ +(s<0)+ +(s<=-10);this.mn=8+8*n,this.un=+l(Math.max(Math.min(this.j-10-8*n,this.Xn*(this.Xi.curNote.start+this.Xi.curNote.pins[t].time)-4-4*n),2)),this.fn=+l(this.uh(this.Xi.curNote.pitches[0]-this.In)-17-(this.bn-this.fh)/2),this.pn=this.Xi.curNote.pins[t].volume,this.th=this.Xi.curNote,this.eh=this.Xi.curNote.pins[t],this.yn=this.U.song.modValueToReal(0,i),this.gn=this.U.song.modValueToReal(this.U.song.mstMaxVols.get(i),i),this.ih=i,this.modDragValueLabel.style.setProperty("left",this.un+"px"),this.modDragValueLabel.style.setProperty("top",this.fn+"px"),this.modDragValueLabel.textContent=""+s}else this.modDragValueLabel.style.setProperty("display","none"),this.modDragValueLabel.style.setProperty("pointer-events","none"),this.modDragValueLabel.setAttribute("contenteditable","false");else this.editingModLabel||(this.modDragValueLabel.style.setProperty("display","none"),this.modDragValueLabel.style.setProperty("pointer-events","none"),this.modDragValueLabel.setAttribute("contenteditable","false"))}else this.modDragValueLabel.style.setProperty("display","none"),this.modDragValueLabel.style.setProperty("pointer-events","none"),this.modDragValueLabel.setAttribute("contenteditable","false");let s=this.dh(this.fe);if(null!=this.Xi.curNote){this.Xi.start=this.Xi.curNote.start,this.Xi.end=this.Xi.curNote.end,this.Xi.pins=this.Xi.curNote.pins;let t,i=0,n=0,h=this.Xi.curNote.pins[0];for(let e=1;eo)continue;if(this.stt.interval&&(o=t.interval),re&&(a=e,this.Xi.nearPinIndex=this.Xi.curNote.pins.indexOf(t))}if(s-=i,this.Xi.pitch=this.mh(s,-o,(this.U.song.getChannelIsNoise(this.U.channel)?e.drumCount-1:e.maxPitch)-r),!this.U.song.getChannelIsNoise(this.U.channel)){let t=n;for(let e=0;et||(t=i,this.Xi.pitch=this.Xi.curNote.pitches[e])}}for(let t=0;te.partsPerBeat)this.Xi.start=i*e.partsPerBeat;else if(t==e.partsPerBeat)this.Xi.start=i*e.partsPerBeat,nn&&(this.Xi.start+=Math.floor(h/n)*n);else{this.Xi.start=i*e.partsPerBeat;let s=e.partsPerBeat%t==0?t:Math.min(t,n);for(;sr&&(this.Xi.end=r)):this.Xi.end>r&&(this.Xi.end=r,this.Xi.start=this.Xi.end-t,this.Xi.starte&&(e=t.volume);if(e>t)for(const i of this.Xi.pins)i.volume=Math.round(i.volume*(t/e))}}this.Xi.valid=!0}yh(){return this.Xi.valid&&this.U.selection.patternSelectionActive&&this.U.selection.patternSelectionStart<=this.Xi.exactPart&&this.Xi.exactPart<=this.U.selection.patternSelectionEnd}gh(){return this.Xi.valid&&this.U.selection.patternSelectionActive&&-1==this.Xi.pitchIndex&&this.U.selection.patternSelectionStart-3<=this.Xi.exactPart&&this.Xi.exactPart<=this.U.selection.patternSelectionStart+1.25}bh(){return this.Xi.valid&&this.U.selection.patternSelectionActive&&-1==this.Xi.pitchIndex&&this.U.selection.patternSelectionEnd-1.25<=this.Xi.exactPart&&this.Xi.exactPart<=this.U.selection.patternSelectionEnd+3}dh(t){return Math.max(0,Math.min(this.wh-1,this.wh-t/this.bn))+this.In}mh(t,i,s){ts&&(t=s);const n=e.scales[this.U.song.scale].flags;if(n[Math.floor(t)%e.pitchesPerOctave]||this.U.song.getChannelIsNoise(this.U.channel)||this.U.song.getChannelIsMod(this.U.channel))return Math.floor(t);{let h=Math.floor(t)+1,o=Math.floor(t)-1;for(;!n[h%e.pitchesPerOctave];)h++;for(;!n[o%e.pitchesPerOctave];)o--;if(h>s)return or-t?h:o}}rh(t){this.ph=[];for(const e of t.pins)this.ph.push(I(0,e.time,e.volume));for(let t=1;t=10)+ +(t>=100)+ +(t<0)+ +(t<=-10);this.un=+l(Math.max(Math.min(this.j-10-8*e,this.Xn*(this.th.start+this.eh.time)-4-4*e),2)),this.modDragValueLabel.style.setProperty("left",this.un+"px");const i=new ht;this.Ln=i,this.U.setProspectiveChange(this.Ln),i.append(new Oe(this.U,this.th,this.eh.time,this.pn,this.eh.interval,this.shiftMode)),this.Ln=null}this.U.lastChangeWas(this.Ln)&&null!=this.Ln&&(this.U.record(this.Ln),this.Ln=null)}}hh(){if(this.U.song.getChannelIsMod(this.U.channel)&&"none"!=this.modDragValueLabel.style.getPropertyValue("display")&&this.st>+this.un-6&&this.st<+this.un+this.mn+6&&this.fe>+this.fn-8&&this.fe<+this.fn+11){if(this.modDragValueLabel.style.setProperty("pointer-events","fill"),this.modDragValueLabel.setAttribute("contenteditable","true"),window.getSelection){let t=window.getSelection();null!=t&&t.selectAllChildren(this.modDragValueLabel)}window.setTimeout((()=>{this.modDragValueLabel.focus()})),this.editingModLabel=!0}else{this.stopEditingModLabel(!1),this.U.enableNotePreview&&this.U.synth.maintainLiveInput(),this.nt=!0,this.Mn=this.st,this.En=this.fe,this.cs(),this.ut();const t=new ht;if(this.Ln=t,this.Hn=this.U.lastChangeWas(this.An),this.U.setProspectiveChange(this.Ln),this.gh())this.Pn=!0;else if(this.bh())this.Tn=!0;else if(this.Sn)if(this.U.selection.patternSelectionActive&&-1==this.Xi.pitchIndex||this.yh())t.append(new Re(this.U,0,0));else if(null!=this.Xi.curNote)t.append(new Re(this.U,this.Xi.curNote.start,this.Xi.curNote.end));else{const i=Math.max(0,Math.min((this.U.song.beatsPerBar-1)*e.partsPerBeat,Math.floor(this.Xi.exactPart/e.partsPerBeat)*e.partsPerBeat)),s=i+e.partsPerBeat;t.append(new Re(this.U,i,s))}else if(this.yh())this.Bn=!0;else if(this.Xi.valid&&null==this.Xi.curNote){t.append(new Re(this.U,0,0));const i=new U(this.Xi.pitch,this.Xi.start,this.Xi.end,3,this.U.song.getChannelIsNoise(this.U.channel));i.pins=[];for(const t of this.Xi.pins)i.pins.push(I(0,t.time,t.volume));t.append(new re(this.U,this.U.channel,this.U.bar));const s=this.U.getCurrentPattern(this.Zs);if(null==s)throw new Error;if(t.append(new Ce(this.U,s,i,this.Xi.curIndex)),this.U.enableNotePreview&&!this.U.synth.playing){const t=Math.min(e.partsPerBeat,this.Xi.end-this.Xi.start);this.U.synth.liveInputDuration=t,this.U.synth.liveInputPitches=[this.Xi.pitch],this.U.synth.liveInputStarted=!0}}this.kh()}}wt(){this.U.enableNotePreview&&this.ht&&this.U.synth.maintainLiveInput();const t=this.U.lastChangeWas(this.Ln);if(!this.vn&&this.nt&&this.Xi.valid&&t){const t=this.st-this.Mn,e=this.fe-this.En;Math.sqrt(t*t+e*e)>5&&(this.vn=!0,this.wn=Math.abs(t)>=Math.abs(e))}if(this.Sn&&this.wn&&Math.abs(this.Mn-this.st)>5&&(this.qn=!0),this.vn&&this.nt&&this.Xi.valid&&t){this.Ln.undo();const t=new ht;this.Ln=t,this.U.setProspectiveChange(this.Ln);const i=this.ah(),s=this.lh(this.st/this.Xn);if(this.Pn)t.append(new Re(this.U,Math.max(0,Math.min(this.U.song.beatsPerBar*e.partsPerBeat,s)),this.U.selection.patternSelectionEnd)),this.kh();else if(this.Tn)t.append(new Re(this.U,this.U.selection.patternSelectionStart,Math.max(0,Math.min(this.U.song.beatsPerBar*e.partsPerBeat,s)))),this.kh();else if(this.Bn){const t=this.U.getCurrentPattern(this.Zs);if(this.vn&&null!=t){this.Ln.undo();const s=new ht;this.Ln=s,this.U.setProspectiveChange(this.Ln);const n=e.scales[this.U.song.scale].flags.filter((t=>t)).length,h=this.U.song.getChannelIsNoise(this.U.channel)?1:12/n,o=Math.round((this.st-this.Mn)/(this.Xn*i))*i,r=Math.round((this.En-this.fe)/(this.bn*h));s.append(new Ne(this.U,this.U.channel,t,o,r))}}else if(this.Sn&&this.qn){if(this.vn){let i=Math.max(0,Math.min((this.U.song.beatsPerBar-1)*e.partsPerBeat,Math.floor(this.Xi.exactPart/e.partsPerBeat)*e.partsPerBeat)),n=i+e.partsPerBeat;if(null!=this.Xi.curNote&&(i=Math.max(i,this.Xi.curNote.start),n=Math.min(n,this.Xi.curNote.end)),sn){n=e.partsPerBeat*this.U.song.beatsPerBar;const t=this.U.getCurrentPattern(this.Zs);if(null!=t)for(let e=0;e=s){n=t.notes[e].start;break}if(t.notes[e].end>=s){n=t.notes[e].end;break}}for(let t=0;t<=this.U.song.beatsPerBar;t++){const i=t*e.partsPerBeat;s=5*i&&t%e.partsPerBeat!=0&&t!=3*e.partsPerBeat/4&&t!=3*e.partsPerBeat/2&&t!=4*e.partsPerBeat/3)continue;const s=t;if(s==h){a=s;break}if(sh){athis.U.song.beatsPerBar*e.partsPerBeat&&(r=this.U.song.beatsPerBar*e.partsPerBeat),o=r);i++);const s=new U(this.Xi.pitch,o,r,this.U.song.getVolumeCap(this.U.song.getChannelIsMod(this.U.channel),this.U.channel,this.U.getCurrentInstrument(this.Zs),this.Xi.pitch),this.U.song.getChannelIsNoise(this.U.channel));t.append(new Ce(this.U,e,s,i)),this.rh(s),this.zn=n?o:r,this.Rn=this.Xi.pitch,this.Nn=s.pins[n?0:1].volume,this.Fn=!0}let l=this.Kt;this.Kt=this.U.getCurrentPattern(this.Zs),null!=this.Kt&&this.U.song.getChannelIsMod(this.U.channel)&&this.Ys&&l!=this.Kt&&this.Kt.notes.sort((function(t,e){return t.start==e.start?t.pitches[0]-e.pitches[0]:t.start-e.start}))}else if(this.wn){t.append(new Re(this.U,0,0));const s=(this.st-this.Mn)/this.Xn,n=this.Xi.curNote.pins[this.Xi.nearPinIndex];let h=Math.round((this.Xi.curNote.start+n.time+s)/i)*i;if(h<0&&(h=0),h>this.U.song.beatsPerBar*e.partsPerBeat&&(h=this.U.song.beatsPerBar*e.partsPerBeat),null==this.Kt)throw new Error;if(h<=this.Xi.curNote.start&&this.Xi.nearPinIndex==this.Xi.curNote.pins.length-1||h>=this.Xi.curNote.end&&0==this.Xi.nearPinIndex)t.append(new Ce(this.U,this.Kt,this.Xi.curNote,this.Xi.curIndex,!0)),this.Fn=!1;else{const e=Math.min(this.Xi.curNote.start,h),i=Math.max(this.Xi.curNote.end,h);this.zn=h,this.Rn=this.Xi.curNote.pitches[-1==this.Xi.pitchIndex?0:this.Xi.pitchIndex]+this.Xi.curNote.pins[this.Xi.nearPinIndex].interval,this.Nn=this.Xi.curNote.pins[this.Xi.nearPinIndex].volume,this.Fn=!0,t.append(new qe(this.U,this.Kt,e,i,this.Xi.curNote)),t.append(new ae(this.U,this.Xi.curNote,this.Xi.nearPinIndex,h)),this.rh(this.Xi.curNote)}}else if(-1==this.Xi.pitchIndex||this.U.song.getChannelIsMod(this.U.channel)){t.append(new Re(this.U,0,0));const s=Math.max(this.Xi.curNote.start,Math.min(this.Xi.curNote.end,Math.round(this.st/(this.Xn*i))*i))-this.Xi.curNote.start;let n,h=this.Xi.curNote.pins[0],o=0,r=0,a=this.U.song.getVolumeCap(this.U.song.getChannelIsMod(this.U.channel),this.U.channel,this.U.getCurrentInstrument(this.Zs),this.Xi.pitch),l=25/Math.pow(a,.4),c=22/Math.pow(a,.5),d=this.En>this.fe?1:-1,u=Math.min(Math.abs(this.En-this.fe)/l,8)+Math.max(0,Math.abs(this.En-this.fe)/c-8);u>0&&(this.Sn=!1);for(let t=1;th.time)continue;if(sa&&(o=a),r=this.mh(n.interval*(1-i)+h.interval*i+this.Xi.curNote.pitches[0],0,e.maxPitch)-this.Xi.curNote.pitches[0];break}this.zn=this.Xi.curNote.start+s,this.Rn=this.Xi.curNote.pitches[-1==this.Xi.pitchIndex?0:this.Xi.pitchIndex]+r,this.Nn=o,this.Fn=!0,t.append(new Oe(this.U,this.Xi.curNote,s,o,r,this.shiftMode)),this.rh(this.Xi.curNote)}else{if(t.append(new Re(this.U,0,0)),this.Nn=this.Xi.curNote.pins[this.Xi.nearPinIndex].volume,null==this.Kt)throw new Error;let n,h;this.st>=this.Mn?(n=Math.max(this.Xi.curNote.start,this.Xi.part),h=s+i):(n=Math.min(this.Xi.curNote.end,this.Xi.part+i),h=s),h<0&&(h=0),h>this.U.song.beatsPerBar*e.partsPerBeat&&(h=this.U.song.beatsPerBar*e.partsPerBeat),h>this.Xi.curNote.end&&t.append(new qe(this.U,this.Kt,this.Xi.curNote.start,h,this.Xi.curNote)),ht&&(o=t),rs&&(s=e.volume);if(s>i)for(const e of t.pins)e.volume=Math.round(e.volume*(i/s))}}else this.fh=0,this.wh=this.U.windowPitchCount;this.bn=this.W/this.wh,this.Gn==this.U.song.rhythm&&this.Jn==this.U.song.pitchChannelCount&&this.Kn==this.U.song.noiseChannelCount&&this.Yn==this.U.song.modChannelCount||(this.Gn=this.U.song.rhythm,this.Jn=this.U.song.pitchChannelCount,this.Kn=this.U.song.noiseChannelCount,this.Yn=this.U.song.modChannelCount,this.resetCopiedPins()),this.ph=this.xn[this.U.channel],this._n==this.j&&this.On==this.W||(this._n=this.j,this.On=this.W,this.en.setAttribute("width",""+this.j),this.en.setAttribute("height",""+this.W),this.nn.setAttribute("height",""+this.W),this.hn.setAttribute("y","0"),this.hn.setAttribute("height",""+this.W));const i=this.j/this.U.song.beatsPerBar;if(this.Un!=i||this.Vn!=this.bn){this.Un=i,this.Vn=this.bn,this.Qs.setAttribute("width",""+i),this.Qs.setAttribute("height",""+this.bn*e.pitchesPerOctave),this.Xs.setAttribute("width",""+i),this.Xs.setAttribute("height",""+this.bn),this.tn.setAttribute("width",""+i),this.tn.setAttribute("height",""+this.bn),this.tn.setAttribute("y",""+this.fh/2),this.cn.setAttribute("width",""+(i-2)),this.cn.setAttribute("height",""+(this.bn-2)),this.bn>this.fh&&(this.dn.setAttribute("width",""+(i-2)),this.dn.setAttribute("height",""+(this.bn-this.fh)));for(let t=0;t=0;t--){if(t==this.U.channel)continue;if(this.U.song.getChannelIsNoise(t)!=this.U.song.getChannelIsNoise(this.U.channel))continue;const i=this.U.song.getPattern(t,this.U.bar+this.Zs);if(null!=i)for(const s of i.notes)for(const i of s.pitches){const n=x.path();n.setAttribute("fill",T.getChannelColor(this.U.song,t).secondaryNote),n.setAttribute("pointer-events","none"),this.xh(n,i,s.start,s.pins,.19*this.bn,!1,this.U.song.channels[t].octave*e.pitchesPerOctave),this.sn.appendChild(n)}}if(null!=this.Kt)for(const t of this.Kt.notes){for(let e=0;e1){const s=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument(this.Zs)].getChord();if(!s.harmonizes||s.arpeggiates||s.strumParts>0){let s=x.text();s.setAttribute("x",""+l(this.Xn*t.start+2)),s.setAttribute("y",""+l(this.uh(i-this.In))),s.setAttribute("width","30"),s.setAttribute("fill",T.invertedText),s.setAttribute("text-anchor","start"),s.setAttribute("dominant-baseline","central"),s.setAttribute("pointer-events","none"),s.textContent=""+(e+1),this.sn.appendChild(s)}}}if(this.U.song.getChannelIsMod(this.U.channel)&&this.vn&&!this.wn&&t==this.Xi.curNote){this.modDragValueLabel.style.setProperty("display",""),this.modDragValueLabel.style.setProperty("pointer-events","none"),this.modDragValueLabel.setAttribute("contenteditable","false"),this.modDragValueLabel.style.setProperty("color","#FFFFFF");let i=this.U.song.modValueToReal(this.Nn,this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument(this.Zs)].modSettings[e.modCount-1-t.pitches[0]]),s=+(i>=10)+ +(i>=100)+ +(i<0)+ +(i<=-10);this.mn=8+8*s,this.un=+l(Math.max(Math.min(this.j-10-8*s,this.Xn*this.zn-4-4*s),2)),this.fn=+l(this.uh(t.pitches[0]-this.In)-17-(this.bn-this.fh)/2),this.modDragValueLabel.style.setProperty("left",this.un+"px"),this.modDragValueLabel.style.setProperty("top",this.fn+"px"),this.modDragValueLabel.textContent=""+i}}}xh(t,e,i,s,n,h,o){const r=this.Xn*(s[s.length-1].time+s[0].time),a=.5*Math.min(2,r-1);let c=s[0];const d=this.U.song.getVolumeCap(this.U.song.getChannelIsMod(this.U.channel),this.U.channel,this.U.getCurrentInstrument(this.Zs),e);let u="M "+l(this.Xn*(i+c.time)+a)+" "+l(this.uh(e-o)+n*(h?c.volume/d:1))+" ";for(let t=1;tc.interval&&(u+="L "+l(f+1)+" "+l(p-n*g)+" "),r.interval=0;t--){let r=c;c=s[t];let f=this.Xn*(i+r.time)-(t==s.length-2?a:0),m=this.Xn*(i+c.time)+(0==t?a:0),p=this.uh(e+r.interval-o),y=this.uh(e+c.interval-o),g=h?r.volume/d:1,b=h?c.volume/d:1;u+="L "+l(f)+" "+l(p+n*g)+" ",r.intervalc.interval&&(u+="L "+l(m+1)+" "+l(y+n*b)+" "),u+="L "+l(m)+" "+l(y+n*b)+" "}u+="z",t.setAttribute("d",u)}uh(t){return this.bn*(this.wh-t-.5)}}class ls{constructor(t){this.U=t,this.Mh=k.div({style:"width: 100%; height: 100%; display: flex; flex-direction: column-reverse; align-items: stretch;"}),this.Eh=k.div({style:"width: 100%; height: 100%; display: flex; flex-direction: column-reverse; align-items: stretch;"}),this.Ch=k.div({style:"width: 100%; height: 100%; display: flex; flex-direction: column-reverse; align-items: stretch;"}),this.Sh=k.div({style:`width: 100%; height: 40px; border: 2px solid ${T.primaryText}; position: absolute; box-sizing: border-box; pointer-events: none;`}),this.container=k.div({style:"width: 32px; height: 100%; overflow: hidden; position: relative; flex-shrink: 0; touch-action: none;"},this.Mh,this.Eh,this.Ch,this.Sh),this.W=481,this.qh=[],this.Ph=[],this.Th=[],this.Bh=[],this.zh=[],this.Rh=[],this.fe=0,this.nt=!1,this.ht=!1,this.Nh=-1,this.Fh=-1,this.jn=!1,this.Wn=!1,this.Lh=-1,this.Ah=-1,this.dt=t=>{this.ht||(this.ht=!0,this.ut())},this.ft=t=>{this.ht&&(this.ht=!1,this.ut())},this.yt=t=>{t.preventDefault(),this.U.synth.maintainLiveInput(),this.nt=!0;const e=this.container.getBoundingClientRect();this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.Hh(),this.ut()},this.vt=t=>{(this.nt||this.ht)&&this.U.synth.maintainLiveInput();const e=this.container.getBoundingClientRect();this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.Dh(),this.nt&&this.Hh(),this.ut()},this.$h=t=>{this.nt&&this.Ih(),this.nt=!1,this.ut()},this.bt=t=>{t.preventDefault(),this.U.synth.maintainLiveInput(),this.nt=!0;const e=this.container.getBoundingClientRect();this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.Dh(),this.Hh()},this.kt=t=>{t.preventDefault(),this.U.synth.maintainLiveInput();const e=this.container.getBoundingClientRect();this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.fe)&&(this.fe=0),this.Dh(),this.nt&&this.Hh()},this.ds=t=>{t.preventDefault(),this.Ih()},this.fs=()=>{const t=this.U.song.getChannelIsNoise(this.U.channel),i=this.U.song.getChannelIsMod(this.U.channel);if(t?(this.bn=40,this.wh=e.drumCount):i?(this.bn=80,this.wh=e.modCount):(this.bn=this.W/this.U.windowPitchCount,this.wh=this.U.windowPitchCount),!t&&!i){for(let t=this.Ah;tthis.U.windowPitchCount;t--)this.Mh.removeChild(this.Mh.lastChild),this.Ph.pop(),this.qh.pop();this.Ah=this.U.windowPitchCount}this.Dh(),this.nt&&this.Hh(),this.U.synth.liveInputChannel=this.U.channel,this.us()},this.us=()=>{if(!this.U.showLetters)return;const t=this.U.song.getChannelIsNoise(this.U.channel),i=this.U.song.getChannelIsMod(this.U.channel);if(this.Fh==this.U.song.scale&&this.Lh==this.U.song.key&&this.jn==t&&this.Wn==i)return;this.Fh=this.U.song.scale,this.Lh=this.U.song.key,this.jn=t,this.Wn=i;const s=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()];if(this.Mh.style.display=t||i?"none":"flex",this.Eh.style.display=t?"flex":"none",this.Ch.style.display=i?"flex":"none",t||i){if(i){let t,i="",h="",o=T.modLabelPrimaryText,r=T.modLabelSecondaryText;for(let a=0;a1?t>=10||d>=10?(i="P"+t,i+=" I"+d):(i="Pitch"+t,i+=" Ins"+d):i="Pitch "+t:i=this.U.song.instrumentsPerChannel>1?"P"+t+" "+this.U.song.channels[t-1].name+" I"+d:"P"+t+" "+this.U.song.channels[t-1].name;break;case K.msForNoise:t=s.modChannels[e.modCount-a-1]+1,d=s.modInstruments[e.modCount-a-1]+1,""==this.U.song.channels[t-1].name?this.U.song.instrumentsPerChannel>1?t>=10||d>=10?(i="N"+t,i+=" I"+d):(i="Noise"+t,i+=" Ins"+d):i="Noise "+t:i=this.U.song.instrumentsPerChannel>1?"N"+t+" "+this.U.song.channels[t-1].name+" I"+d:"N"+t+" "+this.U.song.channels[t-1].name;break;case K.msForSong:i="Song"}if(l)switch(s.modSettings[e.modCount-a-1]){case Y.mstNone:r=T.modLabelSecondaryText,h="None",c=!1;break;case Y.mstFilterCut:h="Filter Cut";break;case Y.mstFilterPeak:h="Filter Peak";break;case Y.mstFMFeedback:h="FM Feedback";break;case Y.mstFMSlider1:h="FM 1";break;case Y.mstFMSlider2:h="FM 2";break;case Y.mstFMSlider3:h="FM 3";break;case Y.mstFMSlider4:h="FM 4";break;case Y.mstInsVolume:h="Volume";break;case Y.mstNextBar:h="Next Bar";break;case Y.mstPan:h="Pan";break;case Y.mstDetune:h="Detune";break;case Y.mstVibratoDepth:h="Vibrato Depth";break;case Y.mstVibratoSpeed:h="Vibrato Speed";break;case Y.mstVibratoDelay:h="Vibrato Delay";break;case Y.mstArpeggioSpeed:h="Arp Speed";break;case Y.mstResetArpeggio:h="Reset Arp";break;case Y.mstPanDelay:h="Pan Delay";break;case Y.mstPulseWidth:h="Pulse Width";break;case Y.mstReverb:h="Reverb";break;case Y.mstSongVolume:h="Volume";break;case Y.mstTempo:h="Tempo";break;case Y.mstSongDetune:h="Detune"}const u=this.Th[a],f=this.Bh[a],m=this.zh[a],p=this.Rh[a];if(u.style.fill=o,u.textContent=i,f.style.fill=r,f.textContent=l?h:"Not set",m.textContent=""+(e.modCount-a),p.style.fill=c?T.indicatorPrimary:T.modLabelSecondaryText,""!=this.U.song.channels[s.modChannels[e.modCount-a-1]].name){let t="1",e=u.parentElement.parentElement.getBoundingClientRect().height,i=u.getComputedTextLength(),s=0;for(i>e-8?(t="0.65",s=2):i>e-24&&(t="0.8",s=1),u.style.transform="rotate(-90deg) translate("+(-20-s-Math.round(Math.max(0,(e-80)/2)))+"px, 39px) scale("+t+", 1)";"0.65"==t&&u.getComputedTextLength()>e+8;){var n=4+(d>=10?1:0);u.textContent=u.textContent.substr(0,u.textContent.length-n)+u.textContent.substr(u.textContent.length-n+1)}}else{let t=u.parentElement.parentElement.getBoundingClientRect().height;u.style.transform="rotate(-90deg) translate("+(-20-Math.round(Math.max(0,(t-80)/2)))+"px, 39px) scale(1, 1)"}}}}else for(let t=0;tn-i?e:s}}Hh(){const t=this._h+12*this.U.song.channels[this.U.channel].octave;this.Nh!=t&&(this.Nh=t,this.U.synth.liveInputDuration=Number.MAX_SAFE_INTEGER,this.U.synth.liveInputPitches=[this.Nh],this.U.synth.liveInputStarted=!0)}Ih(){this.Nh=-1,this.U.synth.liveInputDuration=0}ut(){if(this.Sh.style.visibility=!this.ht||this.nt?"hidden":"visible",!this.ht||this.nt)return;const t=this.container.getBoundingClientRect(),e=this.bn/(this.W/(t.bottom-t.top));this.Sh.style.left="0px",this.Sh.style.top=e*(this.wh-this._h-1)+"px",this.Sh.style.height=e+"px"}}const{button:cs,div:ds,span:us,h2:fs,input:ms,br:ps,select:ys,option:gs}=k;class bs{constructor(t){this.U=t,this.Oh=ms({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Uh=ys({style:"width: 100%;"},gs({value:"end"},"Apply change at end of song."),gs({value:"beginning"},"Apply change at beginning of song.")),this.te=cs({class:"cancelButton"}),this.ee=cs({class:"okayButton",style:"width:45%;"},"Okay"),this.container=ds({class:"prompt noSelection",style:"width: 250px;"},fs("Song Length"),ds({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},ds({style:"display: inline-block; text-align: right;"},"Bars per song:",ps(),us({style:`font-size: smaller; color: ${T.secondaryText};`},"(Multiples of 4 are recommended)")),this.Oh),ds({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},ds({class:"selectContainer",style:"width: 100%;"},this.Uh)),ds({style:"display: flex; flex-direction: row-reverse; justify-content: space-between;"},this.ee),this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.Oh.removeEventListener("keypress",bs.ne),this.Oh.removeEventListener("blur",bs.he),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se()},this.se=()=>{window.localStorage.setItem("barCountPosition",this.Uh.value);const t=new nt;t.append(new yt(this.U,bs.re(this.Oh),"beginning"==this.Uh.value)),this.U.prompt=null,this.U.record(t,!0)},this.Oh.value=this.U.song.barCount+"",this.Oh.min=e.barCountMin+"",this.Oh.max=e.barCountMax+"";const i=window.localStorage.getItem("barCountPosition");null!=i&&(this.Uh.value=i),this.Oh.select(),setTimeout((()=>this.Oh.focus())),this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.Oh.addEventListener("keypress",bs.ne),this.Oh.addEventListener("blur",bs.he),this.container.addEventListener("keydown",this.oe)}static ne(t){const e=t.which?t.which:t.keyCode;return 46!=e&&e>31&&(e<48||e>57)&&(t.preventDefault(),!0)}static he(t){const e=t.target;e.value=String(bs.re(e))}static re(t){return Math.floor(Math.max(Number(t.min),Math.min(Number(t.max),Number(t.value))))}}const vs="songVersion: ";function ws(t){return JSON.parse(t.substring(vs.length))}function ks(t){return vs+JSON.stringify(t)}function xs(){return(Math.random()*(-1>>>0)>>>0).toString(32)}function Ms(t,e){return e.versions[0].time-t.versions[0].time}function Es(t,e){return e.time-t.time}class Cs{constructor(){this.Vh=new Q}static getAllRecoveredSongs(){const t=[],e={};for(let i=0;i{try{this.Vh.fromBase64String(i)}catch(t){return void window.alert('Whoops, the song data appears to have been corrupted! Please try to recover the last working version of the song from the "Recover Recent Song..." option in BeepBox\'s "File" menu.')}const e=Cs.getAllRecoveredSongs();let h=null;for(const i of e)i.versions[0].uid==t&&(h=i);null==h&&(h={versions:[]},e.unshift(h));let o=h.versions,r=1e3;if(o.length>0){const t=o[0].time;r=o[0].work+Math.min(18e4,n-t)}const a={uid:t,name:s,time:n,work:r},l=ks(a);o.unshift(a),localStorage.setItem(l,i);let c=6e4;const d=Math.pow(2,.5);for(var u=1;u8;){let t=null,i=Number.POSITIVE_INFINITY;for(let s=Math.round(4);sr&&(i=r,t=h)}for(const e of t.versions)localStorage.removeItem(ks(e));e.splice(e.indexOf(t),1)}}),750)}}const{button:Ss,div:qs,h2:Ps,p:Ts,select:Bs,option:zs,iframe:Rs}=k;class Ns{constructor(t){this.U=t,this.Wh=qs(),this.te=Ss({class:"cancelButton"}),this.container=qs({class:"prompt",style:"width: 300px;"},Ps("Song Recovery"),qs({style:"max-height: 385px; overflow-y: auto;"},Ts("This is a TEMPORARY list of songs you have recently modified. Please keep your own backups of songs you care about!"),this.Wh,Ts('(If "Display Song Data in URL" is enabled in your preferences, then you may also be able to find song versions in your browser history. However, song recovery won\'t work if you were browsing in private/incognito mode.)')),this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.te.removeEventListener("click",this.ie)},this.te.addEventListener("click",this.ie);const e=Cs.getAllRecoveredSongs();0==e.length&&this.Wh.appendChild(Ts("There are no recovered songs available yet. Try making a song!"));for(const t of e){const e=Bs({style:"width: 100%;"});for(const i of t.versions)e.appendChild(zs({value:i.time},i.name+": "+new Date(i.time).toLocaleString()));const i=Rs({style:"width: 100%; height: 60px; border: none; display: block;"});i.src="player/#song="+window.localStorage.getItem(ks(t.versions[0]));const s=qs({style:"margin: 4px 0;"},qs({class:"selectContainer",style:"width: 100%; margin: 2px 0;"},e),i);this.Wh.appendChild(s),e.addEventListener("change",(()=>{const s=t.versions[e.selectedIndex];i.contentWindow.location.replace("player/#song="+window.localStorage.getItem(ks(s))),i.contentWindow.dispatchEvent(new Event("hashchange"))}))}}}class Fs{constructor(t,i){this.U=t,this.Gh=i,this.j=112,this.W=26,this.be=x.path({fill:T.uiWidgetBackground,"pointer-events":"none"}),this.Ge=x.svg({"pointer-events":"none"}),this.Je=x.svg({"pointer-events":"none"}),this.Ke=x.path({fill:"none",stroke:"currentColor","stroke-width":2,"pointer-events":"none"}),this.Jh=x.path({fill:"currentColor","pointer-events":"none"}),this.it=x.svg({style:`background-color: ${T.editorBackground}; touch-action: none; cursor: crosshair;`,width:"100%",height:"100%",viewBox:"0 0 "+this.j+" "+this.W,preserveAspectRatio:"none"},this.be,this.Ge,this.Je,this.Ke,this.Jh),this.container=k.div({class:"spectrum",style:"height: 2em;"},this.it),this.st=0,this.fe=0,this.Qe=0,this.Xe=0,this.nt=!1,this.ti=null,this.ei="",this.ii=!0,this.yt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.Qe=this.si(this.st),this.Xe=this.ni(this.fe),this.wt()},this.bt=t=>{t.preventDefault(),this.nt=!0;const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.Qe=this.si(this.st),this.Xe=this.ni(this.fe),this.wt()},this.vt=t=>{if(null==this.container.offsetParent)return;const e=this.it.getBoundingClientRect();this.st=((t.clientX||t.pageX)-e.left)*this.j/(e.right-e.left),this.fe=((t.clientY||t.pageY)-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.kt=t=>{if(null==this.container.offsetParent)return;if(!this.nt)return;t.preventDefault();const e=this.it.getBoundingClientRect();this.st=(t.touches[0].clientX-e.left)*this.j/(e.right-e.left),this.fe=(t.touches[0].clientY-e.top)*this.W/(e.bottom-e.top),isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.wt()},this.xt=t=>{this.nt&&(this.U.record(this.ti),this.ti=null),this.nt=!1};for(let t=0;t=e.spectrumControlPoints||(n.spectrum[t]=Math.max(0,Math.min(e.spectrumMax,Math.round(t*s+h))))}n.spectrum[Math.max(0,Math.min(e.spectrumControlPoints-1,Math.round(t)))]=Math.max(0,Math.min(e.spectrumMax,Math.round(i))),this.Qe=t,this.Xe=i,this.ti=new Rt(this.U,s,n),this.U.setProspectiveChange(this.ti)}}render(){const t=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()],i=null==this.Gh?t.spectrumWave:t.drumsetSpectrumWaves[this.Gh],s=t=>(1-t/e.spectrumMax)*(this.W-1)+1;let n=0,h="M 0 "+l(this.W)+" ";for(let t=0;t0&&(h+="L "+(this.j-1)+" "+l(o)+" "),this.ei!=h&&(this.ei=h,this.Ke.setAttribute("d",h),this.be.setAttribute("d",h+"L "+this.j+" "+l(o)+" L "+this.j+" "+l(this.W)+" L 0 "+l(this.W)+" z "),this.Jh.setAttribute("d","M "+this.j+" "+l(o)+" L "+(this.j-4)+" "+l(o-4)+" L "+(this.j-4)+" "+l(o+4)+" z"),this.Jh.style.display=n>0?"":"none"),this.ii!=this.U.showFifth&&(this.ii=this.U.showFifth,this.Je.style.display=this.U.showFifth?"":"none")}}const{button:Ls,div:As,h2:Hs,select:Ds,option:$s}=k;class Is{constructor(t){this.U=t,this.Kh=Ds({style:"width: 100%;"},$s({value:"dark classic"},"BeepBox Dark"),$s({value:"light classic"},"BeepBox Light"),$s({value:"dark competition"},"BeepBox Competition Dark"),$s({value:"jummbox classic"},"JummBox Dark"),$s({value:"forest"},"Forest"),$s({value:"canyon"},"Canyon")),this.te=Ls({class:"cancelButton"}),this.ee=Ls({class:"okayButton",style:"width:45%;"},"Okay"),this.container=As({class:"prompt noSelection",style:"width: 220px;"},Hs("Set Theme"),As({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},As({class:"selectContainer",style:"width: 100%;"},this.Kh)),As({style:"display: flex; flex-direction: row-reverse; justify-content: space-between;"},this.ee),this.te),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.ee.removeEventListener("click",this.se),this.te.removeEventListener("click",this.ie),this.container.removeEventListener("keydown",this.oe)},this.oe=t=>{"BUTTON"!=t.target.tagName&&13==t.keyCode&&this.se()},this.se=()=>{window.localStorage.setItem("colorTheme",this.Kh.value),this.U.prompt=null,this.U.colorTheme=this.Kh.value,T.setTheme(this.Kh.value),this.U.undo()};const e=window.localStorage.getItem("colorTheme");null!=e&&(this.Kh.value=e),this.ee.addEventListener("click",this.se),this.te.addEventListener("click",this.ie),this.container.addEventListener("keydown",this.oe)}}const{button:_s,div:Os,p:Us,h2:Vs,h3:js}=k;class Ws{constructor(t,e){let i;switch(this.U=t,this.Yh=_s({class:"cancelButton"}),this.ie=()=>{this.U.undo()},this.cleanUp=()=>{this.Yh.removeEventListener("click",this.ie)},e){case"scale":i=Os(Vs("Scale"),Us("This setting limits the available pitches for adding notes. You may think that there's no point in limiting your choices, but the set of pitches you use has a strong influence on the mood and feel of your song, and these scales serve as guides to help you choose appropriate pitches. Don't worry, you can change the scale at any time, so you're not locked into it. Try making little melodies using all the available notes of a scale to get a sense for how it sounds."),Us('The most common scales are major and minor. Major scales tend to sound more playful or optimistic if you emphasize "tonic" notes (the brown rows in the pattern editor) at various points in your melody, whereas minor scales sound more serious or sad if you emphasize "tonic" notes.'));break;case"key":i=Os(Vs("Song Key"),Us('This setting can shift the frequency of every note in your entire song up or down to align the tonic notes (the brown rows) with the selected "key" pitch.'));break;case"tempo":i=Os(Vs("Song Tempo"),Us("This setting controls the speed of your song, measured in beats-per-minute."));break;case"reverb":i=Os(Vs("Reverb"),Us("Reverb is a kind of echo effect. You can use this slider to control the amount of reverb for instruments that enable it. A little bit helps instruments sound more natural. Adding a lot of reverb can add sense of depth or mystery."));break;case"rhythm":i=Os(Vs("Rhythm"),Us("This setting determines how beats are divided. The pattern editor helps you align notes to fractions of a beat based on this setting."));break;case"instrumentIndex":i=Os(Vs("Instrument Number"),Us("JummBox can have multiple instruments per channel, but it can only play one instrument at a time in each channel. This setting determines which of the instruments should be used to play the currently selected pattern. Different patterns in the channel can use different instruments."));break;case"instrumentVolume":i=Os(Vs("Instrument Volume"),Us("This setting controls the volume of the selected instrument without affecting the volume of the other instruments. This allows you to balance the loudness of each instrument relative to each other."),Us("Please be careful when using volume settings above 0. This indicates amplification and too much of that can trip the audio limiter built into this tool. This can lead to your song sounding muffled if overused. But when used carefully, amplification can be a powerful tool!"));break;case"pan":i=Os(Vs("Instrument Panning"),Us("If you're listening through headphones or some other stereo sound system, this controls the position of the instrument and where the sound is coming from, ranging from left to right."),Us("As a rule of thumb, composers typically put lead melodies, drums, and basses in the center, and spread any other instruments to either side. If too many instruments seem like they're coming from the same place, it can feel crowded and harder to distinguish individual sounds, especially if they cover a similar pitch range."));break;case"panDelay":i=Os(Vs("Stereo Delay"),Us("When panning, a slight delay is often added between the left and right ear to help make a sound feel more 'directional'. For example, in the real world your left ear will hear a sound coming from the left just slightly before the right ear."),Us("This setting controls how much delay is added. When this is set to minimum, panning only affects the volume of the left/right ear without changing the delay. This can help to get a more 'uniform' feeling sound, which can be desirable for making 8-bit music."));break;case"arpeggioSpeed":i=Os(Vs("Arpeggio Speed"),Us("This setting affects how fast your chord will 'arpeggiate', or cycle between notes. With a fast arpeggio speed it will sound rapid-fire, with a slow speed you can hear each note one after another."));break;case"twoNoteArpeggio":i=Os(Vs("Faster Two-Note Arpeggio"),Us("This setting makes arpeggios with only two notes in them happen twice as fast. Arpeggios with more notes in them are unaffected."));break;case"detune":i=Os(Vs("Detune"),Us("This setting can be used to finely control the pitch of your instrument."),Us("Careful - you can quickly get very dissonant sounding songs by using this setting."));break;case"instrumentType":i=Os(Vs("Instrument Type"),Us("JummBox comes with many instrument presets. You can also create your own custom instruments!"),Us("There are also options for copying and pasting instrument settings and for generating random instruments at the top of the instrument type menu."));break;case"filterCutoff":i=Os(Vs("Low-Pass Filter Cutoff Frequency"),Us('The lowest setting feels "muffled" or "dark", and the highest setting feels "harsh" or "bright".'),Us("Most sounds include a range of frequencies from low to high. JummBox instruments have a filter that allows the lowest frequencies to pass through at full volume, but can reduce the volume of the higher frequencies that are above a cutoff frequency. This setting controls the cutoff frequency and thus the range of higher frequencies that are reduced."),Us("This cutoff setting also determines which frequency resonates when the resonance peak setting is used."));break;case"filterResonance":i=Os(Vs("Low-Pass Filter Resonance Peak"),Us("Increasing this setting emphasizes a narrow range of frequencies, based on the position of the filter cutoff setting. This can be used to imitate the resonant bodies of acoustic instruments and other interesting effects."),Us("The filter preserves the volume of frequencies that are below the cutoff frequency, and reduces the volume of frequencies that are above the cutoff. If this setting is used, the filter also increases the volume of frequencies that are near the cutoff."));break;case"filterEnvelope":i=Os(Vs("Low-Pass Filter Envelope"),Us("This setting can dynamically change the filter cutoff frequency over time. Try the different options to see how they sound!"),Us('The "custom" option uses the note volume as drawn in the pattern editor as the cutoff envelope.'));break;case"transition":i=Os(Vs("Transition"),Us("This setting controls how quickly notes begin and end."),Us("Hard transitions start suddenly and sound like instruments that are played by hitting or plucking, whereas soft transitions start gradually and sound like instruments that are played by blowing air. Some transitions also stop suddenly, whereas others fade out slowly after the end of the note."),Us('The "seamless" and "slide" transitions connect the end of a note with the start of the next note.'));break;case"chipWave":i=Os(Vs("Chip Wave"),Us("JummBox comes with some sound waves based on classic electronic sound chips, as well as several unique waves."));break;case"chipNoise":i=Os(Vs("Noise"),Us("JummBox comes with several basic noise sounds. These do not have any distinct musical pitch, and can be used like drums to create beats and emphasize your song's rhythm."));break;case"pulseEnvelope":i=Os(Vs("Pulse Wave Envelope"),Us("This setting can dynamically change the pulse width over time. Try the different options to see how they sound!"),Us('The "custom" option uses the note volume as drawn in the pattern editor as the pulse width envelope.'));break;case"pulseWidth":i=Os(Vs("Pulse Wave Width"),Us("This setting controls the shape and sound of a pulse wave. At the minimum width, it sounds light and buzzy. At the maximum width, it is shaped like a classic square wave."));break;case"interval":i=Os(Vs("Instrument Interval"),Us('Some JummBox instrument types can play two waves at slightly different frequencies. The difference between the frequencies is called an "interval", and this setting controls how large it is.'),Us("When two similar waves play at slightly different frequencies, they move in and out of phase with each other over time as different parts of the waves line up. This creates a dynamic, shifting sound. Pianos are a common example of this kind of sound, because each piano key strikes multiple strings that are tuned to slightly different frequencies."),Us('If the interval is large, then the waves can sound out-of-tune and "dissonant". If the interval is even larger, then the two frequencies can even be distinct pitches.'));break;case"chords":i=Os(Vs("Chords"),Us("When multiple notes occur at the same time, this is called a chord. Chords can be created in JummBox's pattern editor by adding notes above or below another note."),Us('This setting determines how chords are played. The standard option is "harmony" which plays all of the notes out loud simultaneously. The "strum" option is similar, but plays the notes starting at slightly different times. The "arpeggio" option is used in "chiptune" style music and plays a single tone that rapidly alternates between all of the pitches in the chord.'),Us('Some JummBox instruments have an option called "custom interval" which uses the chord notes to control the interval between the waves of a single tone. This can create strange sound effects when combined with FM modulators.'));break;case"vibrato":i=Os(Vs("Vibrato"),Us("This setting causes the frequency of a note to wobble slightly. Singers and violinists often use vibrato."));break;case"vibratoDepth":i=Os(Vs("Vibrato Depth"),Us("This setting affects the depth of your instrument's vibrato, making the wobbling effect sound stronger or weaker."));break;case"vibratoDelay":i=Os(Vs("Vibrato Delay"),Us("This setting changes when vibrato starts to kick in after a note is played. Vibrato is most common for long held notes and less common in short notes, so this can help you achieve that effect."));break;case"vibratoSpeed":i=Os(Vs("Vibrato Speed"),Us("This setting determines how fast the vibrato's up-and-down wobble effect will happen for your instrument."));break;case"vibratoType":i=Os(Vs("Vibrato Type"),Us("This determines the way vibrato causes your instrument's pitch to wobble. The normal type is smooth up and down, the shaky type is chaotic."));break;case"algorithm":i=Os(Vs("FM Algorithm"),Us("FM Synthesis is a mysterious but powerful technique for crafting sounds, popularized by Yamaha keyboards and the Sega Genesis/Mega Drive. It may seem confusing, but try playing around with the options until you get a feel for it, or check out some of the preset examples!"),Us("This FM synthesizer uses up to four waves, numbered 1, 2, 3, and 4. Each wave may have its own frequency, volume, and volume envelope to control its effect over time."),Us('There are two kinds of waves: "carrier" waves play a tone out loud, but "modulator" waves distort other waves instead. Wave 1 is always a carrier and plays a tone, but other waves may distort it. The "Algorithm" setting determines which waves are modulators, and which other waves those modulators distort. For example, "1←2" means that wave 2 modulates wave 1, and wave 1 plays out loud.'));break;case"feedbackType":i=Os(Vs("Feedback"),Us("Modulators distort in one direction (like 1←2), but you can also use the feedback setting to make any wave distort in the opposite direction (1→2), or even itself (1⟲)."));break;case"operatorFrequency":i=Os(Vs("Operator Frequency"),Us('This setting controls the frequency of an individual FM wave. The fundamental frequency (1×) is determined by the pitch of the note, and the frequency (2×) is an octave (12 semitones) above it. The frequencies with a "~" are slightly detuned and shift in and out of phase over time compared to the other frequencies.'),Us('Try different combinations of a "carrier" wave and a "modulator" wave with different frequencies to get a feel for how they sound together.'));break;case"operatorVolume":i=Os(Vs("Operator Volume"),Us('This setting controls the volume of "carrier" waves, or the amount of distortion that "modulator" waves apply to other waves.'));break;case"operatorEnvelope":i=Os(Vs("Operator Envelope"),Us("This setting can dynamically change the FM wave volume over time. Try the different options to see how they sound!"),Us('The "custom" option uses the note volume as drawn in the pattern editor as the FM wave envelope.'));break;case"spectrum":i=Os(Vs("Spectrum"),Us("This setting allows you to draw your own noise spectrum! This is good for making drum sounds when combined with a hard transition and a falling filter cutoff envelope."),Us("If you only use certain frequencies and a soft transition, it's also possible to make howling wind sounds or even musical blown bottle sounds."),Us("The left side of the spectrum editor controls the noise energy at lower frequencies, and the right side controls higher frequencies."));break;case"harmonics":i=Os(Vs("Harmonics"),Us("This setting allows you to design your own sound wave! Most musical waves are actually a combination of sine waves at certain frequencies, and this lets you control the volume of each sine wave individually."),Us("The left side of the harmonics editor controls the sine wave volumes at lower frequencies, and the right side controls higher frequencies."));break;case"effects":i=Os(Vs("Effects"),Us("JummBox has two special effects you can add to instruments. You can turn on either effect, or both at once."),Us('Reverb is a kind of echo effect. You can use the "reverb" slider in the "Song Settings" section above to control the amount of reverb for instruments that enable it. A little bit helps instruments sound more natural. Adding a lot of reverb can add sense of depth or mystery.'),Us("The chorus effect combines multiple copies of the instrument's sound and adds a bit of vibrato to simulate an ensemble of instruments or voices."));break;case"drumsetEnvelope":i=Os(Vs("Drumset Envelope"),Us("This setting can dynamically change the filter cutoff frequency over time. Each row in the pattern editor gets its own envelope."),Us('The "custom" option uses the note volume as drawn in the pattern editor as the drumset cutoff envelope.'));break;case"drumsetSpectrum":i=Os(Vs("Drumset Spectrum"),Us("This setting allows you to draw your own noise spectrum! This is good for making drumsets. Each row in the pattern editor gets its own spectrum."),Us("The left side of the spectrum editor controls the noise energy at lower frequencies, and the right side controls higher frequencies."));break;case"usedInstrument":i=Os(js("'Is this instrument used somewhere else?'"),Us("This indicator will light up when the instrument you're currently looking at is used in another place in your song (outside the selection)."),Us("This can be useful when you're not sure if you've used the instrument before and making edits carelessly could change other parts of the song."));break;case"usedPattern":i=Os(js("'Is this pattern used somewhere else?'"),Us("This indicator will light up when the pattern you're currently looking at is used in another place in your song (outside the selection)."),Us("This can be useful when you're not sure if you've used the pattern before and making edits carelessly could change other parts of the song."));break;case"modChannel":i=Os(Vs("Modulator Channel"),Us("Modulators can be used to change settings in your song automatically over time. This technique is also known as automation."),Us("This setting controls which channel the modulators will take effect for. If you choose 'Song', you can change song-wide settings too!"));break;case"modInstrument":i=Os(Vs("Modulator Instrument"),Us("Modulators can be used to change settings in your song automatically over time. This technique is also known as automation."),Us("This setting controls which instrument your modulator will apply to within the given channel you've chosen."));break;case"modSet":i=Os(Vs("Modulator Setting"),Us("This is the parameter that you want to change with this modulator. For example, if you set this to 'Tempo', you can speed up or slow down your song by laying notes in the pattern editor."),Us("Note that you'll see different options if your channel is set to 'Song' versus a channel number. With 'Song', you'll see song-wide settings such as tempo. With a channel, you'll see specific instrument settings."),Us("Most modulators behave as you'd expect and work just as if you were moving their associated slider. But with the special setting 'Next Bar', the first note you lay will cause the playhead to skip the rest of the bar and jump right to the next one."));break;default:throw new Error("Unhandled TipPrompt type: "+e)}this.container=Os({class:"prompt",style:"width: 250px;"},i,this.Yh),setTimeout((()=>this.Yh.focus())),this.Yh.addEventListener("click",this.ie)}}class Gs{constructor(t,e,i,s){this.Zh=e,this.Qh=i,this.Xh=document.createTextNode("1"),this.eo=x.text({"font-family":"sans-serif","font-size":20,"text-anchor":"middle","font-weight":"bold",fill:"red"},this.Xh),this.io=x.rect({x:1,y:1}),this.container=x.svg(this.io,this.eo),this.so=1,this.no=!0,this.ho=!1,this.oo="",this.io.setAttribute("fill",T.uiWidgetBackground),this.eo.setAttribute("fill",s)}setSize(t,i){this.container.setAttribute("x",""+this.Zh*t),this.container.setAttribute("y",""+(e.barEditorHeight+this.Qh*i)),this.io.setAttribute("width",""+(t-2)),this.io.setAttribute("height",""+(i-2)),this.eo.setAttribute("x",""+t/2),this.eo.setAttribute("y",""+Math.round(i/2+7))}setIndex(t,e,i,s,n,h){this.so!=t&&(this.ho||0==t==(0==this.so)||(0==t?this.io.setAttribute("fill","none"):n?this.io.setAttribute("fill",e?T.trackEditorBgNoiseDim:T.trackEditorBgNoise):h?this.io.setAttribute("fill",e?T.trackEditorBgModDim:T.trackEditorBgMod):this.io.setAttribute("fill",e?T.trackEditorBgPitchDim:T.trackEditorBgPitch)),t>=100?(this.eo.setAttribute("font-size","16"),this.eo.setAttribute("style","transform: translate(0px, -1.5px);")):(this.eo.setAttribute("font-size","20"),this.eo.setAttribute("style","transform: translate(0px, 0px);")),this.so=t,this.Xh.data=""+t),this.no==e&&this.oo==s||(this.no=e,i?this.eo.setAttribute("fill",T.invertedText):(this.eo.setAttribute("fill",s),0==this.so?this.io.setAttribute("fill",T.editorBackground):n?this.io.setAttribute("fill",e?T.trackEditorBgNoiseDim:T.trackEditorBgNoise):h?this.io.setAttribute("fill",e?T.trackEditorBgModDim:T.trackEditorBgMod):this.io.setAttribute("fill",e?T.trackEditorBgPitchDim:T.trackEditorBgPitch))),this.ho==i&&this.oo==s||(this.ho=i,i?(this.io.setAttribute("fill",s),this.eo.setAttribute("fill",T.invertedText)):(this.eo.setAttribute("fill",s),0==this.so?this.io.setAttribute("fill",T.editorBackground):n?this.io.setAttribute("fill",e?T.trackEditorBgNoiseDim:T.trackEditorBgNoise):h?this.io.setAttribute("fill",e?T.trackEditorBgModDim:T.trackEditorBgMod):this.io.setAttribute("fill",e?T.trackEditorBgPitchDim:T.trackEditorBgPitch))),this.oo=s}}class Js{constructor(t,i){this.U=t,this.Me=i,this.ro=k.select({style:"width: 32px; height: "+e.barEditorHeight+"px; top: 0px; position: absolute; opacity: 0"},k.option({value:"barBefore"},"Insert Bar Before"),k.option({value:"barAfter"},"Insert Bar After"),k.option({value:"deleteBar"},"Delete This Bar")),this.ao=x.g(),this.lo=x.g(),this.J=x.rect({fill:T.playhead,x:0,y:0,width:4,height:128}),this.co=x.rect({fill:"none",stroke:T.hoverPreview,"stroke-width":2,"pointer-events":"none",x:1,y:1,width:30,height:30}),this.js=x.path({fill:T.invertedText,stroke:T.invertedText,"stroke-width":1,"pointer-events":"none"}),this.Ws=x.path({fill:T.invertedText,stroke:T.invertedText,"stroke-width":1,"pointer-events":"none"}),this.do=x.path({fill:T.uiWidgetBackground,stroke:T.uiWidgetBackground,"stroke-width":1,"pointer-events":"none"}),this.hn=x.rect({class:"dashed-line dash-move",fill:T.boxSelectionFill,stroke:T.hoverPreview,"stroke-width":2,"stroke-dasharray":"5, 3","fill-opacity":"0.4","pointer-events":"none",visibility:"hidden",x:1,y:1,width:62,height:62}),this.it=x.svg({style:`background-color: ${T.editorBackground}; position: absolute;`,height:128},this.ao,this.do,this.hn,this.lo,this.co,this.js,this.Ws,this.J),this.uo=k.select({class:"trackSelectBox",style:"background: none; border: none; appearance: none; border-radius: initial; box-shadow: none; color: transparent; position: absolute; touch-action: none;"}),this.container=k.div({class:"noSelection",style:"height: 128px; position: relative; overflow:hidden;"},this.it,this.uo,this.ro),this.fo=[],this.mo=[],this.st=0,this.fe=0,this.po=0,this.yo=0,this.bo=0,this.vo=0,this.ht=!1,this.wo=!1,this.vn=!1,this.Qi=32,this.ko=32,this.xs=0,this.rs=0,this.xo=0,this.et=-1,this.ls=-1,this.Ss=-1,this.Mo=a,this.Eo=0,this.Co=0,this.So=t=>{this.Eo=Math.floor(Math.min(this.U.song.barCount-1,Math.max(0,this.st/this.Qi)))},this.qo=t=>{var e="barBefore"==this.ro.value?0:1;"barBefore"==this.ro.value||"barAfter"==this.ro.value?(this.U.bar=this.Eo-1+e,this.U.selection.resetBoxSelection(),this.U.selection.insertBars(),this.U.synth.playhead>=this.Eo+e&&(this.U.synth.playhead++,this.Me.Po.animatePlayhead())):"deleteBar"==this.ro.value&&(this.U.bar=this.Eo,this.U.selection.resetBoxSelection(),this.U.selection.deleteBars(),this.U.synth.playhead>this.Eo&&(this.U.synth.playhead--,this.Me.Po.animatePlayhead())),this.ro.selectedIndex=-1},this.To=()=>{this.U.selection.setPattern(this.uo.selectedIndex)},this.nh=t=>{const e=this.Qi*this.U.synth.playhead-2;this.et!=e&&(this.et=e,this.J.setAttribute("x",""+e)),window.requestAnimationFrame(this.nh)},this.Bo=t=>{this.wo=!0,this.vn=!0,this.zo(t),this.po=this.bo,this.yo=this.vo},this.Ro=t=>{this.zo(t),this.po==this.bo&&this.yo==this.vo||t.preventDefault(),this.wo&&this.No(),this.ut()},this.Fo=t=>{this.wo=!1,this.vn=!1,this.ut()},this.dt=t=>{this.ht||(this.ht=!0)},this.ft=t=>{this.ht&&(this.ht=!1)},this.yt=t=>{t.preventDefault(),this.wo=!0,this.Lo(t),this.po=this.bo,this.yo=this.vo,this.fe>=e.barEditorHeight&&(t.shiftKey?(this.vn=!0,this.U.selection.setTrackSelection(this.U.selection.boxSelectionX0,this.bo,this.U.selection.boxSelectionY0,this.vo),this.U.selection.selectionUpdated()):(this.vn=!1,this.U.channel==this.vo&&this.U.bar==this.bo||(this.U.selection.setChannelBar(this.vo,this.bo),this.vn=!0),this.U.selection.resetBoxSelection()))},this.vt=t=>{this.Lo(t),this.wo&&(this.po==this.bo&&this.yo==this.vo||(this.vn=!0),this.No()),this.ut()},this.$h=t=>{if(this.wo&&!this.vn&&this.U.channel==this.vo&&this.U.bar==this.bo){const t=(this.fe-e.barEditorHeight)%this.ko{s||(this.Mo=!1,this.ut()),s=!0}),!0),document.addEventListener("touchstart",(()=>{s||(this.Mo=!0,this.ut()),s=!0}),!0),this.ro.selectedIndex=-1,this.ro.addEventListener("change",this.qo),this.ro.addEventListener("mousedown",this.So)}movePlayheadToMouse(){this.ht&&(this.U.synth.playhead=this.bo+this.st%this.Qi/this.Qi)}No(){this.U.selection.setTrackSelection(this.U.selection.boxSelectionX0,this.bo,this.U.selection.boxSelectionY0,this.vo),this.U.selection.selectionUpdated()}zo(t){const i=this.it.getBoundingClientRect();this.st=t.touches[0].clientX-i.left,this.fe=t.touches[0].clientY-i.top,isNaN(this.st)&&(this.st=0),isNaN(this.fe)&&(this.fe=0),this.bo=Math.floor(Math.min(this.U.song.barCount-1,Math.max(0,this.st/this.Qi))),this.vo=Math.floor(Math.min(this.U.song.getChannelCount()-1,Math.max(0,(this.fe-e.barEditorHeight)/this.ko)))}Lo(t){const i=this.it.getBoundingClientRect();this.st=(t.clientX||t.pageX)-i.left,this.fe=(t.clientY||t.pageY)-i.top,this.bo=Math.floor(Math.min(this.U.song.barCount-1,Math.max(0,this.st/this.Qi))),this.vo=Math.floor(Math.min(this.U.song.getChannelCount()-1,Math.max(0,(this.fe-e.barEditorHeight)/this.ko)))}ut(){let t=this.vo,i=this.bo;this.Mo&&(i=this.U.bar,t=this.U.channel);const s=i==this.U.bar&&t==this.U.channel,n=this.fe>=e.barEditorHeight;if(this.vn&&this.po!=this.bo){var h=Date.now();h-this.Co>=50&&(i>this.U.barScrollPos+this.U.trackVisibleBars-1&&this.U.barScrollPos0&&this.Me.changeBarScrollPos(-1),this.Co=h)}if(this.ht&&!this.wo&&!s&&n?(this.co.setAttribute("x",""+(1+this.Qi*i)),this.co.setAttribute("y",""+(1+e.barEditorHeight+this.ko*t)),this.co.setAttribute("height",""+(this.ko-2)),this.co.setAttribute("width",""+(this.Qi-2)),this.co.style.visibility="visible"):(this.ht||this.st>=i*this.Qi&&this.st0)&&!n?(this.co.setAttribute("x",""+(1+this.Qi*i)),this.co.setAttribute("y","1"),this.co.setAttribute("height",""+(e.barEditorHeight-3)),this.co.style.visibility="visible"):this.co.style.visibility="hidden",(this.ht||this.Mo)&&s&&n){const s=(this.fe-e.barEditorHeight)%this.kothis.U.song.barCount){for(s=this.rs-1;s>=this.U.song.barCount;s--)this.lo.removeChild(this.mo[s]);this.mo.length=this.U.song.barCount}if(this.ls!=this.Qi)for(s=0;s=this.U.song.pitchChannelCount&&t=this.U.song.pitchChannelCount+this.U.song.noiseChannelCount),h.container.style.visibility="visible"}else h.container.style.visibility="hidden"}this.uo.style.display=this.Mo?"":"none",this.U.selection.boxSelectionWidth>1||this.U.selection.boxSelectionHeight>1?(this.hn.setAttribute("x",String(this.Qi*this.U.selection.boxSelectionBar+1)),this.hn.setAttribute("y",String(e.barEditorHeight+this.ko*this.U.selection.boxSelectionChannel+1)),this.hn.setAttribute("width",String(this.Qi*this.U.selection.boxSelectionWidth-2)),this.hn.setAttribute("height",String(this.ko*this.U.selection.boxSelectionHeight-2)),this.hn.setAttribute("visibility","visible")):this.hn.setAttribute("visibility","hidden"),this.ut()}}const{button:Ks,div:Ys,input:Zs,select:Qs,span:Xs,optgroup:tn,option:en,canvas:sn}=k;function nn(t,e){for(let i=0;i{if(this.mouseDown){var e=(t.clientX||t.pageX)-this.canvas.getBoundingClientRect().left,i=Math.floor((t.clientY||t.pageY)-this.canvas.getBoundingClientRect().top);i<2&&(i=2),i>50&&(i=50);var s=this.canvas.getContext("2d");if(1==this.continuousEdit&&Math.abs(this.lastX-e)<40){var n=e2?e>this.lastX?1-(t-n)/(h-n):(t-n)/(h-n):0,r=Math.round(i+(this.lastY-i)*o);s.fillStyle=T.getComputed("--editor-background"),s.fillRect(2*Math.floor(t/2),0,2,53),s.fillStyle=T.getComputed("--ui-widget-background"),s.fillRect(2*Math.floor(t/2),25,2,2),s.fillStyle=T.getComputed("--track-editor-bg-pitch-dim"),s.fillRect(2*Math.floor(t/2),13,2,1),s.fillRect(2*Math.floor(t/2),39,2,1),s.fillStyle=T.getComputedChannelColor(this.U.song,this.U.channel).primaryNote,s.fillRect(2*Math.floor(t/2),r-2,2,4),this.newArray[Math.floor(t/2)]=r-26}}else s.fillStyle=T.getComputed("--editor-background"),s.fillRect(2*Math.floor(e/2),0,2,52),s.fillStyle=T.getComputed("--ui-widget-background"),s.fillRect(2*Math.floor(e/2),25,2,2),s.fillStyle=T.getComputed("--track-editor-bg-pitch-dim"),s.fillRect(2*Math.floor(e/2),13,2,1),s.fillRect(2*Math.floor(e/2),39,2,1),s.fillStyle=T.getComputedChannelColor(this.U.song,this.U.channel).primaryNote,s.fillRect(2*Math.floor(e/2),i-2,2,4),this.newArray[Math.floor(e/2)]=i-26;this.continuousEdit=!0,this.lastX=e,this.lastY=i;let a=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()],l=0;for(let t=0;t{this.mouseDown=!0,this.Ds(t)},this.Ho=()=>{this.mouseDown=!1,this.continuousEdit=!1,this.li()},this.li=()=>{this.ti=this.hi(this.newArray),this.U.record(this.ti),this.ti=null},t.addEventListener("mousemove",this.Ds),t.addEventListener("mousedown",this.Ao),t.addEventListener("mouseup",this.Ho),t.addEventListener("mouseleave",this.Ho),this.mouseDown=!1,this.continuousEdit=!1,this.lastX=0,this.lastY=0,this.newArray=new Float64Array(64),this.redrawCanvas()}redrawCanvas(){var t=this.canvas.getContext("2d");t.fillStyle=T.getComputed("--editor-background"),t.fillRect(0,0,128,52),t.fillStyle=T.getComputed("--ui-widget-background"),t.fillRect(0,25,128,2),t.fillStyle=T.getComputed("--track-editor-bg-pitch-dim"),t.fillRect(0,13,128,1),t.fillRect(0,39,128,1),t.fillStyle=T.getComputedChannelColor(this.U.song,this.U.channel).primaryNote;for(let i=0;i<64;i++){var e=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].customChipWave[i]+26;t.fillRect(2*i,e-2,2,4),this.newArray[i]=e-26}}}class an{constructor(t){this.U=t,this.prompt=null,this.Do=new as(this.U,!1,-1),this.$o=new as(this.U,!0,0),this.Io=new as(this.U,!1,1),this._o=new Js(this.U,this),this.Oo=new hs(this.U,this),this.Uo=new Ki(this.U),this.Is=new ls(this.U),this.Vo=new os(this.U,this.Is),this.Ee=Ks({style:"width: 80px;",type:"button"}),this.jo=Ks({class:"prevBarButton",style:"width: 40px;",type:"button",title:"Previous Bar (left bracket)"}),this.Wo=Ks({class:"nextBarButton",style:"width: 40px;",type:"button",title:"Next Bar (right bracket)"}),this.Go=new qi(Zs({title:"main volume",style:"width: 5em; flex-grow: 1; margin: 0;",type:"range",min:"0",max:"75",value:"50",step:"1"}),this.U,null,!1),this.Jo=x.rect({"pointer-events":"none",width:"90%",height:"50%",x:"5%",y:"25%",fill:T.uiWidgetBackground}),this.Fi=x.rect({"pointer-events":"none",height:"50%",width:"0%",x:"5%",y:"25%",fill:"url('#volumeGrad2')"}),this.Li=x.rect({"pointer-events":"none",width:"2px",height:"50%",x:"5%",y:"25%",fill:T.uiWidgetFocus}),this.Ai=x.stop({"stop-color":"lime",offset:"60%"}),this.Hi=x.stop({"stop-color":"orange",offset:"90%"}),this.Di=x.stop({"stop-color":"red",offset:"100%"}),this.$i=x.linearGradient({id:"volumeGrad2",gradientUnits:"userSpaceOnUse"},this.Ai,this.Hi,this.Di),this.Ii=x.defs({},this.$i),this.Ko=x.svg({style:"touch-action: none; overflow: visible; margin: auto; max-width: 20vw;",width:"160px",height:"100%",preserveAspectRatio:"none",viewBox:"0 0 160 12"},this.Ii,this.Jo,this.Fi,this.Li),this.Yo=Ys({class:"playback-volume-bar",style:"height: 12px; align-self: center;"},this.Ko),this.Zo=Qs({style:"width: 100%;"},en({selected:!0,disabled:!0,hidden:!1},"File"),en({value:"new"},"+ New Blank Song"),en({value:"import"},"↑ Import Song..."),en({value:"export"},"↓ Export Song..."),en({value:"copyUrl"},"⎘ Copy Song URL"),en({value:"shareUrl"},"⤳ Share Song URL"),en({value:"shortenUrl"},"… Shorten Song URL"),en({value:"viewPlayer"},"▶ View in Song Player"),en({value:"copyEmbed"},"⎘ Copy HTML Embed Code"),en({value:"songRecovery"},"⚠ Recover Recent Song...")),this.Qo=Qs({style:"width: 100%;"},en({selected:!0,disabled:!0,hidden:!1},"Edit"),en({value:"undo"},"Undo (Z)"),en({value:"redo"},"Redo (Y)"),en({value:"copy"},"Copy Pattern (C)"),en({value:"pasteNotes"},"Paste Pattern Notes (V)"),en({value:"pasteNumbers"},"Paste Pattern Numbers (⇧V)"),en({value:"insertBars"},"Insert Bar After Selection (⏎)"),en({value:"deleteBars"},"Delete Selected Bar (⌫)"),en({value:"selectAll"},"Select All (A)"),en({value:"selectChannel"},"Select Channel (⇧A)"),en({value:"duplicatePatterns"},"Duplicate Reused Patterns (D)"),en({value:"transposeUp"},"Move Notes Up (+)"),en({value:"transposeDown"},"Move Notes Down (-)"),en({value:"moveNotesSideways"},"Move All Notes Sideways... (W)"),en({value:"beatsPerBar"},"Change Beats Per Bar..."),en({value:"barCount"},"Change Song Length... (L)"),en({value:"channelSettings"},"Channel Settings... (Q)"),en({value:"limiterSettings"},"Limiter Settings... (⇧L)")),this.Xo=Qs({style:"width: 100%;"},en({selected:!0,disabled:!0,hidden:!1},"Preferences"),en({value:"autoPlay"},"Auto Play On Load"),en({value:"autoFollow"},"Auto Follow Track"),en({value:"enableNotePreview"},"Preview Added Notes"),en({value:"showLetters"},"Show Piano Keys"),en({value:"showFifth"},'Highlight "Fifth" Notes'),en({value:"showChannels"},"Show All Channels"),en({value:"showScrollBar"},"Octave Scroll Bar"),en({value:"alwaysFineNoteVol"},"Always Fine Note Vol."),en({value:"enableChannelMuting"},"Enable Channel Muting"),en({value:"displayBrowserUrl"},"Display Song Data in URL"),en({value:"displayVolumeBar"},"Show Playback Volume"),en({value:"fullScreen"},"Set Layout..."),en({value:"colorTheme"},"Set Theme...")),this.tr=nn(Qs(),e.scales.map((t=>t.name))),this.er=nn(Qs(),e.keys.map((t=>t.name)).reverse()),this.ir=new qi(Zs({style:"margin: 0; vertical-align: middle;",type:"range",min:"30",max:"320",value:"160",step:"1"}),this.U,((t,e)=>new Me(this.U,t,e)),!1),this.sr=Zs({style:"width: 4em; font-size: 80%; margin-left: 0.4em; vertical-align: middle;",type:"number",step:"1"}),this.nr=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:e.reverbRange-1,value:"0",step:"1"}),this.U,((t,e)=>new Ee(this.U,t,e)),!1),this.hr=nn(Qs(),e.rhythms.map((t=>t.name))),this.rr=hn(!1,"pitchPresetSelect"),this.ar=hn(!0,"drumPresetSelect"),this.lr=nn(Qs(),e.algorithms.map((t=>t.name))),this.cr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("algorithm")},"Algorithm: "),Ys({class:"selectContainer"},this.lr)),this.ur=Qs(),this.mr=Ys({class:"selectRow",style:"display: none;"},Xs({class:"tip",onclick:()=>this.dr("instrumentIndex")},"Instrument: "),Ys({class:"selectContainer"},this.ur)),this.pr=new qi(Zs({style:"margin: 0; position: sticky;",type:"range",min:Math.floor(-e.volumeRange/2),max:Math.floor(e.volumeRange/2),value:"0",step:"1"}),this.U,((t,e)=>new Ae(this.U,t,e)),!0),this.yr=Zs({style:"width: 4em; font-size: 80%",id:"volumeSliderInputBox",type:"number",step:"1",min:Math.floor(-e.volumeRange/2),max:Math.floor(e.volumeRange/2),value:"0"}),this.gr=Ys({class:"selectRow",style:"height: 1em"},Xs({class:"tip",style:"font-size: smaller;",onclick:()=>this.dr("instrumentVolume")},"Volume: ")),this.vr=Ys({class:"selectRow"},Ys({},Ys({style:"color: "+T.secondaryText+";"},Xs({class:"tip"},this.gr)),Ys({style:"color: "+T.secondaryText+"; margin-top: -3px;"},this.yr)),this.pr.container),this.wr=new qi(Zs({style:"margin: 0;",position:"sticky;",type:"range",min:"0",max:e.panMax,value:e.panCenter,step:"1"}),this.U,((t,e)=>new $e(this.U,t,e)),!0),this.kr=Ks({style:"margin-left:0em; height:1.5em; width: 10px; padding: 0px; font-size: 8px;",onclick:()=>this.Mr(1)},"▼"),this.Er=Zs({style:"width: 4em; font-size: 80%; ",id:"panSliderInputBox",type:"number",step:"1",min:"0",max:"100",value:"0"}),this.Cr=Ys({class:"selectRow"},Ys({},Xs({class:"tip",tabindex:"0",style:"height:1em; font-size: smaller;",onclick:()=>this.dr("pan")},"Pan: "),Ys({style:"color: "+T.secondaryText+"; margin-top: -3px;"},this.Er)),this.kr,this.wr.container),this.Sr=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:this.U.song.mstMaxVols.get(Y.mstPanDelay),value:"0",step:"1"}),this.U,((t,e)=>new Ie(this.U,t,e)),!1),this.qr=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("panDelay")},"Delay:"),this.Sr.container),this.Pr=Ys({class:"editor-controls"},this.qr),this.Tr=new qi(Zs({style:"margin: 0;",type:"range",min:e.detuneMin,max:e.detuneMax,value:0,step:"1"}),this.U,((t,e)=>new _e(this.U,t,e)),!0),this.Br=Zs({style:"width: 4em; font-size: 80%; ",id:"detuneSliderInputBox",type:"number",step:"1",min:""+e.detuneMin,max:""+e.detuneMax,value:"0"}),this.zr=Ys({class:"selectRow"},Ys({},Xs({class:"tip",style:"height:1em; font-size: smaller;",onclick:()=>this.dr("detune")},"Detune: "),Ys({style:"color: "+T.secondaryText+"; margin-top: -3px;"},this.Br)),this.Tr.container),this.Rr=nn(Qs(),e.chipWaves.map((t=>t.name))),this.Nr=nn(Qs(),e.chipNoises.map((t=>t.name))),this.Fr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("chipWave")},"Wave: "),Ys({class:"selectContainer"},this.Rr)),this.Lr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("chipNoise")},"Noise: "),Ys({class:"selectContainer"},this.Nr)),this.Ar=nn(Qs(),e.transitions.map((t=>t.name))),this.Hr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("transition")},"Transition:"),Ys({class:"selectContainer"},this.Ar)),this.Dr=nn(Qs(),e.effectsNames),this.$r=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:e.filterCutoffRange-1,value:"6",step:"1"}),this.U,((t,e)=>new Dt(this.U,t,e)),!1),this.Ir=Ys({class:"selectRow",title:"Low-pass Filter Cutoff Frequency"},Xs({class:"tip",onclick:()=>this.dr("filterCutoff")},"Filter Cut:"),this.$r.container),this._r=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:e.filterResonanceRange-1,value:"6",step:"1"}),this.U,((t,e)=>new $t(this.U,t,e)),!1),this.Or=Ys({class:"selectRow",title:"Low-pass Filter Peak Resonance"},Xs({class:"tip",onclick:()=>this.dr("filterResonance")},"Filter Peak:"),this._r.container),this.Ur=nn(Qs(),e.envelopes.map((t=>t.name))),this.Vr=Ys({class:"selectRow",title:"Low-pass Filter Envelope"},Xs({class:"tip",onclick:()=>this.dr("filterEnvelope")},"Filter Env:"),Ys({class:"selectContainer"},this.Ur)),this.jr=nn(Qs(),e.envelopes.map((t=>t.name))),this.Wr=Ys({class:"selectRow",title:"Pulse Width Modulator Envelope"},Xs({class:"tip",onclick:()=>this.dr("pulseEnvelope")},"Pulse Env:"),Ys({class:"selectContainer"},this.jr)),this.Gr=new qi(Zs({style:"margin: 0;",type:"range",min:"1",max:e.pulseWidthRange,value:"0",step:"1"}),this.U,((t,e)=>new At(this.U,t,e)),!1),this.Jr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("pulseWidth")},"Pulse Width:"),this.Gr.container),this.Kr=nn(Qs(),e.intervals.map((t=>t.name))),this.Yr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("interval")},"Interval:"),Ys({class:"selectContainer"},this.Kr)),this.Zr=nn(Qs(),e.chords.map((t=>t.name))),this.Qr=Ks({style:"margin-left:0em; height:1.5em; width: 10px; padding: 0px; font-size: 8px;",onclick:()=>this.Mr(2)},"▼"),this.Xr=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("chords")},"Chords:"),this.Qr,Ys({class:"selectContainer",style:"width: 61.5%;"},this.Zr)),this.ta=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:this.U.song.mstMaxVols.get(Y.mstArpeggioSpeed),value:"0",step:"1"}),this.U,((t,e)=>new Bt(this.U,t,e)),!1),this.ea=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("arpeggioSpeed")},"Speed:"),this.ta.container),this.ia=Zs({type:"checkbox",style:"width: 1em; padding: 0; margin-right: 4em;"}),this.sa=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("twoNoteArpeggio")},"Fast Two-Note:"),this.ia),this.na=Ys({class:"editor-controls"},this.ea,this.sa),this.ha=nn(Qs(),e.vibratos.map((t=>t.name))),this.oa=Ks({style:"margin-left:0em; height:1.5em; width: 10px; padding: 0px; font-size: 8px;",onclick:()=>this.Mr(0)},"▼"),this.ra=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("vibrato")},"Vibrato:"),this.oa,Ys({class:"selectContainer",style:"width: 61.5%;"},this.ha)),this.aa=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:this.U.song.mstMaxVols.get(Y.mstVibratoDepth),value:"0",step:"1"}),this.U,((t,e)=>new St(this.U,t,e)),!1),this.la=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("vibratoDepth")},"Depth:"),this.aa.container),this.ca=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:this.U.song.mstMaxVols.get(Y.mstVibratoSpeed),value:"0",step:"1"}),this.U,((t,e)=>new qt(this.U,t,e)),!1),this.da=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("vibratoSpeed")},"Speed:"),this.ca.container),this.ua=new qi(Zs({style:"margin: 0;",type:"range",min:"0",max:this.U.song.mstMaxVols.get(Y.mstVibratoDelay),value:"0",step:"1"}),this.U,((t,e)=>new Pt(this.U,t,e)),!1),this.fa=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("vibratoDelay")},"Delay:"),this.ua.container),this.ma=nn(Qs(),e.vibratoTypes.map((t=>t.name))),this.pa=Ys({class:"selectRow"},Xs({class:"tip",style:"margin-left:10px;",onclick:()=>this.dr("vibratoType")},"Type:"),Ys({class:"selectContainer",style:"width: 61.5%;"},this.ma)),this.ya=Ys({class:"editor-controls"},this.la,this.da,this.fa,this.pa),this.ga=Ys({class:"editor-controls"}),this.ba=nn(Qs(),e.feedbacks.map((t=>t.name))),this.va=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("feedbackType")},"Feedback:"),Ys({class:"selectContainer"},this.ba)),this.wa=new Fs(this.U,null),this.ka=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("spectrum")},"Spectrum:"),this.wa.container),this.xa=new Ei(this.U),this.Ma=Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("harmonics")},"Harmonics:"),this.xa.container),this.Ea=Ys({class:"editor-controls"}),this.Ca=Ys({class:"editor-controls"}),this.Sa=Ks({style:"max-width:86px;",class:"copyButton"},["Copy",x.svg({style:"flex-shrink: 0; position: absolute; left: 0; top: 50%; margin-top: -1em; pointer-events: none;",width:"2em",height:"2em",viewBox:"-5 -21 26 26"},[x.path({d:"M 0 -15 L 1 -15 L 1 0 L 13 0 L 13 1 L 0 1 L 0 -15 z M 2 -1 L 2 -17 L 10 -17 L 14 -13 L 14 -1 z M 3 -2 L 13 -2 L 13 -12 L 9 -12 L 9 -16 L 3 -16 z",fill:"currentColor"})])]),this.qa=Ks({style:"max-width:86px;",class:"pasteButton"},["Paste",x.svg({style:"flex-shrink: 0; position: absolute; left: 0; top: 50%; margin-top: -1em; pointer-events: none;",width:"2em",height:"2em",viewBox:"0 0 26 26"},[x.path({d:"M 8 18 L 6 18 L 6 5 L 17 5 L 17 7 M 9 8 L 16 8 L 20 12 L 20 22 L 9 22 z",stroke:"currentColor",fill:"none"}),x.path({d:"M 9 3 L 14 3 L 14 6 L 9 6 L 9 3 z M 16 8 L 20 12 L 16 12 L 16 8 z",fill:"currentColor"})])]),this.Pa=new rn(sn({width:128,height:52,style:"border:2px solid "+T.uiWidgetBackground,id:"customWaveDrawCanvas"}),this.U,(t=>new ct(this.U,t))),this.Ta=function(t,e,i){e.appendChild(en({selected:!0,disabled:!0,value:t},t));for(const t of i)e.appendChild(en({value:t},t));return e}("Load Preset",Qs({style:"width: 50%; height:1.5em; text-align: center; text-align-last: center;"}),e.chipWaves.map((t=>t.name))),this.Ba=Ks({style:"margin-left:0.5em; height:1.5em; max-width: 20px;",onclick:()=>this.dr("customChipSettings")},"+"),this.za=Ys({style:"height:80px; margin-top:10px; margin-bottom:5px"},[Ys({style:"height:54px; display:flex; justify-content:center;"},[this.Pa.canvas]),Ys({style:"margin-top:5px; display:flex; justify-content:center;"},[this.Ta,this.Ba])]),this.Ra=new Si(Zs({style:"font-weight:bold; border:none; width: 100%; background-color:${ColorConfig.editorBackground}; color:${ColorConfig.primaryText}; text-align:center",maxlength:"30",type:"text",value:c.versionDisplayName}),this.U,((t,e)=>new He(this.U,t,e))),this.Na=new qi(Zs({style:"margin: 0; width: 4em;",type:"range",min:"0",max:e.operatorAmplitudeMax,value:"0",step:"1",title:"Feedback Amplitude"}),this.U,((t,e)=>new Gt(this.U,t,e)),!1),this.Fa=nn(Qs({style:"width: 100%;",title:"Feedback Envelope"}),e.envelopes.map((t=>t.name))),this.La=Ys({class:"operatorRow"},Ys({style:"margin-right: .1em; visibility: hidden;"},"1."),Ys({style:"width: 3em; margin-right: .3em;"}),this.Na.container,Ys({class:"selectContainer",style:"width: 5em; margin-left: .3em;"},this.Fa)),this.Aa=Ys({class:"editor-controls"},this.Fr,this.Lr,this.zr,this.za,this.Ir,this.Or,this.Vr,this.Hr,Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("effects")},"Effects:"),Ys({class:"selectContainer"},this.Dr)),this.Xr,this.na,this.ra,this.ya,this.Yr,this.cr,this.ga,this.va,this.La,this.ka,this.Ma,this.Ea,this.Wr,this.Jr),this.Ha=Ys({class:"editor-controls"},Ys({class:"selectRow"},this.Sa,this.qa)),this.Da=Ys({id:"instrumentSettingsText",style:`margin: 3px 0; text-align: center; color: ${T.secondaryText};`},"Instrument Settings"),this.$a=Ys({class:"editor-controls"},this.Da,this.mr,Ys({class:"selectRow",id:"typeSelectRow"},Xs({class:"tip",onclick:()=>this.dr("instrumentType")},"Type: "),Ys(Ys({class:"pitchSelect"},this.rr),Ys({class:"drumSelect"},this.ar))),this.vr,this.Cr,this.Pr,this.Aa),this.Ia=x.path({d:"M -6 -6 H 6 V 6 H -6 V -6 M -2 -3 L -2 -3 L -1 -4 H 1 V 4 H -1 V -1.2 L -1.2 -1 H -2 V -3 z",fill:T.indicatorSecondary,"fill-rule":"evenodd"}),this._a=x.path({d:"M -6 -0.8 H -3.8 V -6 H 0.8 V 4.4 H 2.2 V -0.8 H 6 V 0.8 H 3.8 V 6 H -0.8 V -4.4 H -2.2 V 0.8 H -6 z",fill:T.indicatorSecondary}),this.Oa=Ys({class:"promptContainer",style:"display: none;"}),this.Ua=Ys({style:"flex: 1; height: 100%; display: flex; overflow: hidden; justify-content: center;"},this.Do.container,this.$o.container,this.Io.container),this.Va=Ys({class:"pattern-area"},this.Is.container,this.Ua,this.Vo.container),this.V=Ys({class:"trackContainer"},this._o.container,this.Uo.container),this.ja=Ys({class:"trackAndMuteContainer"},this.Oo.container,this.V),this.Po=new et(this.U,this.V),this.Wa=Ys({class:"track-area"},this.ja,this.Po.container),this.Ga=Ys({class:"settings-area noSelection"},Ys({class:"version-area"},Ys({style:"text-align: center; color: ${ColorConfig.secondaryText};"},[this.Ra.input])),Ys({class:"play-pause-area"},this.Yo,Ys({class:"playback-bar-controls"},this.Ee,this.jo,this.Wo),Ys({class:"playback-volume-controls"},Xs({class:"volume-speaker"}),this.Go.container)),Ys({class:"menu-area"},Ys({class:"selectContainer menu file"},this.Zo),Ys({class:"selectContainer menu edit"},this.Qo),Ys({class:"selectContainer menu preferences"},this.Xo)),Ys({class:"song-settings-area"},Ys({class:"editor-controls"},Ys({class:"editor-song-settings"},Ys({style:"margin: 3px 0; position: relative; text-align: center; color: ${ColorConfig.secondaryText};"},Ys({class:"tip",style:"flex-shrink: 0; position:absolute; left: 0; top: 0; width: 12px; height: 12px",onclick:()=>this.dr("usedPattern")},x.svg({style:"flex-shrink: 0; position: absolute; left: 0; top: 0; pointer-events: none;",width:"12px",height:"12px","margin-right":"0.5em",viewBox:"-6 -6 12 12"},this.Ia)),Ys({class:"tip",style:"flex-shrink: 0; position: absolute; left: 14px; top: 0; width: 12px; height: 12px",onclick:()=>this.dr("usedInstrument")},x.svg({style:"flex-shrink: 0; position: absolute; left: 0; top: 0; pointer-events: none;",width:"12px",height:"12px","margin-right":"1em",viewBox:"-6 -6 12 12"},this._a)),"Song Settings")),Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("scale")},"Scale: "),Ys({class:"selectContainer"},this.tr)),Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("key")},"Key: "),Ys({class:"selectContainer"},this.er)),Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("tempo")},"Tempo: "),Xs({style:"display: flex;"},this.ir.container,this.sr)),Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("reverb")},"Reverb: "),this.nr.container),Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("rhythm")},"Rhythm: "),Ys({class:"selectContainer"},this.hr)))),Ys({class:"instrument-settings-area"},this.$a,this.Ca)),this.mainLayer=Ys({class:"beepboxEditor",tabIndex:"0"},this.Va,this.Wa,this.Ga,this.Oa),this.Ja=!1,this.Ka=null,this.Ya=[],this.Za=[],this.Qa=[],this.Xa=[],this.tl=[],this.el=[],this.il=[],this.sl=[],this.nl=[],this.hl=!1,this.ol=0,this.rl=0,this.al=0,this.ll=!1,this.cl=!1,this.dl=!1,this.outVolumeHistoricTimer=0,this.outVolumeHistoricCap=0,this.lastOutVolumeCap=0,this.refocusStage=()=>{this.mainLayer.focus({preventScroll:!0})},this.ul=()=>{this.$o.editingModLabel||this.mainLayer.focus({preventScroll:!0})},this.whenUpdated=()=>{this.Oo.container.style.display=this.U.enableChannelMuting?"":"none";const t=this.V.getBoundingClientRect();if(this.U.trackVisibleBars=Math.floor((t.right-t.left)/this.U.getBarWidth()),this.Po.render(),this.Oo.render(),this._o.render(),document.activeElement!=this.$o.modDragValueLabel&&this.$o.editingModLabel&&this.$o.stopEditingModLabel(!1),this.Is.container.style.display=this.U.showLetters?"":"none",this.Vo.container.style.display=this.U.showScrollBar?"":"none",this.Po.container.style.display=this.U.song.barCount>this.U.trackVisibleBars?"":"none",this.Yo.style.display=this.U.displayVolumeBar?"":"none",this.U.getFullScreen()){const t=5*(this.Ua.clientHeight/this.U.windowPitchCount),e=this.Ua.clientWidth/(3*this.U.song.beatsPerBar),i=this.Ua.clientWidth/(this.U.song.beatsPerBar+2),s=Math.max(e,Math.min(i,t))*this.U.song.beatsPerBar;this.Do.container.style.width=s+"px",this.$o.container.style.width=s+"px",this.Io.container.style.width=s+"px",this.Do.container.style.flexShrink="0",this.$o.container.style.flexShrink="0",this.Io.container.style.flexShrink="0",this.Do.container.style.display="",this.Io.container.style.display="",this.Do.render(),this.Io.render()}else this.$o.container.style.width="",this.$o.container.style.flexShrink="",this.Do.container.style.display="none",this.Io.container.style.display="none";this.$o.render();const i=[(this.U.autoPlay?"✓ ":"")+"Auto Play On Load",(this.U.autoFollow?"✓ ":"")+"Auto Follow Track",(this.U.enableNotePreview?"✓ ":"")+"Preview Added Notes",(this.U.showLetters?"✓ ":"")+"Show Piano Keys",(this.U.showFifth?"✓ ":"")+'Highlight "Fifth" Notes',(this.U.showChannels?"✓ ":"")+"Show All Channels",(this.U.showScrollBar?"✓ ":"")+"Octave Scroll Bar",(this.U.alwaysFineNoteVol?"✓ ":"")+"Always Fine Note Vol.",(this.U.enableChannelMuting?"✓ ":"")+"Enable Channel Muting",(this.U.displayBrowserUrl?"✓ ":"")+"Display Song Data in URL",(this.U.displayVolumeBar?"✓ ":"")+"Show Playback Volume","Set Layout...","Set Theme..."];for(let t=0;ti||this.U.channelo)&&(d=!0,e=this.U.song.barCount);for(let e=0;ei||this.U.channelo)&&(c=!0,e=this.U.song.barCount);d?this.Ia.style.setProperty("fill",T.indicatorPrimary):this.Ia.style.setProperty("fill",T.indicatorSecondary),c?this._a.style.setProperty("fill",T.indicatorPrimary):this._a.style.setProperty("fill",T.indicatorSecondary),this.rr.style.display="none",this.ar.style.display="none",$("#pitchPresetSelect").parent().hide(),$("#drumPresetSelect").parent().hide(),this.Ca.appendChild(this.Ha),this.Ca.insertBefore(this.mr,this.Ca.firstChild),this.Ca.insertBefore(this.Da,this.Ca.firstChild),this.Da.textContent="Modulator Settings",this.Lr.style.display="none",this.Fr.style.display="none",this.ka.style.display="none",this.Ma.style.display="none",this.Hr.style.display="none",this.Xr.style.display="none",this.na.style.display="none",this.Ir.style.display="none",this.Or.style.display="none",this.Vr.style.display="none",this.Ea.style.display="none",this.za.style.display="none",this.cr.style.display="none",this.ga.style.display="none",this.va.style.display="none",this.La.style.display="none",this.Wr.style.display="none",this.Jr.style.display="none",this.ra.style.display="none",this.ya.style.display="none",this.Yr.style.display="none",this.zr.style.display="none",this.Cr.style.display="none",this.Pr.style.display="none",this.Ca.style.display="",this.Ca.style.color=T.getChannelColor(this.U.song,this.U.channel).primaryNote;for(let t=0;t=this.U.song.instrumentsPerChannel&&(n=0,e.modInstruments[t]=0,e.modSettings[t]=0),s>=this.U.song.pitchChannelCount&&i==K.msForPitch&&(i=K.msNone,e.modStatuses[t]=K.msNone,e.modSettings[t]=Y.mstNone),s>=this.U.song.pitchChannelCount+this.U.song.noiseChannelCount&&i==K.msForNoise&&(e.modStatuses[t]=K.msNone,e.modSettings[t]=Y.mstNone),this.U.recalcChannelNames||this.fl[t].children.length!=2+this.U.song.pitchChannelCount+this.U.song.noiseChannelCount){for(;this.fl[t].firstChild;)this.fl[t].remove(0);const e=[];e.push("none"),e.push("song");for(let t=0;t1?"":"none",$("#modInstrumentText"+t).get(0).style.display=this.U.song.instrumentsPerChannel>1?"":"none",$("#modChannelText"+t).get(0).innerText=this.U.song.instrumentsPerChannel>1?"Ch:":"Channel:",$("#modSettingText"+t).get(0).style.display="",this.pl[t].parentElement.style.display="")}this.U.recalcChannelNames=!1;for(let t=0;t=this.U.song.pitchChannelCount+this.U.song.noiseChannelCount&&this.Is.forceRender()}else{this.Aa.style.display="",this.Cr.style.display="",this.Pr.style.display=this.ll?"":"none",this.zr.style.display="",this.vr.style.display="",$("#typeSelectRow").css("display",""),this.$a.appendChild(this.Ha),this.$a.insertBefore(this.mr,this.$a.firstChild),this.$a.insertBefore(this.Da,this.$a.firstChild),this.Da.textContent="Instrument Settings",this.Ca.style.display="none";var c=!1,d=!1;if(0!=s.bars[this.U.bar]){let t=Math.min(this.U.selection.boxSelectionX0,this.U.selection.boxSelectionX1),e=Math.max(this.U.selection.boxSelectionX0,this.U.selection.boxSelectionX1),i=Math.min(this.U.selection.boxSelectionY0,this.U.selection.boxSelectionY1),n=Math.max(this.U.selection.boxSelectionY0,this.U.selection.boxSelectionY1);for(let h=0;he||this.U.channeln)&&(d=!0,h=this.U.song.barCount);for(let o=0;oe||this.U.channeln)&&(c=!0,o=this.U.song.barCount)}if(d?this.Ia.style.setProperty("fill",T.indicatorPrimary):this.Ia.style.setProperty("fill",T.indicatorSecondary),c?this._a.style.setProperty("fill",T.indicatorPrimary):this._a.style.setProperty("fill",T.indicatorSecondary),this.U.song.getChannelIsNoise(this.U.channel)?(this.rr.style.display="none",this.ar.style.display="",$("#pitchPresetSelect").parent().hide(),$("#drumPresetSelect").parent().show(),on(this.ar,o.preset)):(this.rr.style.display="",this.ar.style.display="none",$("#pitchPresetSelect").parent().show(),$("#drumPresetSelect").parent().hide(),on(this.rr,o.preset)),this.U.alwaysShowSettings||o.preset==o.type){if(2==o.type?(this.Lr.style.display="",on(this.Nr,o.chipNoise)):this.Lr.style.display="none",3==o.type?(this.Fr.style.display="none",this.ka.style.display="",this.wa.render()):this.ka.style.display="none",5==o.type?(this.Fr.style.display="none",this.Ma.style.display="",this.xa.render()):this.Ma.style.display="none",4==o.type){this.Fr.style.display="none",this.Ea.style.display="",this.Hr.style.display="none",this.Xr.style.display="none",this.na.style.display="none",this.Ir.style.display="none",this.Or.style.display="none",this.Vr.style.display="none";for(let t=0;t0?"":T.secondaryText;for(let t=0;t0?"":T.secondaryText}}else this.cr.style.display="none",this.ga.style.display="none",this.va.style.display="none",this.La.style.display="none";2==o.type?(this.Fr.style.display="none",this.ra.style.display="none",this.ya.style.display="none",this.Yr.style.display="none"):4==o.type?(this.ra.style.display="none",this.Yr.style.display="none",this.ya.style.display="none"):(this.ra.style.display="",3==o.type||1==o.type||6==o.type?this.Yr.style.display="none":this.Yr.style.display="",this.ya.style.display=this.cl?"":"none")}else;for(let t=0;t1?"":"none",this.mr.style.visibility=null==n?"hidden":"",this.ur.children.length!=this.U.song.instrumentsPerChannel){for(;this.ur.firstChild;)this.ur.removeChild(this.ur.firstChild);const t=[];for(let e=0;e{this.Oo.onKeyUp(t),17==t.keyCode?this.$o.controlMode=!1:16==t.keyCode&&(this.$o.shiftMode=!1)},this.vl=t=>{switch(t.keyCode){case 8:case 13:case 38:case 40:case 37:case 39:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:t.stopPropagation()}},this.oe=t=>{if(this.prompt)return(this.prompt instanceof li||this.prompt instanceof Ji)&&this.prompt.whenKeyPressed(t),void(27==t.keyCode&&this.U.undo());if(document.activeElement==this.Ra.input||this.$o.editingModLabel||document.activeElement==this.Oo.ws.input)13!=t.keyCode&&27!=t.keyCode||(this.mainLayer.focus(),this.$o.stopEditingModLabel(27==t.keyCode));else if(document.activeElement!=this.Er&&document.activeElement!=this.Br&&document.activeElement!=this.yr)switch(t.keyCode){case 27:new Re(this.U,0,0),this.U.selection.resetBoxSelection();break;case 16:this.$o.shiftMode=!0;break;case 17:this.$o.controlMode=!0;break;case 32:t.ctrlKey||t.shiftKey?(this.U.synth.playing||this.Ce(),this._o.movePlayheadToMouse(),this.$o.movePlayheadToMouse()):this.Ce(),t.preventDefault();break;case 90:t.shiftKey?this.U.redo():this.U.undo(),t.preventDefault();break;case 89:this.U.redo(),t.preventDefault();break;case 67:this.U.selection.copy(),new Re(this.U,0,0),this.U.selection.resetBoxSelection(),t.preventDefault();break;case 13:this.U.selection.insertBars(),t.preventDefault();break;case 8:this.U.selection.deleteBars(),this.Po.animatePlayhead(),t.preventDefault();break;case 65:t.shiftKey?this.U.selection.selectChannel():this.U.selection.selectAll(),t.preventDefault();break;case 68:this.U.selection.duplicatePatterns(),t.preventDefault();break;case 70:this.U.synth.firstBar(),this.Po.animatePlayhead(),this.U.autoFollow&&new xt(this.U,this.U.channel,Math.floor(this.U.synth.playhead)),t.preventDefault();break;case 72:this.U.synth.jumpToEditingBar(this.U.bar),this.Po.animatePlayhead(),new xt(this.U,this.U.channel,Math.floor(this.U.synth.playhead)),t.preventDefault();break;case 76:t.shiftKey?this.dr("limiterSettings"):this.dr("barCount");break;case 77:this.U.enableChannelMuting&&(this.U.selection.muteChannels(t.shiftKey),t.preventDefault());break;case 78:const i=new nt;if(t.shiftKey||t.ctrlKey){let t=0;for(;t0;)t++;t++,t<=e.barCountMax&&(t>this.U.song.patternsPerChannel&&i.append(new oe(this.U,t)),i.append(new pt(this.U,t,this.U.bar,this.U.channel,1,1)))}else{let t=1;for(;-1!=this.U.song.channels[this.U.channel].bars.indexOf(t)&&t<=this.U.song.patternsPerChannel;)t++;t<=e.barCountMax&&(t>this.U.song.patternsPerChannel&&i.append(new oe(this.U,t)),i.append(new pt(this.U,t,this.U.bar,this.U.channel,1,1)))}this.U.record(i),t.preventDefault();break;case 81:this.dr("channelSettings");break;case 83:this.U.enableChannelMuting&&(t.shiftKey?this.U.selection.muteChannels(!1):this.U.selection.soloChannels(),t.preventDefault());break;case 86:t.shiftKey?this.U.selection.pasteNumbers():this.U.selection.pasteNotes(),t.preventDefault();break;case 87:this.dr("moveNotesSideways");break;case 73:if(t.shiftKey){const t=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].toJsonObject();delete t.volume,delete t.pan,delete t.preset,this.wl(JSON.stringify(t))}t.preventDefault();break;case 219:this.U.synth.prevBar(),this.U.autoFollow&&new xt(this.U,this.U.channel,Math.floor(this.U.synth.playhead)),this.Po.animatePlayhead(),t.preventDefault();break;case 221:this.U.synth.nextBar(),this.U.autoFollow&&new xt(this.U,this.U.channel,Math.floor(this.U.synth.playhead)),this.Po.animatePlayhead(),t.preventDefault();break;case 189:case 173:this.U.selection.transpose(!1,t.shiftKey||t.ctrlKey),t.preventDefault();break;case 187:case 61:case 171:this.U.selection.transpose(!0,t.shiftKey||t.ctrlKey),t.preventDefault();break;case 38:if(t.ctrlKey){if(0==this.U.channel||this.U.channel==this.U.song.pitchChannelCount||this.U.channel==this.U.song.pitchChannelCount+this.U.song.noiseChannelCount)break;this.U.record(new wt(this.U,this.U.channel-1,this.U.channel),!1),this.U.selection.setChannelBar(this.U.channel-1,this.U.bar)}else t.shiftKey?(this.U.selection.boxSelectionY1=Math.max(0,this.U.selection.boxSelectionY1-1),this.U.selection.selectionUpdated()):(this.U.selection.setChannelBar((this.U.channel-1+this.U.song.getChannelCount())%this.U.song.getChannelCount(),this.U.bar),this.U.selection.resetBoxSelection());t.preventDefault();break;case 40:if(t.ctrlKey){if(this.U.channel==this.U.song.pitchChannelCount-1||this.U.channel==this.U.song.pitchChannelCount+this.U.song.noiseChannelCount-1||this.U.channel==this.U.song.getChannelCount()-1)break;this.U.record(new wt(this.U,this.U.channel,this.U.channel+1),!1),this.U.selection.setChannelBar(this.U.channel+1,this.U.bar)}else t.shiftKey?(this.U.selection.boxSelectionY1=Math.min(this.U.song.getChannelCount()-1,this.U.selection.boxSelectionY1+1),this.U.selection.selectionUpdated()):(this.U.selection.setChannelBar((this.U.channel+1)%this.U.song.getChannelCount(),this.U.bar),this.U.selection.resetBoxSelection());t.preventDefault();break;case 37:t.shiftKey?(this.U.selection.boxSelectionX1=Math.max(0,this.U.selection.boxSelectionX1-1),this.U.selection.scrollToSelection(),this.U.selection.selectionUpdated()):(this.U.selection.setChannelBar(this.U.channel,(this.U.bar+this.U.song.barCount-1)%this.U.song.barCount),this.U.selection.resetBoxSelection()),t.preventDefault();break;case 39:t.shiftKey?(this.U.selection.boxSelectionX1=Math.min(this.U.song.barCount-1,this.U.selection.boxSelectionX1+1),this.U.selection.scrollToSelection(),this.U.selection.selectionUpdated()):(this.U.selection.setChannelBar(this.U.channel,(this.U.bar+1)%this.U.song.barCount),this.U.selection.resetBoxSelection()),t.preventDefault();break;case 46:this.U.selection.digits="",this.U.selection.nextDigit("0",!1);break;case 48:this.U.selection.nextDigit("0",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 49:this.U.selection.nextDigit("1",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 50:this.U.selection.nextDigit("2",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 51:this.U.selection.nextDigit("3",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 52:this.U.selection.nextDigit("4",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 53:this.U.selection.nextDigit("5",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 54:this.U.selection.nextDigit("6",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 55:this.U.selection.nextDigit("7",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 56:this.U.selection.nextDigit("8",t.shiftKey||t.ctrlKey),t.preventDefault();break;case 57:this.U.selection.nextDigit("9",t.shiftKey||t.ctrlKey),t.preventDefault();break;default:this.U.selection.digits="",this.U.selection.instrumentDigits=""}else 13!=t.keyCode&&27!=t.keyCode||this.mainLayer.focus()},this.kl=()=>{this.U.synth.prevBar(),this.Po.animatePlayhead()},this.xl=()=>{this.U.synth.nextBar(),this.Po.animatePlayhead()},this.Ce=()=>{this.U.synth.playing?this.Se():(this.U.synth.snapToBar(),this.qe())},this.Ml=()=>{this.El(),this.U.displayVolumeBar&&this.Ui(),this.Po.animatePlayhead(),window.requestAnimationFrame(this.Ml)},this.Ui=()=>{this.outVolumeHistoricTimer--,this.outVolumeHistoricTimer<=0&&(this.outVolumeHistoricCap-=.03),this.U.song.outVolumeCap>this.outVolumeHistoricCap&&(this.outVolumeHistoricCap=this.U.song.outVolumeCap,this.outVolumeHistoricTimer=50),this.U.song.outVolumeCap!=this.lastOutVolumeCap&&(this.lastOutVolumeCap=this.U.song.outVolumeCap,this.Cl(this.U.song.outVolumeCap,this.outVolumeHistoricCap))},this.Sl=()=>{this.U.setVolume(Number(this.Go.input.value))},this.ql=()=>{this.U.record(new Me(this.U,-1,0|parseInt(this.sr.value)))},this.Pl=()=>{if(isNaN(this.tr.value)){switch(this.tr.value){case"forceScale":this.U.selection.forceScale()}this.U.notifier.changed()}else this.U.record(new me(this.U,this.tr.selectedIndex))},this.Tl=()=>{if(isNaN(this.er.value)){switch(this.er.value){case"detectKey":this.U.record(new pe(this.U))}this.U.notifier.changed()}else this.U.record(new Kt(this.U,e.keys.length-1-this.er.selectedIndex))},this.Bl=()=>{if(isNaN(this.hr.value)){switch(this.hr.value){case"forceRhythm":this.U.selection.forceRhythm()}this.U.notifier.changed()}else this.U.record(new Xt(this.U,this.hr.selectedIndex))},this.zl=()=>{var t=this;setTimeout((function(){t.mainLayer.focus()}),20)},this.Rl=()=>{this.Nl($("#pitchPresetSelect").val()+"")},this.Fl=()=>{this.Nl($("#drumPresetSelect").val()+"")},this.Ll=()=>{this.U.record(new Ot(this.U,this.ba.selectedIndex))},this.Al=()=>{this.U.record(new Ut(this.U,this.Fa.selectedIndex))},this.Hl=()=>{this.U.record(new _t(this.U,this.lr.selectedIndex))},this.Dl=()=>{this.U.selection.setInstrument(this.ur.selectedIndex),this.U.channel>=this.U.song.pitchChannelCount+this.U.song.noiseChannelCount&&this.Is.forceRender()},this.$l=t=>{this.U.selection.setModChannel(t,this.fl[t].selectedIndex),this.Is.forceRender()},this.Il=t=>{this.U.selection.setModInstrument(t,this.ml[t].selectedIndex),this.Is.forceRender()},this.yl=t=>{this.U.selection.setModSetting(t,this.pl[t].children[this.pl[t].selectedIndex].textContent),this.Is.forceRender()},this._l=()=>{this.U.record(new Ue(this.U,this.Rr.selectedIndex))},this.Ol=()=>{this.U.record(new Ve(this.U,this.Nr.selectedIndex))},this.Ul=()=>{this.U.record(new It(this.U,this.Ur.selectedIndex))},this.Vl=()=>{this.U.record(new Ht(this.U,this.jr.selectedIndex))},this.jl=()=>{this.U.record(new ft(this.U,this.Ar.selectedIndex))},this.Wl=()=>{this.U.record(new mt(this.U,this.Dr.selectedIndex))},this.Gl=()=>{this.U.record(new Ct(this.U,this.ha.selectedIndex))},this.Jl=()=>{this.U.record(new Tt(this.U,this.ma.selectedIndex))},this.Kl=()=>{this.U.record(new Mt(this.U,this.Kr.selectedIndex))},this.Yl=()=>{this.U.record(new Et(this.U,this.Zr.selectedIndex))},this.Zl=t=>{switch(this.Zo.value){case"new":this.U.goBackToStart();for(const t of this.U.song.channels)t.muted=!1;this.U.record(new be(this.U,""),!1,!0);break;case"export":this.dr("export");break;case"import":this.dr("import");break;case"copyUrl":this.wl(new URL("#"+this.U.song.toBase64String(),location.href).href);break;case"shareUrl":navigator.share({url:new URL("#"+this.U.song.toBase64String(),location.href).href});break;case"shortenUrl":window.open("https://tinyurl.com/api-create.php?url="+encodeURIComponent(new URL("#"+this.U.song.toBase64String(),location.href).href));break;case"viewPlayer":location.href="player/#song="+this.U.song.toBase64String();break;case"copyEmbed":this.wl(``);break;case"songRecovery":this.dr("songRecovery")}this.Zo.selectedIndex=0},this.Ql=t=>{switch(this.Qo.value){case"undo":this.U.undo();break;case"redo":this.U.redo();break;case"copy":this.U.selection.copy();break;case"insertBars":this.U.selection.insertBars();break;case"deleteBars":this.U.selection.deleteBars();break;case"pasteNotes":this.U.selection.pasteNotes();break;case"pasteNumbers":this.U.selection.pasteNumbers();break;case"transposeUp":this.U.selection.transpose(!0,!1);break;case"transposeDown":this.U.selection.transpose(!1,!1);break;case"selectAll":this.U.selection.selectAll();break;case"selectChannel":this.U.selection.selectChannel();break;case"duplicatePatterns":this.U.selection.duplicatePatterns();break;case"barCount":this.dr("barCount");break;case"beatsPerBar":this.dr("beatsPerBar");break;case"moveNotesSideways":this.dr("moveNotesSideways");break;case"channelSettings":this.dr("channelSettings");break;case"limiterSettings":this.dr("limiterSettings")}this.Qo.selectedIndex=0},this.Xl=t=>{switch(this.Xo.value){case"autoPlay":this.U.autoPlay=!this.U.autoPlay;break;case"autoFollow":this.U.autoFollow=!this.U.autoFollow;break;case"enableNotePreview":this.U.enableNotePreview=!this.U.enableNotePreview;break;case"showLetters":this.U.showLetters=!this.U.showLetters;break;case"showFifth":this.U.showFifth=!this.U.showFifth;break;case"showChannels":this.U.showChannels=!this.U.showChannels;break;case"showScrollBar":this.U.showScrollBar=!this.U.showScrollBar;break;case"alwaysFineNoteVol":this.U.alwaysFineNoteVol=!this.U.alwaysFineNoteVol;break;case"enableChannelMuting":this.U.enableChannelMuting=!this.U.enableChannelMuting;for(const t of this.U.song.channels)t.muted=!1;break;case"displayBrowserUrl":this.U.toggleDisplayBrowserUrl();break;case"displayVolumeBar":this.U.displayVolumeBar=!this.U.displayVolumeBar;break;case"fullScreen":this.dr("layout");break;case"colorTheme":this.dr("theme")}this.Xo.selectedIndex=0,this.U.notifier.changed(),this.U.savePreferences()},this.tc=t=>{let i=new Float64Array(64),s=this.Ta.selectedIndex-1,n=Number.MIN_VALUE,h=Number.MAX_VALUE,o=0,r=(e.chipWaves[s].samples.length-1)/64;for(let t=0;t<64;t++)i[t]=(e.chipWaves[s].samples[Math.floor(o)]-e.chipWaves[s].samples[Math.floor(o)+1])/r,i[t]n&&(n=i[t]),o+=r;for(let t=0;t<64;t++)i[t]-=h,i[t]/=n-h,i[t]*=48,i[t]-=24,i[t]=Math.ceil(i[t]),this.Pa.newArray[t]=i[t];this.U.record(new ct(this.U,i)),this.U.record(new Ae(this.U,+this.pr.input.value,-e.volumeRange/2+Math.round(Math.sqrt(e.chipWaves[s].volume)*e.volumeRange/2))),this.Ta.selectedIndex=0,this.U.notifier.changed(),this.U.savePreferences()},this.U.notifier.watch(this.whenUpdated),window.addEventListener("resize",this.whenUpdated),"share"in navigator||this.Zo.removeChild(this.Zo.querySelector("[value='shareUrl']")),this.tr.appendChild(tn({label:"Edit"},en({value:"forceScale"},"Snap Notes To Scale"))),this.er.appendChild(tn({label:"Edit"},en({value:"detectKey"},"Detect Key"))),this.hr.appendChild(tn({label:"Edit"},en({value:"forceRhythm"},"Snap Notes To Rhythm"))),this.ha.appendChild(en({hidden:!0,value:5},"custom")),this.il=new Array(Y.mstMaxValue),this.nl=new Array(Y.mstMaxValue),this.ga.appendChild(Ys({class:"operatorRow",style:"color: ${ColorConfig.secondaryText}; height: 1em; margin-top: 0.5em;"},Ys({style:"margin-right: .1em; visibility: hidden;"},"1."),Ys({style:"width: 3em; margin-right: .3em;",class:"tip",onclick:()=>this.dr("operatorFrequency")},"Freq:"),Ys({style:"width: 4em; margin: 0;",class:"tip",onclick:()=>this.dr("operatorVolume")},"Volume:"),Ys({style:"width: 5em; margin-left: .3em;",class:"tip",onclick:()=>this.dr("operatorEnvelope")},"Envelope:")));for(let t=0;tt.name))),h=new qi(Zs({style:"margin: 0; width: 4em;",type:"range",min:"0",max:e.operatorAmplitudeMax,value:"0",step:"1",title:"Volume"}),this.U,((t,e)=>new Wt(this.U,i,t,e)),!1),o=nn(Qs({style:"width: 100%;",title:"Envelope"}),e.envelopes.map((t=>t.name))),r=Ys({class:"operatorRow"},s,Ys({class:"selectContainer",style:"width: 3em; margin-right: .3em;"},n),h.container,Ys({class:"selectContainer",style:"width: 5em; margin-left: .3em;"},o));this.ga.appendChild(r),this.Ya[t]=r,this.Za[t]=h,this.Qa[t]=o,this.Xa[t]=n,o.addEventListener("change",(()=>{this.U.record(new Vt(this.U,i,o.selectedIndex))})),n.addEventListener("change",(()=>{this.U.record(new jt(this.U,i,n.selectedIndex))}))}this.Ea.appendChild(Ys({class:"selectRow"},Xs({class:"tip",onclick:()=>this.dr("drumsetEnvelope")},"Envelope:"),Xs({class:"tip",onclick:()=>this.dr("drumsetSpectrum")},"Spectrum:")));for(let t=e.drumCount-1;t>=0;t--){const i=t,s=new Fs(this.U,i);s.container.addEventListener("mousedown",this.refocusStage),this.tl[t]=s;const n=nn(Qs({style:"width: 100%;",title:"Filter Envelope"}),e.envelopes.map((t=>t.name)));this.el[t]=n,n.addEventListener("change",(()=>{this.U.record(new Ft(this.U,i,n.selectedIndex))}));const h=Ys({class:"selectRow"},Ys({class:"selectContainer",style:"width: 5em; margin-right: .3em;"},n),this.tl[t].container);this.Ea.appendChild(h)}this.ec=[],this.fl=[],this.ml=[],this.ic=[],this.pl=[];for(let t=0;tthis.dr("modChannel")},"Ch:"),Ys({class:"selectContainer"},e),Ys({class:"tip",style:"width: 1.2em; margin-left: 0.8em;",id:"modInstrumentText"+t,onclick:()=>this.dr("modInstrument")},"Ins:"),Ys({class:"selectContainer"},i)),n=Qs(),h=Ys({class:"selectRow",id:"modSettingText"+t,style:"margin-bottom: 0.9em; color: currentColor;"},Xs({class:"tip",onclick:()=>this.dr("modSet")},"Setting: "),Ys({class:"selectContainer"},n));this.ec.push(s),this.fl.push(e),this.ml.push(i),this.ic.push(h),this.pl.push(n),this.Ca.appendChild(Ys({style:"margin: 3px 0; font-weight: bold; margin-bottom: 0.7em; text-align: center; color: "+T.secondaryText+"; background: "+T.uiWidgetBackground+";"},"Modulator "+(t+1))),this.Ca.appendChild(s),this.Ca.appendChild(h)}this.Zo.addEventListener("change",this.Zl),this.Qo.addEventListener("change",this.Ql),this.Xo.addEventListener("change",this.Xl),this.Ta.addEventListener("change",this.tc),this.sr.addEventListener("change",this.ql),this.tr.addEventListener("change",this.Pl),this.er.addEventListener("change",this.Tl),this.hr.addEventListener("change",this.Bl),this.lr.addEventListener("change",this.Hl),this.ur.addEventListener("change",this.Dl),this.ba.addEventListener("change",this.Ll),this.Fa.addEventListener("change",this.Al),this.Rr.addEventListener("change",this._l),this.Nr.addEventListener("change",this.Ol),this.Ar.addEventListener("change",this.jl),this.Dr.addEventListener("change",this.Wl),this.Ur.addEventListener("change",this.Ul),this.jr.addEventListener("change",this.Vl),this.Kr.addEventListener("change",this.Kl),this.Zr.addEventListener("change",this.Yl),this.ha.addEventListener("change",this.Gl),this.ma.addEventListener("change",this.Jl),this.Ee.addEventListener("click",this.Ce),this.jo.addEventListener("click",this.kl),this.Wo.addEventListener("click",this.xl),this.Go.input.addEventListener("input",this.Sl),this.Va.addEventListener("mousedown",this.ul),this.Wa.addEventListener("mousedown",this.refocusStage),this.Go.container.style.setProperty("flex-grow","1"),this.Go.container.style.setProperty("display","flex"),this.Ko.style.setProperty("flex-grow","1"),this.Ko.style.setProperty("display","flex"),this.Go.container.style.setProperty("--mod-color",T.multiplicativeModSlider),this.Go.container.style.setProperty("--mod-border-radius","50%"),this.pr.container.style.setProperty("--mod-color",T.multiplicativeModSlider),this.pr.container.style.setProperty("--mod-border-radius","50%"),this.Na.container.style.setProperty("--mod-color",T.multiplicativeModSlider),this.Na.container.style.setProperty("--mod-border-radius","50%");for(let t=0;t{this.U.record(new Ae(this.U,this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].volume,Math.min(25,Math.max(-25,Math.round(+this.yr.value)))))})),this.Er.addEventListener("input",(()=>{this.U.record(new $e(this.U,this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].pan,Math.min(100,Math.max(0,Math.round(+this.Er.value)))))})),this.Br.addEventListener("input",(()=>{this.U.record(new _e(this.U,this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].detune,Math.min(e.detuneMax,Math.max(e.detuneMin,Math.round(+this.Br.value)))))})),this.za.addEventListener("input",(()=>{this.U.record(new ct(this.U,this.Pa.newArray))})),this.ia.addEventListener("input",(()=>{this.U.record(new zt(this.U,this.ia.checked))})),this.Oa.addEventListener("click",(t=>{t.target==this.Oa&&this.U.undo()})),a){const t=this.Xo.querySelector("[value=autoPlay]");t.disabled=!0,t.setAttribute("hidden","")}if(window.screen.availWidth<700){const t=this.Xo.querySelector("[value=fullScreen]");t.disabled=!0,t.setAttribute("hidden","")}}Mr(t){let e=this.oa,i=this.ya;switch(t){case 0:e=this.oa,this.cl=!this.cl,i=this.ya;break;case 1:e=this.kr,this.ll=!this.ll,i=this.Pr;break;case 2:e=this.Qr,this.dl=!this.dl,i=this.na}"▼"==e.textContent?(e.textContent="▲",(i!=this.na||2==this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].chord)&&(i.style.display="")):(e.textContent="▼",i.style.display="none")}El(){if(this.U.synth.playing){let e=this.U.getCurrentInstrument();const i=this.U.synth.isAnyModActive(this.U.channel,e);if(i){let e=this.U.getCurrentInstrument();function t(t,e,i,s,n){const h=t.U.synth.song.isSettingForSong(i);if(t.U.synth.isModActive(i,h,s,n)){let o=t.U.synth.song.realToModValue(t.U.synth.getModValue(i,h,s,n,!1),i)/t.U.song.mstMaxVols.get(i);return o!=t.nl[i]&&(t.nl[i]=o,e.container.style.setProperty("--mod-position",96*o+2+"%")),!0}return!1}for(let i=0;i{window.prompt("Copy to clipboard:",t)}));const i=document.createElement("textarea");i.innerText=t,document.body.appendChild(i),i.select();const s=document.execCommand("copy");i.remove(),this.refocusStage(),s||window.prompt("Copy this:",t)}qe(){this.U.synth.play(),this.updatePlayButton(),window.requestAnimationFrame(this.Ml)}Se(){this.U.synth.pause(),this.U.synth.resetEffects(),this.U.autoFollow&&this.U.synth.goToBar(this.U.bar),this.U.synth.snapToBar(),this.updatePlayButton(),window.clearInterval(this.ol),window.clearInterval(this.rl),window.clearInterval(this.al),window.requestAnimationFrame(this.Ml),this.outVolumeHistoricCap=0}Cl(t,e){this.Fi.setAttribute("width",""+Math.min(144,144*t)),this.Li.setAttribute("x",""+(8+Math.min(144,144*e)))}sc(){const t=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()].toJsonObject();t.isDrum=this.U.song.getChannelIsNoise(this.U.channel),window.localStorage.setItem("instrumentCopy",JSON.stringify(t)),this.refocusStage()}nc(){const t=this.U.song.channels[this.U.channel].instruments[this.U.getCurrentInstrument()],e=JSON.parse(String(window.localStorage.getItem("instrumentCopy")));null!=e&&e.isDrum==this.U.song.getChannelIsNoise(this.U.channel)&&this.U.record(new ee(this.U,t,e)),this.refocusStage()}oc(){const t=this.U.song.getChannelIsNoise(this.U.channel);this.U.record(new dt(this.U,ye(t)))}rc(){this.U.record(new ut(this.U))}Nl(t){if(isNaN(t)){switch(t){case"copyInstrument":this.sc();break;case"pasteInstrument":this.nc();break;case"randomPreset":this.oc();break;case"randomGenerated":this.rc()}this.U.notifier.changed()}else this.U.record(new dt(this.U,parseInt(t)))}}class ln{constructor(t){this.U=t,this.boxSelectionX0=0,this.boxSelectionY0=0,this.boxSelectionX1=0,this.boxSelectionY1=0,this.digits="",this.instrumentDigits="",this.patternSelectionStart=0,this.patternSelectionEnd=0,this.patternSelectionActive=!1,this.ac=null}toJSON(){return{x0:this.boxSelectionX0,x1:this.boxSelectionX1,y0:this.boxSelectionY0,y1:this.boxSelectionY1,start:this.patternSelectionStart,end:this.patternSelectionEnd}}fromJSON(t){null!=t&&(this.boxSelectionX0=+t.x0,this.boxSelectionX1=+t.x1,this.boxSelectionY0=+t.y0,this.boxSelectionY1=+t.y1,this.patternSelectionStart=+t.start,this.patternSelectionEnd=+t.end,this.digits="",this.instrumentDigits="",this.patternSelectionActive=this.patternSelectionStart1||this.boxSelectionHeight>1)&&t.append(new Fe(this.U,this.boxSelectionBar,this.boxSelectionWidth,this.boxSelectionChannel,this.boxSelectionHeight));for(const e of this.lc())for(const i of this.cc(e))t.append(new qe(this.U,i,this.U.selection.patternSelectionStart,this.U.selection.patternSelectionEnd));t.append(new Re(this.U,0,0))}else{t.append(new bt(this.U,this.boxSelectionBar,this.boxSelectionWidth));const e=this.boxSelectionWidth;this.boxSelectionX0=Math.max(0,this.boxSelectionX0-e),this.boxSelectionX1=Math.max(0,this.boxSelectionX1-e)}this.U.record(t)}*lc(){for(let t=this.boxSelectionChannel;t=this.patternSelectionEnd||((t.startthis.patternSelectionEnd)&&new Se(null,t,Math.max(t.start,this.patternSelectionStart),Math.min(this.patternSelectionEnd,t.end)),t.start-=this.patternSelectionStart,t.end-=this.patternSelectionStart,o.push(t));else o=s.notes;i[String(n)]={instrument:h,notes:o}}}const n={isNoise:this.U.song.getChannelIsNoise(e),isMod:this.U.song.getChannelIsMod(e),patterns:i,bars:s};t.push(n)}const i={partDuration:this.patternSelectionActive?this.patternSelectionEnd-this.patternSelectionStart:this.U.song.beatsPerBar*e.partsPerBeat,channels:t};window.localStorage.setItem("selectionCopy",JSON.stringify(i))}pasteNotes(){const t=JSON.parse(String(window.localStorage.getItem("selectionCopy")));if(null==t)return;const i=t.channels||[],s=t.partDuration>>>0,n=new nt,h=this.boxSelectionWidth>1||this.boxSelectionHeight>1,o=h?this.boxSelectionHeight:Math.min(i.length,this.U.song.getChannelCount()-this.boxSelectionChannel);for(let t=0;t>>0,r=this.U.song.channels[a].bars[h],l=[o,r].join(",");if(0==o&&0==r)continue;if(null!=t[l]){n.append(new pt(this.U,t[l],h,a,1,1));continue}if(0==r){n.append(new re(this.U,a,h));const t=d[String(o)],e=Math.min(t.instrument>>>0,this.U.song.instrumentsPerChannel-1),i=this.U.song.getPattern(a,h);n.append(new ie(this.U,e,i))}else{const t=this.U.song.getPattern(a,h);if(null==t)throw new Error;if(e[String(r)]){n.append(new pt(this.U,0,h,a,1,1)),n.append(new re(this.U,a,h));const e=this.U.song.getPattern(a,h);if(null==e)throw new Error;n.append(new ie(this.U,t.instrument,e));for(const i of t.cloneNotes())n.append(new Ce(this.U,e,i,e.notes.length,!1))}else e[String(r)]=!0}const c=this.U.song.getPattern(a,h);if(null==c)throw new Error;if(0==o)n.append(new qe(this.U,c,this.patternSelectionStart,this.patternSelectionEnd));else{const t=d[String(o)];n.append(new te(this.U,c,t.notes,this.patternSelectionStart,this.patternSelectionEnd,s))}t[l]=this.U.song.channels[a].bars[h]}}else{for(let t=0;t>>0,r=String(o);if(0==o)continue;if(null!=t[r]){n.append(new pt(this.U,t[r],h,a,1,1));continue}const l=d[String(o)],c=Math.min(l.instrument>>>0,this.U.song.instrumentsPerChannel-1),f=this.U.song.channels[a].patterns[o-1];if(null!=f&&s==e.partsPerBeat*this.U.song.beatsPerBar&&ke(l.notes,f.notes)&&c==f.instrument)n.append(new pt(this.U,o,h,a,1,1));else{null!=f&&this.uc(a,o)?n.append(new pt(this.U,o,h,a,1,1)):n.append(new re(this.U,a,h));const t=this.U.song.getPattern(a,h);if(null==t)throw new Error;n.append(new te(this.U,t,l.notes,this.patternSelectionActive?this.patternSelectionStart:0,this.patternSelectionActive?this.patternSelectionEnd:e.partsPerBeat*this.U.song.beatsPerBar,s)),n.append(new ie(this.U,c,t))}t[r]=this.U.song.channels[a].bars[h]}}else{const t=u[0]>>>0,i=this.boxSelectionBar,h=this.U.song.channels[a].bars[i];if(0==t&&0==h)continue;const o=d[String(t)],r=Math.min(o.instrument>>>0,this.U.song.instrumentsPerChannel-1);if(0==h){const e=this.U.song.channels[a].patterns[t-1];null!=e&&!this.patternSelectionActive&&(ke(o.notes,e.notes)&&r==e.instrument||this.uc(a,t))?n.append(new pt(this.U,t,i,a,1,1)):n.append(new re(this.U,a,i))}const l=this.U.song.getPattern(a,i);if(null==l)throw new Error;n.append(new te(this.U,l,o.notes,this.patternSelectionActive?this.patternSelectionStart:0,this.patternSelectionActive?this.patternSelectionEnd:e.partsPerBeat*this.U.song.beatsPerBar,s)),n.append(new ie(this.U,r,l))}}this.U.record(n)}pasteNumbers(){const t=JSON.parse(String(window.localStorage.getItem("selectionCopy")));if(null==t)return;const e=t.channels||[],i=new nt,s=this.boxSelectionWidth>1||this.boxSelectionHeight>1,n=s?this.boxSelectionHeight:Math.min(e.length,this.U.song.getChannelCount()-this.boxSelectionChannel);for(let t=0;t>>0,s=this.boxSelectionBar+t;e>this.U.song.patternsPerChannel&&i.append(new oe(this.U,e)),i.append(new pt(this.U,e,s,h,1,1))}}this.U.record(i)}selectAll(){new Re(this.U,0,0),0==this.boxSelectionBar&&0==this.boxSelectionChannel&&this.boxSelectionWidth==this.U.song.barCount&&this.boxSelectionHeight==this.U.song.getChannelCount()?this.setTrackSelection(this.U.bar,this.U.bar,this.U.channel,this.U.channel):this.setTrackSelection(0,this.U.song.barCount-1,0,this.U.song.getChannelCount()-1),this.selectionUpdated()}selectChannel(){new Re(this.U,0,0),0==this.boxSelectionBar&&this.boxSelectionWidth==this.U.song.barCount?this.setTrackSelection(this.U.bar,this.U.bar,this.boxSelectionY0,this.boxSelectionY1):this.setTrackSelection(0,this.U.song.barCount-1,this.boxSelectionY0,this.boxSelectionY1),this.selectionUpdated()}duplicatePatterns(){this.U.record(new Fe(this.U,this.boxSelectionBar,this.boxSelectionWidth,this.boxSelectionChannel,this.boxSelectionHeight))}muteChannels(t){if(t){let t=!1;for(let e=0;e=this.boxSelectionChannel+this.boxSelectionHeight;if(this.U.song.channels[e].muted!=i){t=!1;break}}if(t)for(let t=0;t=this.boxSelectionChannel+this.boxSelectionHeight;this.U.notifier.changed()}forceRhythm(){const t=new nt;(this.boxSelectionWidth>1||this.boxSelectionHeight>1)&&t.append(new Fe(this.U,this.boxSelectionBar,this.boxSelectionWidth,this.boxSelectionChannel,this.boxSelectionHeight));for(const e of this.lc())for(const i of this.cc(e))t.append(new ce(this.U,i));this.U.record(t)}forceScale(){const t=new nt;(this.boxSelectionWidth>1||this.boxSelectionHeight>1)&&t.append(new Fe(this.U,this.boxSelectionBar,this.boxSelectionWidth,this.boxSelectionChannel,this.boxSelectionHeight));const i=[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1];for(const t of this.lc())if(!this.U.song.getChannelIsNoise(t)&&!this.U.song.getChannelIsMod(t))for(const e of this.cc(t))ot(e,i);const s=function(t,i){const s=e.scales[i].flags,n=[],h=[];for(let e=0;e<12;e++)t[e]&&n.push(e),s[e]&&h.push(e);const o=n.length>h.length,r=o?h:n,a=o?n:h,l=["root","second","second","third","third","fourth","tritone","fifth","sixth","sixth","seventh","seventh","root"];let c=Number.MAX_SAFE_INTEGER,d=[];const u=[[0]];for(;u.length>0;){const t=u.pop();if(t.length==r.length){let e=0;for(let i=0;ie&&(c=e,d=t)}else{const e=t[t.length-1]+1,i=a.length-r.length+t.length;for(let s=e;s<=i;s++)u.push(t.concat(s))}}const f=[];for(let t=0;ti&&(a=i,r=e)}p[t]=r}return p}(i,this.U.song.scale);for(const e of this.lc())if(!this.U.song.getChannelIsNoise(e)&&!this.U.song.getChannelIsMod(e))for(const i of this.cc(e))t.append(new Le(this.U,i,s));this.U.record(t)}setTrackSelection(t,e,i,s){new ze(this.U,t,e,i,s)}transpose(t,e){const i=this.U.lastChangeWas(this.ac);this.ac=new nt,(this.boxSelectionWidth>1||this.boxSelectionHeight>1)&&this.ac.append(new Fe(this.U,this.boxSelectionBar,this.boxSelectionWidth,this.boxSelectionChannel,this.boxSelectionHeight));for(const i of this.lc())for(const s of this.cc(i))this.ac.append(new Be(this.U,i,s,t,!1,e));this.U.record(this.ac,i)}setInstrument(t){const e=new nt;(this.boxSelectionWidth>1||this.boxSelectionHeight>1)&&e.append(new Fe(this.U,this.boxSelectionBar,this.boxSelectionWidth,this.boxSelectionChannel,this.boxSelectionHeight));for(const i of this.lc())for(const s of this.cc(i))e.append(new ie(this.U,t,s));this.U.record(e)}resetBoxSelection(){this.boxSelectionX0=this.boxSelectionX1=this.U.bar,this.boxSelectionY0=this.boxSelectionY1=this.U.channel}}class cn{constructor(){this.fc=[],this.mc=!1}watch(t){-1==this.fc.indexOf(t)&&this.fc.push(t)}unwatch(t){const e=this.fc.indexOf(t);-1!=e&&this.fc.splice(e,1)}changed(){this.mc=!0}notifyWatchers(){if(this.mc){this.mc=!1;for(const t of this.fc.concat())t()}}}class dn{constructor(){this.notifier=new cn,this.selection=new ln(this),this.channel=0,this.muteEditorChannel=0,this.bar=0,this.alwaysFineNoteVol=!1,this.alwaysShowSettings=!0,this.displayVolumeBar=!0,this.volume=75,this.trackVisibleBars=16,this.barScrollPos=0,this.prompt=null,this.windowOctaves=+(window.localStorage.getItem("extraOctaves")||"0")+3,this.scrollableOctaves=e.pitchOctaves-this.windowOctaves,this.windowPitchCount=this.windowOctaves*e.pitchesPerOctave+1,this.yc=new Cs,this.gc=null,this.bc=0,this.vc=!1,this.wc=!1,this.kc=!1,this.xc=()=>{if(null==window.history.state&&""!=window.location.hash){this.bc++,this.Mc();const t={canUndo:!0,sequenceNumber:this.bc,bar:this.bar,channel:this.channel,recoveryUid:this.Ec,prompt:null,selection:this.selection.toJSON()};return new be(this,window.location.hash),this.prompt=t.prompt,this.displayBrowserUrl?this.Cc(t,this.song.toBase64String()):this.Sc(t,this.song.toBase64String()),this.forgetLastChange(),void this.notifier.notifyWatchers()}const t=this.qc();if(null==t)throw new Error("History state is null.");t.sequenceNumber!=this.bc&&(this.bar=t.bar,this.channel=t.channel,this.bc=t.sequenceNumber,this.prompt=t.prompt,new be(this,this.Pc()),this.Ec=t.recoveryUid,this.selection.fromJSON(t.selection),this.forgetLastChange(),this.notifier.notifyWatchers())},this.Tc=()=>{this.notifier.notifyWatchers()},this.Bc=()=>{(!this.synth.playing&&(this.bar{this.kc=!1;const t=this.song.toBase64String();this.vc&&this.bc++,this.wc?this.Mc():this.yc.saveVersion(this.Ec,this.song.title,t);let e={canUndo:!0,sequenceNumber:this.bc,bar:this.bar,channel:this.channel,recoveryUid:this.Ec,prompt:this.prompt,selection:this.selection.toJSON()};this.vc?this.Sc(e,t):this.Cc(e,t),this.vc=!1,this.wc=!1},this.notifier.watch(this.Bc),this.autoPlay="true"==window.localStorage.getItem("autoPlay"),this.autoFollow="true"==window.localStorage.getItem("autoFollow"),this.enableNotePreview="true"==window.localStorage.getItem("enableNotePreview"),this.showFifth="true"==window.localStorage.getItem("showFifth"),this.showLetters="true"==window.localStorage.getItem("showLetters"),this.showChannels="true"==window.localStorage.getItem("showChannels"),this.showScrollBar="true"==window.localStorage.getItem("showScrollBar"),this.alwaysFineNoteVol="true"==window.localStorage.getItem("alwaysFineNoteVol"),this.enableChannelMuting="true"==window.localStorage.getItem("enableChannelMuting"),this.displayBrowserUrl="false"!=window.localStorage.getItem("displayBrowserUrl"),this.displayVolumeBar="false"!=window.localStorage.getItem("displayVolumeBar"),this.fullScreen=window.localStorage.getItem("fullScreen")||"normal",this.colorTheme=window.localStorage.getItem("colorTheme")||"jummbox classic",T.setTheme(this.colorTheme),Li.setFullScreen(this.fullScreen),null!=window.localStorage.getItem("volume")&&(this.volume=Math.min(window.localStorage.getItem("volume")>>>0,75)),null==window.sessionStorage.getItem("currentUndoIndex")&&(window.sessionStorage.setItem("currentUndoIndex","0"),window.sessionStorage.setItem("oldestUndoIndex","0"),window.sessionStorage.setItem("newestUndoIndex","0"));let t=window.location.hash;""==t&&(t=this.Pc()),this.song=new Q(t),""!=t&&null!=t||ge(this.song),t=this.song.toBase64String(),this.synth=new tt(this.song),this.synth.volume=this.Rc();let i=this.qc();null==i&&(i={canUndo:!1,sequenceNumber:0,bar:0,channel:0,recoveryUid:xs(),prompt:null,selection:this.selection.toJSON()}),null==i.recoveryUid&&(i.recoveryUid=xs()),this.Cc(i,t),window.addEventListener("hashchange",this.xc),window.addEventListener("popstate",this.xc),this.bar=i.bar,this.channel=i.channel,this.Ec=i.recoveryUid,this.barScrollPos=Math.max(0,this.bar-(this.trackVisibleBars-6)),this.prompt=i.prompt,this.selection.fromJSON(i.selection);for(const t of["input","change","click","keyup","keydown","mousedown","mousemove","mouseup","touchstart","touchmove","touchend","touchcancel"])window.addEventListener(t,this.Tc)}toggleDisplayBrowserUrl(){const t=this.qc();this.displayBrowserUrl=!this.displayBrowserUrl,this.Cc(t,this.song.toBase64String())}qc(){if(this.displayBrowserUrl)return window.history.state;{const t=JSON.parse(window.sessionStorage.getItem(window.sessionStorage.getItem("currentUndoIndex")));return null==t?null:t.state}}Pc(){if(this.displayBrowserUrl)return window.location.hash;{const t=JSON.parse(window.sessionStorage.getItem(window.sessionStorage.getItem("currentUndoIndex")));return null==t?"":t.hash}}Cc(t,e){this.displayBrowserUrl?window.history.replaceState(t,"","#"+e):(window.sessionStorage.setItem(window.sessionStorage.getItem("currentUndoIndex")||"0",JSON.stringify({state:t,hash:e})),window.history.replaceState(null,"",location.pathname))}Sc(t,e){if(this.displayBrowserUrl)window.history.pushState(t,"","#"+e);else{let i=Number(window.sessionStorage.getItem("currentUndoIndex")),s=Number(window.sessionStorage.getItem("oldestUndoIndex"));i=(i+1)%dn.Nc,window.sessionStorage.setItem("currentUndoIndex",String(i)),window.sessionStorage.setItem("newestUndoIndex",String(i)),i==s&&(s=(s+1)%dn.Nc,window.sessionStorage.setItem("oldestUndoIndex",String(s))),window.sessionStorage.setItem(String(i),JSON.stringify({state:t,hash:e})),window.history.replaceState(null,"",location.pathname)}}Fc(){if(this.displayBrowserUrl)window.history.forward();else{let t=Number(window.sessionStorage.getItem("currentUndoIndex"));t!=Number(window.sessionStorage.getItem("newestUndoIndex"))&&(t=(t+1)%dn.Nc,window.sessionStorage.setItem("currentUndoIndex",String(t)),setTimeout(this.xc))}}Lc(){if(this.displayBrowserUrl)window.history.back();else{let t=Number(window.sessionStorage.getItem("currentUndoIndex"));t!=Number(window.sessionStorage.getItem("oldestUndoIndex"))&&(t=(t+dn.Nc-1)%dn.Nc,window.sessionStorage.setItem("currentUndoIndex",String(t)),setTimeout(this.xc))}}record(t,e=!1,i=!1){t.isNoop()?(this.gc=null,e&&this.Lc()):(t.commit(),this.gc=t,this.vc=this.vc||!e,this.wc=this.wc||i,this.kc||(window.requestAnimationFrame(this.zc),this.kc=!0))}Mc(){this.Ec=xs()}openPrompt(t){this.prompt=t;const e=this.song.toBase64String();this.bc++;const i={canUndo:!0,sequenceNumber:this.bc,bar:this.bar,channel:this.channel,recoveryUid:this.Ec,prompt:this.prompt,selection:this.selection.toJSON()};this.Sc(i,e)}undo(){this.qc().canUndo&&this.Lc()}redo(){this.Fc()}setProspectiveChange(t){this.gc=t}forgetLastChange(){this.gc=null}lastChangeWas(t){return null!=t&&t==this.gc}goBackToStart(){this.channel=0,this.bar=0,this.barScrollPos=0,this.notifier.changed(),this.synth.snapToStart(),this.notifier.changed()}savePreferences(){window.localStorage.setItem("autoPlay",this.autoPlay?"true":"false"),window.localStorage.setItem("autoFollow",this.autoFollow?"true":"false"),window.localStorage.setItem("enableNotePreview",this.enableNotePreview?"true":"false"),window.localStorage.setItem("showFifth",this.showFifth?"true":"false"),window.localStorage.setItem("showLetters",this.showLetters?"true":"false"),window.localStorage.setItem("showChannels",this.showChannels?"true":"false"),window.localStorage.setItem("showScrollBar",this.showScrollBar?"true":"false"),window.localStorage.setItem("alwaysFineNoteVol",this.alwaysFineNoteVol?"true":"false"),window.localStorage.setItem("enableChannelMuting",this.enableChannelMuting?"true":"false"),window.localStorage.setItem("displayBrowserUrl",this.displayBrowserUrl?"true":"false"),window.localStorage.setItem("displayVolumeBar",this.displayVolumeBar?"true":"false"),window.localStorage.setItem("fullScreen",this.fullScreen),window.localStorage.setItem("colorTheme",this.colorTheme),window.localStorage.setItem("volume",String(this.volume))}setVolume(t){this.volume=t,this.savePreferences(),this.synth.volume=this.Rc()}Rc(){return Math.min(1,Math.pow(this.volume/50,.5))*Math.pow(2,(this.volume-75)/25)}getCurrentPattern(t=0){return this.song.getPattern(this.channel,this.bar+t)}getCurrentInstrument(t=0){const e=this.getCurrentPattern(t);return null==e?0:e.instrument}getMobileLayout(){return"widefullscreen"==this.fullScreen?window.innerWidth<=1e3:window.innerWidth<=700}getBarWidth(){return this.getMobileLayout()||!this.enableChannelMuting||this.getFullScreen()&&"widefullscreen"!=this.fullScreen?32:30}getChannelHeight(){const t=this.getMobileLayout()||this.song.getChannelCount()>4||this.song.barCount>this.trackVisibleBars&&this.song.getChannelCount()>3;return!this.getMobileLayout()&&("widefullscreen"!=this.fullScreen&&this.song.getChannelCount()>11||this.song.getChannelCount()>22)?23:t?27:32}getFullScreen(){return!this.getMobileLayout()&&"normal"!=this.fullScreen}}dn.Nc=100;const un=new dn,fn=new an(un);if(document.getElementById("beepboxEditorContainer").appendChild(fn.mainLayer),fn.whenUpdated(),fn.mainLayer.className+=" load",fn.mainLayer.getElementsByClassName("pattern-area")[0].className+=" load",fn.mainLayer.getElementsByClassName("settings-area")[0].className+=" load",fn.mainLayer.getElementsByClassName("editor-song-settings")[0].className+=" load",fn.mainLayer.getElementsByClassName("instrument-settings-area")[0].className+=" load",fn.mainLayer.getElementsByClassName("trackAndMuteContainer")[0].className+=" load",fn.mainLayer.getElementsByClassName("barScrollBar")[0].className+=" load",$("#pitchPresetSelect").select2({dropdownAutoWidth:!0}),$("#drumPresetSelect").select2({dropdownAutoWidth:!0}),$("body").on("click",".select2-container--open .select2-results__group",(function(){$(this).siblings().toggle()})),$("#pitchPresetSelect").on("select2:open",(function(){$(".select2-dropdown--below").css("opacity",0),$(".select2-dropdown").css("opacity",1),$("#pitchPresetSelect"),setTimeout((()=>{let t=$(".select2-container--open .select2-results__group"),e=$(".select2-container--open .select2-results__option");$.each(t,((t,e)=>{$(e).siblings().hide(),$(e)[0].setAttribute("style","color: "+T.getChannelColor(un.song,un.channel).primaryNote+";")})),$.each(e,((t,e)=>{$(e)[0].setAttribute("style","color: "+T.getChannelColor(un.song,un.channel).primaryNote+";")})),$(".select2-dropdown--below").css("opacity",1)}),0)})),$("#drumPresetSelect").on("select2:open",(function(){$(".select2-dropdown--below").css("opacity",0),$(".select2-dropdown").css("opacity",1),$("#drumPresetSelect"),setTimeout((()=>{let t=$(".select2-container--open .select2-results__group"),e=$(".select2-container--open .select2-results__option");$.each(t,((t,e)=>{$(e).siblings().hide(),$(e)[0].setAttribute("style","color: "+T.getChannelColor(un.song,un.channel).primaryNote+";")})),$.each(e,((t,e)=>{$(e)[0].setAttribute("style","color: "+T.getChannelColor(un.song,un.channel).primaryNote+";")})),$(".select2-dropdown--below").css("opacity",1)}),0)})),$("#pitchPresetSelect").on("change",fn.Rl),$("#pitchPresetSelect").on("select2:close",fn.zl),$("#drumPresetSelect").on("change",fn.Fl),$("#drumPresetSelect").on("select2:close",fn.zl),fn.mainLayer.focus(),!a&&un.autoPlay){function mn(){document.hidden||(un.synth.play(),fn.updatePlayButton(),window.removeEventListener("visibilitychange",mn))}document.hidden?window.addEventListener("visibilitychange",mn):mn()}return"scrollRestoration"in history&&(history.scrollRestoration="manual"),fn.updatePlayButton(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/service_worker.js",{updateViaCache:"all",scope:"/"}).catch((()=>{})),t.ChangePreset=dt,t.Channel=Z,t.ColorConfig=T,t.Config=e,t.EditorConfig=c,t.ExportPrompt=Mi,t.Instrument=J,t.Note=U,t.Pattern=V,t.SongDocument=dn,t.SongEditor=an,t.Synth=tt,Object.defineProperty(t,"Ac",{value:!0}),t}({}); //# sourceMappingURL=beepbox_editor.min.js.map