From e886f7365d642f24bcea52b2382fb9336e12a7e0 Mon Sep 17 00:00:00 2001 From: Nicholas Allen Date: Thu, 11 Jan 2024 12:44:41 +0100 Subject: [PATCH] More work on fixing controllers for manual mapping feedback --- .../maschinemikro/buttons/RgbButton.java | 17 ++++++++-------- .../novation/commonsmk3/LaunchPadButton.java | 20 +++++++++++++------ .../novation/commonsmk3/RgbState.java | 15 +++++++++++--- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/maschinemikro/buttons/RgbButton.java b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/maschinemikro/buttons/RgbButton.java index 51429d6d..78856a2c 100644 --- a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/maschinemikro/buttons/RgbButton.java +++ b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/maschinemikro/buttons/RgbButton.java @@ -1,5 +1,7 @@ package com.bitwig.extensions.controllers.nativeinstruments.maschinemikro.buttons; +import java.util.function.Supplier; + import com.bitwig.extension.controller.api.HardwareSurface; import com.bitwig.extension.controller.api.InternalHardwareLightState; import com.bitwig.extension.controller.api.MidiIn; @@ -9,14 +11,12 @@ import com.bitwig.extensions.controllers.nativeinstruments.maschinemikro.RgbColor; import com.bitwig.extensions.framework.Layer; -import java.util.function.Supplier; - public class RgbButton extends GateButton { private final MultiStateHardwareLight light; - public RgbButton(final int midiId, String name, HardwareSurface surface, MidiProcessor midiProcessor) { + public RgbButton(final int midiId, final String name, final HardwareSurface surface, final MidiProcessor midiProcessor) { super(midiId, midiProcessor); - MidiIn midiIn = midiProcessor.getMidiIn(); + final MidiIn midiIn = midiProcessor.getMidiIn(); hwButton = surface.createHardwareButton(name + "_" + midiId); hwButton.pressedAction().setPressureActionMatcher(midiIn.createNoteOnVelocityValueMatcher(0, midiId)); hwButton.releasedAction().setActionMatcher(midiIn.createNoteOffActionMatcher(0, midiId)); @@ -24,21 +24,22 @@ public RgbButton(final int midiId, String name, HardwareSurface surface, MidiPro hwButton.isPressed().markInterested(); light = surface.createMultiStateHardwareLight(name + "_LIGHT_" + midiId); light.state().setValue(RgbLightState.OFF); + light.setColorToStateFunction(RgbLightState::forColor); hwButton.isPressed().markInterested(); light.state().onUpdateHardware(this::updateState); } - private void updateState(InternalHardwareLightState state) { - if (state instanceof RgbColor rgbState) { + private void updateState(final InternalHardwareLightState state) { + if (state instanceof final RgbColor rgbState) { midiProcessor.updateColorPad(midiId, rgbState); } } - public void bindLight(Layer layer, final Supplier supplier) { + public void bindLight(final Layer layer, final Supplier supplier) { layer.bindLightState(supplier, this.light); } - public void bindDisabled(Layer layer) { + public void bindDisabled(final Layer layer) { this.bindLight(layer, () -> RgbColor.OFF); this.bindRelease(layer, () -> { }); diff --git a/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/LaunchPadButton.java b/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/LaunchPadButton.java index 5f217004..76525ec1 100644 --- a/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/LaunchPadButton.java +++ b/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/LaunchPadButton.java @@ -1,16 +1,22 @@ package com.bitwig.extensions.controllers.novation.commonsmk3; -import com.bitwig.extension.controller.api.*; -import com.bitwig.extensions.framework.Layer; -import com.bitwig.extensions.framework.time.TimeRepeatEvent; -import com.bitwig.extensions.framework.time.TimedDelayEvent; -import com.bitwig.extensions.framework.time.TimedEvent; - import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import com.bitwig.extension.controller.api.BooleanValue; +import com.bitwig.extension.controller.api.HardwareButton; +import com.bitwig.extension.controller.api.HardwareSurface; +import com.bitwig.extension.controller.api.InternalHardwareLightState; +import com.bitwig.extension.controller.api.MidiIn; +import com.bitwig.extension.controller.api.MultiStateHardwareLight; +import com.bitwig.extension.controller.api.SettableBooleanValue; +import com.bitwig.extensions.framework.Layer; +import com.bitwig.extensions.framework.time.TimeRepeatEvent; +import com.bitwig.extensions.framework.time.TimedDelayEvent; +import com.bitwig.extensions.framework.time.TimedEvent; + public abstract class LaunchPadButton { public static final int STD_REPEAT_DELAY = 400; public static final int STD_REPEAT_FREQUENCY = 50; @@ -30,6 +36,8 @@ protected LaunchPadButton(final String id, final HardwareSurface surface, final hwButton = surface.createHardwareButton(id); light = surface.createMultiStateHardwareLight(id + "-light"); light.state().setValue(RgbState.of(0)); + light.setColorToStateFunction(RgbState::forColor); + hwButton.setBackgroundLight(light); hwButton.isPressed().markInterested(); } diff --git a/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/RgbState.java b/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/RgbState.java index ca74a13b..61216bc9 100644 --- a/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/RgbState.java +++ b/src/main/java/com/bitwig/extensions/controllers/novation/commonsmk3/RgbState.java @@ -1,11 +1,12 @@ package com.bitwig.extensions.controllers.novation.commonsmk3; -import com.bitwig.extension.controller.api.HardwareLightVisualState; -import com.bitwig.extension.controller.api.InternalHardwareLightState; - import java.util.HashMap; import java.util.Objects; +import com.bitwig.extension.api.Color; +import com.bitwig.extension.controller.api.HardwareLightVisualState; +import com.bitwig.extension.controller.api.InternalHardwareLightState; + public class RgbState extends InternalHardwareLightState { private static final RgbState[] registry = new RgbState[128]; @@ -36,6 +37,14 @@ public class RgbState extends InternalHardwareLightState { private final int altColorIndex; private LightState state; + public static RgbState forColor(final Color color) { + if (color == null || color.getAlpha() == 0) + return OFF; + + // TODO: Improve this + return WHITE; + } + private RgbState(final int colorIndex, final LightState state) { super(); this.colorIndex = colorIndex;