Skip to content

Commit

Permalink
Refactor grid strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Jul 30, 2023
1 parent ffd9ddc commit 7f9f201
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
21 changes: 12 additions & 9 deletions src/plugs/mapping_strategies/cc_forward_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
This code is licensed under the GPL v3 license. Refer to the LICENSE file for
more details.
"""
import plugins
from common.consts import PARAM_CC_START
from common.param import Param
from . import IMappingStrategy
from devices import DeviceShadow
from plugs.event_filters import filterButtonLift
from common.types import Color
from common.util.api_fixes import isPluginVst
from common.plug_indexes import PluginIndex

from control_surfaces import (
ControlShadowEvent,
Expand Down Expand Up @@ -52,11 +52,14 @@ def apply(self, shadow: DeviceShadow) -> None:
shadow.bindMatches(Encoder, self.process)

@filterButtonLift()
def process(self, control: ControlShadowEvent, index, *args, **kwargs):
if isPluginVst(index):
plugins.setParamValue(
control.value,
PARAM_CC_START + control.midi.data1,
*index,
)
def process(
self,
control: ControlShadowEvent,
index: PluginIndex,
*args,
**kwargs,
):
if index.isVst():
param = Param(PARAM_CC_START + control.midi.data1)
param(index).value = control.value
return False
40 changes: 18 additions & 22 deletions src/plugs/mapping_strategies/grid_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
This code is licensed under the GPL v3 license. Refer to the LICENSE file for
more details.
"""
import mixer
import channels
import itertools
from typing import Callable, Optional, Any

from common.plug_indexes import FlIndex, WindowIndex, PluginIndex
from . import IMappingStrategy
from common.plug_indexes.fl_index import UnsafeIndex
from devices import DeviceShadow
from common.types import Color
from common.util.grid_mapper import GridCell, GridLayout, grid_map
Expand All @@ -25,9 +24,9 @@
ControlShadowEvent,
)

TriggerCallback = Callable[[ControlShadowEvent, UnsafeIndex, GridCell], bool]
ColorCallback = Callable[[ControlShadow, UnsafeIndex, GridCell], Color]
AnnotationCallback = Callable[[ControlShadow, UnsafeIndex, GridCell], str]
TriggerCallback = Callable[[ControlShadowEvent, FlIndex, GridCell], bool]
ColorCallback = Callable[[ControlShadow, FlIndex, GridCell], Color]
AnnotationCallback = Callable[[ControlShadow, FlIndex, GridCell], str]


class color_callbacks:
Expand All @@ -38,7 +37,7 @@ class color_callbacks:
@staticmethod
def white(
control: ControlShadow,
plug_index: UnsafeIndex,
plug_index: FlIndex,
index: GridCell,
) -> Color:
"""
Expand All @@ -49,7 +48,7 @@ def white(
@staticmethod
def channelColor(
control: ControlShadow,
plug_index: UnsafeIndex,
plug_index: FlIndex,
index: GridCell,
) -> Color:
"""
Expand All @@ -59,26 +58,23 @@ def channelColor(
"""

# FL Studio windows should use white
if isinstance(plug_index, int) or plug_index is None:
if isinstance(plug_index, WindowIndex):
return Color.fromGrayscale(0.3)

# Effect plugins use the color of their mixer track
if len(plug_index) == 2:
return Color.fromInteger(mixer.getTrackColor(plug_index[0]))

# Channel plugins use their color
return Color.fromInteger(channels.getChannelColor(*plug_index))
# It's a plugin
assert isinstance(plug_index, PluginIndex)
return plug_index.track.color


class annotation_callbacks:
"""
A collection of simple callbacks for generating colors that can be used to
color drum pads
A collection of simple callbacks for generating annotations that can be
used to describe drum pads
"""
@staticmethod
def empty(
control: ControlShadow,
plug_index: UnsafeIndex,
plug_index: FlIndex,
index: GridCell,
) -> str:
"""
Expand Down Expand Up @@ -175,7 +171,7 @@ def __init__(
data from this event can be used to determine the value and
coordinate of the drum pad.
* `UnsafeIndex`: the index of the plugin or window associated
* `FlIndex`: the index of the plugin or window associated
with this strategy.
* `color_callback` (`ColorCallback`, optional): the callback
Expand All @@ -191,7 +187,7 @@ def __init__(
index. The data from this can be used to determine the value
and coordinate of the drum pad if required.
* `UnsafeIndex`: the index of the plugin or window associated
* `FlIndex`: the index of the plugin or window associated
with this strategy.
* `annotation_callback` (`Callable[[int], str]`, optional): the
Expand Down Expand Up @@ -297,7 +293,7 @@ def apply(self, shadow: DeviceShadow) -> None:
def processTrigger(
self,
control: ControlShadowEvent,
plug: UnsafeIndex,
plug: FlIndex,
*args: Any
) -> bool:
assert self.__mappings is not None
Expand All @@ -314,7 +310,7 @@ def processTrigger(
def tick(
self,
control: ControlShadow,
plug: UnsafeIndex,
plug: FlIndex,
*args: Any
):
assert self.__mappings is not None
Expand Down

0 comments on commit 7f9f201

Please sign in to comment.