/** * 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()); } } }
private void patchSwitchTest(Receiver synthRcvr, Instrument[] loadedInstrms, int onVel, int interSleepMsec) throws Throwable { ShortMessage noteOnMsg = new ShortMessage(); ShortMessage progChangeMsg = new ShortMessage(); ShortMessage notesOffMsg = new ShortMessage(); for (int j = 0; j < 18; j++) { for (int i = 0; i < 16; i++) { int instIdx = (i + 16 * j) % (loadedInstrms.length); Instrument tgtInst = loadedInstrms[instIdx]; Patch tgtPatch = tgtInst.getPatch(); int noteIdx = 59 + i; int offVel = 0; int timeStampImmediate = -1; notesOffMsg.setMessage(ShortMessage.NOTE_OFF, i, noteIdx, offVel); synthRcvr.send(notesOffMsg, timeStampImmediate); getLogger().debug("Program change chanFromZ={} to {}", i, tgtInst); // Appears that sending bank this way is not univerally understood. // Another way (more official?) is to seperately select the bank as a CC-#0 value. progChangeMsg.setMessage(ShortMessage.PROGRAM_CHANGE, i, tgtPatch.getProgram(), tgtPatch.getBank()); synthRcvr.send(progChangeMsg, timeStampImmediate); noteOnMsg.setMessage(ShortMessage.NOTE_ON, i, noteIdx, onVel); // Nice riff! Note that when we play on channel "10" = 9, we get drum hits rather than "notes" synthRcvr.send(noteOnMsg, timeStampImmediate); Thread.sleep(interSleepMsec); } } } private void drumkitsTest(Receiver synthRcvr, Instrument[] drumInstrums, int onVel, int interSleepMsec) throws Throwable {
int timeStampImmediate = -1; progChangeMsg.setMessage(ShortMessage.PROGRAM_CHANGE, drumChanIdx, tgtPatch.getProgram(), tgtPatch.getBank()); synthRcvr.send(progChangeMsg, timeStampImmediate); for (int noteIdx = 0; noteIdx < 128; noteIdx++) {
sm.setMessage(ShortMessage.PROGRAM_CHANGE, 0, instrument.getPatch().getProgram(), 0);