當前位置: 首頁>>代碼示例>>Java>>正文


Java Synthesizer類代碼示例

本文整理匯總了Java中javax.sound.midi.Synthesizer的典型用法代碼示例。如果您正苦於以下問題:Java Synthesizer類的具體用法?Java Synthesizer怎麽用?Java Synthesizer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Synthesizer類屬於javax.sound.midi包,在下文中一共展示了Synthesizer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDefaultProvider

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:31,代碼來源:JDK13Services.java

示例2: playWarningSound

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
private static void playWarningSound() {
//        if (2 > 1) {
//            return;
//        }

        try {
//            int velocity = 127;    // max volume
            int velocity = 90;    // max volume
            int sound = 65;
            Synthesizer synthesizer = MidiSystem.getSynthesizer();
            synthesizer.open();
            MidiChannel channel = synthesizer.getChannels()[9];  // drums channel.
            for (int i = 0; i < 10; i++) {
                Thread.sleep(100);
                channel.noteOn(sound + i, velocity);
                Thread.sleep(100);
                channel.noteOff(sound + i);
            }
        } catch (MidiUnavailableException | InterruptedException e1) {
            e1.printStackTrace();
        }
    }
 
開發者ID:teddyted,項目名稱:iSeleda,代碼行數:23,代碼來源:Dialogs.java

示例3: getDefaultProvider

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:JDK13Services.java

示例4: isMidiInstalled

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
public static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:OpenClose.java

示例5: isMidiInstalled

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
private static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = !(device instanceof Sequencer)
                    && !(device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ClosedReceiver.java

示例6: doAll

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
private static void doAll() throws Exception {
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i=0; i < infos.length; i++) {
        MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
        if ((! (device instanceof Sequencer)) &&
            (! (device instanceof Synthesizer)) &&
            (device.getMaxReceivers() > 0 || device.getMaxReceivers() == -1)) {

            System.out.println("--------------");
            System.out.println("Testing MIDI device: " + infos[i]);
            testDevice(device);
        }
        if (infos.length==0) {
            System.out.println("No MIDI devices available!");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:MidiOutGetMicrosecondPositionBug.java

示例7: isMidiInstalled

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
public static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:MidiOutGetMicrosecondPositionBug.java

示例8: checkInstrumentNames

import javax.sound.midi.Synthesizer; //導入依賴的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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ExtraCharInSoundbank.java

示例9: main

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    // the internal synthesizer needs a soundcard to work properly
    if (!isSoundcardInstalled()) {
        return;
    }
    Synthesizer theSynth = MidiSystem.getSynthesizer();
    System.out.println("Got synth: "+theSynth);
    theSynth.open();
    try {
        Soundbank theSoundbank = theSynth.getDefaultSoundbank();
        System.out.println("Got soundbank: "+theSoundbank);
        theSynth.loadAllInstruments(theSoundbank);
        try {
                if (!checkInstrumentNames(theSynth)) {
                        throw new Exception("Test failed");
                }
        } finally {
                theSynth.unloadAllInstruments(theSoundbank);
        }
    } finally {
        theSynth.close();
    }
    System.out.println("Test passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ExtraCharInSoundbank.java

示例10: openInput

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
public static void openInput() throws Exception {
	setup();

	if (bUseDefaultSynthesizer) {
		Synthesizer synth = MidiSystem.getSynthesizer();
		synth.open();
		r = synth.getReceiver();
		try {
			Transmitter t = launchpad_s_plus.Launchpad.getInputDevice()
					.getTransmitter();
			t.setReceiver(r);
		} catch (MidiUnavailableException e) {
			out("wasn't able to connect the device's Transmitter to the default Synthesizer:");
			out(e);
			launchpad_s_plus.Launchpad.getInputDevice().close();
			System.exit(1);
		}
	}

	out("\nNow taking input.");

}
 
開發者ID:helionmusic,項目名稱:launchpad_s_plus,代碼行數:23,代碼來源:MidiInDump.java

示例11: getSynth

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
public Synthesizer getSynth() {
	try {
		if(!this.synth.isOpen()){
			this.synth.open();
			if(!isSoundbankLoaded( false )){
				String path = MidiConfigUtils.getSoundbankPath(this.context);
				if( path != null ){
					this.loadSoundbank(new File(TGExpressionResolver.getInstance(this.context).resolve(path)));
				}
				
				if(!isSoundbankLoaded( true )){
					this.loadSoundbank(this.synth.getDefaultSoundbank());
				}
				
				if(!isSoundbankLoaded( true )){
					new SBAssistant(this.context, this).process();
				}
			}
		}
		this.synthesizerLoaded = this.synth.isOpen();
	} catch (Throwable throwable) {
		throwable.printStackTrace();
	}
	return this.synth;
}
 
開發者ID:theokyr,項目名稱:TuxGuitar-1.3.1-fork,代碼行數:26,代碼來源:MidiPortSynthesizer.java

示例12: getSynth

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
public Synthesizer getSynth() {
	try {
		if(!this.synth.isOpen()){
			this.synth.open();
			if(!isSoundbankLoaded( false )){
				if(!isSoundbankLoaded( true )){
					this.loadSoundbank(this.synth.getDefaultSoundbank());
				}
			}
		}
		this.synthesizerLoaded = this.synth.isOpen();
	} catch (Throwable throwable) {
		throwable.printStackTrace();
	}
	return this.synth;
}
 
開發者ID:theokyr,項目名稱:TuxGuitar-1.3.1-fork,代碼行數:17,代碼來源:MidiPortSynthesizer.java

示例13: findAudioSynthesizer

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
private Synthesizer findAudioSynthesizer() throws MidiUnavailableException, ClassNotFoundException {
	Class<?> audioSynth = Class.forName("com.sun.media.sound.AudioSynthesizer");

	// First check if default synthesizer is AudioSynthesizer.
	Synthesizer synth = MidiSystem.getSynthesizer();
	if (audioSynth.isAssignableFrom(synth.getClass())) {
		return synth;
	}

	// If default synthesizer is not AudioSynthesizer, check others.
	MidiDevice.Info[] midiDeviceInfo = MidiSystem.getMidiDeviceInfo();
	for (int i = 0; i < midiDeviceInfo.length; i++) {
		MidiDevice dev = MidiSystem.getMidiDevice(midiDeviceInfo[i]);
		if (audioSynth.isAssignableFrom(dev.getClass())) {
			return (Synthesizer)dev;
		}
	}
	return null;
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:20,代碼來源:URLAudioSource.java

示例14: installImp

import javax.sound.midi.Synthesizer; //導入依賴的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();
	}
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:18,代碼來源:SynthesizerDescriptor.java

示例15: getVoiceList

import javax.sound.midi.Synthesizer; //導入依賴的package包/類
/**
 * Return a list of voices for a device. if device does not provide a list
 * return null.
 * 
 * @param dev
 * @param channel
 * @return
 */
public PatchNameMap getVoiceList(MidiDevice dev, int channel) {
	if (! (dev instanceof SynthWrapper) ) return null;
	assert (dev instanceof SynthWrapper);
	if (channel < 0 ) return null;  // Make channel -1 someone elses problem since we will get an array exception
	// use first part of the device string.
	// TODO think ??? Still thinking PJL ?? :) /PJS
	// Still think this is all a bit ugly PJL
	
	if(((SynthWrapper)dev).getRealDevice() instanceof Synthesizer)	{
		return new PatchNameMap((Synthesizer)dev, channel);
	} else if (((SynthWrapper)dev).getRealDevice() instanceof DrumMapper ){
		return null;
	} else	{
		String lookup = dev.getDeviceInfo().toString().split("\\s")[0];

		PatchNameMap vl = voiceTreeMap.get(lookup);
		if (vl == null) {
			System.out.println(" Could not find voice map for \"" + lookup
					+ "\"");
			return voiceTreeMap.get("default");
		}
		return vl;
	}
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:33,代碼來源:MidiResource.java


注:本文中的javax.sound.midi.Synthesizer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。