Search in sources :

Example 1 with IllegalParameterException

use of de.mossgrabers.controller.osc.exception.IllegalParameterException in project DrivenByMoss by git-moss.

the class MidiModule method parseNoteRepeat.

/**
 * Parse note repeat parameters.
 *
 * @param path The rest of the path
 * @param value The value
 * @throws MissingCommandException Could not find the sub-command
 * @throws UnknownCommandException Unknown sub-command
 * @throws IllegalParameterException Added an illegal parameter
 */
private void parseNoteRepeat(final LinkedList<String> path, final Object value) throws MissingCommandException, UnknownCommandException, IllegalParameterException {
    final INoteInput noteInput = this.surface.getMidiInput().getDefaultNoteInput();
    if (noteInput == null)
        return;
    final INoteRepeat noteRepeat = noteInput.getNoteRepeat();
    final String subCommand = getSubCommand(path);
    switch(subCommand) {
        case "isActive":
            noteRepeat.setActive(toInteger(value) > 0);
            break;
        case "period":
            if (value == null)
                throw new IllegalParameterException("Value must not be empty.");
            final Resolution period = Resolution.getByName(value.toString());
            if (period == null)
                throw new IllegalParameterException("Value must be one of {1/4, 1/4t, 1/8, 1/8t, 1/16, 1/16t, 1/32, 1/32t}.");
            noteRepeat.setPeriod(period.getValue());
            break;
        case "length":
            if (value == null)
                throw new IllegalParameterException("Value must not be empty.");
            final Resolution length = Resolution.getByName(value.toString());
            if (length == null)
                throw new IllegalParameterException("Value must be one of {1/4, 1/4t, 1/8, 1/8t, 1/16, 1/16t, 1/32, 1/32t}.");
            noteRepeat.setNoteLength(length.getValue());
            break;
        default:
            throw new UnknownCommandException(subCommand);
    }
}
Also used : INoteRepeat(de.mossgrabers.framework.daw.midi.INoteRepeat) UnknownCommandException(de.mossgrabers.controller.osc.exception.UnknownCommandException) IllegalParameterException(de.mossgrabers.controller.osc.exception.IllegalParameterException) INoteInput(de.mossgrabers.framework.daw.midi.INoteInput) Resolution(de.mossgrabers.framework.daw.constants.Resolution)

Example 2 with IllegalParameterException

use of de.mossgrabers.controller.osc.exception.IllegalParameterException in project DrivenByMoss by git-moss.

the class OSCParser method handle.

/**
 * {@inheritDoc}
 */
@Override
public void handle(final IOpenSoundControlMessage message) {
    this.logMessage(message);
    final LinkedList<String> oscParts = parseAddress(message);
    if (oscParts.isEmpty())
        return;
    final String command = oscParts.removeFirst();
    if ("refresh".equals(command)) {
        this.writer.flush(true);
        return;
    }
    final Object[] values = message.getValues();
    try {
        final IModule module = this.modules.get(command);
        if (module == null)
            throw new UnknownCommandException(command);
        if (values != null && values.length > 1)
            module.execute(command, oscParts, values);
        else
            module.execute(command, oscParts, values == null || values.length == 0 ? null : values[0]);
    } catch (final IllegalParameterException ex) {
        this.host.println("Illegal parameter: " + message.getAddress() + " " + ex.getMessage());
    } catch (final UnknownCommandException ex) {
        this.host.println("Unknown OSC command: " + message.getAddress() + " " + ex.getMessage());
    } catch (final MissingCommandException ex) {
        this.host.println("Missing command: " + message.getAddress());
    }
}
Also used : IModule(de.mossgrabers.controller.osc.module.IModule) UnknownCommandException(de.mossgrabers.controller.osc.exception.UnknownCommandException) IllegalParameterException(de.mossgrabers.controller.osc.exception.IllegalParameterException) MissingCommandException(de.mossgrabers.controller.osc.exception.MissingCommandException)

Aggregations

IllegalParameterException (de.mossgrabers.controller.osc.exception.IllegalParameterException)2 UnknownCommandException (de.mossgrabers.controller.osc.exception.UnknownCommandException)2 MissingCommandException (de.mossgrabers.controller.osc.exception.MissingCommandException)1 IModule (de.mossgrabers.controller.osc.module.IModule)1 Resolution (de.mossgrabers.framework.daw.constants.Resolution)1 INoteInput (de.mossgrabers.framework.daw.midi.INoteInput)1 INoteRepeat (de.mossgrabers.framework.daw.midi.INoteRepeat)1