public Instrument getInstrument(Patch patch) { int program = patch.getProgram(); int bank = patch.getBank(); boolean percussion = false; if (patch instanceof ModelPatch) percussion = ((ModelPatch)patch).isPercussion(); for (Instrument instrument : instruments) { Patch patch2 = instrument.getPatch(); int program2 = patch2.getProgram(); int bank2 = patch2.getBank(); if (program == program2 && bank == bank2) { boolean percussion2 = false; if (patch2 instanceof ModelPatch) percussion2 = ((ModelPatch) patch2).isPercussion(); if (percussion == percussion2) return instrument; } } return null; }
public Instrument getInstrument(Patch patch) { int program = patch.getProgram(); int bank = patch.getBank(); boolean percussion = false; if (patch instanceof ModelPatch) percussion = ((ModelPatch)patch).isPercussion(); for (Instrument instrument : instruments) { Patch patch2 = instrument.getPatch(); int program2 = patch2.getProgram(); int bank2 = patch2.getBank(); if (program == program2 && bank == bank2) { boolean percussion2 = false; if (patch2 instanceof ModelPatch) percussion2 = ((ModelPatch)patch2).isPercussion(); if (percussion == percussion2) return instrument; } } return null; }
public Instrument getInstrument(Patch patch) { int program = patch.getProgram(); int bank = patch.getBank(); boolean percussion = false; if (patch instanceof ModelPatch) percussion = ((ModelPatch) patch).isPercussion(); for (Instrument instrument : instruments) { Patch patch2 = instrument.getPatch(); int program2 = patch2.getProgram(); int bank2 = patch2.getBank(); if (program == program2 && bank == bank2) { boolean percussion2 = false; if (patch2 instanceof ModelPatch) percussion2 = ((ModelPatch) patch2).isPercussion(); if (percussion == percussion2) return instrument; } } return null; }
private boolean loadInstruments(List<ModelInstrument> instruments) { if (!isOpen()) return false; if (!loadSamples(instruments)) return false; synchronized (control_mutex) { if (channels != null) for (SoftChannel c : channels) { c.current_instrument = null; c.current_director = null; } for (Instrument instrument : instruments) { String pat = patchToString(instrument.getPatch()); SoftInstrument softins = new SoftInstrument((ModelInstrument) instrument); inslist.put(pat, softins); loadedlist.put(pat, (ModelInstrument) instrument); } } return true; }
public void unloadInstrument(Instrument instrument) { if (instrument == null || (!(instrument instanceof ModelInstrument))) { throw new IllegalArgumentException("Unsupported instrument: " + instrument); } if (!isOpen()) return; String pat = patchToString(instrument.getPatch()); synchronized (control_mutex) { for (SoftChannel c: channels) c.current_instrument = null; inslist.remove(pat); loadedlist.remove(pat); for (int i = 0; i < channels.length; i++) { channels[i].allSoundOff(); } } }
public boolean remapInstrument(Instrument from, Instrument to) { if (from == null) throw new NullPointerException(); if (to == null) throw new NullPointerException(); if (!(from instanceof ModelInstrument)) { throw new IllegalArgumentException("Unsupported instrument: " + from.toString()); } if (!(to instanceof ModelInstrument)) { throw new IllegalArgumentException("Unsupported instrument: " + to.toString()); } if (!isOpen()) return false; synchronized (control_mutex) { if (!loadedlist.containsValue(to)) throw new IllegalArgumentException("Instrument to is not loaded."); unloadInstrument(from); ModelMappedInstrument mfrom = new ModelMappedInstrument( (ModelInstrument)to, from.getPatch()); return loadInstrument(mfrom); } }
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { Instrument ins3 = defsbk.getInstrument(new Patch(0,3)); Instrument ins10 = defsbk.getInstrument(new Patch(0,10)); assertTrue(synth.remapInstrument(ins3, ins10)); Instrument[] loaded = synth.getLoadedInstruments(); for (int i = 0; i < loaded.length; i++) { if(loaded[i].getPatch().getBank() == ins3.getPatch().getBank()) if(loaded[i].getPatch().getProgram() == ins3.getPatch().getProgram()) { assertEquals(loaded[i].getName(), ins10.getName()); break; } } } synth.close(); }
@Override public Instrument getInstrument(Patch patch) { Instrument ins = getInstrument(); Patch p = ins.getPatch(); if (p.getBank() != patch.getBank()) return null; if (p.getProgram() != patch.getProgram()) return null; if (p instanceof ModelPatch && patch instanceof ModelPatch) { if (((ModelPatch)p).isPercussion() != ((ModelPatch)patch).isPercussion()) { return null; } } return ins; }
@Override public Instrument getInstrument(Patch patch) { int program = patch.getProgram(); int bank = patch.getBank(); boolean percussion = false; if (patch instanceof ModelPatch) percussion = ((ModelPatch)patch).isPercussion(); for (Instrument instrument : instruments) { Patch patch2 = instrument.getPatch(); int program2 = patch2.getProgram(); int bank2 = patch2.getBank(); if (program == program2 && bank == bank2) { boolean percussion2 = false; if (patch2 instanceof ModelPatch) percussion2 = ((ModelPatch) patch2).isPercussion(); if (percussion == percussion2) return instrument; } } return null; }
@Override public Instrument getInstrument(Patch patch) { int program = patch.getProgram(); int bank = patch.getBank(); boolean percussion = false; if (patch instanceof ModelPatch) percussion = ((ModelPatch)patch).isPercussion(); for (Instrument instrument : instruments) { Patch patch2 = instrument.getPatch(); int program2 = patch2.getProgram(); int bank2 = patch2.getBank(); if (program == program2 && bank == bank2) { boolean percussion2 = false; if (patch2 instanceof ModelPatch) percussion2 = ((ModelPatch)patch2).isPercussion(); if (percussion == percussion2) return instrument; } } return null; }
@Override public Instrument getInstrument(Patch patch) { int program = patch.getProgram(); int bank = patch.getBank(); boolean percussion = false; if (patch instanceof ModelPatch) percussion = ((ModelPatch) patch).isPercussion(); for (Instrument instrument : instruments) { Patch patch2 = instrument.getPatch(); int program2 = patch2.getProgram(); int bank2 = patch2.getBank(); if (program == program2 && bank == bank2) { boolean percussion2 = false; if (patch2 instanceof ModelPatch) percussion2 = ((ModelPatch) patch2).isPercussion(); if (percussion == percussion2) return instrument; } } return null; }
@Override public void unloadInstrument(Instrument instrument) { if (instrument == null || (!(instrument instanceof ModelInstrument))) { throw new IllegalArgumentException("Unsupported instrument: " + instrument); } if (!isOpen()) return; String pat = patchToString(instrument.getPatch()); synchronized (control_mutex) { for (SoftChannel c: channels) c.current_instrument = null; inslist.remove(pat); loadedlist.remove(pat); for (int i = 0; i < channels.length; i++) { channels[i].allSoundOff(); } } }
public static boolean checkInstrumentNames(Synthesizer theSynthesizer) { boolean containsControlCharacters = false; Instrument[] theLoadedInstruments = theSynthesizer.getLoadedInstruments(); System.out.println("Checking soundbank..."); for(int theInstrumentIndex = 0; theInstrumentIndex < theLoadedInstruments.length; theInstrumentIndex++) { String name = theLoadedInstruments[theInstrumentIndex].getName(); if (containsControlChar(name)) { containsControlCharacters = true; System.out.print("Instrument[" + theInstrumentIndex + "] contains unexpected control characters: "); printName(name); } } return !containsControlCharacters; }
public Instrument[] getAvailableInstruments() { if (!isOpen()) { Soundbank defsbk = getDefaultSoundbank(); if (defsbk == null) return new Instrument[0]; return defsbk.getInstruments(); } synchronized (control_mutex) { ModelInstrument[] inslist_array = new ModelInstrument[availlist.values().size()]; availlist.values().toArray(inslist_array); Arrays.sort(inslist_array, new ModelInstrumentComparator()); return inslist_array; } }
public boolean remapInstrument(Instrument from, Instrument to) { if (from == null) throw new NullPointerException(); if (to == null) throw new NullPointerException(); if (!(from instanceof ModelInstrument)) { throw new IllegalArgumentException("Unsupported instrument: " + from.toString()); } if (!(to instanceof ModelInstrument)) { throw new IllegalArgumentException("Unsupported instrument: " + to.toString()); } if (!isOpen()) return false; synchronized (control_mutex) { if (!loadedlist.containsValue(to) && !availlist.containsValue(to)) throw new IllegalArgumentException("Instrument to is not loaded."); unloadInstrument(from); ModelMappedInstrument mfrom = new ModelMappedInstrument( (ModelInstrument)to, from.getPatch()); return loadInstrument(mfrom); } }