当前位置: 首页>>代码示例>>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;未经允许,请勿转载。