use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class AbstractPolySequencerView method handleSequencerAreaButtonCombinations.
/**
* Handle button combinations in the sequencer area.
*
* @param clip The sequenced MIDI clip
* @param channel The MIDI channel of the note
* @param step The step in the current page in the clip
* @return True if handled
*/
protected boolean handleSequencerAreaButtonCombinations(final INoteClip clip, final int channel, final int step) {
// Handle note duplicate function
if (this.isButtonCombination(ButtonID.DUPLICATE)) {
if (this.getStep(clip, step).getState() == StepState.START)
this.copyStep = step;
else if (this.copyStep >= 0) {
for (int row = 0; row < 128; row++) {
final IStepInfo stepInfo = clip.getStep(channel, this.copyStep, row);
if (stepInfo != null && stepInfo.getVelocity() > 0)
clip.setStep(channel, step, row, stepInfo);
}
}
return true;
}
if (this.isButtonCombination(ButtonID.MUTE)) {
for (int note = 0; note < 128; note++) {
final IStepInfo stepInfo = clip.getStep(channel, step, note);
final StepState isSet = stepInfo.getState();
if (isSet == StepState.START)
this.getClip().updateMuteState(channel, step, note, !stepInfo.isMuted());
}
return true;
}
// Change length of a note or create a new one with a length
for (int s = step - 1; s >= 0; s--) {
final int x = s % this.numColumns;
final int y = this.numRows - 1 - s / this.numColumns;
final int pad = y * this.numColumns + x;
final IHwButton button = this.surface.getButton(ButtonID.get(ButtonID.PAD1, pad));
if (button.isLongPressed()) {
button.setConsumed();
final int length = step - s + 1;
final double duration = length * Resolution.getValueAt(this.getResolutionIndex());
// Create new note(s)
if (this.getStep(clip, s).getState() != StepState.START) {
for (int row = 0; row < 128; row++) {
final Integer k = Integer.valueOf(row);
if (this.noteMemory.containsKey(k)) {
final Integer vel = this.noteMemory.get(k);
clip.setStep(channel, s, row, this.configuration.isAccentActive() ? this.configuration.getFixedAccentValue() : vel.intValue(), duration);
}
}
return true;
}
// Change length of existing notes
for (int row = 0; row < 128; row++) {
final IStepInfo stepInfo = clip.getStep(channel, s, row);
if (stepInfo != null && stepInfo.getState() == StepState.START)
clip.updateStepDuration(channel, s, row, duration);
}
return true;
}
}
return false;
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class AbstractDrumLaneView method handleNoteAreaButtonCombinations.
/**
* Handle button combinations on the note area of the sequencer.
*
* @param clip The sequenced MIDI clip
* @param channel The MIDI channel of the note
* @param row The row in the current page in the clip
* @param note The note in the current page of the pad in the clip
* @param step The step in the current page in the clip
* @param velocity The velocity
* @param accentVelocity The velocity or accent value
* @return True if handled
*/
protected boolean handleNoteAreaButtonCombinations(final INoteClip clip, final int channel, final int step, final int row, final int note, final int velocity, final int accentVelocity) {
// Handle note duplicate function
if (this.isButtonCombination(ButtonID.DUPLICATE)) {
if (velocity == 0) {
final IStepInfo noteStep = clip.getStep(channel, step, note);
if (noteStep.getState() == StepState.START)
this.copyNote = noteStep;
else if (this.copyNote != null)
clip.setStep(channel, step, note, this.copyNote);
}
return true;
}
if (this.isButtonCombination(ButtonID.MUTE)) {
if (velocity == 0) {
final IStepInfo stepInfo = clip.getStep(channel, step, note);
final StepState isSet = stepInfo.getState();
if (isSet == StepState.START)
this.getClip().updateMuteState(channel, step, note, !stepInfo.isMuted());
}
return true;
}
// Change length of a note or create a new one with a length
final int laneOffset = (this.allRows - row - 1) / this.lanes * this.numColumns;
final int offset = row * this.numColumns;
for (int s = 0; s < step; s++) {
final IHwButton button = this.surface.getButton(ButtonID.get(ButtonID.PAD1, offset + s));
if (button.isLongPressed()) {
final int start = s + laneOffset;
button.setConsumed();
final int length = step - start + 1;
final double duration = length * Resolution.getValueAt(this.getResolutionIndex());
final StepState state = note < 0 ? StepState.OFF : clip.getStep(channel, start, note).getState();
if (state == StepState.START)
clip.updateStepDuration(channel, start, note, duration);
else
clip.setStep(channel, start, note, accentVelocity, duration);
return true;
}
}
return false;
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class AbstractNoteSequencerView method handleSequencerAreaButtonCombinations.
/**
* Handle button combinations on the note area of the sequencer.
*
* @param clip The sequenced MIDI clip
* @param channel The MIDI channel of the note
* @param step The step in the current page in the clip
* @param row The row in the current page in the clip
* @param note The note in the current page of the pad in the clip
* @param velocity The velocity
* @return True if handled
*/
protected boolean handleSequencerAreaButtonCombinations(final INoteClip clip, final int channel, final int step, final int row, final int note, final int velocity) {
// Handle note duplicate function
if (this.isButtonCombination(ButtonID.DUPLICATE)) {
final IStepInfo noteStep = clip.getStep(channel, step, note);
if (noteStep.getState() == StepState.START)
this.copyNote = noteStep;
else if (this.copyNote != null)
clip.setStep(channel, step, note, this.copyNote);
return true;
}
if (this.isButtonCombination(ButtonID.MUTE)) {
final IStepInfo stepInfo = clip.getStep(channel, step, note);
final StepState isSet = stepInfo.getState();
if (isSet == StepState.START)
this.getClip().updateMuteState(channel, step, note, !stepInfo.isMuted());
return true;
}
// Change length of a note or create a new one with a length
final int offset = row * clip.getNumSteps();
for (int s = 0; s < step; s++) {
final IHwButton button = this.surface.getButton(ButtonID.get(ButtonID.PAD1, offset + s));
if (button.isLongPressed()) {
button.setConsumed();
final int length = step - s + 1;
final double duration = length * Resolution.getValueAt(this.getResolutionIndex());
final StepState state = note < 0 ? StepState.OFF : clip.getStep(channel, s, note).getState();
if (state == StepState.START)
clip.updateStepDuration(channel, s, note, duration);
else
clip.setStep(channel, s, note, velocity, duration);
return true;
}
}
return false;
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class HUIControlSurface method handleMidi.
/**
* {@inheritDoc}
*/
@Override
protected void handleMidi(final int status, final int data1, final int data2) {
final int code = status & 0xF0;
if (code != 0xB0)
return;
switch(data1) {
// Move fader high-byte
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07:
// This is an iCON extension
case 0x08:
this.faderHiValues[data1] = data2;
break;
case 0x0d:
final int d = ENCODER.encode(DECODER.decode(data2));
this.getContinuous(ContinuousID.PLAY_POSITION).getCommand().execute(d);
break;
// Button zone selection
case 0x0F:
this.zone = data2;
break;
// Move fader low-byte
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
case 0x27:
final int chnl = data1 - 0x20;
final int value = (this.faderHiValues[chnl] << 7) + data2;
final ContinuousCommand command = this.getContinuous(ContinuousID.get(ContinuousID.FADER1, chnl)).getCommand();
((WorkaroundFader) command).executeHiRes(value);
break;
case 0x28:
final int masterValue = (this.faderHiValues[8] << 7) + data2;
((WorkaroundMasterFader) this.getContinuous(ContinuousID.FADER_MASTER).getCommand()).executeHiRes(masterValue);
break;
// Button port up/down (a button in the selected row)
case 0x2F:
final boolean isDown = data2 >= 0x40;
final int buttonIndex = this.zone * 8 + data2 % 8;
final IHwButton button = this.huiButtons.get(Integer.valueOf(buttonIndex));
if (button == null)
this.host.error("Button " + buttonIndex + " not supported (Zone: " + this.zone + " Index: " + data2 % 8 + ")");
else
button.trigger(isDown ? ButtonEvent.DOWN : ButtonEvent.UP);
break;
case 0x40:
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
case 0x47:
final int channel = data1 - 0x40;
final int v = data2 > 0x40 ? data2 - 0x40 : 128 - data2;
this.getContinuous(ContinuousID.get(ContinuousID.KNOB1, channel)).getCommand().execute(v);
break;
default:
this.host.println("Unhandled MIDI CC: " + data1);
break;
}
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class LaunchkeyMk3ControllerSetup method registerTriggerCommands.
/**
* {@inheritDoc}
*/
@Override
protected void registerTriggerCommands() {
final LaunchkeyMk3ControlSurface surface = this.getSurface();
final ITransport t = this.model.getTransport();
final ViewManager viewManager = surface.getViewManager();
this.addButton(ButtonID.SHIFT, "Shift", NopCommand.INSTANCE, LaunchkeyMk3ControlSurface.LAUNCHKEY_SHIFT);
this.addButton(ButtonID.PLAY, "Play", new LaunchkeyMk3PlayCommand(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_PLAY, t::isPlaying);
this.addButton(ButtonID.STOP, "Stop", new StopCommand<>(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_STOP, () -> !t.isPlaying());
final ConfiguredRecordCommand<LaunchkeyMk3ControlSurface, LaunchkeyMk3Configuration> recordCommand = new ConfiguredRecordCommand<>(this.model, surface);
this.addButton(ButtonID.RECORD, "Record", recordCommand, 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_RECORD, recordCommand::isLit);
this.addButton(ButtonID.REPEAT, "Repeat", new ToggleLoopCommand<>(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_LOOP, t::isLoop);
this.addButton(ButtonID.NEW, "Capture MIDI", new NewCommand<>(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_CAPTURE_MIDI);
this.addButton(ButtonID.QUANTIZE, "Quantize", new QuantizeCommand<>(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_QUANTIZE);
this.addButton(ButtonID.METRONOME, "Metronome", new MetronomeCommand<>(this.model, surface, true), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_CLICK, t::isMetronomeOn);
this.addButton(ButtonID.UNDO, "Undo", new UndoCommand<>(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_UNDO);
this.addDummyButton(ButtonID.F3, 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_DEVICE_SELECT);
this.addButton(ButtonID.TOGGLE_DEVICE, "Device Lock", new DeviceLockCommand(this.model, surface), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_DEVICE_LOCK, () -> this.model.getCursorDevice().isPinned() ? 127 : 40);
this.addButton(ButtonID.MOVE_TRACK_LEFT, "Previous", new SelectPrevNextTrackCommand<>(this.model, surface, true), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_TRACK_LEFT);
this.addButton(ButtonID.MOVE_TRACK_RIGHT, "Next", new SelectPrevNextTrackCommand<>(this.model, surface, false), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_TRACK_RIGHT);
// Scene buttons
this.addButton(ButtonID.SCENE1, "Scene 1", new ViewButtonCommand<>(ButtonID.SCENE1, surface), LaunchkeyMk3ControlSurface.LAUNCHKEY_SCENE1, new FeatureGroupButtonColorSupplier(viewManager, ButtonID.SCENE1));
this.addButton(ButtonID.SCENE2, "Scene 2", new ViewButtonCommand<>(ButtonID.SCENE2, surface), LaunchkeyMk3ControlSurface.LAUNCHKEY_SCENE2, new FeatureGroupButtonColorSupplier(viewManager, ButtonID.SCENE2));
this.addButton(surface, ButtonID.ARROW_UP, "Up", new ViewButtonCommand<>(ButtonID.ARROW_UP, surface), 15, 0, LaunchkeyMk3ControlSurface.LAUNCHKEY_ARROW_UP, -1, true, new FeatureGroupButtonColorSupplier(viewManager, ButtonID.ARROW_UP));
this.addButton(surface, ButtonID.ARROW_DOWN, "Down", new ViewButtonCommand<>(ButtonID.ARROW_DOWN, surface), 15, 0, LaunchkeyMk3ControlSurface.LAUNCHKEY_ARROW_DOWN, -1, true, new FeatureGroupButtonColorSupplier(viewManager, ButtonID.ARROW_DOWN));
// Ignore redundant messages sent by arrow up/down buttons
this.addDummyButton(ButtonID.F1, 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_SCENE1);
this.addDummyButton(ButtonID.F2, 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_SCENE2);
// View selection with Pads in Shift mode
this.createViewButton(ButtonID.ROW2_1, OutputID.LED_RING1, "Session", Views.SESSION, LaunchkeyMk3ControlSurface.PAD_MODE_SESSION);
this.createViewButton(ButtonID.ROW2_2, OutputID.LED_RING2, "Drum", Views.DRUM, LaunchkeyMk3ControlSurface.PAD_MODE_DRUM);
this.createViewButton(ButtonID.ROW2_3, OutputID.LED_RING3, "Scale Chords", Views.DUMMY1, LaunchkeyMk3ControlSurface.PAD_MODE_SCALE_CHORDS);
this.createViewButton(ButtonID.ROW2_4, OutputID.LED_RING4, "User Chords", Views.DUMMY2, LaunchkeyMk3ControlSurface.PAD_MODE_USER_CHORDS);
this.createViewButton(ButtonID.ROW2_5, OutputID.LED_RING5, NAME_CUSTOM_1, Views.DUMMY3, LaunchkeyMk3ControlSurface.PAD_MODE_CUSTOM_MODE0);
this.createViewButton(ButtonID.ROW2_6, OutputID.LED_RING6, NAME_CUSTOM_2, Views.DUMMY4, LaunchkeyMk3ControlSurface.PAD_MODE_CUSTOM_MODE1);
this.createViewButton(ButtonID.ROW2_7, OutputID.LED_RING7, NAME_CUSTOM_3, Views.DUMMY5, LaunchkeyMk3ControlSurface.PAD_MODE_CUSTOM_MODE2);
this.createViewButton(ButtonID.ROW2_8, OutputID.LED_RING8, NAME_CUSTOM_4, Views.DUMMY6, LaunchkeyMk3ControlSurface.PAD_MODE_CUSTOM_MODE3);
this.createViewButton(ButtonID.DEVICE, OutputID.LED_RING9, "Device Select", Views.DEVICE, LaunchkeyMk3ControlSurface.PAD_MODE_DEVICE_SELECT);
this.createViewButton(ButtonID.BROWSE, OutputID.LED_RING10, "Browser", Views.BROWSER, LaunchkeyMk3ControlSurface.PAD_MODE_NAVIGATION);
// Knob mode selection with Pads in Shift mode
this.createModeButton(ButtonID.ROW1_1, OutputID.LED1, "Device", Modes.DEVICE_PARAMS, LaunchkeyMk3ControlSurface.KNOB_MODE_PARAMS);
this.createModeButton(ButtonID.ROW1_2, OutputID.LED2, "Volume", Modes.VOLUME, LaunchkeyMk3ControlSurface.KNOB_MODE_VOLUME);
this.createModeButton(ButtonID.ROW1_3, OutputID.LED3, "Pan", Modes.PAN, LaunchkeyMk3ControlSurface.KNOB_MODE_PAN);
this.createModeButton(ButtonID.ROW1_4, OutputID.LED4, "Send 1", Modes.SEND1, LaunchkeyMk3ControlSurface.KNOB_MODE_SEND1);
this.createModeButton(ButtonID.ROW1_5, OutputID.LED5, "Send 2", Modes.SEND2, LaunchkeyMk3ControlSurface.KNOB_MODE_SEND2);
this.createModeButton(ButtonID.ROW1_6, OutputID.LED6, NAME_CUSTOM_1, Modes.DEVICE_LAYER_SEND1, LaunchkeyMk3ControlSurface.KNOB_MODE_CUSTOM1);
this.createModeButton(ButtonID.ROW1_7, OutputID.LED7, NAME_CUSTOM_2, Modes.DEVICE_LAYER_SEND2, LaunchkeyMk3ControlSurface.KNOB_MODE_CUSTOM2);
this.createModeButton(ButtonID.ROW1_8, OutputID.LED8, NAME_CUSTOM_3, Modes.DEVICE_LAYER_SEND3, LaunchkeyMk3ControlSurface.KNOB_MODE_CUSTOM3);
this.createModeButton(ButtonID.USER, OutputID.LED9, NAME_CUSTOM_4, Modes.DEVICE_LAYER_SEND4, LaunchkeyMk3ControlSurface.KNOB_MODE_CUSTOM4);
// Fader mode selection with fader buttons in Shift mode
this.createFaderModeButton(ButtonID.ROW3_1, OutputID.LIGHT_GUIDE1, "Device", Modes.DEVICE_PARAMS, LaunchkeyMk3ControlSurface.FADER_MODE_PARAMS);
this.createFaderModeButton(ButtonID.ROW3_2, OutputID.LIGHT_GUIDE2, "Volume", Modes.VOLUME, LaunchkeyMk3ControlSurface.FADER_MODE_VOLUME);
this.createFaderModeButton(ButtonID.ROW3_3, OutputID.LIGHT_GUIDE3, "Send 1", Modes.SEND1, LaunchkeyMk3ControlSurface.FADER_MODE_SEND1);
this.createFaderModeButton(ButtonID.ROW3_4, OutputID.LIGHT_GUIDE4, "Send 2", Modes.SEND2, LaunchkeyMk3ControlSurface.FADER_MODE_SEND2);
this.createFaderModeButton(ButtonID.ROW3_5, OutputID.LIGHT_GUIDE5, NAME_CUSTOM_1, Modes.DEVICE_LAYER_SEND1, LaunchkeyMk3ControlSurface.FADER_MODE_CUSTOM1);
this.createFaderModeButton(ButtonID.ROW3_6, OutputID.LIGHT_GUIDE6, NAME_CUSTOM_2, Modes.DEVICE_LAYER_SEND2, LaunchkeyMk3ControlSurface.FADER_MODE_CUSTOM2);
this.createFaderModeButton(ButtonID.ROW3_7, OutputID.LIGHT_GUIDE7, NAME_CUSTOM_3, Modes.DEVICE_LAYER_SEND3, LaunchkeyMk3ControlSurface.FADER_MODE_CUSTOM3);
this.createFaderModeButton(ButtonID.ROW3_8, OutputID.LIGHT_GUIDE8, NAME_CUSTOM_4, Modes.DEVICE_LAYER_SEND4, LaunchkeyMk3ControlSurface.FADER_MODE_CUSTOM4);
// Fader mode buttons
for (int i = 0; i < 8; i++) {
final ButtonID row1ButtonID = ButtonID.get(ButtonID.ROW_SELECT_1, i);
final IHwButton button = surface.createButton(row1ButtonID, "Select " + (i + 1));
final ButtonAreaCommand command = new ButtonAreaCommand(i, this.model, surface);
button.bind(command);
final IMidiInput midiInput = surface.getMidiInput();
final BindType triggerBindType = this.getTriggerBindType(row1ButtonID);
final int midiControl = LaunchkeyMk3ControlSurface.LAUNCHKEY_SELECT1 + i;
button.bind(midiInput, triggerBindType, 15, midiControl);
final IntSupplier supplier = command::getButtonColor;
surface.createLight(null, supplier::getAsInt, color -> surface.setTrigger(color >= 0x1000 ? 2 : 0, midiControl, color >= 0x1000 ? color - 0x1000 : color), state -> this.colorManager.getColor(state >= 0x1000 ? state - 0x1000 : state, row1ButtonID), button);
}
this.addButton(surface, ButtonID.MASTERTRACK, "Toggle Select/RecArm", (event, velocity) -> {
if (event == ButtonEvent.DOWN)
ButtonAreaCommand.toggleSelect();
}, 15, 0, LaunchkeyMk3ControlSurface.LAUNCHKEY_TOGGLE_SELECT, -1, true, () -> ButtonAreaCommand.isSelect() ? 40 : 127);
// Online state
this.addButton(ButtonID.CONTROL, "DAW Online", (event, velocity) -> surface.setDAWConnected(velocity > 0), 15, LaunchkeyMk3ControlSurface.LAUNCHKEY_DAW_ONLINE, surface::isDAWConnected);
}
Aggregations