From e504088da19865d37d7d4fcf6542ea92c971bd2a Mon Sep 17 00:00:00 2001 From: cloudwithax Date: Wed, 12 Oct 2022 18:12:10 -0400 Subject: [PATCH] add function to clear filters on all tracks --- pomice/__init__.py | 3 ++- pomice/filters.py | 49 +++++++++++++++++++++++----------------------- pomice/player.py | 10 +++++++--- pomice/queue.py | 10 ++++++++-- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/pomice/__init__.py b/pomice/__init__.py index f9cd69a..cf09b08 100644 --- a/pomice/__init__.py +++ b/pomice/__init__.py @@ -27,6 +27,7 @@ from .events import * from .exceptions import * from .filters import * from .objects import * +from .queue import * from .player import Player from .pool import * -from .queue import * + diff --git a/pomice/filters.py b/pomice/filters.py index fbd0bea..3c666cb 100644 --- a/pomice/filters.py +++ b/pomice/filters.py @@ -74,8 +74,8 @@ class Equalizer(Filter): @classmethod def metal(cls): - """Equalizer preset which increases the mids of a track, - preferably one of the metal genre, to make it sound + """Equalizer preset which increases the mids of a track, + preferably one of the metal genre, to make it sound more full and concert-like. """ @@ -90,7 +90,7 @@ class Equalizer(Filter): @classmethod def piano(cls): """Equalizer preset which increases the mids and highs - of a track, preferably a piano based one, to make it + of a track, preferably a piano based one, to make it stand out. """ @@ -110,11 +110,11 @@ class Timescale(Filter): """ def __init__( - self, - *, + self, + *, tag: str, - speed: float = 1.0, - pitch: float = 1.0, + speed: float = 1.0, + pitch: float = 1.0, rate: float = 1.0 ): super().__init__() @@ -137,9 +137,9 @@ class Timescale(Filter): @classmethod def vaporwave(cls): - """Timescale preset which slows down the currently playing track, + """Timescale preset which slows down the currently playing track, giving it the effect of a half-speed record/casette playing. - + This preset will assign the tag 'vaporwave'. """ @@ -149,11 +149,11 @@ class Timescale(Filter): def nightcore(cls): """Timescale preset which speeds up the currently playing track, which matches up to nightcore, a genre of sped-up music - + This preset will assign the tag 'nightcore'. """ - return cls(tag="nightcore", speed=1.25, pitch=1.3) + return cls(tag="nightcore", speed=1.25, pitch=1.3) def __repr__(self): return f"" @@ -199,10 +199,10 @@ class Tremolo(Filter): """ def __init__( - self, - *, + self, + *, tag: str, - frequency: float = 2.0, + frequency: float = 2.0, depth: float = 0.5 ): super().__init__() @@ -231,10 +231,10 @@ class Vibrato(Filter): """ def __init__( - self, - *, + self, + *, tag: str, - frequency: float = 2.0, + frequency: float = 2.0, depth: float = 0.5 ): @@ -252,7 +252,7 @@ class Vibrato(Filter): self.payload = {"vibrato": {"frequency": self.frequency, "depth": self.depth}} - + def __repr__(self): return f"" @@ -308,22 +308,22 @@ class ChannelMix(Filter): self.right_to_right = right_to_right self.tag = tag - self.payload = {"channelMix": {"leftToLeft": self.left_to_left, - "leftToRight": self.left_to_right, - "rightToLeft": self.right_to_left, + 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 ( + return ( f"" + f"right_to_left={self.right_to_left} right_to_right={self.right_to_right}>" ) class Distortion(Filter): """Filter which generates a distortion effect. Useful for certain filter implementations where - distortion is needed. + distortion is needed. """ def __init__( @@ -374,7 +374,6 @@ 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, *, tag: str, smoothing: float = 20): super().__init__() diff --git a/pomice/player.py b/pomice/player.py index 2ba1248..4543584 100644 --- a/pomice/player.py +++ b/pomice/player.py @@ -21,6 +21,7 @@ from .exceptions import FilterInvalidArgument, FilterTagAlreadyInUse, FilterTagI from .filters import Filter from .objects import Track from .pool import Node, NodePool +from .queue import Queue class Filters: """Helper class for filters""" @@ -54,6 +55,7 @@ class Filters: """Removes all filters from the list""" self._filters = [] + def get_all_payloads(self): """Returns a formatted dict of all the filter payloads""" @@ -373,7 +375,7 @@ class Player(VoiceProtocol): self._volume = volume return self._volume - async def add_filter(self, filter: Filter, fast_apply=False) -> Filter: + async def add_filter(self, filter: Filter, fast_apply: bool = False) -> Filter: """Adds a filter to the player. Takes a pomice.Filter object. This will only work if you are using a version of Lavalink that supports filters. If you would like for the filter to apply instantly, set the `fast_apply` arg to `True`. @@ -389,7 +391,7 @@ class Player(VoiceProtocol): return self._filters - async def remove_filter(self, filter_tag: str, fast_apply=False) -> Filter: + async def remove_filter(self, filter_tag: str, fast_apply: bool = False) -> Filter: """Removes a filter from the player. Takes a filter tag. This will only work if you are using a version of Lavalink that supports filters. If you would like for the filter to apply instantly, set the `fast_apply` arg to `True`. @@ -405,7 +407,7 @@ class Player(VoiceProtocol): return self._filters - async def reset_filters(self, *, fast_apply=False): + async def reset_filters(self, *, fast_apply: bool = False): """Resets all currently applied filters to their default parameters. You must have filters applied in order for this to work. If you would like the filters to be removed instantly, set the `fast_apply` arg to `True`. @@ -419,6 +421,8 @@ class Player(VoiceProtocol): ) self._filters.reset_filters() await self._node.send(op="filters", guildId=str(self.guild.id)) + + if fast_apply: await self.seek(self.position) diff --git a/pomice/queue.py b/pomice/queue.py index 790b2e7..a44a8aa 100644 --- a/pomice/queue.py +++ b/pomice/queue.py @@ -17,6 +17,7 @@ from .exceptions import QueueEmpty, QueueException, QueueFull class Queue(Iterable[Track]): + """Queue for Pomice. This queue takes pomice.Track as an input and includes looping and shuffling.""" def __init__( self, max_size: Optional[int] = None, @@ -24,7 +25,7 @@ class Queue(Iterable[Track]): overflow: bool = True, ): self.max_size: Optional[int] = max_size - self._queue = [] # type: ignore + self._queue: List[Track] = [] # type: ignore self._overflow: bool = overflow self._loop_mode: Optional[LoopMode] = None self._current_item: Optional[Track] = None @@ -331,4 +332,9 @@ class Queue(Iterable[Track]): def shuffle(self): """Shuffles the queue.""" - return random.shuffle(self._queue) \ No newline at end of file + return random.shuffle(self._queue) + + def clear_track_filters(self): + """Clears all filters applied to tracks""" + for track in self._queue: + track.filters = None \ No newline at end of file