本文整理匯總了Java中javax.sound.midi.InvalidMidiDataException類的典型用法代碼示例。如果您正苦於以下問題:Java InvalidMidiDataException類的具體用法?Java InvalidMidiDataException怎麽用?Java InvalidMidiDataException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InvalidMidiDataException類屬於javax.sound.midi包,在下文中一共展示了InvalidMidiDataException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: play
import javax.sound.midi.InvalidMidiDataException; //導入依賴的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: testReceiverSend
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
/**
* Execute Receiver.send() and expect that there is no exception.
*/
private static boolean testReceiverSend() {
boolean result = true;
Receiver receiver;
ShortMessage shMsg = new ShortMessage();
try {
receiver = MidiSystem.getReceiver();
shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
try {
receiver.send( shMsg, -1 );
} catch(IllegalStateException ilEx) {
ilEx.printStackTrace(System.out);
out("IllegalStateException was thrown incorrectly!");
result = false;
}
receiver.close();
} catch(MidiUnavailableException e) {
out("Midi unavailable, cannot test.");
} catch(InvalidMidiDataException ine) {
out("InvalidMidiDataException, cannot test.");
}
return result;
}
示例3: main
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
boolean failed = false;
try {
String filename = "GetSoundBankIOException.java";
System.out.println("Opening "+filename+" as soundbank...");
File midiFile = new File(System.getProperty("test.src", "."), filename);
MidiSystem.getSoundbank(midiFile);
//Soundbank sBank = MidiSystem.getSoundbank(new NonMarkableIS());
System.err.println("InvalidMidiDataException was not thrown!");
failed = true;
} catch (InvalidMidiDataException invMidiEx) {
System.err.println("InvalidMidiDataException was thrown. OK.");
} catch (IOException ioEx) {
System.err.println("Unexpected IOException was caught!");
System.err.println(ioEx.getMessage());
ioEx.printStackTrace();
failed = true;
}
if (failed) throw new Exception("Test FAILED!");
System.out.println("Test passed.");
}
示例4: getSoundbank
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
ais.close();
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(file, 0, file.length()), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (UnsupportedAudioFileException e1) {
return null;
} catch (IOException e) {
return null;
}
}
示例5: getSequence
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
SMFParser smfParser = new SMFParser();
MidiFileFormat format = getMidiFileFormatFromStream(stream,
MidiFileFormat.UNKNOWN_LENGTH,
smfParser);
// must be MIDI Type 0 or Type 1
if ((format.getType() != 0) && (format.getType() != 1)) {
throw new InvalidMidiDataException("Invalid or unsupported file type: " + format.getType());
}
// construct the sequence object
Sequence sequence = new Sequence(format.getDivisionType(), format.getResolution());
// for each track, go to the beginning and read the track events
for (int i = 0; i < smfParser.tracks; i++) {
if (smfParser.nextTrack()) {
smfParser.readTrack(sequence.createTrack());
} else {
break;
}
}
return sequence;
}
示例6: getMidiFileFormat
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
FileInputStream fis = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);
// $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
long length = file.length();
if (length > Integer.MAX_VALUE) {
length = MidiFileFormat.UNKNOWN_LENGTH;
}
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
} finally {
bis.close();
}
return fileFormat;
}
示例7: getSoundbank
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
@Override
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
ais.close();
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(file, 0, file.length()), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (UnsupportedAudioFileException e1) {
return null;
} catch (IOException e) {
return null;
}
}
示例8: sendMessage
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
void sendMessage(byte[] data, long timeStamp) {
try {
synchronized(transmitters) {
int size = transmitters.size();
if (TRACE_TRANSMITTER) Printer.println("Sending long message to "+size+" transmitter's receivers");
for (int i = 0; i < size; i++) {
Receiver receiver = transmitters.get(i).getReceiver();
if (receiver != null) {
//$$fb 2002-04-02: SysexMessages are mutable, so
// an application could change the contents of this object,
// or try to use the object later. So we can't get around object creation
// But the array need not be unique for each FastSysexMessage object,
// because it cannot be modified.
receiver.send(new FastSysexMessage(data), timeStamp);
}
}
}
} catch (InvalidMidiDataException e) {
// this happens when invalid data comes over the wire. Ignore it.
return;
}
}
示例9: getMidiFileFormat
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
@Override
public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
FileInputStream fis = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);
// $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
long length = file.length();
if (length > Integer.MAX_VALUE) {
length = MidiFileFormat.UNKNOWN_LENGTH;
}
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
} finally {
bis.close();
}
return fileFormat;
}
示例10: getSequence
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
@Override
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
SMFParser smfParser = new SMFParser();
MidiFileFormat format = getMidiFileFormatFromStream(stream,
MidiFileFormat.UNKNOWN_LENGTH,
smfParser);
// must be MIDI Type 0 or Type 1
if ((format.getType() != 0) && (format.getType() != 1)) {
throw new InvalidMidiDataException("Invalid or unsupported file type: " + format.getType());
}
// construct the sequence object
Sequence sequence = new Sequence(format.getDivisionType(), format.getResolution());
// for each track, go to the beginning and read the track events
for (int i = 0; i < smfParser.tracks; i++) {
if (smfParser.nextTrack()) {
smfParser.readTrack(sequence.createTrack());
} else {
break;
}
}
return sequence;
}
示例11: getMessage
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
@Override
public byte[] getMessage() {
int length = 0;
try {
// fix for bug 4851018: MidiMessage.getLength and .getData return wrong values
// fix for bug 4890405: Reading MidiMessage byte array fails in 1.4.2
length = getDataLength(packedMsg & 0xFF) + 1;
} catch (InvalidMidiDataException imde) {
// should never happen
}
byte[] returnedArray = new byte[length];
if (length>0) {
returnedArray[0] = (byte) (packedMsg & 0xFF);
if (length>1) {
returnedArray[1] = (byte) ((packedMsg & 0xFF00) >> 8);
if (length>2) {
returnedArray[2] = (byte) ((packedMsg & 0xFF0000) >> 16);
}
}
}
return returnedArray;
}
示例12: startPlay
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
/**
* Starts playing the MIDI file using the sequencer.
*
* @param midiFile the MIDI file.
*/
public void startPlay(File midiFile) {
try {
startPlay(MidiSystem.getSequence(midiFile));
} catch (InvalidMidiDataException | IOException e) {
throw SpongeUtils.wrapException(e);
}
}
示例13: setMessageType
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
/**
* Sets the MIDI MetaMessage type.
*
* @param type the MIDI MetaMessage type.
*/
public void setMessageType(int type) {
try {
getMessage().setMessage(type, getData(), getData().length);
} catch (InvalidMidiDataException e) {
throw SpongeUtils.wrapException(e);
}
}
示例14: setData
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
/**
* Sets the MIDI MetaMessage data.
*
* @param data the MIDI MetaMessage data.
*/
public void setData(byte[] data) {
try {
getMessage().setMessage(getMessageType(), data, data.length);
} catch (InvalidMidiDataException e) {
throw SpongeUtils.wrapException(e);
}
}
示例15: setCommand
import javax.sound.midi.InvalidMidiDataException; //導入依賴的package包/類
/**
* Sets the MIDI short message command.
*
* @param command the MIDI short message command.
*/
public void setCommand(int command) {
try {
getMessage().setMessage(command, getChannel(), getData1(), getData2());
} catch (InvalidMidiDataException e) {
throw SpongeUtils.wrapException(e);
}
}