Java Code Examples for javax.sound.midi.MidiSystem#getSoundbank()

The following examples show how to use javax.sound.midi.MidiSystem#getSoundbank() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetSoundBankIOException.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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.");
}
 
Example 2
Source File: MidiToAudioSynth.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);
		}
	}
}
 
Example 3
Source File: MidiSynthesizerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example 4
Source File: GervillSoundbankFactory.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Soundbank createSoundbank(TGContext context, String soundbankPath) {
	try {
		return MidiSystem.getSoundbank(new File(TGExpressionResolver.getInstance(context).resolve(soundbankPath)));
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}