本文整理汇总了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);
}
}