use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class LaunchpadControlSurface method setLaunchpadMode.
private void setLaunchpadMode(final String data) {
this.sendLaunchpadSysEx(data);
for (final Entry<ButtonID, IHwButton> entry : this.getButtons().entrySet()) {
final ButtonID key = entry.getKey();
final int keyValue = key.ordinal();
if (ButtonID.PAD1.ordinal() < keyValue || ButtonID.PAD64.ordinal() > keyValue)
entry.getValue().getLight().forceFlush();
}
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class LaunchkeyMk3ControlSurface method createPads.
/**
* {@inheritDoc}
*/
@Override
protected void createPads() {
((LaunchkeyPadGrid) this.padGrid).setView(Views.SESSION);
super.createPads();
// Map alternative MIDI notes for grid...
final int size = this.padGrid.getRows() * this.padGrid.getCols();
final int startNote = this.padGrid.getStartNote();
for (int i = 0; i < size; i++) {
final int note = startNote + i;
final ButtonID buttonID = ButtonID.get(ButtonID.PAD17, i);
IHwButton pad = this.createButton(buttonID, "D " + (i + 1));
pad.addLight(this.surfaceFactory.createLight(this.surfaceID, null, () -> this.padGrid.getLightInfo(note).getEncoded(), state -> this.padGrid.sendState(note), colorIndex -> this.colorManager.getColor(colorIndex, buttonID), null));
int[] translated = LaunchkeyPadGrid.translateToController(Views.DRUM, note);
pad.bind(this.input, BindType.NOTE, translated[0], translated[1]);
pad.bind((event, velocity) -> this.handleGridNote(event, note, velocity));
final ButtonID buttonID2 = ButtonID.get(ButtonID.PAD33, i);
pad = this.createButton(buttonID2, "DS " + (i + 1));
pad.addLight(this.surfaceFactory.createLight(this.surfaceID, null, () -> this.padGrid.getLightInfo(note).getEncoded(), state -> this.padGrid.sendState(note), colorIndex -> this.colorManager.getColor(colorIndex, buttonID2), null));
translated = LaunchkeyPadGrid.translateToController(Views.DEVICE, note);
pad.bind(this.input, BindType.NOTE, translated[0], translated[1]);
pad.bind((event, velocity) -> this.handleGridNote(event, note, velocity));
}
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class AbstractControllerSetup method addButton.
/**
* Create a hardware button proxy, bind a trigger command to it and bind it to the trigger bind
* type retrieved from {@link #getTriggerBindType(ButtonID)}.
*
* @param surface The control surface
* @param buttonID The ID of the button (for later access)
* @param label The label of the button
* @param supplier Callback for retrieving the state of the light
* @param midiInputChannel The MIDI input channel
* @param midiOutputChannel The MIDI output channel
* @param midiControl The MIDI CC or note
* @param value The specific value of the control to bind to
* @param command The command to bind
* @param hasLight True create and add a light
* @param colorIds The color IDs to map to the states
*/
protected void addButton(final S surface, final ButtonID buttonID, final String label, final TriggerCommand command, final int midiInputChannel, final int midiOutputChannel, final int midiControl, final int value, final boolean hasLight, final IntSupplier supplier, final String... colorIds) {
final IHwButton button = surface.createButton(buttonID, label);
button.bind(command);
if (midiControl < 0)
return;
final IMidiInput midiInput = surface.getMidiInput();
final BindType triggerBindType = this.getTriggerBindType(buttonID);
if (value == -1)
button.bind(midiInput, triggerBindType, midiInputChannel, midiControl);
else
button.bind(midiInput, triggerBindType, midiInputChannel, midiControl, value);
if (hasLight) {
final IntSupplier intSupplier = () -> button.isPressed() ? 1 : 0;
final IntSupplier supp = supplier == null ? intSupplier : supplier;
this.addLight(surface, null, buttonID, button, midiOutputChannel, midiControl, supp, colorIds);
}
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class AbstractControllerSetup method test.
/**
* {@inheritDoc}
*/
@Override
public void test(final TestCallback callback) {
final TestFramework framework = new TestFramework(this.host);
this.getSurfaces().forEach(surface -> {
framework.scheduleFunction(() -> this.host.println("Testing controller: " + this.getClass().getName()));
final ViewManager viewManager = surface.getViewManager();
final ModeManager modeManager = surface.getModeManager();
final int max = this.model.getValueChanger().getUpperBound() - 1;
for (final Views viewID : Views.values()) {
if (viewManager.get(viewID) == null)
continue;
for (final Modes modeID : Modes.values()) {
if (modeManager.get(modeID) == null)
continue;
framework.scheduleFunction(() -> {
this.host.println("- View " + viewID + " Mode " + modeID);
viewManager.setActive(viewID);
modeManager.setActive(modeID);
for (final ButtonID buttonID : ButtonID.values()) {
final IHwButton button = surface.getButton(buttonID);
if (button == null)
continue;
button.trigger(ButtonEvent.DOWN);
button.trigger(ButtonEvent.LONG);
button.trigger(ButtonEvent.UP);
}
for (final ContinuousID continuousID : ContinuousID.values()) {
final IHwContinuousControl continuous = surface.getContinuous(continuousID);
if (continuous == null)
continue;
final TriggerCommand touchCommand = continuous.getTouchCommand();
if (touchCommand != null) {
touchCommand.execute(ButtonEvent.DOWN, 127);
touchCommand.execute(ButtonEvent.LONG, 127);
touchCommand.execute(ButtonEvent.UP, 0);
}
final ContinuousCommand command = continuous.getCommand();
if (command != null) {
command.execute(0);
command.execute(max);
command.execute(max / 2);
}
final PitchbendCommand pitchbendCommand = continuous.getPitchbendCommand();
if (pitchbendCommand != null) {
pitchbendCommand.onPitchbend(0, 0);
pitchbendCommand.onPitchbend(0, 127);
pitchbendCommand.onPitchbend(0, 64);
}
}
});
}
}
});
callback.startTesting();
framework.executeScheduler(callback);
}
use of de.mossgrabers.framework.controller.hardware.IHwButton in project DrivenByMoss by git-moss.
the class AbstractView method simulateButtonPress.
/**
* Simulate pressing a button by sending a button down and up event.
*
* @param buttonID The ID of the button to trigger
*/
protected void simulateButtonPress(final ButtonID buttonID) {
final IHwButton button = this.surface.getButton(buttonID);
final AbstractTriggerCommand<?, ?> triggerCommand = (AbstractTriggerCommand<?, ?>) button.getCommand();
triggerCommand.executeNormal(ButtonEvent.DOWN);
triggerCommand.executeNormal(ButtonEvent.UP);
}
Aggregations