Search in sources :

Example 1 with CommandSlot

use of de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot 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);
}
Also used : IIntegerSetting(de.mossgrabers.framework.configuration.IIntegerSetting) CommandSlot(de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot) CommandCategory(de.mossgrabers.controller.generic.controller.CommandCategory) IActionSetting(de.mossgrabers.framework.configuration.IActionSetting) IEnumSetting(de.mossgrabers.framework.configuration.IEnumSetting)

Example 2 with CommandSlot

use of de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot in project DrivenByMoss by git-moss.

the class GenericFlexiConfiguration method fixKnobMode.

/**
 * Always set the knob mode to absolute for trigger commands.
 */
private void fixKnobMode() {
    final CommandSlot slot = this.getSelectedSlot();
    final FlexiCommand command = slot.getCommand();
    if (!command.isTrigger())
        return;
    if (!AbstractHandler.isAbsolute(slot.getKnobMode()) || slot.getType() == CommandSlot.TYPE_MMC)
        this.knobModeSetting.set(KnobMode.ABSOLUTE.getLabel());
}
Also used : CommandSlot(de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot) FlexiCommand(de.mossgrabers.controller.generic.controller.FlexiCommand)

Example 3 with CommandSlot

use of de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot in project DrivenByMoss by git-moss.

the class GenericFlexiConfiguration method importFrom.

/**
 * Import the configuration from the given file.
 *
 * @param importFile Where to import from
 * @throws IOException Could not save the file
 */
public void importFrom(final File importFile) throws IOException {
    this.slotSelectionSetting.set("1");
    this.host.scheduleTask(() -> {
        try {
            final Properties props = new Properties();
            try (final Reader reader = new FileReader(importFile)) {
                props.load(reader);
            }
            for (int i = 0; i < this.commandSlots.length; i++) {
                final String slotName = "SLOT" + i + "_";
                final CommandSlot slot = this.commandSlots[i];
                final String typeProperty = props.getProperty(slotName + TAG_TYPE);
                if (typeProperty == null)
                    continue;
                int type = Integer.parseInt(typeProperty);
                final FlexiCommand command = FlexiCommand.lookupByName(props.getProperty(slotName + TAG_COMMAND));
                // For backwards compatibility
                if (command == FlexiCommand.OFF)
                    type = CommandSlot.TYPE_OFF;
                final String numberProperty = props.getProperty(slotName + TAG_NUMBER);
                final String midiChannelProperty = props.getProperty(slotName + TAG_MIDI_CHANNEL);
                final String knobModeProperty = props.getProperty(slotName + TAG_KNOB_MODE);
                slot.setType(type);
                slot.setNumber(numberProperty == null ? 0 : Integer.parseInt(numberProperty));
                slot.setMidiChannel(midiChannelProperty == null ? 0 : Integer.parseInt(midiChannelProperty));
                slot.setResolution(Boolean.parseBoolean(props.getProperty(slotName + TAG_RESOLUTION)));
                slot.setKnobMode(readKnobMode(knobModeProperty));
                slot.setCommand(command);
                slot.setSendValue(Boolean.parseBoolean(props.getProperty(slotName + TAG_SEND_VALUE)));
                slot.setSendValueWhenReceived(Boolean.parseBoolean(props.getProperty(slotName + TAG_SEND_VALUE_WHEN_RECEIVED)));
            }
        } catch (final IOException | NumberFormatException ex) {
            this.host.error("Could not import from file.", ex);
            this.host.showNotification("Could not import from file. Check Script Console for detailed error.");
            return;
        }
        this.clearNoteMap();
        this.selectSlot("1");
    }, 1000);
}
Also used : Reader(java.io.Reader) FileReader(java.io.FileReader) CommandSlot(de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties) FlexiCommand(de.mossgrabers.controller.generic.controller.FlexiCommand)

Example 4 with CommandSlot

use of de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot in project DrivenByMoss by git-moss.

the class GenericFlexiControlSurface method handleCommand.

/**
 * Handle a command.
 *
 * @param slotIndex The slot index where the command is stored
 * @param value The received parameter value to handle
 */
private void handleCommand(final int slotIndex, final MidiValue value) {
    if (slotIndex < 0)
        return;
    final CommandSlot commandSlot = this.configuration.getCommandSlots()[slotIndex];
    final FlexiCommand command = commandSlot.getCommand();
    if (command == FlexiCommand.OFF)
        return;
    this.isUpdatingValue = true;
    this.handlers.get(command).handle(command, commandSlot.getKnobMode(), value);
    this.host.scheduleTask(() -> {
        this.valueCache[slotIndex] = this.getCommandValue(command);
        this.isUpdatingValue = false;
    }, 400);
}
Also used : CommandSlot(de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot)

Example 5 with CommandSlot

use of de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot in project DrivenByMoss by git-moss.

the class GenericFlexiConfiguration method exportTo.

/**
 * Export the configuration to the given file.
 *
 * @param exportFile Where to export to
 * @throws IOException Could not save the file
 */
public void exportTo(final File exportFile) throws IOException {
    final Properties props = new Properties();
    for (int i = 0; i < this.commandSlots.length; i++) {
        final String slotName = "SLOT" + i + "_";
        final CommandSlot slot = this.commandSlots[i];
        props.put(slotName + TAG_TYPE, Integer.toString(slot.getType()));
        props.put(slotName + TAG_NUMBER, Integer.toString(slot.getNumber()));
        props.put(slotName + TAG_MIDI_CHANNEL, Integer.toString(slot.getMidiChannel()));
        props.put(slotName + TAG_RESOLUTION, Boolean.toString(slot.getResolution()));
        props.put(slotName + TAG_KNOB_MODE, Integer.toString(slot.getKnobMode().ordinal()));
        props.put(slotName + TAG_COMMAND, slot.getCommand().getName());
        props.put(slotName + TAG_SEND_VALUE, Boolean.toString(slot.isSendValue()));
        props.put(slotName + TAG_SEND_VALUE_WHEN_RECEIVED, Boolean.toString(slot.isSendValueWhenReceived()));
    }
    try (final Writer writer = new FileWriter(exportFile)) {
        props.store(writer, "Generic Flexi");
    }
}
Also used : FileWriter(java.io.FileWriter) CommandSlot(de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot) Properties(java.util.Properties) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

CommandSlot (de.mossgrabers.controller.generic.flexihandler.utils.CommandSlot)8 FlexiCommand (de.mossgrabers.controller.generic.controller.FlexiCommand)3 CommandCategory (de.mossgrabers.controller.generic.controller.CommandCategory)2 Properties (java.util.Properties)2 IActionSetting (de.mossgrabers.framework.configuration.IActionSetting)1 IEnumSetting (de.mossgrabers.framework.configuration.IEnumSetting)1 IIntegerSetting (de.mossgrabers.framework.configuration.IIntegerSetting)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1