Skip to content

Commit

Permalink
Refactor drum pads to use new indexing system
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Jul 30, 2023
1 parent e92a1e1 commit 79606f4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
8 changes: 5 additions & 3 deletions src/plugs/windows/channel_rack/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import channels

from common.context_manager import getContext
from common.plug_indexes import WindowIndex
from common.tracks import Channel
from control_surfaces import ControlShadow, DrumPad

INDEX = 1
INDEX = WindowIndex.CHANNEL_RACK


def getNumDrumCols() -> int:
Expand All @@ -38,7 +40,7 @@ def coordToIndex(control: ControlShadow) -> int:
return index


def getChannelRows() -> list[int]:
def getChannelRows() -> list[Channel]:
"""
Returns the rows which should be used by the channel rack, when using the
drum pad as a step sequencer
Expand All @@ -59,7 +61,7 @@ def getChannelRows() -> list[int]:
s = channels.selectedChannel(False)
ret = []
for i in range(s, channels.channelCount(False)):
ret.append(i)
ret.append(Channel(i))
return ret[:num_cols]

# s = getSelectedChannels(global_mode=False)
Expand Down
11 changes: 5 additions & 6 deletions src/plugs/windows/channel_rack/omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

from typing import Any
import channels
from common.plug_indexes import WindowIndex
from common.types.color import Color
from common.plug_indexes.fl_index import UnsafeIndex
from common.plug_indexes import FlIndex
from control_surfaces import ControlShadowEvent
from control_surfaces import (
DrumPad,
)
from control_surfaces import DrumPad
from devices import DeviceShadow
from plugs import WindowPlugin
from .helpers import coordToIndex, INDEX
Expand All @@ -34,7 +33,7 @@ def __init__(self, shadow: DeviceShadow) -> None:
super().__init__(shadow, [])

@classmethod
def getWindowId(cls) -> int:
def getWindowId(cls) -> WindowIndex:
return INDEX

@classmethod
Expand All @@ -44,7 +43,7 @@ def create(cls, shadow: DeviceShadow) -> 'WindowPlugin':
def drumPads(
self,
control: ControlShadowEvent,
idx: UnsafeIndex,
window_index: FlIndex,
*args: Any
) -> bool:
"""Bind drum pads to omni preview"""
Expand Down
13 changes: 3 additions & 10 deletions src/plugs/windows/channel_rack/plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
This code is licensed under the GPL v3 license. Refer to the LICENSE file for
more details.
"""
import channels
from common.extension_manager import ExtensionManager
from common.plug_indexes import WindowIndex
from common.types import Color
from devices import DeviceShadow
from plugs import WindowPlugin, PluginPager
Expand All @@ -29,18 +29,11 @@ def __init__(self, shadow: DeviceShadow) -> None:
PluginPager.__init__(self, shadow)
self.addPage(StepSequencer(shadow.copy()), Color.fromRgb(0, 127, 255))
self.addPage(OmniPreview(shadow.copy()), Color.fromRgb(127, 0, 255))
mute_solo = MuteSoloStrategy(
lambda i: getChannelRows()[i],
channels.muteChannel,
channels.isChannelMuted,
channels.soloChannel,
channels.isChannelSolo,
channels.getChannelColor,
)
mute_solo = MuteSoloStrategy(lambda i: getChannelRows()[i])
WindowPlugin.__init__(self, shadow, [mute_solo])

@classmethod
def getWindowId(cls) -> int:
def getWindowId(cls) -> WindowIndex:
return INDEX

@classmethod
Expand Down
14 changes: 7 additions & 7 deletions src/plugs/windows/channel_rack/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import channels
import ui
from common.types.color import Color
from common.plug_indexes.fl_index import UnsafeIndex
from common.plug_indexes import FlIndex, WindowIndex
from common.util.grid_mapper import GridCell
from control_surfaces import ControlShadowEvent
from control_surfaces import (
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, shadow: DeviceShadow) -> None:
super().__init__(shadow, [self._drums])

@classmethod
def getWindowId(cls) -> int:
def getWindowId(cls) -> WindowIndex:
return INDEX

@classmethod
Expand All @@ -74,7 +74,7 @@ def create(cls, shadow: DeviceShadow) -> 'WindowPlugin':
def triggerDrumPad(
self,
control: ControlShadowEvent,
idx: UnsafeIndex,
idx: FlIndex,
cell: GridCell,
) -> bool:
"""
Expand All @@ -84,7 +84,7 @@ def triggerDrumPad(
# TODO: Later use them to implement graph editor features
if not control.value:
return False
channel = cell.group_number + getChannelRows()[0]
channel = cell.group_number + getChannelRows()[0].index
index = cell.group_index + self._scroll * SCROLL_MULTIPLIER

val = channels.getGridBit(channel, index)
Expand All @@ -94,13 +94,13 @@ def triggerDrumPad(
def colorDrumPad(
self,
control: ControlShadow,
idx: UnsafeIndex,
idx: FlIndex,
cell: GridCell,
) -> Color:
"""
Determine color for drum pads
"""
channel = cell.group_number + getChannelRows()[0]
channel = cell.group_number + getChannelRows()[0].index
index = cell.group_index + self._scroll * SCROLL_MULTIPLIER

on_color = Color.fromGrayscale(1)
Expand All @@ -119,7 +119,7 @@ def showGrid(self) -> None:
col = self._scroll * SCROLL_MULTIPLIER

# FIXME: This might get an index error on controllers with no drum pads
row = getChannelRows()[0]
row = getChannelRows()[0].index

width = self._drums.get_group_size()
height = self._drums.get_num_groups_mapped()
Expand Down

0 comments on commit 79606f4

Please sign in to comment.