Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nick fix controller light feedback #73

Merged
merged 16 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

9 changes: 0 additions & 9 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

4 changes: 0 additions & 4 deletions .settings/org.eclipse.m2e.core.prefs

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.bitwig.extensions.controllers.akai.apc40_mkii;

import com.bitwig.extension.api.Color;
import com.bitwig.extension.controller.api.HardwareLightVisualState;
import com.bitwig.extension.controller.api.InternalHardwareLightState;
import com.bitwig.extension.controller.api.Track;

class CrossFadeMode extends InternalHardwareLightState
{
public static final CrossFadeMode A = new CrossFadeMode("A", 0, 1);

public static final CrossFadeMode B = new CrossFadeMode("B", 1, 2);

public static final CrossFadeMode AB = new CrossFadeMode("AB", 2, 0);

public static CrossFadeMode getBestModeForColor(final Color color)
{
if (color == null || color.getAlpha() == 0
|| color.getRed() == 0 && color.getGreen() == 0 && color.getBlue() == 0)
return AB;

if (B_COLOR.equals(color))
return B;

return A;
}

public static CrossFadeMode forEnumName(final String name)
{
if (name.equals(A.mEnumName))
return A;
if (name.equals(B.mEnumName))
return B;
return AB;
}

public static CrossFadeMode forTrack(final Track track)
{
return forEnumName(track.crossFadeMode().get());
}

private static CrossFadeMode forIndex(final int index)
{
final CrossFadeMode mode = switch (index)
{
case 0 -> A;
case 1 -> B;
default -> AB;
};

assert mode.getIndex() == index;

return mode;
}

private CrossFadeMode(final String enumName, final int index, final int colorIndex)
{
mEnumName = enumName;
mIndex = index;
mColorIndex = colorIndex;
}

public int getIndex()
{
return mIndex;
}

/** The color value we need to send to the hardware */
public int getColorIndex()
{
return mColorIndex;
}

public CrossFadeMode getNext()
{
final int index = (mColorIndex + 1) % 3;

return forIndex(index);
}

public String getEnumName()
{
return mEnumName;
}

@Override
public HardwareLightVisualState getVisualState()
{
if (this == AB)
return null;

if (this == A)
return A_VISUAL_STATE;

return B_VISUAL_STATE;
}

@Override
public boolean equals(final Object obj)
{
return this == obj;
}

private final String mEnumName;

private final int mColorIndex, mIndex;

private static final Color A_COLOR = Color.fromRGB(1, 0.64, 0);

private static final Color B_COLOR = Color.fromRGB(0, 0, 1);

private static final HardwareLightVisualState A_VISUAL_STATE = HardwareLightVisualState
.createForColor(A_COLOR);

private static final HardwareLightVisualState B_VISUAL_STATE = HardwareLightVisualState
.createForColor(B_COLOR);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RGBLedState extends InternalHardwareLightState

private static final Map<Integer, Color> COLOR_VALUE_TO_COLOR_MAP = new HashMap<>();

public static final RGBLedState OFF_STATE = new RGBLedState(COLOR_NONE, COLOR_NONE, BLINK_NONE);

private static void registerColor(final int rgb, final int value)
{
COLOR_VALUE_TO_COLOR_MAP.put(value,
Expand Down Expand Up @@ -110,11 +112,39 @@ public static int getColorValueForRGB(final int rgb)
return 13;
}

public static int getColorValueForRGB(final double red, final double green, final double blue)
{
final int r8 = (int)(red * 255);
final int g8 = (int)(green * 255);
final int b8 = (int)(blue * 255);
final int total = (r8 << 16) | (g8 << 8) | b8;

return getColorValueForRGB(total);
}

public static int getColorValueForColor(final Color color)
{
if (color == null || color.getAlpha() == 0)
return getColorValueForRGB(0);

return getColorValueForRGB(color.getRed(), color.getGreen(), color.getBlue());
}

public static Color getColorForColorValue(final int colorValue)
{
return COLOR_VALUE_TO_COLOR_MAP.get(colorValue);
}

public static RGBLedState getBestStateForColor(final Color color)
{
if (color == null || color.getAlpha() == 0)
return OFF_STATE;

final int colorValue = getColorValueForColor(color);

return new RGBLedState(colorValue, COLOR_NONE, BLINK_NONE);
}

public RGBLedState(final int color, final int blinkColor, final int blinkType)
{
super();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bitwig.extensions.controllers.akai.apc40_mkii;

import com.bitwig.extension.controller.api.ColorValue;
import com.bitwig.extension.controller.api.HardwareButton;
import com.bitwig.extension.controller.api.HardwareSurface;
import com.bitwig.extension.controller.api.MidiOut;
Expand All @@ -14,86 +13,53 @@ protected RgbLed(
final HardwareButton button,
final HardwareSurface surface,
final int message,
final int data1)
final int data1,
final MidiOut midiOut)
{
super();
mMessage = message;
mData1 = data1;

MultiStateHardwareLight hardwareLight = surface.createMultiStateHardwareLight(button.getId() + "-light");
final MultiStateHardwareLight hardwareLight = surface.createMultiStateHardwareLight(button.getId() + "-light");
hardwareLight.state().setValueSupplier(this::getState);
hardwareLight.setColorToStateFunction(RGBLedState::getBestStateForColor);
hardwareLight.state().onUpdateHardware(state -> sendLightState(midiOut, (RGBLedState)state));
button.setBackgroundLight(hardwareLight);
}

public void paint(final MidiOut midiOut)
private void sendLightState(final MidiOut midiOut, RGBLedState state)
{
if (mColor != mDisplayedColor || mBlinkColor != mDisplayedBlinkColor
|| mBlinkType != mDisplayedBlinkType)
if (state == null)
state = RGBLedState.OFF_STATE;

final var color = state.getColor();
final var blinkColor = state.getBlinkColor();
final var blinkType = state.getBlinkType();

midiOut.sendMidi(mMessage << 4, mData1, color);

if (blinkType != RGBLedState.BLINK_NONE)
{
midiOut.sendMidi(mMessage << 4, mData1, mColor);

if (mBlinkType != RGBLedState.BLINK_NONE)
{
midiOut.sendMidi(mMessage << 4, mData1, mBlinkColor);
midiOut.sendMidi((mMessage << 4) | mBlinkType, mData1, mColor);
}
else
{
midiOut.sendMidi(mMessage << 4, mData1, mColor);
}

mDisplayedColor = mColor;
mDisplayedBlinkColor = mBlinkColor;
mDisplayedBlinkType = mBlinkType;
midiOut.sendMidi(mMessage << 4, mData1, blinkColor);
midiOut.sendMidi((mMessage << 4) | blinkType, mData1, color);
}
else
{
midiOut.sendMidi(mMessage << 4, mData1, color);
}
}

public void setColor(final float red, final float green, final float blue)
{
final int r8 = (int)(red * 255);
final int g8 = (int)(green * 255);
final int b8 = (int)(blue * 255);
final int total = (r8 << 16) | (g8 << 8) | b8;

mColor = RGBLedState.getColorValueForRGB(total);
}

public void setColor(final int color)
{
mColor = color;
}

public void setColor(final ColorValue color)
{
setColor(color.red(), color.green(), color.blue());
}

public void setBlinkType(final int blinkType)
{
mBlinkType = blinkType;
}

public void setBlinkColor(final int blinkColor)
public RGBLedState getState()
{
mBlinkColor = blinkColor;
return mState;
}

public RGBLedState getState()
public void setState(final RGBLedState state)
{
return new RGBLedState(mDisplayedColor, mDisplayedBlinkColor, mDisplayedBlinkType);
mState = state;
}

private final int mMessage, mData1;

private int mColor = RGBLedState.COLOR_NONE;

private int mDisplayedColor = -1;

private int mBlinkColor = RGBLedState.COLOR_NONE;

private int mDisplayedBlinkColor = -1;

private int mBlinkType = RGBLedState.BLINK_NONE;

private int mDisplayedBlinkType = -1;
private RGBLedState mState;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.bitwig.extensions.controllers.akai.apcmk2.control;

import com.bitwig.extension.controller.api.*;
import java.util.function.Function;
import java.util.function.Supplier;

import com.bitwig.extension.controller.api.HardwareActionBindable;
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.extensions.controllers.akai.apcmk2.led.RgbLightState;
import com.bitwig.extensions.controllers.akai.apcmk2.midi.MidiProcessor;
import com.bitwig.extensions.framework.Layer;
import com.bitwig.extensions.framework.time.TimeRepeatEvent;
import com.bitwig.extensions.framework.time.TimedEvent;

import java.util.function.Function;
import java.util.function.Supplier;

public abstract class ApcButton {
public static final int STD_REPEAT_DELAY = 400;
public static final int STD_REPEAT_FREQUENCY = 50;
Expand All @@ -21,7 +26,7 @@ public abstract class ApcButton {
private long recordedDownTime;
protected final int midiId;

protected ApcButton(final int channel, final int midiId, String name, HardwareSurface surface,
protected ApcButton(final int channel, final int midiId, final String name, final HardwareSurface surface,
final MidiProcessor midiProcessor) {
this.midiProcessor = midiProcessor;
final MidiIn midiIn = midiProcessor.getMidiIn();
Expand All @@ -30,7 +35,9 @@ protected ApcButton(final int channel, final int midiId, String name, HardwareSu
hwButton.pressedAction().setPressureActionMatcher(midiIn.createNoteOnVelocityValueMatcher(channel, midiId));
hwButton.releasedAction().setActionMatcher(midiIn.createNoteOffActionMatcher(channel, midiId));
light = surface.createMultiStateHardwareLight(name + "_LIGHT_" + midiId);
hwButton.setBackgroundLight(light);
light.state().setValue(RgbLightState.OFF);
light.setColorToStateFunction(RgbLightState::forColor);
hwButton.isPressed().markInterested();
}

Expand Down
Loading
Loading