use of de.mossgrabers.framework.daw.midi.IMidiOutput in project DrivenByMoss by git-moss.
the class MaschineControllerSetup method flush.
/**
* {@inheritDoc}
*/
@Override
public void flush() {
super.flush();
final MaschineControlSurface surface = this.getSurface();
final TouchstripCommand command = (TouchstripCommand) surface.getContinuous(ContinuousID.CROSSFADER).getCommand();
if (command != null)
command.updateValue();
if (this.maschine == Maschine.STUDIO) {
// Update main VU
final IMidiOutput midiOutput = surface.getMidiOutput();
final int value;
if (this.encoderManager.isParameterMode()) {
final EncoderMode activeEncoderMode = this.encoderManager.getActiveEncoderMode();
switch(activeEncoderMode) {
case MASTER_VOLUME:
value = this.valueChanger.toMidiValue(this.model.getMasterTrack().getVolume());
break;
case MASTER_PANORAMA:
value = this.valueChanger.toMidiValue(this.model.getMasterTrack().getPan());
break;
case SELECTED_TRACK_VOLUME:
case SELECTED_TRACK_PANORAMA:
final ITrack track;
final Optional<ITrack> trackOptional = this.model.getTrackBank().getSelectedItem();
if (trackOptional.isPresent())
track = trackOptional.get();
else
track = EmptyTrack.INSTANCE;
value = this.valueChanger.toMidiValue(activeEncoderMode == EncoderMode.SELECTED_TRACK_VOLUME ? track.getVolume() : track.getPan());
break;
case CUE_VOLUME:
value = this.valueChanger.toMidiValue(this.model.getProject().getCueVolume());
break;
case CUE_MIX:
value = this.valueChanger.toMidiValue(this.model.getProject().getCueMix());
break;
case METRONOME_VOLUME:
value = this.valueChanger.toMidiValue(this.model.getTransport().getMetronomeVolume());
break;
default:
value = 0;
break;
}
} else {
final ITrack track;
if (this.encoderManager.isActiveEncoderMode(EncoderMode.SELECTED_TRACK_VOLUME)) {
final Optional<ITrack> trackOptional = this.model.getTrackBank().getSelectedItem();
if (trackOptional.isPresent())
track = trackOptional.get();
else
track = EmptyTrack.INSTANCE;
} else
track = this.model.getMasterTrack();
value = this.valueChanger.toMidiValue(track.getVu());
}
midiOutput.sendCC(MaschineControlSurface.MONITOR_ENCODER, value);
}
}
use of de.mossgrabers.framework.daw.midi.IMidiOutput in project DrivenByMoss by git-moss.
the class GenericFlexiControllerSetup method createSurface.
/**
* {@inheritDoc}
*/
@Override
protected void createSurface() {
final IMidiAccess midiAccess = this.factory.createMidiAccess();
final IMidiOutput output = midiAccess.createOutput();
final String inputName;
if (this.configuration.isMPEEndabled())
inputName = "Generic Flexi (MPE)";
else
inputName = this.configuration.getKeyboardChannel() < 0 ? null : "Generic Flexi";
final List<String> filters = this.getMidiFilters();
final IMidiInput input = midiAccess.createInput(inputName, filters.toArray(new String[filters.size()]));
final GenericFlexiControlSurface surface = new GenericFlexiControlSurface(this.host, this.configuration, this.colorManager, output, input);
this.surfaces.add(surface);
this.registerHandlers(surface);
this.configuration.setCommandObserver(this);
}
use of de.mossgrabers.framework.daw.midi.IMidiOutput in project DrivenByMoss by git-moss.
the class GenericFlexiControllerSetup method init.
/**
* {@inheritDoc}
*/
@Override
public void init() {
super.init();
// Load program name file and create selection list if present
final Optional<FileEx> programsFileOpt = this.configuration.getProgramsFile();
if (programsFileOpt.isEmpty())
return;
try {
final FileEx programsFile = programsFileOpt.get();
final String nameWithoutType = programsFile.getNameWithoutType();
this.banks.addAll(ProgramBank.parse(programsFile.readUTF8()));
final IEnumSetting[] bankSettings = new IEnumSetting[this.banks.size()];
for (int i = 0; i < this.banks.size(); i++) {
final int bankPos = i;
final ProgramBank pb = this.banks.get(bankPos);
final String[] programs = pb.getPrograms();
final String[] opts = new String[programs.length + 1];
System.arraycopy(programs, 0, opts, 1, programs.length);
opts[0] = PROGRAM_NONE;
bankSettings[bankPos] = this.documentSettings.getEnumSetting(pb.getName(), nameWithoutType + " Program Banks", opts, opts[0]);
bankSettings[bankPos].addValueObserver(value -> {
final int program = pb.lookupProgram(value);
if (program < 0)
return;
final GenericFlexiControlSurface surface = this.getSurface();
if (surface == null)
return;
final IMidiOutput midiOutput = surface.getMidiOutput();
if (midiOutput != null)
midiOutput.sendProgramChange(pb.getMidiChannel(), pb.getMSB(), pb.getLSB(), program);
final int channel = pb.getMidiChannel();
for (int b = 0; b < bankSettings.length; b++) {
if (bankPos != b && this.banks.get(b).getMidiChannel() == channel)
bankSettings[b].set(PROGRAM_NONE);
}
});
}
} catch (final IOException ex) {
this.host.error("Could not load programs file.", ex);
} catch (final ParseException ex) {
this.host.error("Could not parse programs file.", ex);
}
}
use of de.mossgrabers.framework.daw.midi.IMidiOutput in project DrivenByMoss by git-moss.
the class BeatstepControllerSetup method createSurface.
/**
* {@inheritDoc}
*/
@Override
protected void createSurface() {
final IMidiAccess midiAccess = this.factory.createMidiAccess();
final IMidiOutput output = midiAccess.createOutput();
final IMidiInput input = midiAccess.createInput("Control/Pads", "82????", "92????", "A2????");
// Sequencer 1 is on channel 1
final INoteInput seqNoteInput = input.createNoteInput("Hardware Sequencer", "90????", "80????");
final Integer[] table = new Integer[128];
for (int i = 0; i < 128; i++) {
// Block the Shift key
table[i] = Integer.valueOf(i == 7 ? -1 : i);
}
seqNoteInput.setKeyTranslationTable(table);
this.surfaces.add(new BeatstepControlSurface(this.host, this.colorManager, this.configuration, output, input));
}
use of de.mossgrabers.framework.daw.midi.IMidiOutput in project DrivenByMoss by git-moss.
the class GenericFlexiControlSurface method reflectValue.
/**
* Send back the current value type of a command slot to the device.
*
* @param slot The slot
* @param value The value to reflect
*/
private void reflectValue(final CommandSlot slot, final int value) {
if (value < 0 || value > 127) {
this.host.error(String.format("Attempt to reflect value out of range from slot command: %s Value: %d", slot.getCommand().getName(), Integer.valueOf(value)));
return;
}
final IMidiOutput output = this.getMidiOutput();
final int midiChannel = slot.getMidiChannel();
// Cannot reflect "All" setting
if (midiChannel > 15)
return;
switch(slot.getType()) {
case CommandSlot.TYPE_NOTE:
output.sendNoteEx(midiChannel, slot.getNumber(), value);
break;
case CommandSlot.TYPE_CC:
output.sendCCEx(midiChannel, slot.getNumber(), value);
break;
case CommandSlot.TYPE_PITCH_BEND:
output.sendPitchbend(midiChannel, 0, value);
break;
default:
// Other types not supported
break;
}
}
Aggregations