Skip to content

Commit

Permalink
Add player.equalizer which allows the user to get the currently app…
Browse files Browse the repository at this point in the history
…lied EQ.

Apply `__str__` to each EQ for easily gathering the name.

EQ's are now only able to be made via the provided class methods. Trying to initialise a Equalizer out side of the class methods will raise.

For custom EQ's please use `Equalizer.build()`.
  • Loading branch information
EvieePy committed Jun 20, 2020
1 parent 5b35165 commit bea1a6a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion wavelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__author__ = 'EvieePy'
__license__ = 'MIT'
__copyright__ = 'Copyright 2019-2020 (c) PythonistaGuild'
__version__ = '0.9.0'
__version__ = '0.9.1'

from .client import Client
from .errors import *
Expand Down
72 changes: 55 additions & 17 deletions wavelink/eqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,59 @@
class Equalizer:
"""Class representing a usuable equalizer.
.. warning::
You can only create Equalizers through the provided class methods.
Attributes
------------
eq: list
A list of {'band': int, 'gain': float}
raw: list
A list of tuple pairs containing a band int and gain float.
"""
def __init__(self, levels: list):
def __init__(self):
raise NotImplementedError

@staticmethod
def _factory(levels: list):
_dict = collections.defaultdict(int)

_dict.update(levels)
_dict = [{"band": i, "gain": _dict[i]} for i in range(15)]

self.eq = _dict
self.raw = levels
return _dict

@classmethod
def build(cls, *, levels: list):
"""Build an Equalizer class with the provided levels.
"""Build a custom Equalizer class with the provided levels.
Parameters
------------
levels: List[Tuple[int, float]]
A list of tuple pairs containing a band int and gain float.
"""
return cls(levels)
self = cls.__new__(cls)
self.eq = cls._factory(levels)
self.raw = levels

cls.__str__ = lambda _: 'CustomEqualizer'
return self

@classmethod
def flat(cls):
"""Flat Equalizer.
Resets your EQ to Flat.
"""
return cls([(0, .0), (1, .0), (2, .0), (3, .0), (4, .0),
(5, .0), (6, .0), (7, .0), (8, .0), (9, .0),
(10, .0), (11, .0), (12, .0), (13, .0), (14, .0)])
levels = [(0, .0), (1, .0), (2, .0), (3, .0), (4, .0),
(5, .0), (6, .0), (7, .0), (8, .0), (9, .0),
(10, .0), (11, .0), (12, .0), (13, .0), (14, .0)]
self = cls.__new__(cls)
self.eq = cls._factory(levels)
self.raw = levels

cls.__str__ = lambda _: 'Flat'
return self

@classmethod
def boost(cls):
Expand All @@ -70,19 +87,33 @@ def boost(cls):
This equalizer emphasizes Punchy Bass and Crisp Mid-High tones.
Not suitable for tracks with Deep/Low Bass.
"""
return cls([(0, -0.075), (1, .125), (2, .125), (3, .1), (4, .1),
(5, .05), (6, 0.075), (7, .0), (8, .0), (9, .0),
(10, .0), (11, .0), (12, .125), (13, .15), (14, .05)])
levels = [(0, -0.075), (1, .125), (2, .125), (3, .1), (4, .1),
(5, .05), (6, 0.075), (7, .0), (8, .0), (9, .0),
(10, .0), (11, .0), (12, .125), (13, .15), (14, .05)]

self = cls.__new__(cls)
self.eq = cls._factory(levels)
self.raw = levels

cls.__str__ = lambda _: 'Boost'
return self

@classmethod
def metal(cls):
"""Experimental Metal/Rock Equalizer.
Expect clipping on Bassy songs.
"""
return cls([(0, .0), (1, .1), (2, .1), (3, .15), (4, .13),
(5, .1), (6, .0), (7, .125), (8, .175), (9, .175),
(10, .125), (11, .125), (12, .1), (13, .075), (14, .0)])
levels = [(0, .0), (1, .1), (2, .1), (3, .15), (4, .13),
(5, .1), (6, .0), (7, .125), (8, .175), (9, .175),
(10, .125), (11, .125), (12, .1), (13, .075), (14, .0)]

self = cls.__new__(cls)
self.eq = cls._factory(levels)
self.raw = levels

cls.__str__ = lambda _: 'Metal'
return self

@classmethod
def piano(cls):
Expand All @@ -91,6 +122,13 @@ def piano(cls):
Suitable for Piano tracks, or tacks with an emphasis on Female Vocals.
Could also be used as a Bass Cutoff.
"""
return cls([(0, -0.25), (1, -0.25), (2, -0.125), (3, 0.0),
(4, 0.25), (5, 0.25), (6, 0.0), (7, -0.25), (8, -0.25),
(9, 0.0), (10, 0.0), (11, 0.5), (12, 0.25), (13, -0.025)])
levels = [(0, -0.25), (1, -0.25), (2, -0.125), (3, 0.0),
(4, 0.25), (5, 0.25), (6, 0.0), (7, -0.25), (8, -0.25),
(9, 0.0), (10, 0.0), (11, 0.5), (12, 0.25), (13, -0.025)]

self = cls.__new__(cls)
self.eq = cls._factory(levels)
self.raw = levels

cls.__str__ = lambda _: 'Piano'
return self
13 changes: 11 additions & 2 deletions wavelink/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,18 @@ def __init__(self, bot: Union[commands.Bot, commands.AutoShardedBot], guild_id:
self.volume = 100
self.paused = False
self.current = None
self._equalizer = Equalizer.flat()
self.channel_id = None

self.equalizers = {'FLAT': Equalizer.flat(), 'BOOST': Equalizer.boost(), 'METAL': Equalizer.metal(),
'PIANO': Equalizer.piano()}
@property
def equalizer(self):
"""The currently applied Equalizer."""
return self._equalizer

@property
def eq(self):
"""Alias to :func:`equalizer`."""
return self.equalizer

@property
def is_connected(self) -> bool:
Expand Down Expand Up @@ -345,6 +353,7 @@ async def set_eq(self, equalizer: Equalizer) -> None:
The Equalizer to set.
"""
await self.node._send(op='equalizer', guildId=str(self.guild_id), bands=equalizer.eq)
self._equalizer = Equalizer

async def set_equalizer(self, equalizer: Equalizer) -> None:
"""|coro|
Expand Down

0 comments on commit bea1a6a

Please sign in to comment.