当前位置: 首页>>代码示例>>Java>>正文


Java MidiSystem.getSynthesizer方法代码示例

本文整理汇总了Java中javax.sound.midi.MidiSystem.getSynthesizer方法的典型用法代码示例。如果您正苦于以下问题:Java MidiSystem.getSynthesizer方法的具体用法?Java MidiSystem.getSynthesizer怎么用?Java MidiSystem.getSynthesizer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.midi.MidiSystem的用法示例。


在下文中一共展示了MidiSystem.getSynthesizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: playWarningSound

import javax.sound.midi.MidiSystem; //导入方法依赖的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

示例2: open

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private void open () throws MidiUnavailableException{
        synth = MidiSystem.getSynthesizer();
        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
        MidiDevice.Info msInfo = null;
        StringBuilder sb = new StringBuilder();
        sb.append("Available MidiDevice are\n");
        for ( MidiDevice.Info i:infos ){
            if ( i.toString().contains("Microsoft GS Wavetable Synth") ){
                msInfo = i;
                sb.append(" *****");
            }
            sb.append("\t" + i.toString() + ": " + i.getDescription() + '\n');
        }
//        MidiDevice msDevice = MidiSystem.getMidiDevice(msInfo);
        synth.open();

        sb.append("synth=" + synth.getDeviceInfo().toString() + " with default soundbank " + synth.getDefaultSoundbank().getDescription() + '\n');
        sb.append("max synthesizer latency =" + synth.getLatency() + " us\n");
        log.info(sb.toString());
        channels = synth.getChannels();
        channel = channels[PERCUSSION_CHANNEL];
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:23,代码来源:DrumSound.java

示例3: main

import javax.sound.midi.MidiSystem; //导入方法依赖的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

示例4: openInput

import javax.sound.midi.MidiSystem; //导入方法依赖的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

示例5: init

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
 * This method initializes the MusicPlayer
 */
public static boolean init()
{
	try
	{
		if (synth == null)
			synth = MidiSystem.getSynthesizer();
		if (!synth.isOpen())
			synth.open();
		return true;
	} catch (MidiUnavailableException e)
	{
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:creativitRy,项目名称:ClearComposer,代码行数:19,代码来源:MusicPlayer.java

示例6: findAudioSynthesizer

import javax.sound.midi.MidiSystem; //导入方法依赖的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

示例7: setupMidi

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public void setupMidi() throws Exception {
	synthesizer = MidiSystem.getSynthesizer();
	synthesizer.open();
	midiChannels = synthesizer.getChannels();
	sequencer = MidiSystem.getSequencer();
	sequence = new Sequence(Sequence.PPQ, 10);
	Soundbank sb = synthesizer.getDefaultSoundbank();
	if (sb != null) {
		instruments = synthesizer.getDefaultSoundbank().getInstruments();
		for (int i = 0; i < instruments.length; i++) {
			System.out.printf("%4d: %s%n", i, instruments[i]);
		}
		if (instruments.length > 0) {
			synthesizer.loadInstrument(instruments[0]);
			midiChannels[currentChannel].programChange(0);
		}
		if (instruments.length > 14) {
			synthesizer.loadInstrument(instruments[14]);
			midiChannels[currentChannel].programChange(14);
		}
	}
}
 
开发者ID:haogrgr,项目名称:haogrgr-projects,代码行数:23,代码来源:ActorDemo.java

示例8: initSynthesizer

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private boolean initSynthesizer() {
    if (null == m_synth) {
        try {
            if (MidiSystem.getSequencer() == null) {
                System.err.println("MidiSystem Sequencer Unavailable");
                return false;
            }

            m_synth = MidiSystem.getSynthesizer();
            m_synth.open();
            m_sequencer = MidiSystem.getSequencer();
            //m_sequencer.open();
        }
        catch (MidiUnavailableException e) {
            System.err.println("Midi System Unavailable:" + e);
            return false;
        }
    }
    return true;
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:21,代码来源:MidiSynth.java

示例9: findAudioSynthesizer

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
 * Find available AudioSynthesizer
 */
public static AudioSynthesizer findAudioSynthesizer() throws MidiUnavailableException
{
	// First check if default synthesizer is AudioSynthesizer.
	Synthesizer synth = MidiSystem.getSynthesizer();
	if (synth instanceof AudioSynthesizer)
		return (AudioSynthesizer) synth;

	// If default synhtesizer is not AudioSynthesizer, check others.
	for (Info info : MidiSystem.getMidiDeviceInfo())
	{
		MidiDevice dev = MidiSystem.getMidiDevice(info);
		if (dev instanceof AudioSynthesizer)
			return (AudioSynthesizer) dev;
	}

	// No AudioSynthesizer was found, return null.
	return null;
}
 
开发者ID:digero,项目名称:maestro,代码行数:22,代码来源:SynthesizerFactory.java

示例10: findAudioSynthesizer

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static AudioSynthesizer findAudioSynthesizer() throws MidiUnavailableException, IOException, InvalidMidiDataException {
    // First check if default synthesizer is AudioSynthesizer.
    Synthesizer synth = MidiSystem.getSynthesizer();
    if (synth instanceof AudioSynthesizer) {
        return (AudioSynthesizer) synth;
    }

    // If default synhtesizer is not AudioSynthesizer, check others.
    Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        MidiDevice dev = MidiSystem.getMidiDevice(infos[i]);
        if (dev instanceof AudioSynthesizer) {
            return (AudioSynthesizer) dev;
        }
    }

    // No AudioSynthesizer was found, return null.
    return null;
}
 
开发者ID:Glamdring,项目名称:computoser,代码行数:20,代码来源:Midi2WavRenderer.java

示例11: MIDIPlayer

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
MIDIPlayer(int playerChannel, int playerProgram) {

        this.zapis=new LinkedBlockingQueue(); // Ustvari izravnalnik
        
        try {
            this.sintetizator = MidiSystem.getSynthesizer(); // Ustvari napravo MIDI (glej Vajo 3)
            this.sintetizator.open(); // Odpri napravo MIDI
        } catch (MidiUnavailableException ex) {
            ex.printStackTrace();
            System.exit(1);
        }

        this.kanal = this.sintetizator.getChannels()[playerChannel]; // Doloci kanal MIID
        
        kanal.programChange(playerProgram); // Doloci glasbilo http://en.wikipedia.org/wiki/General_MIDI
    }
 
开发者ID:balohmatevz,项目名称:MusicGenerator,代码行数:17,代码来源:MIDIPlayer.java

示例12: findAudioSynthesizer

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static AudioSynthesizer findAudioSynthesizer()
		throws MidiUnavailableException {
	// First check if default synthesizer is AudioSynthesizer.
	Synthesizer synth = MidiSystem.getSynthesizer();
	if (synth instanceof AudioSynthesizer)
		return (AudioSynthesizer) synth;

	// If default synhtesizer is not AudioSynthesizer, check others.
	Info[] infos = MidiSystem.getMidiDeviceInfo();
	for (int i = 0; i < infos.length; i++) {
		MidiDevice dev = MidiSystem.getMidiDevice(infos[i]);
		if (dev instanceof AudioSynthesizer)
			return (AudioSynthesizer) dev;
	}

	// No AudioSynthesizer was found, return null.
	return null;
}
 
开发者ID:bluenote10,项目名称:gervill,代码行数:19,代码来源:SimpleMidiPlayer.java

示例13: main

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
			
	Synthesizer synth = MidiSystem.getSynthesizer();
	synth.open();
	synth.unloadAllInstruments(synth.getDefaultSoundbank());
	synth.loadAllInstruments(new MyOscillator());
	Sequence seq = MidiSystem.getSequence(FMTest1.class.getResource("/FMTest1.mid"));
	Sequencer seqr = MidiSystem.getSequencer(false);
	seqr.open();
	seqr.getTransmitter().setReceiver(synth.getReceiver());
	seqr.setSequence(seq);
	seqr.start();
	
	System.out.println();
	System.out.println("Is active, press enter to stop");
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	br.readLine();
	System.out.println("Stop...");
	
	seqr.stop();
	seqr.close();
	synth.close();
	
	System.exit(0);
}
 
开发者ID:bluenote10,项目名称:gervill,代码行数:26,代码来源:FMTest1.java

示例14: SoundPlayer

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public SoundPlayer() {
    try {
        synthesizer = MidiSystem.getSynthesizer();
        synthesizer.open();
        midiChannel = synthesizer.getChannels()[0];
    } catch (MidiUnavailableException e) {
        e.printStackTrace();
    }
}
 
开发者ID:rafzby,项目名称:chip8-emulator,代码行数:10,代码来源:SoundPlayer.java

示例15: onStartup

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
 * Starts up this plugin. Obtains and opens the required MIDI devices and sets up receivers and transmitters. Any setters for MIDI
 * devices must be invoked before the Sponge startup.
 */
@Override
public void onStartup() {
    try {
        logMidiSystemInfo();

        // Use the default sequencer if not set.
        if (sequencer == null) {
            sequencer = MidiSystem.getSequencer(sequencerConnectedToSynthesizer);
            if (sequencer == null) {
                throw new SpongeException("The sequencer device is not supported");
            }
        }

        // Use the default synthesizer if not set.
        if (synthesizer == null) {
            synthesizer = MidiSystem.getSynthesizer();
            if (synthesizer == null) {
                throw new SpongeException("The synthesizer device is not supported");
            }
        }

        update();

        if (loadAllInstruments) {
            loadAllInstruments();
        }
    } catch (MidiUnavailableException e) {
        throw SpongeUtils.wrapException(e);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:35,代码来源:MidiPlugin.java


注:本文中的javax.sound.midi.MidiSystem.getSynthesizer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。