Skip to content

Commit

Permalink
Implement new interface method
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwig-thomas committed Jun 19, 2024
1 parent 1d4cc25 commit 9e8709e
Showing 1 changed file with 62 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.bitwig.extension.callback.IntegerValueChangedCallback;
import com.bitwig.extension.controller.api.AbsoluteHardwareControl;
import com.bitwig.extension.controller.api.AbsoluteHardwareControlBinding;
import com.bitwig.extension.controller.api.DoubleValue;
import com.bitwig.extension.controller.api.HardwareSlider;
import com.bitwig.extension.controller.api.Parameter;
import com.bitwig.extension.controller.api.RelativeHardwareControl;
Expand All @@ -27,15 +28,15 @@
import com.bitwig.extensions.controllers.mackie.value.ModifierValueObject;

public class ParameterPage implements SettableRangedValue {

private static final int RING_RANGE = 10;
private DeviceParameter currentParameter;

private ResetableRelativeValueBinding relativeEncoderBinding;
private ResetableAbsoluteValueBinding absoluteEncoderBinding;
private RingParameterBankDisplayBinding ringBinding;
private FaderParameterBankBinding faderBinding;

// listeners for the parameter Name
private final List<Consumer<String>> nameChangeCallbacks = new ArrayList<>();
// listeners for the display values
Expand All @@ -44,16 +45,16 @@ public class ParameterPage implements SettableRangedValue {
private final List<IntConsumer> intValueCallbacks = new ArrayList<>();
// listeners for existence of value
private final List<DoubleConsumer> doulbeValueCallbacks = new ArrayList<>();

private final List<DeviceParameter> pages = new ArrayList<>();

public ParameterPage(final int index, final SpecificDevice device) {

for (int page = 0; page < device.getPages(); page++) {
final int pIndex = pages.size();
final DeviceParameter deviceParameter = device.createDeviceParameter(page, index);
final Parameter param = deviceParameter.parameter;

param.value().markInterested();
param.value().addValueObserver(v -> {
if (pIndex == device.getCurrentPage()) {
Expand All @@ -76,17 +77,17 @@ public ParameterPage(final int index, final SpecificDevice device) {
}
});
}

pages.add(deviceParameter);
}
currentParameter = pages.get(device.getCurrentPage());
}

public Parameter getParameter(final int pageIndex) {
assert pageIndex < pages.size();
return pages.get(pageIndex).parameter;
}

public void triggerUpdate() {
if (ringBinding != null) {
ringBinding.update();
Expand All @@ -95,32 +96,32 @@ public void triggerUpdate() {
faderBinding.update();
}
}

public RingParameterBankDisplayBinding createRingBinding(final RingDisplay display) {
ringBinding = new RingParameterBankDisplayBinding(this, display);
return ringBinding;
}

public FaderParameterBankBinding createFaderBinding(final FaderResponse fader) {
faderBinding = new FaderParameterBankBinding(this, fader);
return faderBinding;
}

public ResetableRelativeValueBinding getRelativeEncoderBinding(final RelativeHardwareKnob encoder) {
relativeEncoderBinding = new ResetableRelativeValueBinding(encoder, this);
return relativeEncoderBinding;
}

public ResetableAbsoluteValueBinding getFaderBinding(final HardwareSlider fader) {
absoluteEncoderBinding = new ResetableAbsoluteValueBinding(fader, this);
return absoluteEncoderBinding;
}

public void updatePage(final int currentPage) {
currentParameter = pages.get(currentPage);
resetBindings();
}

public void resetBindings() {
if (relativeEncoderBinding != null) {
relativeEncoderBinding.reset();
Expand All @@ -131,187 +132,192 @@ public void resetBindings() {
notifyValueChanged(getCurrentValue());
notifyNameChanged(getCurrentName());
}

public Parameter getCurrentParameter() {
return currentParameter.parameter;
}

@Override
public double get() {
return currentParameter.parameter.get();
}

@Override
public void markInterested() {
currentParameter.parameter.markInterested();
}

public void addStringValueObserver(final Consumer<String> callback) {
valueChangeCallbacks.add(callback);
}

@Override
public void addValueObserver(final DoubleValueChangedCallback callback) {
}

@Override
public boolean isSubscribed() {
return currentParameter.parameter.isSubscribed();
}

@Override
public void setIsSubscribed(final boolean value) {
}

@Override
public void subscribe() {
currentParameter.parameter.subscribe();
}

@Override
public void unsubscribe() {
currentParameter.parameter.unsubscribe();
}

@Override
public void set(final double value) {
currentParameter.parameter.set(value);
}

@Override
public void inc(final double amount) {
currentParameter.parameter.inc(amount);
}

@Override
public double getRaw() {
return currentParameter.parameter.getRaw();
}


@Override
public DoubleValue getOrigin() {
return currentParameter.parameter.getOrigin();
}

@Override
public StringValue displayedValue() {
return currentParameter.parameter.displayedValue();
}

@Override
public void addValueObserver(final int range, final IntegerValueChangedCallback callback) {
// Not needed
}

@Override
public void addRawValueObserver(final DoubleValueChangedCallback callback) {
// Not needed
}

@Override
public void setImmediately(final double value) {
currentParameter.parameter.setImmediately(value);
}

@Override
public void set(final Number value, final Number resolution) {
currentParameter.parameter.set(value, resolution);
}

@Override
public void inc(final Number increment, final Number resolution) {
currentParameter.parameter.inc(increment, resolution);
}

@Override
public void setRaw(final double value) {
currentParameter.parameter.setRaw(value);
}

@Override
public void incRaw(final double delta) {
currentParameter.parameter.incRaw(delta);
}

@Override
public AbsoluteHardwareControlBinding addBindingWithRange(final AbsoluteHardwareControl hardwareControl,
final double minNormalizedValue, final double maxNormalizedValue) {
return currentParameter.parameter.addBindingWithRange(hardwareControl, minNormalizedValue, maxNormalizedValue);
}

@Override
public RelativeHardwareControlToRangedValueBinding addBindingWithRangeAndSensitivity(
final RelativeHardwareControl hardwareControl, final double minNormalizedValue, final double maxNormalizedValue,
final double sensitivity) {
return currentParameter.parameter.addBindingWithRangeAndSensitivity(hardwareControl, minNormalizedValue,
maxNormalizedValue, currentParameter.getSensitivity());
}

private void notifyValueChanged(final String value) {
valueChangeCallbacks.forEach(callback -> callback.accept(value));
}

public String getCurrentValue() {
return currentParameter.getStringValue();
}

public void addNameObserver(final Consumer<String> callback) {
nameChangeCallbacks.add(callback);
}

private void notifyNameChanged(final String name) {
nameChangeCallbacks.forEach(callback -> callback.accept(currentParameter.getName()));
}

public String getCurrentName() {
return currentParameter.getName();
}

public void addIntValueObserver(final IntConsumer listener) {
intValueCallbacks.add(listener);
}

private void notifyIntValueChanged(final int value) {
intValueCallbacks.forEach(callback -> callback.accept(value));
}

private void notifyValueChanged(final double value) {
doulbeValueCallbacks.forEach(callback -> callback.accept(value));
}

public int getIntValue() {
return (int) (currentParameter.parameter.value().get() * RING_RANGE);
}

public RingDisplayType getRingDisplayType() {
return currentParameter.getRingDisplayType();
}

public double getParamValue() {
return currentParameter.parameter.value().get();
}

// @Override
// public DoubleValue getOrigin()
// {
// return currentParameter.parameter.getOrigin();
// }

public void addDoubleValueObserver(final DoubleConsumer listener) {
doulbeValueCallbacks.add(listener);
}

public void doReset() {
currentParameter.parameter.reset();
}

public void resetAll() {
for (final DeviceParameter parameter : pages) {
parameter.doReset();
}
}

public void notifyEnablement(final int value) {
ringBinding.handleEnabled(value);
}

public void doReset(final ModifierValueObject modifier) {
currentParameter.parameter.reset();
}

}

0 comments on commit 9e8709e

Please sign in to comment.