本文整理匯總了Java中javax.sound.midi.MidiSystem.getSequencer方法的典型用法代碼示例。如果您正苦於以下問題:Java MidiSystem.getSequencer方法的具體用法?Java MidiSystem.getSequencer怎麽用?Java MidiSystem.getSequencer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.getSequencer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: play
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void play() {
if (isPlaying) { // 如果已經在播放,返回
return;
}
try {
sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.setSequence(sequence);
sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY );
sequencer.addMetaEventListener(this);
} catch (InvalidMidiDataException ex) {
} catch (MidiUnavailableException e) {
}
thread = new Thread(this);
thread.start();
}
示例2: main
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void main(String argv[]) {
Sequencer seq = null;
try {
seq = MidiSystem.getSequencer();
seq.open();
} catch (final MidiUnavailableException ignored) {
// the test is not applicable
return;
}
try {
seq.startRecording();
System.out.println("Test passed.");
} catch (NullPointerException npe) {
System.out.println("Caught NPE: "+npe);
npe.printStackTrace();
throw new RuntimeException("Test FAILED!");
} catch (Exception e) {
System.out.println("Unexpected Exception: "+e);
e.printStackTrace();
System.out.println("Test NOT failed.");
} finally {
seq.close();
}
}
示例3: DesktopMidiPlayer
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public DesktopMidiPlayer() throws MidiUnavailableException, IOException, InvalidMidiDataException {
// Obtains the default Sequencer connected to a default device.
Sequencer sequencer = MidiSystem.getSequencer();
// Opens the device, indicating that it should now acquire any
// system resources it requires and become operational.
sequencer.open();
// create a stream from a file
// FileHandle fh = Gdx.files.internal(Constants.MUSIC);
// InputStream is = new BufferedInputStream(new FileInputStream(fh.file()));
InputStream is = new BufferedInputStream(new FileInputStream(new File(Constants.MUSIC2)));
// Sets the current sequence on which the sequencer operates.
// The stream must point to MIDI file data.
sequencer.setSequence(is);
// Starts playback of the MIDI data in the currently loaded sequence.
sequencer.start();
/*try {
this.sequencer = MidiSystem.getSequencer();
} catch (MidiUnavailableException e) {
// Log.error("Error opening midi device.", e);
}*/
}
示例4: 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);
}
}
}
示例5: 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;
}
示例6: go
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void go() {
setUpGui();
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.addControllerEventListener(ml, new int[] {127});
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
int r = 0;
for (int i = 0; i < 60; i+=4) {
r = (int) ((Math.random() * 50) + 1);
track.add(makeEvent(144, 1, r, 100, i));
track.add(makeEvent(176, 1, 127, 0, i));
track.add(makeEvent(128, 1, r, 100, i + 2));
} // end loop
sequencer.setSequence(seq);
sequencer.start();
sequencer.setTempoInBPM(120);
} catch (Exception ex) {ex.printStackTrace();}
}
示例7: go
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void go() {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
int[] eventsIWant = {127};
sequencer.addControllerEventListener(this, eventsIWant);
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
for (int i = 5; i < 60; i+= 4) {
track.add(makeEvent(144, 1, i, 100, i));
track.add(makeEvent(176, 1, 127, 0, i));
track.add(makeEvent(128, 1, i, 100, i + 2));
} // end loop
sequencer.setSequence(seq);
sequencer.setTempoInBPM(220);
sequencer.start();
} catch (Exception ex) {ex.printStackTrace();}
}
示例8: main
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
// make and open a sequencer
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
// make a sequence and a track
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
// make a bunch of events to make the notes keep going up
// (from piano note 5 to piano note 61)
for (int i = 5; i < 61; i+=4) {
track.add(makeEvent(144, 1, i, 100, i));
track.add(makeEvent(128, 1, i, 100, i + 2));
} // end loop
sequencer.setSequence(seq);
sequencer.setTempoInBPM(220);
sequencer.start();
} catch (Exception ex) {ex.printStackTrace();}
}
示例9: load
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
/**
* MIDI�t�@�C�������[�h
* @param url MIDI�t�@�C����URL
*/
public static void load(URL url) throws MidiUnavailableException, InvalidMidiDataException, IOException {
if (sequencer == null) {
// �V�[�P���T���擾
sequencer = MidiSystem.getSequencer();
// �V�[�P���T���J��
sequencer.open();
// ���^�C�x���g���X�i�[��o�^
sequencer.addMetaEventListener(new MyMetaEventListener());
}
// MIDI�V�[�P���X��o�^
sequences[counter] = MidiSystem.getSequence(url);
counter++;
}
示例10: LMidiSound
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public LMidiSound() {
if (rendererStatus == UNINITIALIZED) {
rendererStatus = INITIALIZING;
Thread thread = new Thread() {
public final void run() {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
volumeSupported = (sequencer instanceof Synthesizer);
sequencer.close();
available = true;
} catch (Throwable e) {
available = false;
}
rendererStatus = INITIALIZED;
}
};
thread.setDaemon(true);
thread.start();
}
}
示例11: load
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
/**
* MIDI�t�@�C�������[�h
*
* @param url MIDI�t�@�C����URL
*/
public static void load(URL url) throws MidiUnavailableException,
InvalidMidiDataException, IOException {
if (sequencer == null) {
// �V�[�P���T���擾
sequencer = MidiSystem.getSequencer();
// �V�[�P���T���J��
sequencer.open();
// ���^�C�x���g���X�i�[��o�^
sequencer.addMetaEventListener(new MyMetaEventListener());
}
// MIDI�V�[�P���X��o�^
sequences[counter] = MidiSystem.getSequence(url);
counter++;
}
示例12: realize
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void realize(){
if(!useAudioBuffer){
try{
if(midi){
if(sequencer==null)
sequencer=MidiSystem.getSequencer();
}
else{
if(clip!=null && !clip.isOpen()){
clip.open();
}
}
} catch(Exception e){
System.err.println("Error realizing media \""+mc.mediaFileName+"\"\n"+e);
//e.printStackTrace();
}
}
}
示例13: realize
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void realize(){
if(!useAudioBuffer){
try{
if(midi){
if(sequencer==null)
sequencer=MidiSystem.getSequencer();
}
else{
if(player==null && dataSource!=null){
player=javax.media.Manager.createPlayer(dataSource);
if(player!=null) player.addControllerListener(this);
}
if(player!=null && player.getState()<Player.Realized)
player.realize();
}
} catch(Exception e){
System.err.println("Error realizing media \""+mc.mediaFileName+"\"\n"+e);
}
}
}
示例14: cargarSonidos
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void cargarSonidos(){
player = new Sequencer[Const.rutasSonidos.length];
Sequence currentSound;
InputStream is;
try{
for(int i = 0; i < Const.rutasSonidos.length; i++){
currentSound = MidiSystem.getSequence(Blox.class.getResourceAsStream(Const.rutasSonidos[i]));
is = Blox.class.getResourceAsStream(Const.rutasSonidos[i]);
is.close();
player[i] = MidiSystem.getSequencer();
player[i].open();
player[i].setSequence(currentSound);
if(i == Const.SONIDO_BGM)
player[i].setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
}
}catch(Exception e){ e.printStackTrace(); }
}
示例15: 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);
}