本文整理匯總了Java中javax.sound.midi.MidiSystem.getSequence方法的典型用法代碼示例。如果您正苦於以下問題:Java MidiSystem.getSequence方法的具體用法?Java MidiSystem.getSequence怎麽用?Java MidiSystem.getSequence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.getSequence方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadSongs
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
private Sequence[] loadSongs() {
if(sequencer == null) {
return null;
}
for(int i = 0; i < songs.length; i++) {
try {
Path path = Paths.get(SLData.get().getDataPath(), "MUSIC", String.format("ULTIMA%02d.MID", i));
songs[i] = MidiSystem.getSequence(path.toFile());
} catch (Exception e) {
continue;
}
}
return new Sequence[0];
}
示例2: RegisterSong
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
@Override
public int RegisterSong(byte[] data) {
try {
Sequence sequence;
ByteArrayInputStream bis;
try {
// If data is a midi file, load it directly
bis = new ByteArrayInputStream(data);
sequence = MidiSystem.getSequence(bis);
} catch (InvalidMidiDataException ex) {
// Well, it wasn't. Dude.
bis = new ByteArrayInputStream(data);
sequence = MusReader.getSequence(bis);
}
sequencer.stop(); // stops current music if any
sequencer.setSequence(sequence); // Create a sequencer for the sequence
songloaded=true;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
// In good old C style, we return 0 upon success?
return 0;
}
示例3: playSound
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void playSound(InputStream in) {
try {
System.setProperty("javax.sound.midi.Sequencer", "com.sun.media.sound.RealTimeSequencerProvider");
if (this.sequencer == null) {
this.sequencer = MidiSystem.getSequencer();
if (!this.sequencer.isOpen()) {
this.sequencer.open();
}
}
Sequence seq = MidiSystem.getSequence(in);
this.sequencer.setSequence(seq);
this.sequencer.start();
this.sequencer.addMetaEventListener(this);
if (this.volume != 1) {
this.setSoundVolume(this.volume);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: 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++;
}
示例5: 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++;
}
示例6: scoreToSequence
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
private Sequence scoreToSequence(Score s)
{
Sequence sq = null;
Log.info("RealtimeMidiPlayer > PlayScore > Converting score.");
SMF smf = new SMF();
smf.clearTracks();
jm.midi.MidiParser.scoreToSMF(s, smf);
OutputStream os = new ByteArrayOutputStream();
try {
smf.write(os);
sq = MidiSystem.getSequence(new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray()));
} catch (InvalidMidiDataException imde) {
Log.severe("RealtimeMidiPlayer > PlayScore > Invalid Midi data!");
} catch (IOException ioe) {
Log.severe("RealtimeMidiPlayer > PlayScore > Score conversion error!");
return null;
}
Log.info("RealtimeMidiPlayer > PlayScore > Score converted to MIDI.");
return sq;
}
示例7: 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(); }
}
示例8: loadMidiSeq
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public void loadMidiSeq(File newseqfile) {
try {
seq_errmsg = null;
Sequence newseq = MidiSystem.getSequence(newseqfile);
seq = newseq;
seqfile = newseqfile;
// boolean running = seqr.isRunning();
seqr.stop();
// Reset All Channels
for(MidiChannel c : softsynth.getChannels())
c.resetAllControllers();
seqr.setSequence(seq);
seqr.setTickPosition(0);
seqr.start();
} catch (Throwable e1) {
seq_errmsg = e1.toString();
}
}
示例9: 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);
}
示例10: main
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void main(String[] args) {
if (args.length >= 2)
try {
File midi_file = new File(args[0]);
if (!midi_file.exists())
throw new FileNotFoundException();
Sequence sequence = MidiSystem.getSequence(midi_file);
Soundbank soundbank = null;
if (args.length >= 3) {
File soundbank_file = new File(args[2]);
if (soundbank_file.exists())
soundbank = MidiSystem.getSoundbank(soundbank_file);
}
render(soundbank, sequence, new File(args[1]));
System.exit(0);
} catch (Exception e) {
System.out.println(e.toString());
System.out.println();
}
System.out.println("MIDI to WAVE Render: usages:");
System.out
.println("java Midi2WavRender <midi_file_in> <wave_file_out> <soundbank_file>");
System.exit(1);
}
示例11: createSequencer
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
private boolean createSequencer(BufferedInputStream in) throws IOException {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");
// get the sequencer
try {
sequencer = MidiSystem.getSequencer( );
} catch(MidiUnavailableException me) {
if (DEBUG || Printer.err)me.printStackTrace();
return false;
}
if (sequencer==null) {
return false;
}
try {
sequence = MidiSystem.getSequence(in);
if (sequence == null) {
return false;
}
} catch (InvalidMidiDataException e) {
if (DEBUG || Printer.err)e.printStackTrace();
return false;
}
if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
return true;
}
示例12: LoadMidiFile
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
/**
* Loads a midi sequence from a file
* @param file The path to the midi file
* @return A midi sequence
*/
public static Sequence LoadMidiFile(String file) {
try {
return MidiSystem.getSequence(new FileInputStream(file));
} catch (InvalidMidiDataException | IOException e) {
System.err.println("Midi file '"+file+"' not found");
return null;
}
}
示例13: main
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Sequence s = null;
//File midiFile = new File("outsmpte.mid");
//InputStream is = new FileInputStream(midiFile);
//is = new BufferedInputStream(is);
InputStream is = new ByteArrayInputStream(smptemidifile);
s = MidiSystem.getSequence(is);
long duration = s.getMicrosecondLength() / 1000000;
System.out.println("Duration: "+duration+" seconds ");
if (duration > 14) {
throw new Exception("SMPTE time reader is broken! Test FAILED");
}
System.out.println("Test passed");
}
示例14: main
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void main(String args[]) throws Exception {
// Test to read MIDI files with Cp037 character set - close enough
// for EBCDIC simulation
System.setProperty("file.encoding", "Cp037");
// try to read this file with Cp037 encoding
MidiSystem.getSequence(new ByteArrayInputStream(SHORT_SMF));
System.out.println(" test passed.");
}
示例15: main
import javax.sound.midi.MidiSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
InputStream is = new ByteArrayInputStream(midifile);
// create a buffered input stream that seems
// to be on an unfortunate boundary for the
// 1.4.2 SMF parser implementation
is = new ChunkInputStream(is, 32);
Sequence sequence = MidiSystem.getSequence(is);
long duration = sequence.getMicrosecondLength() / 10000;
System.out.println("Duration: "+duration+" deciseconds ");
// the test is passed if no exception thrown
System.out.println("Test passed");
}