Skip to content

Commit

Permalink
More work on fixing controllers for manual mapping feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJAllen committed Jan 11, 2024
1 parent 4672c12 commit e886f73
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,36 +11,35 @@
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));

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<InternalHardwareLightState> supplier) {
public void bindLight(final Layer layer, final Supplier<InternalHardwareLightState> 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, () -> {
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e886f73

Please sign in to comment.