use of de.mossgrabers.controller.generic.controller.CommandCategory in project DrivenByMoss by git-moss.
the class GenericFlexiConfiguration method setCommand.
/**
* Set the command.
*
* @param value The command name
*/
private void setCommand(final FlexiCommand value) {
final CommandCategory category = value.getCategory();
final CommandCategory[] values = CommandCategory.values();
this.commandIsUpdating.set(true);
for (int i = 0; i < values.length; i++) this.functionSettings.get(i).set(category == values[i] ? value.getName() : FlexiCommand.OFF.getName());
this.host.scheduleTask(() -> this.commandIsUpdating.set(false), 600);
}
use of de.mossgrabers.controller.generic.controller.CommandCategory in project DrivenByMoss by git-moss.
the class GenericFlexiConfiguration method init.
/**
* {@inheritDoc}
*/
@Override
public void init(final ISettingsUI globalSettings, final ISettingsUI documentSettings) {
String category = "Slot";
final String[] slotEntries = new String[NUM_SLOTS];
for (int i = 0; i < NUM_SLOTS; i++) {
this.commandSlots[i] = new CommandSlot();
slotEntries[i] = Integer.toString(i + 1);
}
this.slotSelectionSetting = globalSettings.getEnumSetting("Selected:", category, slotEntries, slotEntries[0]);
// /////////////////////////////////////////////
// The MIDI learn section
category = "Use a knob/fader/button then click Set...";
this.learnTypeSetting = globalSettings.getEnumSetting("Type:", category, OPTIONS_TYPE, OPTIONS_TYPE.get(0));
this.learnNumberSetting = globalSettings.getEnumSetting("Number:", category, NUMBER_NAMES, NUMBER_NAMES.get(0));
this.learnMidiChannelSetting = globalSettings.getEnumSetting("Midi Channel:", category, OPTIONS_MIDI_CHANNEL, OPTIONS_MIDI_CHANNEL[0]);
this.learnResolutionSetting = globalSettings.getEnumSetting("Resolution:", category, OPTIONS_RESOLUTION, OPTIONS_RESOLUTION.get(0));
this.learnTypeSetting.setEnabled(false);
this.learnNumberSetting.setEnabled(false);
this.learnMidiChannelSetting.setEnabled(false);
this.learnResolutionSetting.setEnabled(false);
globalSettings.getSignalSetting(" ", category, "Set").addSignalObserver(value -> {
if (this.learnTypeValue == null)
return;
this.typeSetting.set(this.learnTypeValue);
this.midiChannelSetting.set(this.learnMidiChannelValue);
// CC? For 14-bit values only set CCs below 32
if (OPTIONS_TYPE.get(1).equals(this.learnTypeValue) && this.learnResolution) {
final int number = AbstractConfiguration.lookupIndex(NUMBER_NAMES, this.learnNumberValue);
if (number >= 32 && number < 64)
this.learnNumberValue = NUMBER_NAMES.get(number - 32);
else if (number >= 64)
this.learnResolution = false;
}
this.resolutionSetting.set(OPTIONS_RESOLUTION.get(this.learnResolution ? 1 : 0));
this.numberSetting.set(this.learnNumberValue);
});
// /////////////////////////////////////////////
// Selected Slot - MIDI trigger
category = "Selected Slot - MIDI trigger";
this.typeSetting = globalSettings.getEnumSetting("Type:", category, OPTIONS_TYPE, OPTIONS_TYPE.get(0));
this.numberSetting = globalSettings.getEnumSetting("Number:", category, NUMBER_NAMES, NUMBER_NAMES.get(0));
this.midiChannelSetting = globalSettings.getEnumSetting("Midi Channel:", category, CONTROLLER_CHANNELS, CONTROLLER_CHANNELS.get(0));
this.resolutionSetting = globalSettings.getEnumSetting("Resolution:", category, OPTIONS_RESOLUTION, OPTIONS_RESOLUTION.get(0));
final String[] knobModeLabels = KnobMode.getLabels();
this.knobModeSetting = globalSettings.getEnumSetting("Knob Mode:", category, knobModeLabels, knobModeLabels[0]);
// /////////////////////////////////////////////
// Selected Slot - MIDI device update
category = "Selected Slot - MIDI device update";
this.sendValueSetting = globalSettings.getEnumSetting("Send value to device:", category, AbstractConfiguration.ON_OFF_OPTIONS, AbstractConfiguration.ON_OFF_OPTIONS[1]);
this.sendValueWhenReceivedSetting = globalSettings.getEnumSetting("Send value to device when received (only buttons):", category, AbstractConfiguration.ON_OFF_OPTIONS, AbstractConfiguration.ON_OFF_OPTIONS[1]);
// /////////////////////////////////////////////
// Selected Slot - Function
category = "Selected Slot - Function";
final CommandCategory[] values = CommandCategory.values();
for (final CommandCategory value : values) {
final IEnumSetting fs = createFunctionSetting(value.getName(), category, globalSettings);
this.functionSettings.add(fs);
this.functionSettingsMap.put(value, fs);
fs.addValueObserver(this::handleFunctionChange);
}
// /////////////////////////////////////////////
// Export/Import section
category = "Load / Save";
// The Setlist file to auto-load
this.fileSetting = globalSettings.getStringSetting("Filename", category, -1, "");
this.filename = this.fileSetting.get();
this.fileSetting.addValueObserver(value -> this.filename = value);
// The different blank labels are necessary to distinguish the widgets!
globalSettings.getSignalSetting(" ", category, "Save").addSignalObserver(value -> this.notifyObservers(BUTTON_SAVE));
globalSettings.getSignalSetting(" ", category, "Load").addSignalObserver(value -> this.notifyObservers(BUTTON_LOAD));
this.learnTypeSetting.set(OPTIONS_TYPE.get(0));
this.typeSetting.addValueObserver(value -> {
final int type = AbstractConfiguration.lookupIndex(OPTIONS_TYPE, value) - 1;
this.getSelectedSlot().setType(type);
// High resolution is only true for pitchbend as the default
final int number = AbstractConfiguration.lookupIndex(NUMBER_NAMES, this.numberSetting.get());
if (type != CommandSlot.TYPE_PITCH_BEND && (type != CommandSlot.TYPE_CC || number >= 32))
this.resolutionSetting.set(OPTIONS_RESOLUTION.get(0));
this.clearNoteMap();
this.updateVisibility(!OPTIONS_TYPE.get(0).equals(value));
});
this.numberSetting.addValueObserver(value -> {
final int numberIndex = AbstractConfiguration.lookupIndex(NUMBER_NAMES, value);
this.getSelectedSlot().setNumber(numberIndex);
// Switch resolution setting to low for CC >= 32
final int type = AbstractConfiguration.lookupIndex(OPTIONS_TYPE, this.typeSetting.get()) - 1;
if (type == CommandSlot.TYPE_CC && numberIndex >= 32)
this.resolutionSetting.set(OPTIONS_RESOLUTION.get(0));
this.clearNoteMap();
});
this.midiChannelSetting.addValueObserver(value -> {
this.getSelectedSlot().setMidiChannel(AbstractConfiguration.lookupIndex(CONTROLLER_CHANNELS, value));
this.clearNoteMap();
});
this.resolutionSetting.addValueObserver(value -> {
final boolean isHighRes = OPTIONS_RESOLUTION.get(1).equals(value);
this.getSelectedSlot().setResolution(OPTIONS_RESOLUTION.get(1).equals(value));
// High resolution can only be set for CC < 32 and pitchbend (fixed to high res)
final int type = AbstractConfiguration.lookupIndex(OPTIONS_TYPE, this.typeSetting.get()) - 1;
if (isHighRes) {
final int number = AbstractConfiguration.lookupIndex(NUMBER_NAMES, this.numberSetting.get());
if ((type != CommandSlot.TYPE_CC || number >= 32) && type != CommandSlot.TYPE_PITCH_BEND)
this.resolutionSetting.set(OPTIONS_RESOLUTION.get(0));
} else {
if (type == CommandSlot.TYPE_PITCH_BEND)
this.resolutionSetting.set(OPTIONS_RESOLUTION.get(1));
}
});
this.knobModeSetting.addValueObserver(value -> {
this.getSelectedSlot().setKnobMode(KnobMode.lookupByLabel(value));
this.fixKnobMode();
});
this.sendValueSetting.addValueObserver(value -> this.getSelectedSlot().setSendValue(AbstractConfiguration.lookupIndex(AbstractConfiguration.ON_OFF_OPTIONS, value) > 0));
this.sendValueWhenReceivedSetting.addValueObserver(value -> this.getSelectedSlot().setSendValueWhenReceived(AbstractConfiguration.lookupIndex(AbstractConfiguration.ON_OFF_OPTIONS, value) > 0));
// /////////////////////////////////////////////
// Keyboard / Pads
final IEnumSetting enableMPESetting = globalSettings.getEnumSetting("MIDI Polyphonic Expression (MPE)", CATEGORY_KEYBOARD, ON_OFF_OPTIONS, ON_OFF_OPTIONS[0]);
this.isMPEEnabled = ON_OFF_OPTIONS[1].equals(enableMPESetting.get());
final IIntegerSetting pitchBendRangeSetting = globalSettings.getRangeSetting("MPE Pitch Bend Sensitivity", CATEGORY_KEYBOARD, 1, 96, 1, "", 48);
this.mpePitchBendRange = pitchBendRangeSetting.get().intValue();
final IEnumSetting keyboardMidiChannelSetting = globalSettings.getEnumSetting("Midi Channel", CATEGORY_KEYBOARD, KEYBOARD_CHANNELS, KEYBOARD_CHANNELS.get(1));
this.keyboardChannel = AbstractConfiguration.lookupIndex(KEYBOARD_CHANNELS, keyboardMidiChannelSetting.get()) - 1;
final IEnumSetting routeTimbreSetting = globalSettings.getEnumSetting("Route Timbre (CC74)", CATEGORY_KEYBOARD, AbstractConfiguration.ON_OFF_OPTIONS, AbstractConfiguration.ON_OFF_OPTIONS[0]);
this.keyboardRouteTimbre = "On".equals(routeTimbreSetting.get());
final IEnumSetting routeModulationSetting = globalSettings.getEnumSetting("Route Modulation (CC01)", CATEGORY_KEYBOARD, AbstractConfiguration.ON_OFF_OPTIONS, AbstractConfiguration.ON_OFF_OPTIONS[1]);
this.keyboardRouteModulation = "On".equals(routeModulationSetting.get());
final IEnumSetting routeSustainSetting = globalSettings.getEnumSetting("Route Sustain (CC64)", CATEGORY_KEYBOARD, AbstractConfiguration.ON_OFF_OPTIONS, AbstractConfiguration.ON_OFF_OPTIONS[1]);
this.keyboardRouteSustain = "On".equals(routeSustainSetting.get());
final IEnumSetting routePitchbendSetting = globalSettings.getEnumSetting("Route Pitchbend", CATEGORY_KEYBOARD, AbstractConfiguration.ON_OFF_OPTIONS, AbstractConfiguration.ON_OFF_OPTIONS[1]);
this.keyboardRoutePitchbend = "On".equals(routePitchbendSetting.get());
enableMPESetting.addValueObserver(value -> {
this.isMPEEnabled = ON_OFF_OPTIONS[1].equals(value);
this.notifyObservers(ENABLED_MPE_ZONES);
pitchBendRangeSetting.setEnabled(this.isMPEEnabled);
keyboardMidiChannelSetting.setEnabled(!this.isMPEEnabled);
routePitchbendSetting.setEnabled(!this.isMPEEnabled);
});
pitchBendRangeSetting.addValueObserver(value -> {
this.mpePitchBendRange = value.intValue();
this.notifyObservers(MPE_PITCHBEND_RANGE);
});
// /////////////////////////////////////////////
// Options
this.selectedModeSetting = globalSettings.getEnumSetting("Selected Mode", CATEGORY_OPTIONS, MODES, MODES.get(0));
this.selectedModeSetting.addValueObserver(value -> {
this.selectedMode = value;
this.notifyObservers(SELECTED_MODE);
});
for (int i = 0; i < this.assignableFunctionActions.length; i++) {
final int pos = i;
final IActionSetting actionSetting = globalSettings.getActionSetting("Action " + (i + 1), CATEGORY_OPTIONS);
actionSetting.addValueObserver(value -> this.assignableFunctionActions[pos] = actionSetting.get());
}
// /////////////////////////////////////////////
// Workflow
this.activateKnobSpeedSetting(globalSettings);
this.activateExcludeDeactivatedItemsSetting(globalSettings);
this.activateNoteRepeatSetting(documentSettings);
this.slotSelectionSetting.addValueObserver(this::selectSlot);
}
use of de.mossgrabers.controller.generic.controller.CommandCategory in project DrivenByMoss by git-moss.
the class GenericFlexiConfiguration method handleFunctionChange.
/**
* Handles changing the function selection by the user.
*
* @param value The new value
*/
private void handleFunctionChange(final String value) {
if (this.commandIsUpdating.get())
return;
if (this.doNotFire.get()) {
this.doNotFire.set(false);
return;
}
final CommandSlot slot = this.getSelectedSlot();
final FlexiCommand oldCommand = slot.getCommand();
final FlexiCommand newCommand = FlexiCommand.lookupByName(value);
slot.setCommand(newCommand);
this.fixKnobMode();
this.notifyCommandObserver();
final CommandCategory oldCategory = oldCommand.getCategory();
if (oldCategory != null && oldCategory != newCommand.getCategory()) {
this.doNotFire.set(true);
this.functionSettingsMap.get(oldCategory).set(FlexiCommand.OFF.getName());
}
}
Aggregations