/** * Loads a MIDI instrument by name. Throws exception if not found. * * @param synthesizer the synthesizer. * @param instrumentName the instrument name. * @return the instrument or {@code null} if the instrument couldn't be loaded. */ public static Instrument loadInstrument(Synthesizer synthesizer, String instrumentName) { Optional<Instrument> result = Arrays.stream(synthesizer.getAvailableInstruments()) .filter(instrument -> instrument.getName().equals(instrumentName)).findFirst(); if (!result.isPresent()) { throw new IllegalArgumentException("Instrument named " + instrumentName + " is not available"); } return synthesizer.loadInstrument(result.get()) ? result.get() : null; }
/** * Sets the synthesizer instrument from the currently selected bank of instruments. * * @param synthesizer the synthesizer. * @param channel the channel. * @param instrumentName the instrument name. * @return the new instrument. */ public static Instrument setInstrument(Synthesizer synthesizer, int channel, String instrumentName) { Optional<Instrument> result = Arrays.stream(synthesizer.getAvailableInstruments()) .filter(instrument -> instrument.getName().equals(instrumentName)).findFirst(); if (!result.isPresent()) { throw new IllegalArgumentException("Instrument named " + instrumentName + " is not available"); } return setInstrument(synthesizer, channel, result.get().getPatch().getProgram()); }
/** * Logs available synthesizer instruments. */ public void logInstruments() { for (Instrument instrument : synthesizer.getAvailableInstruments()) { logger.info("Instrument {} ({}/{})", instrument.getName(), instrument.getPatch().getBank(), instrument.getPatch().getProgram()); } } }
for (Instrument inst : availInstrms) { Patch instPatch = inst.getPatch(); getLogger().info("Instrument name=[{}] class=[{}] data-class=[{}] ", inst.getName(), inst.getClass(), inst.getDataClass()); all.append("[" + inst.toString() + "], "); String instrDumpTxt = inst.toString();