use of de.mossgrabers.controller.generic.flexihandler.utils.ProgramBank 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);
}
}
Aggregations