lavalink-client 2.1.4 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,899 +1,899 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EQList = exports.audioOutputsData = exports.FilterManager = void 0;
4
- /**
5
- * The FilterManager for each player
6
- */
7
- class FilterManager {
8
- /** The Equalizer bands currently applied to the Lavalink Server */
9
- equalizerBands = [];
10
- /** Private Util for the instaFix Filters option */
11
- filterUpdatedState = 0;
12
- /** All "Active" / "disabled" Player Filters */
13
- filters = {
14
- volume: false,
15
- vaporwave: false,
16
- custom: false,
17
- nightcore: false,
18
- rotation: false,
19
- karaoke: false,
20
- tremolo: false,
21
- vibrato: false,
22
- lowPass: false,
23
- lavalinkFilterPlugin: {
24
- echo: false,
25
- reverb: false,
26
- },
27
- lavalinkLavaDspxPlugin: {
28
- lowPass: false,
29
- highPass: false,
30
- normalization: false,
31
- echo: false,
32
- },
33
- audioOutput: "stereo",
34
- };
35
- /** The Filter Data sent to Lavalink, only if the filter is enabled (ofc.) */
36
- data = {
37
- lowPass: {
38
- smoothing: 0
39
- },
40
- karaoke: {
41
- level: 0,
42
- monoLevel: 0,
43
- filterBand: 0,
44
- filterWidth: 0
45
- },
46
- timescale: {
47
- speed: 1,
48
- pitch: 1,
49
- rate: 1 // 0 = x
50
- },
51
- rotation: {
52
- rotationHz: 0
53
- },
54
- tremolo: {
55
- frequency: 0,
56
- depth: 0 // 0 < x = 1
57
- },
58
- vibrato: {
59
- frequency: 0,
60
- depth: 0 // 0 < x <= 1
61
- },
62
- pluginFilters: {
63
- "lavalink-filter-plugin": {
64
- echo: {
65
- delay: 0,
66
- decay: 0 // 0 < 1
67
- },
68
- reverb: {
69
- delays: [],
70
- gains: [] // [0.84, 0.83, 0.82, 0.81]
71
- }
72
- },
73
- "high-pass": { // Cuts off frequencies lower than the specified {cutoffFrequency}.
74
- // "cutoffFrequency": 1475, // Integer, higher than zero, in Hz.
75
- // "boostFactor": 1.0 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
76
- },
77
- "low-pass": { // Cuts off frequencies higher than the specified {cutoffFrequency}.
78
- // "cutoffFrequency": 284, // Integer, higher than zero, in Hz.
79
- // "boostFactor": 1.24389 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
80
- },
81
- "normalization": { // Attenuates peaking where peaks are defined as having a higher value than {maxAmplitude}.
82
- // "maxAmplitude": 0.6327, // Float, within the range of 0.0 - 1.0. A value of 0.0 mutes the output.
83
- // "adaptive": true // false
84
- },
85
- "echo": { // Self-explanatory; provides an echo effect.
86
- // "echoLength": 0.5649, // Float, higher than 0.0, in seconds (1.0 = 1 second).
87
- // "decay": 0.4649 // Float, within the range of 0.0 - 1.0. A value of 1.0 means no decay, and a value of 0.0 means
88
- },
89
- },
90
- channelMix: exports.audioOutputsData.stereo,
91
- /*distortion: {
92
- sinOffset: 0,
93
- sinScale: 1,
94
- cosOffset: 0,
95
- cosScale: 1,
96
- tanOffset: 0,
97
- tanScale: 1,
98
- offset: 0,
99
- scale: 1
100
- }*/
101
- };
102
- /** The Player assigned to this Filter Manager */
103
- player;
104
- /** The Constructor for the FilterManager */
105
- constructor(player) {
106
- /** Assign the player to the filter manager */
107
- this.player = player;
108
- }
109
- /**
110
- * Apply Player filters for lavalink filter sending data, if the filter is enabled / not
111
- */
112
- async applyPlayerFilters() {
113
- const sendData = { ...this.data };
114
- this.checkFiltersState();
115
- if (!this.filters.volume)
116
- delete sendData.volume;
117
- if (!this.filters.tremolo)
118
- delete sendData.tremolo;
119
- if (!this.filters.vibrato)
120
- delete sendData.vibrato;
121
- if (!this.filters.lavalinkFilterPlugin.echo)
122
- delete sendData.pluginFilters?.["lavalink-filter-plugin"]?.echo;
123
- if (!this.filters.lavalinkFilterPlugin.reverb)
124
- delete sendData.pluginFilters?.["lavalink-filter-plugin"]?.reverb;
125
- if (!this.filters.lavalinkLavaDspxPlugin.echo)
126
- delete sendData.pluginFilters?.echo;
127
- if (!this.filters.lavalinkLavaDspxPlugin.normalization)
128
- delete sendData.pluginFilters?.normalization;
129
- if (!this.filters.lavalinkLavaDspxPlugin.highPass)
130
- delete sendData.pluginFilters?.["high-pass"];
131
- if (!this.filters.lavalinkLavaDspxPlugin.lowPass)
132
- delete sendData.pluginFilters?.["low-pass"];
133
- if (sendData.pluginFilters?.["lavalink-filter-plugin"] && Object.values(sendData.pluginFilters?.["lavalink-filter-plugin"]).length === 0)
134
- delete sendData.pluginFilters["lavalink-filter-plugin"];
135
- if (sendData.pluginFilters && Object.values(sendData.pluginFilters).length === 0)
136
- delete sendData.pluginFilters;
137
- if (!this.filters.lowPass)
138
- delete sendData.lowPass;
139
- if (!this.filters.karaoke)
140
- delete sendData.karaoke;
141
- if (!this.filters.rotation)
142
- delete sendData.rotation;
143
- if (this.filters.audioOutput === "stereo")
144
- delete sendData.channelMix;
145
- if (Object.values(this.data.timescale).every(v => v === 1))
146
- delete sendData.timescale;
147
- if (!this.player.node.sessionId)
148
- throw new Error("The Lavalink-Node is either not ready or not up to date");
149
- sendData.equalizer = [...this.equalizerBands];
150
- if (sendData.equalizer.length === 0)
151
- delete sendData.equalizer;
152
- for (const key of [...Object.keys(sendData)]) {
153
- // delete disabled filters
154
- if (key === "pluginFilters") {
155
- // for(const key of [...Object.keys(sendData.pluginFilters)]) {
156
- // // if (this.player.node.info && !this.player.node.info?.plugins?.find?.(v => v.name === key)) delete sendData[key];
157
- // }
158
- }
159
- else if (this.player.node.info && !this.player.node.info?.filters?.includes?.(key))
160
- delete sendData[key];
161
- }
162
- const now = performance.now();
163
- await this.player.node.updatePlayer({
164
- guildId: this.player.guildId,
165
- playerOptions: {
166
- filters: sendData,
167
- }
168
- });
169
- this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
170
- if (this.player.options.instaUpdateFiltersFix === true)
171
- this.filterUpdatedState = 1;
172
- return;
173
- }
174
- /**
175
- * Checks if the filters are correctly stated (active / not-active)
176
- * @param oldFilterTimescale
177
- * @returns
178
- */
179
- checkFiltersState(oldFilterTimescale) {
180
- this.filters.rotation = this.data.rotation.rotationHz !== 0;
181
- this.filters.vibrato = this.data.vibrato.frequency !== 0 || this.data.vibrato.depth !== 0;
182
- this.filters.tremolo = this.data.tremolo.frequency !== 0 || this.data.tremolo.depth !== 0;
183
- const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...((this.data.pluginFilters.reverb) || {}) } });
184
- this.filters.lavalinkFilterPlugin.echo = lavalinkFilterData.echo.decay !== 0 || lavalinkFilterData.echo.delay !== 0;
185
- this.filters.lavalinkFilterPlugin.reverb = lavalinkFilterData.reverb?.delays?.length !== 0 || lavalinkFilterData.reverb?.gains?.length !== 0;
186
- this.filters.lavalinkLavaDspxPlugin.highPass = Object.values(this.data.pluginFilters["high-pass"] || {}).length > 0;
187
- this.filters.lavalinkLavaDspxPlugin.lowPass = Object.values(this.data.pluginFilters["low-pass"] || {}).length > 0;
188
- this.filters.lavalinkLavaDspxPlugin.normalization = Object.values(this.data.pluginFilters.normalization || {}).length > 0;
189
- this.filters.lavalinkLavaDspxPlugin.echo = Object.values(this.data.pluginFilters.echo || {}).length > 0 && typeof this.data.pluginFilters?.echo?.delay === "undefined";
190
- this.filters.lowPass = this.data.lowPass.smoothing !== 0;
191
- this.filters.karaoke = Object.values(this.data.karaoke).some(v => v !== 0);
192
- if ((this.filters.nightcore || this.filters.vaporwave) && oldFilterTimescale) {
193
- if (oldFilterTimescale.pitch !== this.data.timescale.pitch || oldFilterTimescale.rate !== this.data.timescale.rate || oldFilterTimescale.speed !== this.data.timescale.speed) {
194
- this.filters.custom = Object.values(this.data.timescale).some(v => v !== 1);
195
- this.filters.nightcore = false;
196
- this.filters.vaporwave = false;
197
- }
198
- }
199
- return true;
200
- }
201
- /**
202
- * Reset all Filters
203
- */
204
- async resetFilters() {
205
- this.filters.lavalinkLavaDspxPlugin.echo = false;
206
- this.filters.lavalinkLavaDspxPlugin.normalization = false;
207
- this.filters.lavalinkLavaDspxPlugin.highPass = false;
208
- this.filters.lavalinkLavaDspxPlugin.lowPass = false;
209
- this.filters.lavalinkFilterPlugin.echo = false;
210
- this.filters.lavalinkFilterPlugin.reverb = false;
211
- this.filters.nightcore = false;
212
- this.filters.lowPass = false;
213
- this.filters.rotation = false;
214
- this.filters.tremolo = false;
215
- this.filters.vibrato = false;
216
- this.filters.karaoke = false;
217
- this.filters.karaoke = false;
218
- this.filters.volume = false;
219
- this.filters.audioOutput = "stereo";
220
- // reset all filter datas
221
- for (const [key, value] of Object.entries({
222
- volume: 1,
223
- lowPass: {
224
- smoothing: 0
225
- },
226
- karaoke: {
227
- level: 0,
228
- monoLevel: 0,
229
- filterBand: 0,
230
- filterWidth: 0
231
- },
232
- timescale: {
233
- speed: 1,
234
- pitch: 1,
235
- rate: 1 // 0 = x
236
- },
237
- pluginFilters: {
238
- "lavalink-filter-plugin": {
239
- echo: {
240
- // delay: 0, // in seconds
241
- // decay: 0 // 0 < 1
242
- },
243
- reverb: {
244
- // delays: [], // [0.037, 0.042, 0.048, 0.053]
245
- // gains: [] // [0.84, 0.83, 0.82, 0.81]
246
- }
247
- },
248
- "high-pass": { // Cuts off frequencies lower than the specified {cutoffFrequency}.
249
- // "cutoffFrequency": 1475, // Integer, higher than zero, in Hz.
250
- // "boostFactor": 1.0 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
251
- },
252
- "low-pass": { // Cuts off frequencies higher than the specified {cutoffFrequency}.
253
- // "cutoffFrequency": 284, // Integer, higher than zero, in Hz.
254
- // "boostFactor": 1.24389 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
255
- },
256
- "normalization": { // Attenuates peaking where peaks are defined as having a higher value than {maxAmplitude}.
257
- // "maxAmplitude": 0.6327, // Float, within the range of 0.0 - 1.0. A value of 0.0 mutes the output.
258
- // "adaptive": true // false
259
- },
260
- "echo": { // Self-explanatory; provides an echo effect.
261
- // "echoLength": 0.5649, // Float, higher than 0.0, in seconds (1.0 = 1 second).
262
- // "decay": 0.4649 // Float, within the range of 0.0 - 1.0. A value of 1.0 means no decay, and a value of 0.0 means
263
- },
264
- },
265
- rotation: {
266
- rotationHz: 0
267
- },
268
- tremolo: {
269
- frequency: 0,
270
- depth: 0 // 0 < x = 1
271
- },
272
- vibrato: {
273
- frequency: 0,
274
- depth: 0 // 0 < x = 1
275
- },
276
- channelMix: exports.audioOutputsData.stereo,
277
- })) {
278
- this.data[key] = value;
279
- }
280
- await this.applyPlayerFilters();
281
- return this.filters;
282
- }
283
- /**
284
- * Set the Filter Volume
285
- * @param volume
286
- * @returns
287
- */
288
- async setVolume(volume) {
289
- if (volume < 0 || volume > 5)
290
- throw new SyntaxError("Volume-Filter must be between 0 and 5");
291
- this.data.volume = volume;
292
- await this.applyPlayerFilters();
293
- return this.filters.volume;
294
- }
295
- /**
296
- * Set the AudioOutput Filter
297
- * @param type
298
- * @returns
299
- */
300
- async setAudioOutput(type) {
301
- if (this.player.node.info && !this.player.node.info?.filters?.includes("channelMix"))
302
- throw new Error("Node#Info#filters does not include the 'channelMix' Filter (Node has it not enable)");
303
- if (!type || !exports.audioOutputsData[type])
304
- throw "Invalid audio type added, must be 'mono' / 'stereo' / 'left' / 'right'";
305
- this.data.channelMix = exports.audioOutputsData[type];
306
- this.filters.audioOutput = type;
307
- await this.applyPlayerFilters();
308
- return this.filters.audioOutput;
309
- }
310
- /**
311
- * Set custom filter.timescale#speed . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
312
- * @param speed
313
- * @returns
314
- */
315
- async setSpeed(speed = 1) {
316
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
317
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
318
- // reset nightcore / vaporwave filter if enabled
319
- if (this.filters.nightcore || this.filters.vaporwave) {
320
- this.data.timescale.pitch = 1;
321
- this.data.timescale.speed = 1;
322
- this.data.timescale.rate = 1;
323
- this.filters.nightcore = false;
324
- this.filters.vaporwave = false;
325
- }
326
- this.data.timescale.speed = speed;
327
- // check if custom filter is active / not
328
- this.isCustomFilterActive();
329
- await this.applyPlayerFilters();
330
- return this.filters.custom;
331
- }
332
- /**
333
- * Set custom filter.timescale#pitch . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
334
- * @param speed
335
- * @returns
336
- */
337
- async setPitch(pitch = 1) {
338
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
339
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
340
- // reset nightcore / vaporwave filter if enabled
341
- if (this.filters.nightcore || this.filters.vaporwave) {
342
- this.data.timescale.pitch = 1;
343
- this.data.timescale.speed = 1;
344
- this.data.timescale.rate = 1;
345
- this.filters.nightcore = false;
346
- this.filters.vaporwave = false;
347
- }
348
- this.data.timescale.pitch = pitch;
349
- // check if custom filter is active / not
350
- this.isCustomFilterActive();
351
- await this.applyPlayerFilters();
352
- return this.filters.custom;
353
- }
354
- /**
355
- * Set custom filter.timescale#rate . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
356
- * @param speed
357
- * @returns
358
- */
359
- async setRate(rate = 1) {
360
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
361
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
362
- // reset nightcore / vaporwave filter if enabled
363
- if (this.filters.nightcore || this.filters.vaporwave) {
364
- this.data.timescale.pitch = 1;
365
- this.data.timescale.speed = 1;
366
- this.data.timescale.rate = 1;
367
- this.filters.nightcore = false;
368
- this.filters.vaporwave = false;
369
- }
370
- this.data.timescale.rate = rate;
371
- // check if custom filter is active / not
372
- this.isCustomFilterActive();
373
- await this.applyPlayerFilters();
374
- return this.filters.custom;
375
- }
376
- /**
377
- * Enables / Disables the rotation effect, (Optional: provide your Own Data)
378
- * @param rotationHz
379
- * @returns
380
- */
381
- async toggleRotation(rotationHz = 0.2) {
382
- if (this.player.node.info && !this.player.node.info?.filters?.includes("rotation"))
383
- throw new Error("Node#Info#filters does not include the 'rotation' Filter (Node has it not enable)");
384
- this.data.rotation.rotationHz = this.filters.rotation ? 0 : rotationHz;
385
- this.filters.rotation = !this.filters.rotation;
386
- return await this.applyPlayerFilters(), this.filters.rotation;
387
- }
388
- /**
389
- * Enables / Disables the Vibrato effect, (Optional: provide your Own Data)
390
- * @param frequency
391
- * @param depth
392
- * @returns
393
- */
394
- async toggleVibrato(frequency = 10, depth = 1) {
395
- if (this.player.node.info && !this.player.node.info?.filters?.includes("vibrato"))
396
- throw new Error("Node#Info#filters does not include the 'vibrato' Filter (Node has it not enable)");
397
- this.data.vibrato.frequency = this.filters.vibrato ? 0 : frequency;
398
- this.data.vibrato.depth = this.filters.vibrato ? 0 : depth;
399
- this.filters.vibrato = !this.filters.vibrato;
400
- await this.applyPlayerFilters();
401
- return this.filters.vibrato;
402
- }
403
- /**
404
- * Enables / Disables the Tremolo effect, (Optional: provide your Own Data)
405
- * @param frequency
406
- * @param depth
407
- * @returns
408
- */
409
- async toggleTremolo(frequency = 4, depth = 0.8) {
410
- if (this.player.node.info && !this.player.node.info?.filters?.includes("tremolo"))
411
- throw new Error("Node#Info#filters does not include the 'tremolo' Filter (Node has it not enable)");
412
- this.data.tremolo.frequency = this.filters.tremolo ? 0 : frequency;
413
- this.data.tremolo.depth = this.filters.tremolo ? 0 : depth;
414
- this.filters.tremolo = !this.filters.tremolo;
415
- await this.applyPlayerFilters();
416
- return this.filters.tremolo;
417
- }
418
- /**
419
- * Enables / Disables the LowPass effect, (Optional: provide your Own Data)
420
- * @param smoothing
421
- * @returns
422
- */
423
- async toggleLowPass(smoothing = 20) {
424
- if (this.player.node.info && !this.player.node.info?.filters?.includes("lowPass"))
425
- throw new Error("Node#Info#filters does not include the 'lowPass' Filter (Node has it not enable)");
426
- this.data.lowPass.smoothing = this.filters.lowPass ? 0 : smoothing;
427
- this.filters.lowPass = !this.filters.lowPass;
428
- await this.applyPlayerFilters();
429
- return this.filters.lowPass;
430
- }
431
- lavalinkLavaDspxPlugin = {
432
- toggleLowPass: async (boostFactor = 1.0, cutoffFrequency = 80) => {
433
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
434
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
435
- if (this.player.node.info && !this.player.node.info?.filters?.includes("low-pass"))
436
- throw new Error("Node#Info#filters does not include the 'low-pass' Filter (Node has it not enable)");
437
- if (!this.data)
438
- this.data = {};
439
- if (!this.data.pluginFilters)
440
- this.data.pluginFilters = {};
441
- if (!this.data.pluginFilters["low-pass"])
442
- this.data.pluginFilters["low-pass"] = {};
443
- if (this.filters.lavalinkLavaDspxPlugin.lowPass) {
444
- delete this.data.pluginFilters["low-pass"];
445
- }
446
- else {
447
- this.data.pluginFilters["low-pass"] = {
448
- boostFactor: boostFactor,
449
- cutoffFrequency: cutoffFrequency
450
- };
451
- }
452
- this.filters.lavalinkLavaDspxPlugin.lowPass = !this.filters.lavalinkLavaDspxPlugin.lowPass;
453
- await this.applyPlayerFilters();
454
- return this.filters.lavalinkLavaDspxPlugin.lowPass;
455
- },
456
- toggleHighPass: async (boostFactor = 1.0, cutoffFrequency = 80) => {
457
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
458
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
459
- if (this.player.node.info && !this.player.node.info?.filters?.includes("high-pass"))
460
- throw new Error("Node#Info#filters does not include the 'high-pass' Filter (Node has it not enable)");
461
- if (!this.data)
462
- this.data = {};
463
- if (!this.data.pluginFilters)
464
- this.data.pluginFilters = {};
465
- if (!this.data.pluginFilters["high-pass"])
466
- this.data.pluginFilters["high-pass"] = {};
467
- if (this.filters.lavalinkLavaDspxPlugin.highPass) {
468
- delete this.data.pluginFilters["high-pass"];
469
- }
470
- else {
471
- this.data.pluginFilters["high-pass"] = {
472
- boostFactor: boostFactor,
473
- cutoffFrequency: cutoffFrequency
474
- };
475
- }
476
- this.filters.lavalinkLavaDspxPlugin.highPass = !this.filters.lavalinkLavaDspxPlugin.highPass;
477
- await this.applyPlayerFilters();
478
- return this.filters.lavalinkLavaDspxPlugin.highPass;
479
- },
480
- toggleNormalization: async (maxAmplitude = 0.75, adaptive = true) => {
481
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
482
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
483
- if (this.player.node.info && !this.player.node.info?.filters?.includes("normalization"))
484
- throw new Error("Node#Info#filters does not include the 'normalization' Filter (Node has it not enable)");
485
- if (!this.data)
486
- this.data = {};
487
- if (!this.data.pluginFilters)
488
- this.data.pluginFilters = {};
489
- if (!this.data.pluginFilters.normalization)
490
- this.data.pluginFilters.normalization = {};
491
- if (this.filters.lavalinkLavaDspxPlugin.normalization) {
492
- delete this.data.pluginFilters.normalization;
493
- }
494
- else {
495
- this.data.pluginFilters.normalization = {
496
- adaptive: adaptive,
497
- maxAmplitude: maxAmplitude
498
- };
499
- }
500
- this.filters.lavalinkLavaDspxPlugin.normalization = !this.filters.lavalinkLavaDspxPlugin.normalization;
501
- await this.applyPlayerFilters();
502
- return this.filters.lavalinkLavaDspxPlugin.normalization;
503
- },
504
- toggleEcho: async (decay = 0.5, echoLength = 0.5) => {
505
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
506
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
507
- if (this.player.node.info && !this.player.node.info?.filters?.includes("echo"))
508
- throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable)");
509
- if (!this.data)
510
- this.data = {};
511
- if (!this.data.pluginFilters)
512
- this.data.pluginFilters = {};
513
- if (!this.data.pluginFilters.echo)
514
- this.data.pluginFilters.echo = {};
515
- if (this.filters.lavalinkLavaDspxPlugin.echo) {
516
- delete this.data.pluginFilters.echo;
517
- }
518
- else {
519
- this.data.pluginFilters.echo = {
520
- decay: decay,
521
- echoLength: echoLength
522
- };
523
- }
524
- this.filters.lavalinkLavaDspxPlugin.echo = !this.filters.lavalinkLavaDspxPlugin.echo;
525
- await this.applyPlayerFilters();
526
- return this.filters.lavalinkLavaDspxPlugin.echo;
527
- }
528
- };
529
- lavalinkFilterPlugin = {
530
- /**
531
- * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
532
- * @param delay
533
- * @param decay
534
- * @returns
535
- */
536
- toggleEcho: async (delay = 4, decay = 0.8) => {
537
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavalink-filter-plugin"))
538
- throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
539
- if (this.player.node.info && !this.player.node.info?.filters?.includes("echo"))
540
- throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable aka not installed!)");
541
- if (!this.data)
542
- this.data = {};
543
- if (!this.data.pluginFilters)
544
- this.data.pluginFilters = {};
545
- if (!this.data.pluginFilters["lavalink-filter-plugin"])
546
- this.data.pluginFilters["lavalink-filter-plugin"] = { echo: { decay: 0, delay: 0 }, reverb: { delays: [], gains: [] } };
547
- if (!this.data.pluginFilters["lavalink-filter-plugin"].echo)
548
- this.data.pluginFilters["lavalink-filter-plugin"].echo = { decay: 0, delay: 0 };
549
- this.data.pluginFilters["lavalink-filter-plugin"].echo.delay = this.filters.lavalinkFilterPlugin.echo ? 0 : delay;
550
- this.data.pluginFilters["lavalink-filter-plugin"].echo.decay = this.filters.lavalinkFilterPlugin.echo ? 0 : decay;
551
- this.filters.lavalinkFilterPlugin.echo = !this.filters.lavalinkFilterPlugin.echo;
552
- await this.applyPlayerFilters();
553
- return this.filters.lavalinkFilterPlugin.echo;
554
- },
555
- /**
556
- * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
557
- * @param delays
558
- * @param gains
559
- * @returns
560
- */
561
- toggleReverb: async (delays = [0.037, 0.042, 0.048, 0.053], gains = [0.84, 0.83, 0.82, 0.81]) => {
562
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavalink-filter-plugin"))
563
- throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
564
- if (this.player.node.info && !this.player.node.info?.filters?.includes("reverb"))
565
- throw new Error("Node#Info#filters does not include the 'reverb' Filter (Node has it not enable aka not installed!)");
566
- if (!this.data)
567
- this.data = {};
568
- if (!this.data.pluginFilters)
569
- this.data.pluginFilters = {};
570
- if (!this.data.pluginFilters["lavalink-filter-plugin"])
571
- this.data.pluginFilters["lavalink-filter-plugin"] = { echo: { decay: 0, delay: 0 }, reverb: { delays: [], gains: [] } };
572
- if (!this.data.pluginFilters["lavalink-filter-plugin"].reverb)
573
- this.data.pluginFilters["lavalink-filter-plugin"].reverb = { delays: [], gains: [] };
574
- this.data.pluginFilters["lavalink-filter-plugin"].reverb.delays = this.filters.lavalinkFilterPlugin.reverb ? [] : delays;
575
- this.data.pluginFilters["lavalink-filter-plugin"].reverb.gains = this.filters.lavalinkFilterPlugin.reverb ? [] : gains;
576
- this.filters.lavalinkFilterPlugin.reverb = !this.filters.lavalinkFilterPlugin.reverb;
577
- await this.applyPlayerFilters();
578
- return this.filters.lavalinkFilterPlugin.reverb;
579
- }
580
- };
581
- /**
582
- * Enables / Disables a Nightcore-like filter Effect. Disables/Overrides both: custom and Vaporwave Filter
583
- * @param speed
584
- * @param pitch
585
- * @param rate
586
- * @returns
587
- */
588
- async toggleNightcore(speed = 1.289999523162842, pitch = 1.289999523162842, rate = 0.9365999523162842) {
589
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
590
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
591
- this.data.timescale.speed = this.filters.nightcore ? 1 : speed;
592
- this.data.timescale.pitch = this.filters.nightcore ? 1 : pitch;
593
- this.data.timescale.rate = this.filters.nightcore ? 1 : rate;
594
- this.filters.nightcore = !this.filters.nightcore;
595
- this.filters.vaporwave = false;
596
- this.filters.custom = false;
597
- await this.applyPlayerFilters();
598
- return this.filters.nightcore;
599
- }
600
- /**
601
- * Enables / Disables a Vaporwave-like filter Effect. Disables/Overrides both: custom and nightcore Filter
602
- * @param speed
603
- * @param pitch
604
- * @param rate
605
- * @returns
606
- */
607
- async toggleVaporwave(speed = 0.8500000238418579, pitch = 0.800000011920929, rate = 1) {
608
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
609
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
610
- this.data.timescale.speed = this.filters.vaporwave ? 1 : speed;
611
- this.data.timescale.pitch = this.filters.vaporwave ? 1 : pitch;
612
- this.data.timescale.rate = this.filters.vaporwave ? 1 : rate;
613
- this.filters.vaporwave = !this.filters.vaporwave;
614
- this.filters.nightcore = false;
615
- this.filters.custom = false;
616
- await this.applyPlayerFilters();
617
- return this.filters.vaporwave;
618
- }
619
- /**
620
- * Enable / Disables a Karaoke like Filter Effect
621
- * @param level
622
- * @param monoLevel
623
- * @param filterBand
624
- * @param filterWidth
625
- * @returns
626
- */
627
- async toggleKaraoke(level = 1, monoLevel = 1, filterBand = 220, filterWidth = 100) {
628
- if (this.player.node.info && !this.player.node.info?.filters?.includes("karaoke"))
629
- throw new Error("Node#Info#filters does not include the 'karaoke' Filter (Node has it not enable)");
630
- this.data.karaoke.level = this.filters.karaoke ? 0 : level;
631
- this.data.karaoke.monoLevel = this.filters.karaoke ? 0 : monoLevel;
632
- this.data.karaoke.filterBand = this.filters.karaoke ? 0 : filterBand;
633
- this.data.karaoke.filterWidth = this.filters.karaoke ? 0 : filterWidth;
634
- this.filters.karaoke = !this.filters.karaoke;
635
- await this.applyPlayerFilters();
636
- return this.filters.karaoke;
637
- }
638
- /** Function to find out if currently there is a custom timescamle etc. filter applied */
639
- isCustomFilterActive() {
640
- this.filters.custom = !this.filters.nightcore && !this.filters.vaporwave && Object.values(this.data.timescale).some(d => d !== 1);
641
- return this.filters.custom;
642
- }
643
- /**
644
- * Sets the players equalizer band on-top of the existing ones.
645
- * @param bands
646
- */
647
- async setEQ(bands) {
648
- if (!Array.isArray(bands))
649
- bands = [bands];
650
- if (!bands.length || !bands.every((band) => JSON.stringify(Object.keys(band).sort()) === '["band","gain"]'))
651
- throw new TypeError("Bands must be a non-empty object array containing 'band' and 'gain' properties.");
652
- for (const { band, gain } of bands)
653
- this.equalizerBands[band] = { band, gain };
654
- if (!this.player.node.sessionId)
655
- throw new Error("The Lavalink-Node is either not ready or not up to date");
656
- const now = performance.now();
657
- await this.player.node.updatePlayer({
658
- guildId: this.player.guildId,
659
- playerOptions: {
660
- filters: { equalizer: this.equalizerBands }
661
- }
662
- });
663
- this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
664
- if (this.player.options.instaUpdateFiltersFix === true)
665
- this.filterUpdatedState = 1;
666
- return this;
667
- }
668
- /** Clears the equalizer bands. */
669
- async clearEQ() {
670
- return this.setEQ(new Array(15).fill(0.0).map((gain, band) => ({ band, gain })));
671
- }
672
- }
673
- exports.FilterManager = FilterManager;
674
- /** The audio Outputs Data map declaration */
675
- exports.audioOutputsData = {
676
- mono: {
677
- leftToLeft: 0.5,
678
- leftToRight: 0.5,
679
- rightToLeft: 0.5,
680
- rightToRight: 0.5,
681
- },
682
- stereo: {
683
- leftToLeft: 1,
684
- leftToRight: 0,
685
- rightToLeft: 0,
686
- rightToRight: 1,
687
- },
688
- left: {
689
- leftToLeft: 1,
690
- leftToRight: 0,
691
- rightToLeft: 1,
692
- rightToRight: 0,
693
- },
694
- right: {
695
- leftToLeft: 0,
696
- leftToRight: 1,
697
- rightToLeft: 0,
698
- rightToRight: 1,
699
- },
700
- };
701
- exports.EQList = {
702
- /** A Bassboost Equalizer, so high it distorts the audio */
703
- BassboostEarrape: [
704
- { band: 0, gain: 0.6 * 0.375 },
705
- { band: 1, gain: 0.67 * 0.375 },
706
- { band: 2, gain: 0.67 * 0.375 },
707
- { band: 3, gain: 0.4 * 0.375 },
708
- { band: 4, gain: -0.5 * 0.375 },
709
- { band: 5, gain: 0.15 * 0.375 },
710
- { band: 6, gain: -0.45 * 0.375 },
711
- { band: 7, gain: 0.23 * 0.375 },
712
- { band: 8, gain: 0.35 * 0.375 },
713
- { band: 9, gain: 0.45 * 0.375 },
714
- { band: 10, gain: 0.55 * 0.375 },
715
- { band: 11, gain: -0.6 * 0.375 },
716
- { band: 12, gain: 0.55 * 0.375 },
717
- { band: 13, gain: -0.5 * 0.375 },
718
- { band: 14, gain: -0.75 * 0.375 },
719
- ],
720
- /** A High and decent Bassboost Equalizer */
721
- BassboostHigh: [
722
- { band: 0, gain: 0.6 * 0.25 },
723
- { band: 1, gain: 0.67 * 0.25 },
724
- { band: 2, gain: 0.67 * 0.25 },
725
- { band: 3, gain: 0.4 * 0.25 },
726
- { band: 4, gain: -0.5 * 0.25 },
727
- { band: 5, gain: 0.15 * 0.25 },
728
- { band: 6, gain: -0.45 * 0.25 },
729
- { band: 7, gain: 0.23 * 0.25 },
730
- { band: 8, gain: 0.35 * 0.25 },
731
- { band: 9, gain: 0.45 * 0.25 },
732
- { band: 10, gain: 0.55 * 0.25 },
733
- { band: 11, gain: -0.6 * 0.25 },
734
- { band: 12, gain: 0.55 * 0.25 },
735
- { band: 13, gain: -0.5 * 0.25 },
736
- { band: 14, gain: -0.75 * 0.25 },
737
- ],
738
- /** A decent Bassboost Equalizer */
739
- BassboostMedium: [
740
- { band: 0, gain: 0.6 * 0.1875 },
741
- { band: 1, gain: 0.67 * 0.1875 },
742
- { band: 2, gain: 0.67 * 0.1875 },
743
- { band: 3, gain: 0.4 * 0.1875 },
744
- { band: 4, gain: -0.5 * 0.1875 },
745
- { band: 5, gain: 0.15 * 0.1875 },
746
- { band: 6, gain: -0.45 * 0.1875 },
747
- { band: 7, gain: 0.23 * 0.1875 },
748
- { band: 8, gain: 0.35 * 0.1875 },
749
- { band: 9, gain: 0.45 * 0.1875 },
750
- { band: 10, gain: 0.55 * 0.1875 },
751
- { band: 11, gain: -0.6 * 0.1875 },
752
- { band: 12, gain: 0.55 * 0.1875 },
753
- { band: 13, gain: -0.5 * 0.1875 },
754
- { band: 14, gain: -0.75 * 0.1875 },
755
- ],
756
- /** A slight Bassboost Equalizer */
757
- BassboostLow: [
758
- { band: 0, gain: 0.6 * 0.125 },
759
- { band: 1, gain: 0.67 * 0.125 },
760
- { band: 2, gain: 0.67 * 0.125 },
761
- { band: 3, gain: 0.4 * 0.125 },
762
- { band: 4, gain: -0.5 * 0.125 },
763
- { band: 5, gain: 0.15 * 0.125 },
764
- { band: 6, gain: -0.45 * 0.125 },
765
- { band: 7, gain: 0.23 * 0.125 },
766
- { band: 8, gain: 0.35 * 0.125 },
767
- { band: 9, gain: 0.45 * 0.125 },
768
- { band: 10, gain: 0.55 * 0.125 },
769
- { band: 11, gain: -0.6 * 0.125 },
770
- { band: 12, gain: 0.55 * 0.125 },
771
- { band: 13, gain: -0.5 * 0.125 },
772
- { band: 14, gain: -0.75 * 0.125 },
773
- ],
774
- /** Makes the Music slightly "better" */
775
- BetterMusic: [
776
- { band: 0, gain: 0.25 },
777
- { band: 1, gain: 0.025 },
778
- { band: 2, gain: 0.0125 },
779
- { band: 3, gain: 0 },
780
- { band: 4, gain: 0 },
781
- { band: 5, gain: -0.0125 },
782
- { band: 6, gain: -0.025 },
783
- { band: 7, gain: -0.0175 },
784
- { band: 8, gain: 0 },
785
- { band: 9, gain: 0 },
786
- { band: 10, gain: 0.0125 },
787
- { band: 11, gain: 0.025 },
788
- { band: 12, gain: 0.25 },
789
- { band: 13, gain: 0.125 },
790
- { band: 14, gain: 0.125 },
791
- ],
792
- /** Makes the Music sound like rock music / sound rock music better */
793
- Rock: [
794
- { band: 0, gain: 0.300 },
795
- { band: 1, gain: 0.250 },
796
- { band: 2, gain: 0.200 },
797
- { band: 3, gain: 0.100 },
798
- { band: 4, gain: 0.050 },
799
- { band: 5, gain: -0.050 },
800
- { band: 6, gain: -0.150 },
801
- { band: 7, gain: -0.200 },
802
- { band: 8, gain: -0.100 },
803
- { band: 9, gain: -0.050 },
804
- { band: 10, gain: 0.050 },
805
- { band: 11, gain: 0.100 },
806
- { band: 12, gain: 0.200 },
807
- { band: 13, gain: 0.250 },
808
- { band: 14, gain: 0.300 },
809
- ],
810
- /** Makes the Music sound like Classic music / sound Classic music better */
811
- Classic: [
812
- { band: 0, gain: 0.375 },
813
- { band: 1, gain: 0.350 },
814
- { band: 2, gain: 0.125 },
815
- { band: 3, gain: 0 },
816
- { band: 4, gain: 0 },
817
- { band: 5, gain: 0.125 },
818
- { band: 6, gain: 0.550 },
819
- { band: 7, gain: 0.050 },
820
- { band: 8, gain: 0.125 },
821
- { band: 9, gain: 0.250 },
822
- { band: 10, gain: 0.200 },
823
- { band: 11, gain: 0.250 },
824
- { band: 12, gain: 0.300 },
825
- { band: 13, gain: 0.250 },
826
- { band: 14, gain: 0.300 },
827
- ],
828
- /** Makes the Music sound like Pop music / sound Pop music better */
829
- Pop: [
830
- { band: 0, gain: 0.2635 },
831
- { band: 1, gain: 0.22141 },
832
- { band: 2, gain: -0.21141 },
833
- { band: 3, gain: -0.1851 },
834
- { band: 4, gain: -0.155 },
835
- { band: 5, gain: 0.21141 },
836
- { band: 6, gain: 0.22456 },
837
- { band: 7, gain: 0.237 },
838
- { band: 8, gain: 0.237 },
839
- { band: 9, gain: 0.237 },
840
- { band: 10, gain: -0.05 },
841
- { band: 11, gain: -0.116 },
842
- { band: 12, gain: 0.192 },
843
- { band: 13, gain: 0 },
844
- ],
845
- /** Makes the Music sound like Electronic music / sound Electronic music better */
846
- Electronic: [
847
- { band: 0, gain: 0.375 },
848
- { band: 1, gain: 0.350 },
849
- { band: 2, gain: 0.125 },
850
- { band: 3, gain: 0 },
851
- { band: 4, gain: 0 },
852
- { band: 5, gain: -0.125 },
853
- { band: 6, gain: -0.125 },
854
- { band: 7, gain: 0 },
855
- { band: 8, gain: 0.25 },
856
- { band: 9, gain: 0.125 },
857
- { band: 10, gain: 0.15 },
858
- { band: 11, gain: 0.2 },
859
- { band: 12, gain: 0.250 },
860
- { band: 13, gain: 0.350 },
861
- { band: 14, gain: 0.400 },
862
- ],
863
- /** Boosts all Bands slightly for louder and fuller sound */
864
- FullSound: [
865
- { band: 0, gain: 0.25 + 0.375 },
866
- { band: 1, gain: 0.25 + 0.025 },
867
- { band: 2, gain: 0.25 + 0.0125 },
868
- { band: 3, gain: 0.25 + 0 },
869
- { band: 4, gain: 0.25 + 0 },
870
- { band: 5, gain: 0.25 + -0.0125 },
871
- { band: 6, gain: 0.25 + -0.025 },
872
- { band: 7, gain: 0.25 + -0.0175 },
873
- { band: 8, gain: 0.25 + 0 },
874
- { band: 9, gain: 0.25 + 0 },
875
- { band: 10, gain: 0.25 + 0.0125 },
876
- { band: 11, gain: 0.25 + 0.025 },
877
- { band: 12, gain: 0.25 + 0.375 },
878
- { band: 13, gain: 0.25 + 0.125 },
879
- { band: 14, gain: 0.25 + 0.125 },
880
- ],
881
- /** Boosts basses + lower highs for a pro gaming sound */
882
- Gaming: [
883
- { band: 0, gain: 0.350 },
884
- { band: 1, gain: 0.300 },
885
- { band: 2, gain: 0.250 },
886
- { band: 3, gain: 0.200 },
887
- { band: 4, gain: 0.150 },
888
- { band: 5, gain: 0.100 },
889
- { band: 6, gain: 0.050 },
890
- { band: 7, gain: -0.0 },
891
- { band: 8, gain: -0.050 },
892
- { band: 9, gain: -0.100 },
893
- { band: 10, gain: -0.150 },
894
- { band: 11, gain: -0.200 },
895
- { band: 12, gain: -0.250 },
896
- { band: 13, gain: -0.300 },
897
- { band: 14, gain: -0.350 },
898
- ],
899
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EQList = exports.audioOutputsData = exports.FilterManager = void 0;
4
+ /**
5
+ * The FilterManager for each player
6
+ */
7
+ class FilterManager {
8
+ /** The Equalizer bands currently applied to the Lavalink Server */
9
+ equalizerBands = [];
10
+ /** Private Util for the instaFix Filters option */
11
+ filterUpdatedState = 0;
12
+ /** All "Active" / "disabled" Player Filters */
13
+ filters = {
14
+ volume: false,
15
+ vaporwave: false,
16
+ custom: false,
17
+ nightcore: false,
18
+ rotation: false,
19
+ karaoke: false,
20
+ tremolo: false,
21
+ vibrato: false,
22
+ lowPass: false,
23
+ lavalinkFilterPlugin: {
24
+ echo: false,
25
+ reverb: false,
26
+ },
27
+ lavalinkLavaDspxPlugin: {
28
+ lowPass: false,
29
+ highPass: false,
30
+ normalization: false,
31
+ echo: false,
32
+ },
33
+ audioOutput: "stereo",
34
+ };
35
+ /** The Filter Data sent to Lavalink, only if the filter is enabled (ofc.) */
36
+ data = {
37
+ lowPass: {
38
+ smoothing: 0
39
+ },
40
+ karaoke: {
41
+ level: 0,
42
+ monoLevel: 0,
43
+ filterBand: 0,
44
+ filterWidth: 0
45
+ },
46
+ timescale: {
47
+ speed: 1,
48
+ pitch: 1,
49
+ rate: 1 // 0 = x
50
+ },
51
+ rotation: {
52
+ rotationHz: 0
53
+ },
54
+ tremolo: {
55
+ frequency: 0,
56
+ depth: 0 // 0 < x = 1
57
+ },
58
+ vibrato: {
59
+ frequency: 0,
60
+ depth: 0 // 0 < x <= 1
61
+ },
62
+ pluginFilters: {
63
+ "lavalink-filter-plugin": {
64
+ echo: {
65
+ delay: 0,
66
+ decay: 0 // 0 < 1
67
+ },
68
+ reverb: {
69
+ delays: [],
70
+ gains: [] // [0.84, 0.83, 0.82, 0.81]
71
+ }
72
+ },
73
+ "high-pass": { // Cuts off frequencies lower than the specified {cutoffFrequency}.
74
+ // "cutoffFrequency": 1475, // Integer, higher than zero, in Hz.
75
+ // "boostFactor": 1.0 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
76
+ },
77
+ "low-pass": { // Cuts off frequencies higher than the specified {cutoffFrequency}.
78
+ // "cutoffFrequency": 284, // Integer, higher than zero, in Hz.
79
+ // "boostFactor": 1.24389 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
80
+ },
81
+ "normalization": { // Attenuates peaking where peaks are defined as having a higher value than {maxAmplitude}.
82
+ // "maxAmplitude": 0.6327, // Float, within the range of 0.0 - 1.0. A value of 0.0 mutes the output.
83
+ // "adaptive": true // false
84
+ },
85
+ "echo": { // Self-explanatory; provides an echo effect.
86
+ // "echoLength": 0.5649, // Float, higher than 0.0, in seconds (1.0 = 1 second).
87
+ // "decay": 0.4649 // Float, within the range of 0.0 - 1.0. A value of 1.0 means no decay, and a value of 0.0 means
88
+ },
89
+ },
90
+ channelMix: exports.audioOutputsData.stereo,
91
+ /*distortion: {
92
+ sinOffset: 0,
93
+ sinScale: 1,
94
+ cosOffset: 0,
95
+ cosScale: 1,
96
+ tanOffset: 0,
97
+ tanScale: 1,
98
+ offset: 0,
99
+ scale: 1
100
+ }*/
101
+ };
102
+ /** The Player assigned to this Filter Manager */
103
+ player;
104
+ /** The Constructor for the FilterManager */
105
+ constructor(player) {
106
+ /** Assign the player to the filter manager */
107
+ this.player = player;
108
+ }
109
+ /**
110
+ * Apply Player filters for lavalink filter sending data, if the filter is enabled / not
111
+ */
112
+ async applyPlayerFilters() {
113
+ const sendData = { ...this.data };
114
+ this.checkFiltersState();
115
+ if (!this.filters.volume)
116
+ delete sendData.volume;
117
+ if (!this.filters.tremolo)
118
+ delete sendData.tremolo;
119
+ if (!this.filters.vibrato)
120
+ delete sendData.vibrato;
121
+ if (!this.filters.lavalinkFilterPlugin.echo)
122
+ delete sendData.pluginFilters?.["lavalink-filter-plugin"]?.echo;
123
+ if (!this.filters.lavalinkFilterPlugin.reverb)
124
+ delete sendData.pluginFilters?.["lavalink-filter-plugin"]?.reverb;
125
+ if (!this.filters.lavalinkLavaDspxPlugin.echo)
126
+ delete sendData.pluginFilters?.echo;
127
+ if (!this.filters.lavalinkLavaDspxPlugin.normalization)
128
+ delete sendData.pluginFilters?.normalization;
129
+ if (!this.filters.lavalinkLavaDspxPlugin.highPass)
130
+ delete sendData.pluginFilters?.["high-pass"];
131
+ if (!this.filters.lavalinkLavaDspxPlugin.lowPass)
132
+ delete sendData.pluginFilters?.["low-pass"];
133
+ if (sendData.pluginFilters?.["lavalink-filter-plugin"] && Object.values(sendData.pluginFilters?.["lavalink-filter-plugin"]).length === 0)
134
+ delete sendData.pluginFilters["lavalink-filter-plugin"];
135
+ if (sendData.pluginFilters && Object.values(sendData.pluginFilters).length === 0)
136
+ delete sendData.pluginFilters;
137
+ if (!this.filters.lowPass)
138
+ delete sendData.lowPass;
139
+ if (!this.filters.karaoke)
140
+ delete sendData.karaoke;
141
+ if (!this.filters.rotation)
142
+ delete sendData.rotation;
143
+ if (this.filters.audioOutput === "stereo")
144
+ delete sendData.channelMix;
145
+ if (Object.values(this.data.timescale).every(v => v === 1))
146
+ delete sendData.timescale;
147
+ if (!this.player.node.sessionId)
148
+ throw new Error("The Lavalink-Node is either not ready or not up to date");
149
+ sendData.equalizer = [...this.equalizerBands];
150
+ if (sendData.equalizer.length === 0)
151
+ delete sendData.equalizer;
152
+ for (const key of [...Object.keys(sendData)]) {
153
+ // delete disabled filters
154
+ if (key === "pluginFilters") {
155
+ // for(const key of [...Object.keys(sendData.pluginFilters)]) {
156
+ // // if (this.player.node.info && !this.player.node.info?.plugins?.find?.(v => v.name === key)) delete sendData[key];
157
+ // }
158
+ }
159
+ else if (this.player.node.info && !this.player.node.info?.filters?.includes?.(key))
160
+ delete sendData[key];
161
+ }
162
+ const now = performance.now();
163
+ await this.player.node.updatePlayer({
164
+ guildId: this.player.guildId,
165
+ playerOptions: {
166
+ filters: sendData,
167
+ }
168
+ });
169
+ this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
170
+ if (this.player.options.instaUpdateFiltersFix === true)
171
+ this.filterUpdatedState = 1;
172
+ return;
173
+ }
174
+ /**
175
+ * Checks if the filters are correctly stated (active / not-active)
176
+ * @param oldFilterTimescale
177
+ * @returns
178
+ */
179
+ checkFiltersState(oldFilterTimescale) {
180
+ this.filters.rotation = this.data.rotation.rotationHz !== 0;
181
+ this.filters.vibrato = this.data.vibrato.frequency !== 0 || this.data.vibrato.depth !== 0;
182
+ this.filters.tremolo = this.data.tremolo.frequency !== 0 || this.data.tremolo.depth !== 0;
183
+ const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...((this.data.pluginFilters.reverb) || {}) } });
184
+ this.filters.lavalinkFilterPlugin.echo = lavalinkFilterData.echo.decay !== 0 || lavalinkFilterData.echo.delay !== 0;
185
+ this.filters.lavalinkFilterPlugin.reverb = lavalinkFilterData.reverb?.delays?.length !== 0 || lavalinkFilterData.reverb?.gains?.length !== 0;
186
+ this.filters.lavalinkLavaDspxPlugin.highPass = Object.values(this.data.pluginFilters["high-pass"] || {}).length > 0;
187
+ this.filters.lavalinkLavaDspxPlugin.lowPass = Object.values(this.data.pluginFilters["low-pass"] || {}).length > 0;
188
+ this.filters.lavalinkLavaDspxPlugin.normalization = Object.values(this.data.pluginFilters.normalization || {}).length > 0;
189
+ this.filters.lavalinkLavaDspxPlugin.echo = Object.values(this.data.pluginFilters.echo || {}).length > 0 && typeof this.data.pluginFilters?.echo?.delay === "undefined";
190
+ this.filters.lowPass = this.data.lowPass.smoothing !== 0;
191
+ this.filters.karaoke = Object.values(this.data.karaoke).some(v => v !== 0);
192
+ if ((this.filters.nightcore || this.filters.vaporwave) && oldFilterTimescale) {
193
+ if (oldFilterTimescale.pitch !== this.data.timescale.pitch || oldFilterTimescale.rate !== this.data.timescale.rate || oldFilterTimescale.speed !== this.data.timescale.speed) {
194
+ this.filters.custom = Object.values(this.data.timescale).some(v => v !== 1);
195
+ this.filters.nightcore = false;
196
+ this.filters.vaporwave = false;
197
+ }
198
+ }
199
+ return true;
200
+ }
201
+ /**
202
+ * Reset all Filters
203
+ */
204
+ async resetFilters() {
205
+ this.filters.lavalinkLavaDspxPlugin.echo = false;
206
+ this.filters.lavalinkLavaDspxPlugin.normalization = false;
207
+ this.filters.lavalinkLavaDspxPlugin.highPass = false;
208
+ this.filters.lavalinkLavaDspxPlugin.lowPass = false;
209
+ this.filters.lavalinkFilterPlugin.echo = false;
210
+ this.filters.lavalinkFilterPlugin.reverb = false;
211
+ this.filters.nightcore = false;
212
+ this.filters.lowPass = false;
213
+ this.filters.rotation = false;
214
+ this.filters.tremolo = false;
215
+ this.filters.vibrato = false;
216
+ this.filters.karaoke = false;
217
+ this.filters.karaoke = false;
218
+ this.filters.volume = false;
219
+ this.filters.audioOutput = "stereo";
220
+ // reset all filter datas
221
+ for (const [key, value] of Object.entries({
222
+ volume: 1,
223
+ lowPass: {
224
+ smoothing: 0
225
+ },
226
+ karaoke: {
227
+ level: 0,
228
+ monoLevel: 0,
229
+ filterBand: 0,
230
+ filterWidth: 0
231
+ },
232
+ timescale: {
233
+ speed: 1,
234
+ pitch: 1,
235
+ rate: 1 // 0 = x
236
+ },
237
+ pluginFilters: {
238
+ "lavalink-filter-plugin": {
239
+ echo: {
240
+ // delay: 0, // in seconds
241
+ // decay: 0 // 0 < 1
242
+ },
243
+ reverb: {
244
+ // delays: [], // [0.037, 0.042, 0.048, 0.053]
245
+ // gains: [] // [0.84, 0.83, 0.82, 0.81]
246
+ }
247
+ },
248
+ "high-pass": { // Cuts off frequencies lower than the specified {cutoffFrequency}.
249
+ // "cutoffFrequency": 1475, // Integer, higher than zero, in Hz.
250
+ // "boostFactor": 1.0 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
251
+ },
252
+ "low-pass": { // Cuts off frequencies higher than the specified {cutoffFrequency}.
253
+ // "cutoffFrequency": 284, // Integer, higher than zero, in Hz.
254
+ // "boostFactor": 1.24389 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
255
+ },
256
+ "normalization": { // Attenuates peaking where peaks are defined as having a higher value than {maxAmplitude}.
257
+ // "maxAmplitude": 0.6327, // Float, within the range of 0.0 - 1.0. A value of 0.0 mutes the output.
258
+ // "adaptive": true // false
259
+ },
260
+ "echo": { // Self-explanatory; provides an echo effect.
261
+ // "echoLength": 0.5649, // Float, higher than 0.0, in seconds (1.0 = 1 second).
262
+ // "decay": 0.4649 // Float, within the range of 0.0 - 1.0. A value of 1.0 means no decay, and a value of 0.0 means
263
+ },
264
+ },
265
+ rotation: {
266
+ rotationHz: 0
267
+ },
268
+ tremolo: {
269
+ frequency: 0,
270
+ depth: 0 // 0 < x = 1
271
+ },
272
+ vibrato: {
273
+ frequency: 0,
274
+ depth: 0 // 0 < x = 1
275
+ },
276
+ channelMix: exports.audioOutputsData.stereo,
277
+ })) {
278
+ this.data[key] = value;
279
+ }
280
+ await this.applyPlayerFilters();
281
+ return this.filters;
282
+ }
283
+ /**
284
+ * Set the Filter Volume
285
+ * @param volume
286
+ * @returns
287
+ */
288
+ async setVolume(volume) {
289
+ if (volume < 0 || volume > 5)
290
+ throw new SyntaxError("Volume-Filter must be between 0 and 5");
291
+ this.data.volume = volume;
292
+ await this.applyPlayerFilters();
293
+ return this.filters.volume;
294
+ }
295
+ /**
296
+ * Set the AudioOutput Filter
297
+ * @param type
298
+ * @returns
299
+ */
300
+ async setAudioOutput(type) {
301
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("channelMix"))
302
+ throw new Error("Node#Info#filters does not include the 'channelMix' Filter (Node has it not enable)");
303
+ if (!type || !exports.audioOutputsData[type])
304
+ throw "Invalid audio type added, must be 'mono' / 'stereo' / 'left' / 'right'";
305
+ this.data.channelMix = exports.audioOutputsData[type];
306
+ this.filters.audioOutput = type;
307
+ await this.applyPlayerFilters();
308
+ return this.filters.audioOutput;
309
+ }
310
+ /**
311
+ * Set custom filter.timescale#speed . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
312
+ * @param speed
313
+ * @returns
314
+ */
315
+ async setSpeed(speed = 1) {
316
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
317
+ throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
318
+ // reset nightcore / vaporwave filter if enabled
319
+ if (this.filters.nightcore || this.filters.vaporwave) {
320
+ this.data.timescale.pitch = 1;
321
+ this.data.timescale.speed = 1;
322
+ this.data.timescale.rate = 1;
323
+ this.filters.nightcore = false;
324
+ this.filters.vaporwave = false;
325
+ }
326
+ this.data.timescale.speed = speed;
327
+ // check if custom filter is active / not
328
+ this.isCustomFilterActive();
329
+ await this.applyPlayerFilters();
330
+ return this.filters.custom;
331
+ }
332
+ /**
333
+ * Set custom filter.timescale#pitch . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
334
+ * @param speed
335
+ * @returns
336
+ */
337
+ async setPitch(pitch = 1) {
338
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
339
+ throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
340
+ // reset nightcore / vaporwave filter if enabled
341
+ if (this.filters.nightcore || this.filters.vaporwave) {
342
+ this.data.timescale.pitch = 1;
343
+ this.data.timescale.speed = 1;
344
+ this.data.timescale.rate = 1;
345
+ this.filters.nightcore = false;
346
+ this.filters.vaporwave = false;
347
+ }
348
+ this.data.timescale.pitch = pitch;
349
+ // check if custom filter is active / not
350
+ this.isCustomFilterActive();
351
+ await this.applyPlayerFilters();
352
+ return this.filters.custom;
353
+ }
354
+ /**
355
+ * Set custom filter.timescale#rate . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
356
+ * @param speed
357
+ * @returns
358
+ */
359
+ async setRate(rate = 1) {
360
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
361
+ throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
362
+ // reset nightcore / vaporwave filter if enabled
363
+ if (this.filters.nightcore || this.filters.vaporwave) {
364
+ this.data.timescale.pitch = 1;
365
+ this.data.timescale.speed = 1;
366
+ this.data.timescale.rate = 1;
367
+ this.filters.nightcore = false;
368
+ this.filters.vaporwave = false;
369
+ }
370
+ this.data.timescale.rate = rate;
371
+ // check if custom filter is active / not
372
+ this.isCustomFilterActive();
373
+ await this.applyPlayerFilters();
374
+ return this.filters.custom;
375
+ }
376
+ /**
377
+ * Enables / Disables the rotation effect, (Optional: provide your Own Data)
378
+ * @param rotationHz
379
+ * @returns
380
+ */
381
+ async toggleRotation(rotationHz = 0.2) {
382
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("rotation"))
383
+ throw new Error("Node#Info#filters does not include the 'rotation' Filter (Node has it not enable)");
384
+ this.data.rotation.rotationHz = this.filters.rotation ? 0 : rotationHz;
385
+ this.filters.rotation = !this.filters.rotation;
386
+ return await this.applyPlayerFilters(), this.filters.rotation;
387
+ }
388
+ /**
389
+ * Enables / Disables the Vibrato effect, (Optional: provide your Own Data)
390
+ * @param frequency
391
+ * @param depth
392
+ * @returns
393
+ */
394
+ async toggleVibrato(frequency = 10, depth = 1) {
395
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("vibrato"))
396
+ throw new Error("Node#Info#filters does not include the 'vibrato' Filter (Node has it not enable)");
397
+ this.data.vibrato.frequency = this.filters.vibrato ? 0 : frequency;
398
+ this.data.vibrato.depth = this.filters.vibrato ? 0 : depth;
399
+ this.filters.vibrato = !this.filters.vibrato;
400
+ await this.applyPlayerFilters();
401
+ return this.filters.vibrato;
402
+ }
403
+ /**
404
+ * Enables / Disables the Tremolo effect, (Optional: provide your Own Data)
405
+ * @param frequency
406
+ * @param depth
407
+ * @returns
408
+ */
409
+ async toggleTremolo(frequency = 4, depth = 0.8) {
410
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("tremolo"))
411
+ throw new Error("Node#Info#filters does not include the 'tremolo' Filter (Node has it not enable)");
412
+ this.data.tremolo.frequency = this.filters.tremolo ? 0 : frequency;
413
+ this.data.tremolo.depth = this.filters.tremolo ? 0 : depth;
414
+ this.filters.tremolo = !this.filters.tremolo;
415
+ await this.applyPlayerFilters();
416
+ return this.filters.tremolo;
417
+ }
418
+ /**
419
+ * Enables / Disables the LowPass effect, (Optional: provide your Own Data)
420
+ * @param smoothing
421
+ * @returns
422
+ */
423
+ async toggleLowPass(smoothing = 20) {
424
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("lowPass"))
425
+ throw new Error("Node#Info#filters does not include the 'lowPass' Filter (Node has it not enable)");
426
+ this.data.lowPass.smoothing = this.filters.lowPass ? 0 : smoothing;
427
+ this.filters.lowPass = !this.filters.lowPass;
428
+ await this.applyPlayerFilters();
429
+ return this.filters.lowPass;
430
+ }
431
+ lavalinkLavaDspxPlugin = {
432
+ toggleLowPass: async (boostFactor = 1.0, cutoffFrequency = 80) => {
433
+ if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
434
+ throw new Error("Node#Info#plugins does not include the lavadspx plugin");
435
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("low-pass"))
436
+ throw new Error("Node#Info#filters does not include the 'low-pass' Filter (Node has it not enable)");
437
+ if (!this.data)
438
+ this.data = {};
439
+ if (!this.data.pluginFilters)
440
+ this.data.pluginFilters = {};
441
+ if (!this.data.pluginFilters["low-pass"])
442
+ this.data.pluginFilters["low-pass"] = {};
443
+ if (this.filters.lavalinkLavaDspxPlugin.lowPass) {
444
+ delete this.data.pluginFilters["low-pass"];
445
+ }
446
+ else {
447
+ this.data.pluginFilters["low-pass"] = {
448
+ boostFactor: boostFactor,
449
+ cutoffFrequency: cutoffFrequency
450
+ };
451
+ }
452
+ this.filters.lavalinkLavaDspxPlugin.lowPass = !this.filters.lavalinkLavaDspxPlugin.lowPass;
453
+ await this.applyPlayerFilters();
454
+ return this.filters.lavalinkLavaDspxPlugin.lowPass;
455
+ },
456
+ toggleHighPass: async (boostFactor = 1.0, cutoffFrequency = 80) => {
457
+ if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
458
+ throw new Error("Node#Info#plugins does not include the lavadspx plugin");
459
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("high-pass"))
460
+ throw new Error("Node#Info#filters does not include the 'high-pass' Filter (Node has it not enable)");
461
+ if (!this.data)
462
+ this.data = {};
463
+ if (!this.data.pluginFilters)
464
+ this.data.pluginFilters = {};
465
+ if (!this.data.pluginFilters["high-pass"])
466
+ this.data.pluginFilters["high-pass"] = {};
467
+ if (this.filters.lavalinkLavaDspxPlugin.highPass) {
468
+ delete this.data.pluginFilters["high-pass"];
469
+ }
470
+ else {
471
+ this.data.pluginFilters["high-pass"] = {
472
+ boostFactor: boostFactor,
473
+ cutoffFrequency: cutoffFrequency
474
+ };
475
+ }
476
+ this.filters.lavalinkLavaDspxPlugin.highPass = !this.filters.lavalinkLavaDspxPlugin.highPass;
477
+ await this.applyPlayerFilters();
478
+ return this.filters.lavalinkLavaDspxPlugin.highPass;
479
+ },
480
+ toggleNormalization: async (maxAmplitude = 0.75, adaptive = true) => {
481
+ if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
482
+ throw new Error("Node#Info#plugins does not include the lavadspx plugin");
483
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("normalization"))
484
+ throw new Error("Node#Info#filters does not include the 'normalization' Filter (Node has it not enable)");
485
+ if (!this.data)
486
+ this.data = {};
487
+ if (!this.data.pluginFilters)
488
+ this.data.pluginFilters = {};
489
+ if (!this.data.pluginFilters.normalization)
490
+ this.data.pluginFilters.normalization = {};
491
+ if (this.filters.lavalinkLavaDspxPlugin.normalization) {
492
+ delete this.data.pluginFilters.normalization;
493
+ }
494
+ else {
495
+ this.data.pluginFilters.normalization = {
496
+ adaptive: adaptive,
497
+ maxAmplitude: maxAmplitude
498
+ };
499
+ }
500
+ this.filters.lavalinkLavaDspxPlugin.normalization = !this.filters.lavalinkLavaDspxPlugin.normalization;
501
+ await this.applyPlayerFilters();
502
+ return this.filters.lavalinkLavaDspxPlugin.normalization;
503
+ },
504
+ toggleEcho: async (decay = 0.5, echoLength = 0.5) => {
505
+ if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
506
+ throw new Error("Node#Info#plugins does not include the lavadspx plugin");
507
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("echo"))
508
+ throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable)");
509
+ if (!this.data)
510
+ this.data = {};
511
+ if (!this.data.pluginFilters)
512
+ this.data.pluginFilters = {};
513
+ if (!this.data.pluginFilters.echo)
514
+ this.data.pluginFilters.echo = {};
515
+ if (this.filters.lavalinkLavaDspxPlugin.echo) {
516
+ delete this.data.pluginFilters.echo;
517
+ }
518
+ else {
519
+ this.data.pluginFilters.echo = {
520
+ decay: decay,
521
+ echoLength: echoLength
522
+ };
523
+ }
524
+ this.filters.lavalinkLavaDspxPlugin.echo = !this.filters.lavalinkLavaDspxPlugin.echo;
525
+ await this.applyPlayerFilters();
526
+ return this.filters.lavalinkLavaDspxPlugin.echo;
527
+ }
528
+ };
529
+ lavalinkFilterPlugin = {
530
+ /**
531
+ * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
532
+ * @param delay
533
+ * @param decay
534
+ * @returns
535
+ */
536
+ toggleEcho: async (delay = 4, decay = 0.8) => {
537
+ if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavalink-filter-plugin"))
538
+ throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
539
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("echo"))
540
+ throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable aka not installed!)");
541
+ if (!this.data)
542
+ this.data = {};
543
+ if (!this.data.pluginFilters)
544
+ this.data.pluginFilters = {};
545
+ if (!this.data.pluginFilters["lavalink-filter-plugin"])
546
+ this.data.pluginFilters["lavalink-filter-plugin"] = { echo: { decay: 0, delay: 0 }, reverb: { delays: [], gains: [] } };
547
+ if (!this.data.pluginFilters["lavalink-filter-plugin"].echo)
548
+ this.data.pluginFilters["lavalink-filter-plugin"].echo = { decay: 0, delay: 0 };
549
+ this.data.pluginFilters["lavalink-filter-plugin"].echo.delay = this.filters.lavalinkFilterPlugin.echo ? 0 : delay;
550
+ this.data.pluginFilters["lavalink-filter-plugin"].echo.decay = this.filters.lavalinkFilterPlugin.echo ? 0 : decay;
551
+ this.filters.lavalinkFilterPlugin.echo = !this.filters.lavalinkFilterPlugin.echo;
552
+ await this.applyPlayerFilters();
553
+ return this.filters.lavalinkFilterPlugin.echo;
554
+ },
555
+ /**
556
+ * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
557
+ * @param delays
558
+ * @param gains
559
+ * @returns
560
+ */
561
+ toggleReverb: async (delays = [0.037, 0.042, 0.048, 0.053], gains = [0.84, 0.83, 0.82, 0.81]) => {
562
+ if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavalink-filter-plugin"))
563
+ throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
564
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("reverb"))
565
+ throw new Error("Node#Info#filters does not include the 'reverb' Filter (Node has it not enable aka not installed!)");
566
+ if (!this.data)
567
+ this.data = {};
568
+ if (!this.data.pluginFilters)
569
+ this.data.pluginFilters = {};
570
+ if (!this.data.pluginFilters["lavalink-filter-plugin"])
571
+ this.data.pluginFilters["lavalink-filter-plugin"] = { echo: { decay: 0, delay: 0 }, reverb: { delays: [], gains: [] } };
572
+ if (!this.data.pluginFilters["lavalink-filter-plugin"].reverb)
573
+ this.data.pluginFilters["lavalink-filter-plugin"].reverb = { delays: [], gains: [] };
574
+ this.data.pluginFilters["lavalink-filter-plugin"].reverb.delays = this.filters.lavalinkFilterPlugin.reverb ? [] : delays;
575
+ this.data.pluginFilters["lavalink-filter-plugin"].reverb.gains = this.filters.lavalinkFilterPlugin.reverb ? [] : gains;
576
+ this.filters.lavalinkFilterPlugin.reverb = !this.filters.lavalinkFilterPlugin.reverb;
577
+ await this.applyPlayerFilters();
578
+ return this.filters.lavalinkFilterPlugin.reverb;
579
+ }
580
+ };
581
+ /**
582
+ * Enables / Disables a Nightcore-like filter Effect. Disables/Overrides both: custom and Vaporwave Filter
583
+ * @param speed
584
+ * @param pitch
585
+ * @param rate
586
+ * @returns
587
+ */
588
+ async toggleNightcore(speed = 1.289999523162842, pitch = 1.289999523162842, rate = 0.9365999523162842) {
589
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
590
+ throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
591
+ this.data.timescale.speed = this.filters.nightcore ? 1 : speed;
592
+ this.data.timescale.pitch = this.filters.nightcore ? 1 : pitch;
593
+ this.data.timescale.rate = this.filters.nightcore ? 1 : rate;
594
+ this.filters.nightcore = !this.filters.nightcore;
595
+ this.filters.vaporwave = false;
596
+ this.filters.custom = false;
597
+ await this.applyPlayerFilters();
598
+ return this.filters.nightcore;
599
+ }
600
+ /**
601
+ * Enables / Disables a Vaporwave-like filter Effect. Disables/Overrides both: custom and nightcore Filter
602
+ * @param speed
603
+ * @param pitch
604
+ * @param rate
605
+ * @returns
606
+ */
607
+ async toggleVaporwave(speed = 0.8500000238418579, pitch = 0.800000011920929, rate = 1) {
608
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
609
+ throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
610
+ this.data.timescale.speed = this.filters.vaporwave ? 1 : speed;
611
+ this.data.timescale.pitch = this.filters.vaporwave ? 1 : pitch;
612
+ this.data.timescale.rate = this.filters.vaporwave ? 1 : rate;
613
+ this.filters.vaporwave = !this.filters.vaporwave;
614
+ this.filters.nightcore = false;
615
+ this.filters.custom = false;
616
+ await this.applyPlayerFilters();
617
+ return this.filters.vaporwave;
618
+ }
619
+ /**
620
+ * Enable / Disables a Karaoke like Filter Effect
621
+ * @param level
622
+ * @param monoLevel
623
+ * @param filterBand
624
+ * @param filterWidth
625
+ * @returns
626
+ */
627
+ async toggleKaraoke(level = 1, monoLevel = 1, filterBand = 220, filterWidth = 100) {
628
+ if (this.player.node.info && !this.player.node.info?.filters?.includes("karaoke"))
629
+ throw new Error("Node#Info#filters does not include the 'karaoke' Filter (Node has it not enable)");
630
+ this.data.karaoke.level = this.filters.karaoke ? 0 : level;
631
+ this.data.karaoke.monoLevel = this.filters.karaoke ? 0 : monoLevel;
632
+ this.data.karaoke.filterBand = this.filters.karaoke ? 0 : filterBand;
633
+ this.data.karaoke.filterWidth = this.filters.karaoke ? 0 : filterWidth;
634
+ this.filters.karaoke = !this.filters.karaoke;
635
+ await this.applyPlayerFilters();
636
+ return this.filters.karaoke;
637
+ }
638
+ /** Function to find out if currently there is a custom timescamle etc. filter applied */
639
+ isCustomFilterActive() {
640
+ this.filters.custom = !this.filters.nightcore && !this.filters.vaporwave && Object.values(this.data.timescale).some(d => d !== 1);
641
+ return this.filters.custom;
642
+ }
643
+ /**
644
+ * Sets the players equalizer band on-top of the existing ones.
645
+ * @param bands
646
+ */
647
+ async setEQ(bands) {
648
+ if (!Array.isArray(bands))
649
+ bands = [bands];
650
+ if (!bands.length || !bands.every((band) => JSON.stringify(Object.keys(band).sort()) === '["band","gain"]'))
651
+ throw new TypeError("Bands must be a non-empty object array containing 'band' and 'gain' properties.");
652
+ for (const { band, gain } of bands)
653
+ this.equalizerBands[band] = { band, gain };
654
+ if (!this.player.node.sessionId)
655
+ throw new Error("The Lavalink-Node is either not ready or not up to date");
656
+ const now = performance.now();
657
+ await this.player.node.updatePlayer({
658
+ guildId: this.player.guildId,
659
+ playerOptions: {
660
+ filters: { equalizer: this.equalizerBands }
661
+ }
662
+ });
663
+ this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
664
+ if (this.player.options.instaUpdateFiltersFix === true)
665
+ this.filterUpdatedState = 1;
666
+ return this;
667
+ }
668
+ /** Clears the equalizer bands. */
669
+ async clearEQ() {
670
+ return this.setEQ(new Array(15).fill(0.0).map((gain, band) => ({ band, gain })));
671
+ }
672
+ }
673
+ exports.FilterManager = FilterManager;
674
+ /** The audio Outputs Data map declaration */
675
+ exports.audioOutputsData = {
676
+ mono: {
677
+ leftToLeft: 0.5,
678
+ leftToRight: 0.5,
679
+ rightToLeft: 0.5,
680
+ rightToRight: 0.5,
681
+ },
682
+ stereo: {
683
+ leftToLeft: 1,
684
+ leftToRight: 0,
685
+ rightToLeft: 0,
686
+ rightToRight: 1,
687
+ },
688
+ left: {
689
+ leftToLeft: 1,
690
+ leftToRight: 0,
691
+ rightToLeft: 1,
692
+ rightToRight: 0,
693
+ },
694
+ right: {
695
+ leftToLeft: 0,
696
+ leftToRight: 1,
697
+ rightToLeft: 0,
698
+ rightToRight: 1,
699
+ },
700
+ };
701
+ exports.EQList = {
702
+ /** A Bassboost Equalizer, so high it distorts the audio */
703
+ BassboostEarrape: [
704
+ { band: 0, gain: 0.6 * 0.375 },
705
+ { band: 1, gain: 0.67 * 0.375 },
706
+ { band: 2, gain: 0.67 * 0.375 },
707
+ { band: 3, gain: 0.4 * 0.375 },
708
+ { band: 4, gain: -0.5 * 0.375 },
709
+ { band: 5, gain: 0.15 * 0.375 },
710
+ { band: 6, gain: -0.45 * 0.375 },
711
+ { band: 7, gain: 0.23 * 0.375 },
712
+ { band: 8, gain: 0.35 * 0.375 },
713
+ { band: 9, gain: 0.45 * 0.375 },
714
+ { band: 10, gain: 0.55 * 0.375 },
715
+ { band: 11, gain: -0.6 * 0.375 },
716
+ { band: 12, gain: 0.55 * 0.375 },
717
+ { band: 13, gain: -0.5 * 0.375 },
718
+ { band: 14, gain: -0.75 * 0.375 },
719
+ ],
720
+ /** A High and decent Bassboost Equalizer */
721
+ BassboostHigh: [
722
+ { band: 0, gain: 0.6 * 0.25 },
723
+ { band: 1, gain: 0.67 * 0.25 },
724
+ { band: 2, gain: 0.67 * 0.25 },
725
+ { band: 3, gain: 0.4 * 0.25 },
726
+ { band: 4, gain: -0.5 * 0.25 },
727
+ { band: 5, gain: 0.15 * 0.25 },
728
+ { band: 6, gain: -0.45 * 0.25 },
729
+ { band: 7, gain: 0.23 * 0.25 },
730
+ { band: 8, gain: 0.35 * 0.25 },
731
+ { band: 9, gain: 0.45 * 0.25 },
732
+ { band: 10, gain: 0.55 * 0.25 },
733
+ { band: 11, gain: -0.6 * 0.25 },
734
+ { band: 12, gain: 0.55 * 0.25 },
735
+ { band: 13, gain: -0.5 * 0.25 },
736
+ { band: 14, gain: -0.75 * 0.25 },
737
+ ],
738
+ /** A decent Bassboost Equalizer */
739
+ BassboostMedium: [
740
+ { band: 0, gain: 0.6 * 0.1875 },
741
+ { band: 1, gain: 0.67 * 0.1875 },
742
+ { band: 2, gain: 0.67 * 0.1875 },
743
+ { band: 3, gain: 0.4 * 0.1875 },
744
+ { band: 4, gain: -0.5 * 0.1875 },
745
+ { band: 5, gain: 0.15 * 0.1875 },
746
+ { band: 6, gain: -0.45 * 0.1875 },
747
+ { band: 7, gain: 0.23 * 0.1875 },
748
+ { band: 8, gain: 0.35 * 0.1875 },
749
+ { band: 9, gain: 0.45 * 0.1875 },
750
+ { band: 10, gain: 0.55 * 0.1875 },
751
+ { band: 11, gain: -0.6 * 0.1875 },
752
+ { band: 12, gain: 0.55 * 0.1875 },
753
+ { band: 13, gain: -0.5 * 0.1875 },
754
+ { band: 14, gain: -0.75 * 0.1875 },
755
+ ],
756
+ /** A slight Bassboost Equalizer */
757
+ BassboostLow: [
758
+ { band: 0, gain: 0.6 * 0.125 },
759
+ { band: 1, gain: 0.67 * 0.125 },
760
+ { band: 2, gain: 0.67 * 0.125 },
761
+ { band: 3, gain: 0.4 * 0.125 },
762
+ { band: 4, gain: -0.5 * 0.125 },
763
+ { band: 5, gain: 0.15 * 0.125 },
764
+ { band: 6, gain: -0.45 * 0.125 },
765
+ { band: 7, gain: 0.23 * 0.125 },
766
+ { band: 8, gain: 0.35 * 0.125 },
767
+ { band: 9, gain: 0.45 * 0.125 },
768
+ { band: 10, gain: 0.55 * 0.125 },
769
+ { band: 11, gain: -0.6 * 0.125 },
770
+ { band: 12, gain: 0.55 * 0.125 },
771
+ { band: 13, gain: -0.5 * 0.125 },
772
+ { band: 14, gain: -0.75 * 0.125 },
773
+ ],
774
+ /** Makes the Music slightly "better" */
775
+ BetterMusic: [
776
+ { band: 0, gain: 0.25 },
777
+ { band: 1, gain: 0.025 },
778
+ { band: 2, gain: 0.0125 },
779
+ { band: 3, gain: 0 },
780
+ { band: 4, gain: 0 },
781
+ { band: 5, gain: -0.0125 },
782
+ { band: 6, gain: -0.025 },
783
+ { band: 7, gain: -0.0175 },
784
+ { band: 8, gain: 0 },
785
+ { band: 9, gain: 0 },
786
+ { band: 10, gain: 0.0125 },
787
+ { band: 11, gain: 0.025 },
788
+ { band: 12, gain: 0.25 },
789
+ { band: 13, gain: 0.125 },
790
+ { band: 14, gain: 0.125 },
791
+ ],
792
+ /** Makes the Music sound like rock music / sound rock music better */
793
+ Rock: [
794
+ { band: 0, gain: 0.300 },
795
+ { band: 1, gain: 0.250 },
796
+ { band: 2, gain: 0.200 },
797
+ { band: 3, gain: 0.100 },
798
+ { band: 4, gain: 0.050 },
799
+ { band: 5, gain: -0.050 },
800
+ { band: 6, gain: -0.150 },
801
+ { band: 7, gain: -0.200 },
802
+ { band: 8, gain: -0.100 },
803
+ { band: 9, gain: -0.050 },
804
+ { band: 10, gain: 0.050 },
805
+ { band: 11, gain: 0.100 },
806
+ { band: 12, gain: 0.200 },
807
+ { band: 13, gain: 0.250 },
808
+ { band: 14, gain: 0.300 },
809
+ ],
810
+ /** Makes the Music sound like Classic music / sound Classic music better */
811
+ Classic: [
812
+ { band: 0, gain: 0.375 },
813
+ { band: 1, gain: 0.350 },
814
+ { band: 2, gain: 0.125 },
815
+ { band: 3, gain: 0 },
816
+ { band: 4, gain: 0 },
817
+ { band: 5, gain: 0.125 },
818
+ { band: 6, gain: 0.550 },
819
+ { band: 7, gain: 0.050 },
820
+ { band: 8, gain: 0.125 },
821
+ { band: 9, gain: 0.250 },
822
+ { band: 10, gain: 0.200 },
823
+ { band: 11, gain: 0.250 },
824
+ { band: 12, gain: 0.300 },
825
+ { band: 13, gain: 0.250 },
826
+ { band: 14, gain: 0.300 },
827
+ ],
828
+ /** Makes the Music sound like Pop music / sound Pop music better */
829
+ Pop: [
830
+ { band: 0, gain: 0.2635 },
831
+ { band: 1, gain: 0.22141 },
832
+ { band: 2, gain: -0.21141 },
833
+ { band: 3, gain: -0.1851 },
834
+ { band: 4, gain: -0.155 },
835
+ { band: 5, gain: 0.21141 },
836
+ { band: 6, gain: 0.22456 },
837
+ { band: 7, gain: 0.237 },
838
+ { band: 8, gain: 0.237 },
839
+ { band: 9, gain: 0.237 },
840
+ { band: 10, gain: -0.05 },
841
+ { band: 11, gain: -0.116 },
842
+ { band: 12, gain: 0.192 },
843
+ { band: 13, gain: 0 },
844
+ ],
845
+ /** Makes the Music sound like Electronic music / sound Electronic music better */
846
+ Electronic: [
847
+ { band: 0, gain: 0.375 },
848
+ { band: 1, gain: 0.350 },
849
+ { band: 2, gain: 0.125 },
850
+ { band: 3, gain: 0 },
851
+ { band: 4, gain: 0 },
852
+ { band: 5, gain: -0.125 },
853
+ { band: 6, gain: -0.125 },
854
+ { band: 7, gain: 0 },
855
+ { band: 8, gain: 0.25 },
856
+ { band: 9, gain: 0.125 },
857
+ { band: 10, gain: 0.15 },
858
+ { band: 11, gain: 0.2 },
859
+ { band: 12, gain: 0.250 },
860
+ { band: 13, gain: 0.350 },
861
+ { band: 14, gain: 0.400 },
862
+ ],
863
+ /** Boosts all Bands slightly for louder and fuller sound */
864
+ FullSound: [
865
+ { band: 0, gain: 0.25 + 0.375 },
866
+ { band: 1, gain: 0.25 + 0.025 },
867
+ { band: 2, gain: 0.25 + 0.0125 },
868
+ { band: 3, gain: 0.25 + 0 },
869
+ { band: 4, gain: 0.25 + 0 },
870
+ { band: 5, gain: 0.25 + -0.0125 },
871
+ { band: 6, gain: 0.25 + -0.025 },
872
+ { band: 7, gain: 0.25 + -0.0175 },
873
+ { band: 8, gain: 0.25 + 0 },
874
+ { band: 9, gain: 0.25 + 0 },
875
+ { band: 10, gain: 0.25 + 0.0125 },
876
+ { band: 11, gain: 0.25 + 0.025 },
877
+ { band: 12, gain: 0.25 + 0.375 },
878
+ { band: 13, gain: 0.25 + 0.125 },
879
+ { band: 14, gain: 0.25 + 0.125 },
880
+ ],
881
+ /** Boosts basses + lower highs for a pro gaming sound */
882
+ Gaming: [
883
+ { band: 0, gain: 0.350 },
884
+ { band: 1, gain: 0.300 },
885
+ { band: 2, gain: 0.250 },
886
+ { band: 3, gain: 0.200 },
887
+ { band: 4, gain: 0.150 },
888
+ { band: 5, gain: 0.100 },
889
+ { band: 6, gain: 0.050 },
890
+ { band: 7, gain: -0.0 },
891
+ { band: 8, gain: -0.050 },
892
+ { band: 9, gain: -0.100 },
893
+ { band: 10, gain: -0.150 },
894
+ { band: 11, gain: -0.200 },
895
+ { band: 12, gain: -0.250 },
896
+ { band: 13, gain: -0.300 },
897
+ { band: 14, gain: -0.350 },
898
+ ],
899
+ };