com.sun.media.sound.ModelPatch Java Examples

The following examples show how to use com.sun.media.sound.ModelPatch. 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: GervillSoundbankFactory.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Instrument createInstrument(TGContext context, GervillProgram program) throws Exception {
	Instrument instrument = null;
	if( program.getSoundbankPath() != null && program.getSoundbankPath().length() > 0 ) {
		Soundbank soundbank = this.createSoundbank(context, program.getSoundbankPath());
		
		boolean percussion = (program.getBank() == 128);
		Patch patch = new ModelPatch((percussion ? 0 : program.getBank()), program.getProgram(), percussion);
		instrument = soundbank.getInstrument(patch);
	}
	if( instrument == null ) {
		instrument = getDefaultInstrument(context, program);
	}
	if( instrument != null ) {
		((SF2Instrument) instrument).setPatch(new Patch(0, 0));
	}
	return instrument;
}
 
Example #2
Source File: GervillSoundbankFactory.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Instrument getDefaultInstrument(TGContext context, GervillProgram program) throws Exception {
	synchronized (GervillProcessorFactory.class) {
		if( defaultInstruments == null ) {
			defaultInstruments = new Instrument[129][128];
			
			Soundbank soundbank = null;
			String soundbankPath = new GervillSettings(context).getSoundbankPath();
			if( soundbankPath != null && soundbankPath.length() > 0 ) {
				soundbank = this.createSoundbank(context, soundbankPath);
			}
			if( soundbank == null ) {
				soundbank = EmergencySoundbank.createSoundbank();
			}
			if( soundbank != null ) {
				Instrument[] instruments = soundbank.getInstruments();
				for(Instrument instrument : instruments) {
					ModelPatch patch = (ModelPatch) instrument.getPatch();
					if( patch.getProgram() < 128 && patch.getBank() < 128 ) {
						defaultInstruments[patch.isPercussion() ? 128 : patch.getBank()][patch.getProgram()] = instrument;
					}
				}
			}
		}
	}
	return defaultInstruments[program.getBank()][program.getProgram()];
}
 
Example #3
Source File: SF2Soundbank.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #4
Source File: SimpleSoundbank.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #5
Source File: SimpleInstrument.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
    }
}
 
Example #6
Source File: SF2Instrument.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
    }
}
 
Example #7
Source File: MidiSynthesizerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelPatch toModelPatch(Patch patch) {
	if( patch instanceof ModelPatch ) {
		return (ModelPatch) patch;
	}
	return new ModelPatch(patch.getBank() == PERCUSSION_BANK ? 0 : patch.getBank(), patch.getProgram(), patch.getBank() == PERCUSSION_BANK);
}
 
Example #8
Source File: MidiSynthesizerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean isSamePatch(Patch p1, Patch p2) {
	ModelPatch mp1 = this.toModelPatch(p1);
	ModelPatch mp2 = this.toModelPatch(p2);
	
	return (mp1.getBank() == mp2.getBank() && mp1.getProgram() == mp2.getProgram() && mp1.isPercussion() == mp2.isPercussion());
}
 
Example #9
Source File: SimpleInstrument.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ModelPatch getPatch() {
    return new ModelPatch(bank, preset, percussion);
}
 
Example #10
Source File: SF2Instrument.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Patch getPatch() {
    if (bank == 128)
        return new ModelPatch(0, preset, true);
    else
        return new ModelPatch(bank << 7, preset, false);
}