本文整理汇总了Java中javax.sound.midi.MidiSystem.getSoundbank方法的典型用法代码示例。如果您正苦于以下问题:Java MidiSystem.getSoundbank方法的具体用法?Java MidiSystem.getSoundbank怎么用?Java MidiSystem.getSoundbank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.getSoundbank方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
boolean failed = false;
try {
String filename = "GetSoundBankIOException.java";
System.out.println("Opening "+filename+" as soundbank...");
File midiFile = new File(System.getProperty("test.src", "."), filename);
MidiSystem.getSoundbank(midiFile);
//Soundbank sBank = MidiSystem.getSoundbank(new NonMarkableIS());
System.err.println("InvalidMidiDataException was not thrown!");
failed = true;
} catch (InvalidMidiDataException invMidiEx) {
System.err.println("InvalidMidiDataException was thrown. OK.");
} catch (IOException ioEx) {
System.err.println("Unexpected IOException was caught!");
System.err.println(ioEx.getMessage());
ioEx.printStackTrace();
failed = true;
}
if (failed) throw new Exception("Test FAILED!");
System.out.println("Test passed.");
}
示例2: loadSoundbank
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void loadSoundbank(List<Patch> patchList, String soundbankPath) throws Throwable {
Soundbank soundbank = null;
if( soundbankPath == null || soundbankPath.length() == 0 ){
soundbank = this.synthesizer.getDefaultSoundbank();
} else{
soundbank = MidiSystem.getSoundbank(new File(soundbankPath));
}
Iterator<Patch> it = patchList.iterator();
while( it.hasNext() ){
Patch patch = (Patch)it.next();
boolean percussion = (patch.getBank() == 128);
int bank = (percussion ? 0 : patch.getBank());
int program = patch.getProgram();
Instrument instrument = soundbank.getInstrument(createModelPatch(bank, program, percussion));
if( instrument != null ){
this.synthesizer.loadInstrument(instrument);
}
}
}
示例3: findInstrument
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public Instrument findInstrument(Patch patch) {
Instrument instrument = null;
try {
Patch resourcePatch = patch;
InputStream inputStream = this.findResource(resourcePatch);
if( inputStream == null ) {
resourcePatch = this.toDefaultPatch(patch);
if( resourcePatch.getBank() != patch.getBank() || resourcePatch.getProgram() != patch.getProgram() ) {
inputStream = this.findResource(resourcePatch);
}
}
if( inputStream != null ) {
Soundbank soundbank = MidiSystem.getSoundbank(inputStream);
if( soundbank != null ) {
instrument = soundbank.getInstrument(this.toModelPatch(resourcePatch));
}
}
if( instrument != null ) {
this.setInstrumentPatch(instrument, patch);
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return instrument;
}
示例4: installImp
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
@Override
protected void installImp(ProjectContainer project) {
super.installImp(project);
if(soundBankFileName != null)
try
{
Soundbank soundbank;
if(midiDevice instanceof SynthWrapper)
soundbank = ((SynthWrapper)midiDevice).getSoundbank(new File(soundBankFileName));
else
soundbank = MidiSystem.getSoundbank(new File(soundBankFileName));
((Synthesizer)midiDevice).loadAllInstruments(soundbank);
System.out.println("Soundbank loaded");
} catch(Exception e){
e.printStackTrace();
}
}
示例5: getSoundBank
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private Soundbank getSoundBank(Instrument instrument) throws IOException {
System.out.println("Loading soundfont " + instrument.getSoundFont());
Soundbank sb = null;
if (!soundBanks.containsKey(instrument.getSoundFont())) {
File file = new File(instrument.getSoundFont());
if (file.exists()) {
try {
sb = MidiSystem.getSoundbank(file);
} catch (InvalidMidiDataException e) {
throw new IOException("Could not load soundbank " + file.getPath(), e);
}
}
soundBanks.put(instrument.getSoundFont(), sb);
}
sb = soundBanks.get(instrument.getSoundFont());
return sb;
}
示例6: getLotroSoundbank
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static Soundbank getLotroSoundbank() throws InvalidMidiDataException, IOException
{
if (lotroSoundbank == null)
{
try
{
lotroSoundbank = MidiSystem.getSoundbank(soundFontFile);
}
catch (NullPointerException npe)
{
// JARSoundbankReader throws a NullPointerException if the file doesn't exist
StackTraceElement trace = npe.getStackTrace()[0];
if (trace.getClassName().equals("com.sun.media.sound.JARSoundbankReader")
&& trace.getMethodName().equals("isZIP"))
{
throw new IOException("Soundbank file not found");
}
else
{
throw npe;
}
}
}
return lotroSoundbank;
}
示例7: main
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length >= 2)
try {
File midi_file = new File(args[0]);
if (!midi_file.exists())
throw new FileNotFoundException();
Sequence sequence = MidiSystem.getSequence(midi_file);
Soundbank soundbank = null;
if (args.length >= 3) {
File soundbank_file = new File(args[2]);
if (soundbank_file.exists())
soundbank = MidiSystem.getSoundbank(soundbank_file);
}
render(soundbank, sequence, new File(args[1]));
System.exit(0);
} catch (Exception e) {
System.out.println(e.toString());
System.out.println();
}
System.out.println("MIDI to WAVE Render: usages:");
System.out
.println("java Midi2WavRender <midi_file_in> <wave_file_out> <soundbank_file>");
System.exit(1);
}
示例8: loadSoundbank
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void loadSoundbank(File newsbkfile) {
try {
sbk_errmsg = null;
Soundbank newsbk = MidiSystem.getSoundbank(newsbkfile);
if (sbk != null)
softsynth.unloadAllInstruments(sbk);
sbkfile = newsbkfile;
sbk = newsbk;
softsynth.loadAllInstruments(sbk);
} catch (Throwable e1) {
sbk_errmsg = e1.toString();
}
}
示例9: loadBank
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static void loadBank(MidiDevice mididevice) throws Exception
{
Soundbank soundbank = MidiSystem.getSoundbank(new File("soundfonts/Club.SF2"));
((Synthesizer)mididevice).loadAllInstruments(soundbank);
}
示例10: main
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static void main(String args[]) {
try {
for (MidiDevice.Info inf : MidiSystem.getMidiDeviceInfo()) {
if (inf.getName().equals("Gervill")) {
Synthesizer dev = (Synthesizer) MidiSystem.getMidiDevice(inf);
dev.open();
// String sf = "/home/pjl/frinika/soundfonts/Club.SF2";
// String sf = "/home/pjl/frinika/soundfonts/8MBGMSFX.SF2";
String sf="/home/pjl/frinika/soundfonts/ChoriumRevA.SF2";
Soundbank sbk;
sbk = MidiSystem.getSoundbank(new File(sf));
dev.loadAllInstruments(sbk);
Instrument insts[] = dev.getLoadedInstruments();
// Instrument insts[] = dev.getAvailableInstruments();
for (Instrument ins : insts) {
System.out.print("\n ***************** INST :" + ins);
System.out.println(ins.getName() + " " + ins.getPatch().getBank() + " " + ins.getPatch().getProgram() + " ");
Method getChannels = ins.getClass().getMethod(
"getChannels");
boolean[] channels = null;
if (getChannels != null) {
channels = (boolean[]) getChannels.invoke(ins, (Object[]) null);
if (channels[9]) {
Method getKeys = ins.getClass().getMethod(
"getKeys");
if (getKeys != null) {
String[] keyNames = (String[]) getKeys.invoke(ins, (Object[]) null);
int i = 0;
for (String keyname : keyNames) {
if (keyname != null) System.out.println((i++) + ":" + keyname);
}
}
}
}
}
}
}
System.out.println(" HIT cntrl-C ");
Thread.sleep(100000);
} catch (Exception ex) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex1) {
Logger.getLogger(ListKeyNames.class.getName()).log(Level.SEVERE, null, ex1);
}
ex.printStackTrace();
}
}