leref.ts
Version:
Something upcoming for aoi.js and npm packages uses
1 lines • 18.1 kB
JavaScript
"use strict";var FilterUtils_1,EqualizerUtils_1,KaraokeUtils_1,TimescaleUtils_1,TremoloUtils_1,VibratoUtils_1,RotationUtils_1,DistortionUtils_1,ChannelMixUtils_1,LowPassUtils_1,__decorate=this&&this.__decorate||function(t,e,i,s){var r,o=arguments.length,n=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;0<=a;a--)(r=t[a])&&(n=(o<3?r(n):3<o?r(e,i,n):r(e,i))||n);return 3<o&&n&&Object.defineProperty(e,i,n),n};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LowPassUtils=exports.ChannelMixUtils=exports.DistortionUtils=exports.RotationUtils=exports.VibratoUtils=exports.TremoloUtils=exports.TimescaleUtils=exports.KaraokeUtils=exports.EqualizerUtils=exports.FilterUtils=void 0;const validators_1=require("./decorators/validators"),constructs_1=require("./decorators/constructs");let FilterUtils=FilterUtils_1=class{constructor(t){this.volume=t.volume,this.equalizers=new EqualizerUtils(t.equalizer),this.karaoke=new KaraokeUtils(t.karaoke),this.timescale=new TimescaleUtils(t.timescale),this.tremolo=new TremoloUtils(t.tremolo),this.vibrato=new VibratoUtils(t.vibrato),this.rotation=new RotationUtils(t.rotation),this.distortion=new DistortionUtils(t.distortion),this.channelMix=new ChannelMixUtils(t.channelMix),this.lowPass=new LowPassUtils(t.lowPass)}setVolume(t){return this.volume=t,this}build(){const t={};return this.volume&&!isNaN(this.volume)&&1!==this.volume&&(t.volume=this.volume),this.equalizers.enabled&&(t.equalizer=this.equalizers.build()),this.karaoke.enabled&&(t.karaoke=this.karaoke.build()),this.timescale.enabled&&(t.timescale=this.timescale.build()),this.tremolo.enabled&&(t.tremolo=this.tremolo.build()),this.vibrato.enabled&&(t.vibrato=this.vibrato.build()),this.rotation.enabled&&(t.rotation=this.rotation.build()),this.distortion.enabled&&(t.distortion=this.distortion.build()),this.channelMix.enabled&&(t.channelMix=this.channelMix.build()),this.lowPass.enabled&&(t.lowPass=this.lowPass.build()),t}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'volume' must be present and be a number");if(e<0)throw new TypeError("Parameter 'volume' must be more or equal than 0");return t(e)})],FilterUtils.prototype,"setVolume",null),FilterUtils=FilterUtils_1=__decorate([constructs_1.construct(function(t,e){e=e[0]??{};if("object"!=typeof e||null===e)throw new TypeError("FilterUtils parameter 'filters' must be an object");return new t(e)})],FilterUtils),exports.FilterUtils=FilterUtils;let EqualizerUtils=EqualizerUtils_1=class{constructor(t){if(this.enabled=!1,this.equalizers=new Map,Array.isArray(t))for(const e of t)this.equalizers.set(e.band,e)}setBand(t,e){return this.equalizers.set(t,{band:t,gain:e}),0!==e?this.enabled=!0:this.equalizers.size&&![...this.equalizers.values()].every(t=>0===t.gain)||(this.enabled=!1),this}clear(){return this.equalizers.clear(),this.enabled=!1,this}build(){const t=[...this.equalizers.values()].filter(t=>0!==t.gain);return t.sort((t,e)=>t.band-e.band),t}};__decorate([validators_1.check(function(t,e,i){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'band' must be present be a number");if("number"!=typeof i||isNaN(i))throw new TypeError("Parameter 'gain' must be present and be a number");if(e<0||14<e)throw new TypeError("Parameter 'band' must be between 0 to 14");if(i<-.25||1<i)throw new TypeError("Parameter 'gain' must be between -0.25 to 1");return t(e,i)})],EqualizerUtils.prototype,"setBand",null),EqualizerUtils=EqualizerUtils_1=__decorate([constructs_1.construct(function(t,e){const i=e[0];let s=!1;Array.isArray(i)&&i.length&&i.some(t=>0!==t.gain)&&(s=!0);const r=new t(i);return r.enabled=s,r})],EqualizerUtils),exports.EqualizerUtils=EqualizerUtils;let KaraokeUtils=KaraokeUtils_1=class{constructor(t){this.enabled=!1,this.karaoke=t}setLevel(t){return this.karaoke.level=t,this.enabled=!0,this}setMonoLevel(t){return this.karaoke.monoLevel=t,this.enabled=!0,this}setFilterBand(t){return this.karaoke.filterBand=t,this.enabled=!0,this}setFilterWidth(t){return this.karaoke.filterWidth=t,this.enabled=!0,this}disable(){return this.enabled=!1,this}build(){return this.karaoke}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'level' must be present and be a number");return t(e)})],KaraokeUtils.prototype,"setLevel",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'monoLevel' must be present and be a number");return t(e)})],KaraokeUtils.prototype,"setMonoLevel",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'filterband' must be present and be a number");return t(e)})],KaraokeUtils.prototype,"setFilterBand",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'filterWidth' must be present and be a number");return t(e)})],KaraokeUtils.prototype,"setFilterWidth",null),KaraokeUtils=KaraokeUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"==typeof i&&null!==i?s=!0:i={level:1,monoLevel:1,filterBand:220,filterWidth:100};const r=new t(i);return r.enabled=s,r})],KaraokeUtils),exports.KaraokeUtils=KaraokeUtils;let TimescaleUtils=TimescaleUtils_1=class{constructor(t){this.enabled=!1,this.timescale=t}setSpeed(t){return 1!==(this.timescale.speed=t)?this.enabled=!0:1===this.timescale.speed&&1===this.timescale.pitch&&1===this.timescale.rate&&(this.enabled=!1),this}setPitch(t){return 1!==(this.timescale.pitch=t)?this.enabled=!0:1===this.timescale.speed&&1===this.timescale.pitch&&1===this.timescale.rate&&(this.enabled=!1),this}setRate(t){return 1!==(this.timescale.rate=t)?this.enabled=!0:1===this.timescale.speed&&1===this.timescale.pitch&&1===this.timescale.rate&&(this.enabled=!1),this}build(){return this.timescale}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'speed' must be present and be a number");if(e<=0)throw new TypeError("Parameter 'speed' must be more than 0");return t(e)})],TimescaleUtils.prototype,"setSpeed",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'pitch' must be present and be a number");if(e<=0)throw new TypeError("Parameter 'pitch' must be more than 0");return t(e)})],TimescaleUtils.prototype,"setPitch",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'rate' must be present and be a number");if(e<=0)throw new TypeError("Parameter 'rate' must be more than 0");return t(e)})],TimescaleUtils.prototype,"setRate",null),TimescaleUtils=TimescaleUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"!=typeof i||null===i||1===i.speed&&1===i.pitch&&1===i.rate?i={speed:1,pitch:1,rate:1}:s=!0;const r=new t(i);return r.enabled=s,r})],TimescaleUtils),exports.TimescaleUtils=TimescaleUtils;let TremoloUtils=TremoloUtils_1=class{constructor(t){this.enabled=!1,this.tremolo=t}setFrequency(t){return this.tremolo.frequency=t,this}setDepth(t){return this.tremolo.depth=t,this.enabled=0!==t,this}build(){return this.tremolo}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'frequency' must be present and be a number");if(e<=0)throw new TypeError("Parameter 'frequency' must be more than 0");return t(e)})],TremoloUtils.prototype,"setFrequency",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'depth' must be present and be a number");if(e<0||1<e)throw new TypeError("Parameter 'depth' must be between 0 to 1");return t(e)})],TremoloUtils.prototype,"setDepth",null),TremoloUtils=TremoloUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"==typeof i&&null!==i&&0!==i.depth?s=!0:i={frequency:2,depth:.5};const r=new t(i);return r.enabled=s,r})],TremoloUtils),exports.TremoloUtils=TremoloUtils;let VibratoUtils=VibratoUtils_1=class{constructor(t){this.enabled=!1,this.vibrato=t}setFrequency(t){return this.vibrato.frequency=t,this}setDepth(t){return this.vibrato.depth=t,this.enabled=0!==t,this}build(){return this.vibrato}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'frequency' must be present and be a number");if(e<=0||14<e)throw new TypeError("Parameter 'frequency' must be between 0 and 15");return t(e)})],VibratoUtils.prototype,"setFrequency",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'depth' must be present and be a number");if(e<0||1<e)throw new TypeError("Parameter 'depth' must be between 0 to 1");return t(e)})],VibratoUtils.prototype,"setDepth",null),VibratoUtils=VibratoUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"==typeof i&&null!==i&&0!==i.depth?s=!0:i={frequency:2,depth:.5};const r=new t(i);return r.enabled=s,r})],VibratoUtils),exports.VibratoUtils=VibratoUtils;let RotationUtils=RotationUtils_1=class{constructor(t){this.enabled=!1,this.rotation=t}setRotationSpeed(t){return this.rotation.rotationHz=t,this.enabled=0!==t,this}build(){return this.rotation}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'rotationHz' must be present and be a number");return t(e)})],RotationUtils.prototype,"setRotationSpeed",null),RotationUtils=RotationUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"==typeof i&&null!==i&&0!==i.rotationHz?s=!0:i={rotationHz:5};const r=new t(i);return r.enabled=s,r})],RotationUtils),exports.RotationUtils=RotationUtils;let DistortionUtils=DistortionUtils_1=class{constructor(t){this.enabled=!1,this.distortion=t}setSinOffset(t){return 0!==(this.distortion.sinOffset=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setSinScale(t){return 1!==(this.distortion.sinScale=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setCosOffset(t){return 0!==(this.distortion.cosOffset=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setCosScale(t){return 1!==(this.distortion.cosScale=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setTanOffset(t){return 0!==(this.distortion.tanOffset=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setTanScale(t){return 1!==(this.distortion.tanScale=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setOffset(t){return 0!==(this.distortion.offset=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}setScale(t){return 1!==(this.distortion.scale=t)?this.enabled=!0:0===this.distortion.sinOffset&&1===this.distortion.sinScale&&0===this.distortion.cosOffset&&1===this.distortion.cosScale&&0===this.distortion.tanOffset&&1===this.distortion.tanScale&&0===this.distortion.offset&&1===this.distortion.scale&&(this.enabled=!1),this}build(){return this.distortion}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'sinOffset' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setSinOffset",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'sinScale' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setSinScale",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'cosOffset' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setCosOffset",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'cosScale' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setCosScale",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'tanOffset' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setTanOffset",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'tanScale' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setTanScale",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'offset' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setOffset",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'scale' must be present and be a number");return t(e)})],DistortionUtils.prototype,"setScale",null),DistortionUtils=DistortionUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"!=typeof i||null===i||0===i.sinOffset&&1===i.sinScale&&0===i.cosOffset&&1===i.cosScale&&0===i.tanOffset&&1===i.tanScale&&0===i.offset&&1===i.scale?i={sinOffset:0,sinScale:1,cosOffset:0,cosScale:1,tanOffset:0,tanScale:1,offset:0,scale:1}:s=!0;const r=new t(i);return r.enabled=s,r})],DistortionUtils),exports.DistortionUtils=DistortionUtils;let ChannelMixUtils=ChannelMixUtils_1=class{constructor(t){this.enabled=!1,this.channelMix=t}setLeftToLeft(t){return 1!==(this.channelMix.leftToLeft=t)?this.enabled=!0:1===this.channelMix.leftToLeft&&0===this.channelMix.leftToRight&&0===this.channelMix.rightToLeft&&1===this.channelMix.rightToRight&&(this.enabled=!1),this}setLeftToRight(t){return 0!==(this.channelMix.leftToRight=t)?this.enabled=!0:1===this.channelMix.leftToLeft&&0===this.channelMix.leftToRight&&0===this.channelMix.rightToLeft&&1===this.channelMix.rightToRight&&(this.enabled=!1),this}setRightToLeft(t){return 0!==(this.channelMix.rightToLeft=t)?this.enabled=!0:1===this.channelMix.leftToLeft&&0===this.channelMix.leftToRight&&0===this.channelMix.rightToLeft&&1===this.channelMix.rightToRight&&(this.enabled=!1),this}setRightToRight(t){return 1!==(this.channelMix.rightToRight=t)?this.enabled=!0:1===this.channelMix.leftToLeft&&0===this.channelMix.leftToRight&&0===this.channelMix.rightToLeft&&1===this.channelMix.rightToRight&&(this.enabled=!1),this}build(){return this.channelMix}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'leftToLeft' must be present and be a number");if(e<0||1<e)throw new TypeError("Parameter 'leftToLeft' must be between 0 to 1");return t(e)})],ChannelMixUtils.prototype,"setLeftToLeft",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'leftToRight' must be present and be a number");if(e<0||1<e)throw new TypeError("Parameter 'leftToRight' must be between 0 to 1");return t(e)})],ChannelMixUtils.prototype,"setLeftToRight",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'rightToLeft' must be present and be a number");if(e<0||1<e)throw new TypeError("Parameter 'rightToLeft' must be between 0 to 1");return t(e)})],ChannelMixUtils.prototype,"setRightToLeft",null),__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'rightToRight' must be present and be a number");if(e<0||1<e)throw new TypeError("Parameter 'rightToRight' must be between 0 to 1");return t(e)})],ChannelMixUtils.prototype,"setRightToRight",null),ChannelMixUtils=ChannelMixUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"!=typeof i||null===i||1===i.leftToLeft&&0===i.leftToRight&&0===i.rightToLeft&&1===i.rightToRight?i={leftToLeft:1,leftToRight:0,rightToLeft:0,rightToRight:1}:s=!0;const r=new t(i);return r.enabled=s,r})],ChannelMixUtils),exports.ChannelMixUtils=ChannelMixUtils;let LowPassUtils=LowPassUtils_1=class{constructor(t){this.enabled=!1,this.lowPass=t}setSmoothing(t){return this.lowPass.smoothing=t,this.enabled=20!==t,this}build(){return this.lowPass}};__decorate([validators_1.check(function(t,e){if("number"!=typeof e||isNaN(e))throw new TypeError("Parameter 'smoothing' must be present and be a number");return t(e)})],LowPassUtils.prototype,"setSmoothing",null),LowPassUtils=LowPassUtils_1=__decorate([constructs_1.construct(function(t,e){let i=e[0],s=!1;"object"==typeof i&&null!==i&&20!==i.smoothing?s=!0:i={smoothing:20};const r=new t(i);return r.enabled=s,r})],LowPassUtils),exports.LowPassUtils=LowPassUtils;