Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -293,5 +308,4 @@ public void updateParameterValue(final int index, final int value) {
midiOut.sendMidi(0xBF, 0x70 + index, value);
}


}