From aa1238153c1d2aa97b6134dbda214249ae3efea6 Mon Sep 17 00:00:00 2001 From: ericahrens Date: Wed, 20 May 2026 19:43:36 +0200 Subject: [PATCH] NKS Device handling improved --- .../komplete/KompleteKontrolExtension.java | 65 ++++++++----------- .../nativeinstruments/komplete/NksDevice.java | 53 +++++++++++++++ .../komplete/midi/MidiProcessor.java | 18 ++++- 3 files changed, 97 insertions(+), 39 deletions(-) create mode 100644 src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/NksDevice.java diff --git a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/KompleteKontrolExtension.java b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/KompleteKontrolExtension.java index 4f713658..d5f7ead0 100644 --- a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/KompleteKontrolExtension.java +++ b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/KompleteKontrolExtension.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import com.bitwig.extension.api.Color; @@ -13,6 +14,9 @@ import com.bitwig.extension.controller.api.ControllerHost; import com.bitwig.extension.controller.api.CursorRemoteControlsPage; import com.bitwig.extension.controller.api.CursorTrack; +import com.bitwig.extension.controller.api.Device; +import com.bitwig.extension.controller.api.DeviceBank; +import com.bitwig.extension.controller.api.DeviceMatcher; import com.bitwig.extension.controller.api.DocumentState; import com.bitwig.extension.controller.api.HardwareButton; import com.bitwig.extension.controller.api.HardwareElement; @@ -239,39 +243,6 @@ protected void handle4DShiftPressed(final Track rootTrack, final CursorTrack cur } } - protected void createKompleteKontrolDeviceKompleteKontrol(final PinnableCursorDevice cursorDevice) { - final SpecificPluginDevice kompleteKontrolVst3Id = - cursorDevice.createSpecificVst3Device(KOMPLETE_KONTROL_VST3_ID); - final Parameter kompleteKontrolVst3InstId = kompleteKontrolVst3Id.createParameter(0); - kompleteKontrolVst3InstId.name().addValueObserver(midiProcessor::updateKompleteKontrolInstance); - - final SpecificPluginDevice kompleteKontrolPluginVst2 = - cursorDevice.createSpecificVst2Device(KOMPLETE_KONTROL_DEVICE_ID); - final Parameter kompleteKontrolVst2InstId = kompleteKontrolPluginVst2.createParameter(0); - kompleteKontrolVst2InstId.markInterested(); - kompleteKontrolVst2InstId.name().markInterested(); - kompleteKontrolVst2InstId.exists().markInterested(); - kompleteKontrolVst2InstId.name().addValueObserver(midiProcessor::updateKompleteKontrolInstance); - } - - protected void createKontaktDeviceKompleteKontrol(final PinnableCursorDevice cursorDevice) { - final SpecificPluginDevice kontaktVst3Id = cursorDevice.createSpecificVst3Device(KONTAKT_7_VST3_ID); - final Parameter instId = kontaktVst3Id.createParameter(2048); - instId.name().addValueObserver(midiProcessor::updateKompleteKontrolInstance); - } - - protected void createKontakt8DeviceKompleteKontrol(final PinnableCursorDevice cursorDevice) { - final SpecificPluginDevice kontaktVst3Id = cursorDevice.createSpecificVst3Device(KONTAKT_8_VST3_ID); - final Parameter instId = kontaktVst3Id.createParameter(2048); - instId.name().addValueObserver(midiProcessor::updateKompleteKontrolInstance); - } - - protected void createMaschineDeviceKompleteKontrol(final PinnableCursorDevice cursorDevice) { - final SpecificPluginDevice kontaktVst3Id = cursorDevice.createSpecificVst3Device(MASCHINE_3_VST3_ID); - final Parameter instId = kontaktVst3Id.createParameter(128); - instId.name().addValueObserver(midiProcessor::updateKompleteKontrolInstance); - } - private void changeMode(final int mode) { if (mode == 0) { navigationLayer.activate(); @@ -286,14 +257,18 @@ protected void initTrackBank() { final PinnableCursorDevice cursorDevice = viewControl.getCursorDevice(); final CursorTrack cursorTrack = viewControl.getCursorTrack(); final TrackBank mixerTrackBank = viewControl.getMixerTrackBank(); - createKompleteKontrolDeviceKompleteKontrol(cursorDevice); - createKontaktDeviceKompleteKontrol(cursorDevice); - createKontakt8DeviceKompleteKontrol(cursorDevice); - createMaschineDeviceKompleteKontrol(cursorDevice); if (hasDeviceControl()) { mixerTrackBank.scrollPosition().addValueObserver(this::handleTrackScrollChanged); } + // else { + // for (final NksDevice deviceType : NksDevice.values()) { + // final SpecificPluginDevice specDevice = deviceType.createSpecDevice(cursorDevice); + // final Parameter instId = specDevice.createParameter(deviceType.getParamOffset()); + // instId.name().addValueObserver(midiProcessor::updateKompleteKontrolInstance); + // } + // } + initNksDiscovery(cursorTrack); mainLayer.bindPressed(controlElements.getMuteSelectedButton(), cursorTrack.mute().toggleAction()); mainLayer.bindPressed(controlElements.getSoloSelectedButton(), cursorTrack.solo().toggleAction()); @@ -308,6 +283,22 @@ protected void initTrackBank() { } } + private void initNksDiscovery(final CursorTrack cursorTrack) { + final DeviceBank nksDiscoverBank = cursorTrack.createDeviceBank(1); + final DeviceMatcher matcher = getHost().createOrDeviceMatcher(Arrays.stream(NksDevice.values()) // + .map(type -> type.createMatcher(getHost())) // + .toArray(DeviceMatcher[]::new)); + + nksDiscoverBank.setDeviceMatcher(matcher); + final Device nksDevice = nksDiscoverBank.getDevice(0); + for (final NksDevice deviceType : NksDevice.values()) { + final SpecificPluginDevice specDevice = deviceType.createSpecDevice(nksDevice); + final Parameter instId = specDevice.createParameter(deviceType.getParamOffset()); + instId.name().addValueObserver(name -> midiProcessor.registerNksParam(deviceType, name)); + } + nksDevice.name().addValueObserver(name -> midiProcessor.registerNksDevice(name)); + } + private void handleTrackScrollChanged(final int pos) { midiProcessor.refreshSelectedColor(); } diff --git a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/NksDevice.java b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/NksDevice.java new file mode 100644 index 00000000..1e721dee --- /dev/null +++ b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/NksDevice.java @@ -0,0 +1,53 @@ +package com.bitwig.extensions.controllers.nativeinstruments.komplete; + +import com.bitwig.extension.controller.api.ControllerHost; +import com.bitwig.extension.controller.api.Device; +import com.bitwig.extension.controller.api.DeviceMatcher; +import com.bitwig.extension.controller.api.SpecificPluginDevice; + +public enum NksDevice { + KOMPLETE(KompleteKontrolExtension.KOMPLETE_KONTROL_VST3_ID, 0), + KOMPLETE_VST2(KompleteKontrolExtension.KOMPLETE_KONTROL_DEVICE_ID, 0), + KONTAKT7(KompleteKontrolExtension.KONTAKT_7_VST3_ID, 2048), + KONTAKT8(KompleteKontrolExtension.KONTAKT_8_VST3_ID, 2048), + MASCHINE(KompleteKontrolExtension.MASCHINE_3_VST3_ID, 128); + final String id; + final int paramOffset; + final int vst2id; + + NksDevice(final String id, final int paramOffset) { + this(id, paramOffset, -1); + } + + NksDevice(final int id, final int paramOffset) { + this(null, paramOffset, id); + } + + NksDevice(final String id, final int paramOffset, final int vst2Id) { + this.id = id; + this.paramOffset = paramOffset; + this.vst2id = vst2Id; + } + + public String getId() { + return id; + } + + public int getParamOffset() { + return paramOffset; + } + + public DeviceMatcher createMatcher(final ControllerHost host) { + if (this.id != null) { + return host.createVST3DeviceMatcher(this.id); + } + return host.createVST2DeviceMatcher(this.vst2id); + } + + public SpecificPluginDevice createSpecDevice(final Device device) { + if (this.id != null) { + return device.createSpecificVst3Device(this.id); + } + return device.createSpecificVst2Device(this.vst2id); + } +} diff --git a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/midi/MidiProcessor.java b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/midi/MidiProcessor.java index 8e6efff0..2ecb3d54 100644 --- a/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/midi/MidiProcessor.java +++ b/src/main/java/com/bitwig/extensions/controllers/nativeinstruments/komplete/midi/MidiProcessor.java @@ -19,6 +19,7 @@ import com.bitwig.extensions.controllers.nativeinstruments.komplete.DataStringUtil; import com.bitwig.extensions.controllers.nativeinstruments.komplete.KompleteKontrolExtension; import com.bitwig.extensions.controllers.nativeinstruments.komplete.LayoutType; +import com.bitwig.extensions.controllers.nativeinstruments.komplete.NksDevice; import com.bitwig.extensions.controllers.nativeinstruments.komplete.device.DeviceSelectionTab; public class MidiProcessor { @@ -142,7 +143,22 @@ public HardwareButton createButton(final String name, final int ccNr, final int return hwButton; } + private String currentNksDeviceName = ""; + + public void registerNksDevice(final String name) { + currentNksDeviceName = name; + } + + public void registerNksParam(final NksDevice deviceTyp, final String paramId) { + if (!paramId.isBlank()) { + updateKompleteKontrolInstance(paramId); + } + } + public void updateKompleteKontrolInstance(final String instanceParamName) { + if (instanceParamName.isBlank()) { + return; + } if (lastReportedKKInstance == null || !lastReportedKKInstance.equals(instanceParamName)) { sendTextCommand(TextCommand.SELECTED_TRACK, instanceParamName); host.scheduleTask(() -> sendTextCommand(TextCommand.SELECTED_TRACK, instanceParamName), 100); @@ -184,7 +200,6 @@ public void sendSelectCommand(final int index, final boolean selected) { if (selectedState[index] == selected) { return; } - final int nowSelected = getSelectedIndex(); selectedState[index] = selected; ValueCommand.SELECT.send(midiOut, index, selected); } @@ -293,5 +308,4 @@ public void updateParameterValue(final int index, final int value) { midiOut.sendMidi(0xBF, 0x70 + index, value); } - }