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 static SF2Instrument newInstrument(SF2Soundbank sf2, String name, Patch patch, SF2Layer... layers) { /* * Create SoundFont2 instrument. */ SF2Instrument ins = new SF2Instrument(sf2); ins.setPatch(patch); ins.setName(name); sf2.addInstrument(ins); /* * Create region for instrument. */ for (int i = 0; i < layers.length; i++) { SF2InstrumentRegion insregion = new SF2InstrumentRegion(); insregion.setLayer(layers[i]); ins.getRegions().add(insregion); } return ins; }
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 static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.sf2"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis); assertTrue(sf2.getInstruments().length == 1); Patch patch = sf2.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
public static void main(String[] args) throws Exception { // RealTime: Scale/Octave tuning in 1-byte format int[] msg = {0xf0,0x7f,0x7f,0x08,0x08,0x03,0x7f,0x7f, 5,10,15,20,25,30,35,40,45,50,51,52, 0xf7}; int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52}; byte[] bmsg = new byte[msg.length]; for (int i = 0; i < bmsg.length; i++) bmsg[i] = (byte)msg[i]; SoftTuning tuning = new SoftTuning(new Patch(8,32),bmsg); double[] tunings = tuning.getTuning(); for (int i = 0; i < tunings.length; i++) assertTrue(Math.abs(tunings[i]-(i*100 + (oct[i%12]-64))) < 0.00001); assertEquals(tuning.getPatch().getProgram(), 32); assertEquals(tuning.getPatch().getBank(), 8); }
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { InputStream badis = new BadInputStream(bis); Soundbank dls = new DLSSoundbankReader().getSoundbank(badis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 1); } synth.close(); }
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 1); synth.unloadInstrument(ins2); assertTrue(synth.getLoadedInstruments().length == 0); } synth.close(); }
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadInstruments(sbk, new Patch[] {ins2.getPatch()}); assertTrue(synth.getLoadedInstruments().length == 1); } synth.close(); }
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(); }
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.sf2"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { Soundbank sf2 = new SF2SoundbankReader().getSoundbank(bis); assertTrue(sf2.getInstruments().length == 1); Patch patch = sf2.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.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; }
public static void main(String[] args) throws Exception { File file = new File(System.getProperty("test.src", "."), "ding.dls"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); try { Soundbank dls = new DLSSoundbankReader().getSoundbank(bis); assertTrue(dls.getInstruments().length == 1); Patch patch = dls.getInstruments()[0].getPatch(); assertTrue(patch.getProgram() == 0); assertTrue(patch.getBank() == 0); } finally { bis.close(); } }
public static void main(String[] args) throws Exception { AudioSynthesizer synth = new SoftSynthesizer(); synth.openStream(null, null); Soundbank defsbk = synth.getDefaultSoundbank(); if(defsbk != null) { synth.unloadAllInstruments(defsbk); SimpleSoundbank sbk = new SimpleSoundbank(); SimpleInstrument ins = new SimpleInstrument(); ins.setPatch(new Patch(0,1)); sbk.addInstrument(ins); SimpleInstrument ins2 = new SimpleInstrument(); ins2.setPatch(new Patch(0,2)); sbk.addInstrument(ins2); synth.loadAllInstruments(sbk); assertTrue(synth.getLoadedInstruments().length == 2); } synth.close(); }
public void setPatch(Patch patch) { if (patch instanceof ModelPatch && ((ModelPatch)patch).isPercussion()) { druminstrument = true; bank = patch.getBank(); preset = patch.getProgram(); } else { druminstrument = false; bank = patch.getBank(); preset = patch.getProgram(); } }
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; }
public void setPatch(Patch patch) { if (patch instanceof ModelPatch && ((ModelPatch)patch).isPercussion()) { percussion = true; bank = patch.getBank(); preset = patch.getProgram(); } else { percussion = false; bank = patch.getBank(); preset = patch.getProgram(); } }
public final Patch getPatchAlias() { Patch patch = getPatch(); int program = patch.getProgram(); int bank = patch.getBank(); if (bank != 0) return patch; boolean percussion = false; if (getPatch() instanceof ModelPatch) percussion = ((ModelPatch)getPatch()).isPercussion(); if (percussion) return new Patch(0x78 << 7, program); else return new Patch(0x79 << 7, program); }
public void setPatch(Patch patch) { if (patch instanceof ModelPatch && ((ModelPatch) patch).isPercussion()) { bank = 128; preset = patch.getProgram(); } else { bank = patch.getBank() >> 7; preset = patch.getProgram(); } }
public int compare(Instrument arg0, Instrument arg1) { Patch p0 = arg0.getPatch(); Patch p1 = arg1.getPatch(); int a = p0.getBank() * 128 + p0.getProgram(); int b = p1.getBank() * 128 + p1.getProgram(); if (p0 instanceof ModelPatch) { a += ((ModelPatch)p0).isPercussion() ? 2097152 : 0; } if (p1 instanceof ModelPatch) { b += ((ModelPatch)p1).isPercussion() ? 2097152 : 0; } return a - b; }
SoftTuning getTuning(Patch patch) { String t_id = patchToString(patch); SoftTuning tuning = tunings.get(t_id); if (tuning == null) { tuning = new SoftTuning(patch); tunings.put(t_id, tuning); } return tuning; }
public boolean loadInstruments(Soundbank soundbank, Patch[] patchList) { List<ModelInstrument> instruments = new ArrayList<ModelInstrument>(); for (Patch patch: patchList) { Instrument ins = soundbank.getInstrument(patch); if (ins == null || !(ins instanceof ModelInstrument)) { throw new IllegalArgumentException( "Unsupported instrument: " + ins); } instruments.add((ModelInstrument)ins); } return loadInstruments(instruments); }
public void unloadInstruments(Soundbank soundbank, Patch[] patchList) { if (soundbank == null || !isSoundbankSupported(soundbank)) throw new IllegalArgumentException("Unsupported soundbank: " + soundbank); if (!isOpen()) return; for (Patch pat: patchList) { Instrument ins = soundbank.getInstrument(pat); if (ins instanceof ModelInstrument) { unloadInstrument(ins); } } }