Skip to content

Commit

Permalink
Update mute solo strategy to be way simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Jul 30, 2023
1 parent 127309f commit 9aa47fe
Showing 1 changed file with 24 additions and 48 deletions.
72 changes: 24 additions & 48 deletions src/plugs/mapping_strategies/mute_solo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"""

from typing import Callable, Any
from common.tracks import AbstractTrack
from common.types import Color
from common.plug_indexes.fl_index import UnsafeIndex
from common.plug_indexes.fl_index import FlIndex
from control_surfaces import (
ControlShadowEvent,
ControlShadow,
Expand Down Expand Up @@ -51,12 +52,7 @@ class MuteSoloStrategy(IMappingStrategy):
"""
def __init__(
self,
selected_callback: Callable[[int], int],
mute_callback: Callable[[int], None],
is_mute_callback: Callable[[int], bool],
solo_callback: Callable[[int], None],
is_solo_callback: Callable[[int], bool],
color_callback: Callable[[int], int],
selected_callback: Callable[[int], AbstractTrack],
) -> None:
"""
Create a MuteSoloStrategy
Expand All @@ -66,31 +62,11 @@ def __init__(
events from the controls and color the controls.
### Args:
* `selected_callback` (`Callable[[int], int]`): given an int n, returns
the nth selected track index. Note that if there aren't enough
* `selected_callback` (`Callable[[int], AbstractTrack]`): given an int
n, returns the nth selected track. Note that if there aren't enough
tracks, an IndexError should be raised.
* `mute_callback` (`Callable[[int], None]`): toggles whether the track
at the given index is muted.
* `is_mute_callback` (`Callable[[int], bool]`): returns whether the
track at the given index is muted.
* `solo_callback` (`Callable[[int], None]`): toggles whether the track
at the given index is solo.
* `is_solo_callback` (`Callable[[int], bool]`): returns whether the
track at the given index is solo.
* `color_callback` (`Callable[[int], int]`): returns the color of the
track at the given index.
"""
self.selected = selected_callback
self.mute = mute_callback
self.is_mute = is_mute_callback
self.solo = solo_callback
self.is_solo = is_solo_callback
self.color = color_callback

def apply(self, shadow: DeviceShadow) -> None:
self._buttons = shadow.bindMatches(
Expand All @@ -116,24 +92,24 @@ def apply(self, shadow: DeviceShadow) -> None:
def eGeneric(
self,
control: ControlShadowEvent,
index: UnsafeIndex,
index: FlIndex,
number: int,
*args: Any,
) -> bool:
try:
track = self.selected(number)
except IndexError:
return True
if control.double or self.is_solo(track):
self.solo(track)
if control.double or track.solo:
track.soloToggle()
else:
self.mute(track)
track.muteToggle()
return True

def tGeneric(
self,
control: ControlShadow,
index: UnsafeIndex,
index: FlIndex,
number: int,
*args: Any,
):
Expand All @@ -143,31 +119,31 @@ def tGeneric(
# Out of range tracks should be disabled
control.color = Color()
return
if self.is_mute(track):
if track.mute:
control.color = COLOR_DISABLED
else:
control.color = Color.fromInteger(self.color(track), enabled=True)
control.color = track.color
return True

@filterButtonLift()
def eMute(
self,
control: ControlShadowEvent,
index: UnsafeIndex,
index: FlIndex,
number: int,
*args: Any,
) -> bool:
try:
track = self.selected(number)
except IndexError:
return True
self.mute(track)
track.muteToggle()
return True

def tMute(
self,
control: ControlShadow,
index: UnsafeIndex,
index: FlIndex,
number: int,
*args: Any,
):
Expand All @@ -177,8 +153,8 @@ def tMute(
# Out of range tracks should be disabled
control.color = Color()
return
if self.is_mute(track):
control.color = Color.fromInteger(self.color(track), enabled=True)
if track.mute:
control.color = track.color
else:
control.color = COLOR_DISABLED
return True
Expand All @@ -187,24 +163,24 @@ def tMute(
def eSolo(
self,
control: ControlShadowEvent,
index: UnsafeIndex,
index: FlIndex,
number: int,
*args: Any,
) -> bool:
try:
track = self.selected(number)
except IndexError:
return True
if self.is_mute(track):
self.mute(track)
if track.mute:
track.muteToggle()
else:
self.solo(track)
track.soloToggle()
return True

def tSolo(
self,
control: ControlShadow,
index: UnsafeIndex,
index: FlIndex,
number: int,
*args: Any,
):
Expand All @@ -214,8 +190,8 @@ def tSolo(
# Out of range tracks should be disabled
control.color = Color()
return
if self.is_mute(track):
if track.mute:
control.color = COLOR_DISABLED
else:
control.color = Color.fromInteger(self.color(track), enabled=True)
control.color = track.color
return True

0 comments on commit 9aa47fe

Please sign in to comment.