本文整理汇总了Java中javax.sound.midi.Instrument类的典型用法代码示例。如果您正苦于以下问题:Java Instrument类的具体用法?Java Instrument怎么用?Java Instrument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Instrument类属于javax.sound.midi包,在下文中一共展示了Instrument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
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;
}
示例2: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
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;
}
示例3: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
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;
}
示例4: loadInstruments
import javax.sound.midi.Instrument; //导入依赖的package包/类
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;
}
示例5: unloadInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
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();
}
}
}
示例6: remapInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
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);
}
}
示例7: main
import javax.sound.midi.Instrument; //导入依赖的package包/类
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();
}
示例8: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
@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;
}
示例9: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
@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;
}
示例10: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
@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;
}
示例11: getInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
@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;
}
示例12: unloadInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
@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();
}
}
}
示例13: checkInstrumentNames
import javax.sound.midi.Instrument; //导入依赖的package包/类
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;
}
示例14: getAvailableInstruments
import javax.sound.midi.Instrument; //导入依赖的package包/类
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;
}
}
示例15: remapInstrument
import javax.sound.midi.Instrument; //导入依赖的package包/类
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);
}
}