use of de.mossgrabers.framework.utils.FileEx in project DrivenByMoss by git-moss.
the class GenericFlexiConfiguration method getProgramsFile.
/**
* Gets the file with program names, if present. This is the stored properties file name with
* the ending "programs".
*
* @return The file or null if not present
*/
public Optional<FileEx> getProgramsFile() {
if (this.filename == null || this.filename.isBlank())
return Optional.empty();
final FileEx file = new FileEx(this.filename);
final String name = file.getNameWithoutType();
final FileEx programsFile = new FileEx(file.getParent(), name + ".programs");
final boolean exists = programsFile.exists();
this.host.println("Scanning for: " + programsFile.getAbsolutePath() + " (" + (exists ? "present" : "not present") + ")");
return exists ? Optional.of(programsFile) : Optional.empty();
}
use of de.mossgrabers.framework.utils.FileEx 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