diff --git a/src/common/tracks/abstract.py b/src/common/tracks/abstract.py index ddc78195..2f315eaa 100644 --- a/src/common/tracks/abstract.py +++ b/src/common/tracks/abstract.py @@ -9,6 +9,13 @@ class AbstractTrack: Allows for their properties to be get/set in a simplified manner """ + @abstractmethod + @property + def index(self) -> int: + """ + Index of the track + """ + @abstractmethod @property def color(self) -> Color: diff --git a/src/common/tracks/channel.py b/src/common/tracks/channel.py index eaaacf13..141e062f 100644 --- a/src/common/tracks/channel.py +++ b/src/common/tracks/channel.py @@ -2,7 +2,7 @@ import channels from .abstract import AbstractTrack -from typing import TypeVar, ParamSpec, Concatenate, Callable, Union +from typing import Optional, TypeVar, ParamSpec, Concatenate, Callable, Union from common.types import Color from common.util.api_fixes import getGroupChannelIndex @@ -83,11 +83,39 @@ class Channel(AbstractTrack): def __init__(self, index: int) -> None: self.__index = index - def triggerNote(self, note_number: int, value: float) -> None: + @property + def index(self) -> int: + """ + Global index of the channel + """ + return self.__index + + @property + def group_index(self) -> Optional[int]: + """ + Index of the channel, respecting groups + """ + return getGroupChannelIndex(self.__index) + + def triggerNote( + self, + note_number: int, + value: float, + channel: Optional[int] = None, + ) -> None: """ Trigger a note on this channel """ - channels.midiNoteOn(self.__index, note_number, int(value * 127)) + if channel is None: + channel = -1 + channels.midiNoteOn( + self.__index, + note_number, + int(value * 127), + # NOTE: Currently FL Studio won't set the note color correctly + # from this channel + channel, + ) @property def color(self) -> Color: diff --git a/src/plugs/mapping_strategies/note_strategy.py b/src/plugs/mapping_strategies/note_strategy.py index 68d36e44..45a7f874 100644 --- a/src/plugs/mapping_strategies/note_strategy.py +++ b/src/plugs/mapping_strategies/note_strategy.py @@ -10,10 +10,8 @@ more details. """ -import channels - from typing import Any -from common.plug_indexes.fl_index import UnsafeIndex +from common.plug_indexes.fl_index import FlIndex from common import getContext from control_surfaces import Note @@ -38,21 +36,13 @@ def apply(self, shadow: DeviceShadow) -> None: def noteCallback( self, control: ControlShadowEvent, - index: UnsafeIndex, + index: FlIndex, *args: Any, **kwargs: Any ) -> bool: - try: - i = channels.getChannelIndex(*getContext().activity.getGenerator()) - except TypeError: - # Index out of range - we're using a plugin from a different group - i = channels.channelNumber() - channels.midiNoteOn( - i, + getContext().activity.getGenerator().track.triggerNote( control.getControl().coordinate[1], - int(control.value*127), - # NOTE: Currently FL Studio won't set the note color correctly - # from this channel - control.channel + control.value, + control.channel, ) return True