From 36bddc1de6dadff17c43ea38550a36fb31e2dbda Mon Sep 17 00:00:00 2001 From: cloudwithax Date: Sat, 30 Oct 2021 12:02:45 -0400 Subject: [PATCH] Added 100% coverage of all filters and exception field for TrackExceptionEvent for Lavalink 3.4 release --- pomice/__init__.py | 2 +- pomice/events.py | 11 +++- pomice/filters.py | 154 ++++++++++++++++++++++++++++++++++++++++++--- pyproject.toml | 8 ++- setup.py | 2 +- 5 files changed, 164 insertions(+), 13 deletions(-) diff --git a/pomice/__init__.py b/pomice/__init__.py index 8bbf555..b89386d 100644 --- a/pomice/__init__.py +++ b/pomice/__init__.py @@ -11,7 +11,7 @@ if discord.__version__ != "2.0.0a": "using 'pip install git+https://github.com/Rapptz/discord.py@master'" ) -__version__ = "1.1.0" +__version__ = "1.1.1" __title__ = "pomice" __author__ = "cloudwithax" diff --git a/pomice/events.py b/pomice/events.py index 8f2dcd5..4c3eb98 100644 --- a/pomice/events.py +++ b/pomice/events.py @@ -85,13 +85,18 @@ class TrackExceptionEvent(PomiceEvent): def __init__(self, data: dict): self.player = NodePool.get_node().get_player(int(data["guildId"])) self.track = self.player._ending_track - self.error: str = data["error"] + if data.get('error'): + # User is running Lavalink <= 3.3 + self.exception: str = data["error"] + else: + # User is running Lavalink >=3.4 + self.exception: str = data["exception"] # on_pomice_track_exception(player, track, error) - self.handler_args = self.player, self.track, self.error + self.handler_args = self.player, self.track, self.exception def __repr__(self) -> str: - return f"" + return f"" class WebSocketClosedPayload: diff --git a/pomice/filters.py b/pomice/filters.py index 452040a..9f61531 100644 --- a/pomice/filters.py +++ b/pomice/filters.py @@ -44,7 +44,13 @@ class Timescale(Filter): This is not the library's fault. """ - def __init__(self, *, speed: float = 1.0, pitch: float = 1.0, rate: float = 1.0): + def __init__( + self, + *, + speed: float = 1.0, + pitch: float = 1.0, + rate: float = 1.0 + ): super().__init__() if speed < 0: @@ -74,10 +80,10 @@ class Karaoke(Filter): def __init__( self, *, - level: float, - mono_level: float, - filter_band: float, - filter_width: float + level: float = 1.0, + mono_level: float = 1.0, + filter_band: float = 220.0, + filter_width: float = 100.0 ): super().__init__() @@ -103,7 +109,12 @@ class Tremolo(Filter): causing it to sound like the music is changing in volume rapidly. """ - def __init__(self, *, frequency: float, depth: float): + def __init__( + self, + *, + frequency: float = 2.0, + depth: float = 0.5 + ): super().__init__() if frequency < 0: @@ -128,7 +139,12 @@ class Vibrato(Filter): but changes in pitch rather than volume. """ - def __init__(self, *, frequency: float, depth: float): + def __init__( + self, + *, + frequency: float = 2.0, + depth: float = 0.5 + ): super().__init__() if frequency < 0 or frequency > 14: @@ -146,3 +162,127 @@ class Vibrato(Filter): def __repr__(self): return f"" + + +class Rotation(Filter): + """Filter which produces a stereo-like panning effect, which sounds like + the audio is being rotated around the listener's head + """ + + def __init__(self, *, rotation_hertz: float = 5): + super().__init__() + + self.rotation_hertz = rotation_hertz + self.payload = {"rotation": {"rotationHz": self.rotation_hertz}} + + def __repr__(self) -> str: + return f"" + + +class ChannelMix(Filter): + """Filter which manually adjusts the panning of the audio, which can make + for some cool effects when done correctly. + """ + + def __init__( + self, + *, + left_to_left: float = 1, + right_to_right: float = 1, + left_to_right: float = 0, + right_to_left: float = 0 + ): + super().__init__() + + if 0 > left_to_left > 1: + raise ValueError( + "'left_to_left' value must be more than or equal to 0 or less than or equal to 1.") + if 0 > right_to_right > 1: + raise ValueError( + "'right_to_right' value must be more than or equal to 0 or less than or equal to 1.") + if 0 > left_to_right > 1: + raise ValueError( + "'left_to_right' value must be more than or equal to 0 or less than or equal to 1.") + if 0 > right_to_left > 1: + raise ValueError( + "'right_to_left' value must be more than or equal to 0 or less than or equal to 1.") + + self.left_to_left = left_to_left + self.left_to_right = left_to_right + self.right_to_left = right_to_left + self.right_to_right = right_to_right + + self.payload = {"channelMix": {"leftToLeft": self.left_to_left, + "leftToRight": self.left_to_right, + "rightToLeft": self.right_to_left, + "rightToRight": self.right_to_right} + } + + def __repr__(self) -> str: + return ( + f"" + ) + +class Distortion(Filter): + """Filter which generates a distortion effect. Useful for certain filter implementations where + distortion is needed. + """ + + def __init__( + self, + *, + sin_offset: float = 0, + sin_scale: float = 1, + cos_offset: float = 0, + cos_scale: float = 1, + tan_offset: float = 0, + tan_scale: float = 1, + offset: float = 0, + scale: float = 1 + ): + super().__init__() + + self.sin_offset = sin_offset + self.sin_scale = sin_scale + self.cos_offset = cos_offset + self.cos_scale = cos_scale + self.tan_offset = tan_offset + self.tan_scale = tan_scale + self.offset = offset + self.scale = scale + + self.payload = {"distortion": { + "sinOffset": self.sin_offset, + "sinScale": self.sin_scale, + "cosOffset": self.cos_offset, + "cosScale": self.cos_scale, + "tanOffset": self.tan_offset, + "tanScale": self.tan_scale, + "offset": self.offset, + "scale": self.scale + }} + + def __repr__(self) -> str: + return ( + f" " + f"cos_offset={self.cos_offset} cos_scale={self.cos_scale} tan_offset={self.tan_offset} " + f"tan_scale={self.tan_scale} offset={self.offset} scale={self.scale}" + ) + + +class LowPass(Filter): + """Filter which supresses higher frequencies and allows lower frequencies to pass. + You can also do this with the Equalizer filter, but this is an easier way to do it. + """ + + def __init__(self, *, smoothing: float = 20): + super().__init__() + + self.smoothing = smoothing + self.payload = {"lowPass": {"smoothing": self.smoothing}} + + def __repr__(self) -> str: + return f"" + + diff --git a/pyproject.toml b/pyproject.toml index b5a3c46..659d40e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,4 +3,10 @@ requires = [ "setuptools>=42", "wheel" ] -build-backend = "setuptools.build_meta" \ No newline at end of file +build-backend = "setuptools.build_meta" + +[tool.autopep8] +max_line_length = 100 +in-place = true +recursive = true +aggressive = 3 \ No newline at end of file diff --git a/setup.py b/setup.py index 28950fb..f5fce49 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md") as f: setuptools.setup( name="pomice", author="cloudwithax", - version="1.1.0", + version="1.1.1", url="https://github.com/cloudwithax/pomice", packages=setuptools.find_packages(), license="GPL",