Java 类javax.sound.midi.InvalidMidiDataException 实例源码

项目:LinkGame    文件:BackMusic.java   
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();
}
项目:openjdk-jdk10    文件:ClosedReceiver.java   
/**
 * 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;
}
项目:openjdk-jdk10    文件:GetSoundBankIOException.java   
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.");
}
项目:OpenJSharp    文件:AudioFileSoundbankReader.java   
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;
    }
}
项目:OpenJSharp    文件:StandardMidiFileReader.java   
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;
}
项目:jdk8u-jdk    文件:AudioFileSoundbankReader.java   
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;
    }
}
项目:jdk8u-jdk    文件:StandardMidiFileReader.java   
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;
}
项目:jdk8u-jdk    文件:StandardMidiFileReader.java   
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;
}
项目:openjdk-jdk10    文件:AudioFileSoundbankReader.java   
@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;
    }
}
项目:openjdk-jdk10    文件:AbstractMidiDevice.java   
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;
    }
}
项目:openjdk-jdk10    文件:StandardMidiFileReader.java   
@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;
}
项目:openjdk-jdk10    文件:StandardMidiFileReader.java   
@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;
}
项目:openjdk-jdk10    文件:FastShortMessage.java   
@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;
}
项目:sponge    文件:MidiPlugin.java   
/**
 * 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);
    }
}
项目:sponge    文件:MidiPlugin.java   
/**
 * Starts playing the MIDI file using the sequencer.
 *
 * @param url the MIDI file url.
 */
public void startPlay(URL url) {
    try {
        startPlay(MidiSystem.getSequence(url));
    } catch (InvalidMidiDataException | IOException e) {
        throw SpongeUtils.wrapException(e);
    }
}
项目:sponge    文件:MidiPlugin.java   
/**
 * Starts playing the MIDI file using the sequencer.
 *
 * @param sequence the MIDI sequence.
 */
public void startPlay(Sequence sequence) {
    try {
        sequencer.setSequence(sequence);
    } catch (InvalidMidiDataException e) {
        throw SpongeUtils.wrapException(e);
    }
    sequencer.start();
}
项目:sponge    文件:MidiMetaMessageEvent.java   
/**
 * 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);
    }
}
项目:sponge    文件:MidiMetaMessageEvent.java   
/**
 * 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);
    }
}
项目:sponge    文件:MidiShortMessageEvent.java   
/**
 * 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);
    }
}
项目:openjdk-jdk10    文件:MetaCallback.java   
static ShortMessage MidiMsg3(int a, int b, int c) {
    try {
        ShortMessage msg = new ShortMessage();
        msg.setMessage((byte)a,(byte)b,(byte)c);
        return msg;
    } catch(InvalidMidiDataException ex) {
        throw new RuntimeException();
    }
}
项目:sponge    文件:MidiShortMessageEvent.java   
/**
 * Sets the MIDI short message data1.
 *
 * @param data1 the MIDI short message data1.
 */
public void setData1(int data1) {
    try {
        getMessage().setMessage(getCommand(), getChannel(), data1, getData2());
    } catch (InvalidMidiDataException e) {
        throw SpongeUtils.wrapException(e);
    }
}
项目:sponge    文件:MidiShortMessageEvent.java   
/**
 * Sets the MIDI short message data2.
 *
 * @param data2 the MIDI short message data2.
 */
public void setData2(int data2) {
    try {
        getMessage().setMessage(getCommand(), getChannel(), getData1(), data2);
    } catch (InvalidMidiDataException e) {
        throw SpongeUtils.wrapException(e);
    }
}
项目:sponge    文件:MidiSysexMessageEvent.java   
/**
 * Sets the MIDI SysexMessage data.
 *
 * @param data the MIDI SysexMessage data.
 */
public void setData(byte[] data) {
    try {
        getMessage().setMessage(data, data.length);
    } catch (InvalidMidiDataException e) {
        throw SpongeUtils.wrapException(e);
    }
}
项目:OpenJSharp    文件:JavaSoundAudioClip.java   
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;
    }
项目:OpenJSharp    文件:AudioFileSoundbankReader.java   
public Soundbank getSoundbank(AudioInputStream ais)
        throws InvalidMidiDataException, IOException {
    try {
        byte[] buffer;
        if (ais.getFrameLength() == -1) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buff = new byte[1024
                    - (1024 % ais.getFormat().getFrameSize())];
            int ret;
            while ((ret = ais.read(buff)) != -1) {
                baos.write(buff, 0, ret);
            }
            ais.close();
            buffer = baos.toByteArray();
        } else {
            buffer = new byte[(int) (ais.getFrameLength()
                                * ais.getFormat().getFrameSize())];
            new DataInputStream(ais).readFully(buffer);
        }
        ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
                new ModelByteBuffer(buffer), ais.getFormat(), -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 (Exception e) {
        return null;
    }
}
项目:OpenJSharp    文件:SF2SoundbankReader.java   
public Soundbank getSoundbank(URL url)
        throws InvalidMidiDataException, IOException {
    try {
        return new SF2Soundbank(url);
    } catch (RIFFInvalidFormatException e) {
        return null;
    } catch(IOException ioe) {
        return null;
    }
}
项目:OpenJSharp    文件:SF2SoundbankReader.java   
public Soundbank getSoundbank(InputStream stream)
        throws InvalidMidiDataException, IOException {
    try {
        stream.mark(512);
        return new SF2Soundbank(stream);
    } catch (RIFFInvalidFormatException e) {
        stream.reset();
        return null;
    }
}
项目:OpenJSharp    文件:SF2SoundbankReader.java   
public Soundbank getSoundbank(File file)
        throws InvalidMidiDataException, IOException {
    try {
        return new SF2Soundbank(file);
    } catch (RIFFInvalidFormatException e) {
        return null;
    }
}
项目:KraftigAudio    文件:DSPUtil.java   
public static void midi(MidiReceiver receiver, int command, int channel, int data1, int data2)
{
    try
    {
        ShortMessage msg = new ShortMessage(command, channel, data1, data2);
        receiver.send(msg, Main.instance().getTime());
    }
    catch (InvalidMidiDataException ex)
    {
        throw new RuntimeException(ex);
    }
}
项目:OpenJSharp    文件:DLSSoundbankReader.java   
public Soundbank getSoundbank(URL url)
        throws InvalidMidiDataException, IOException {
    try {
        return new DLSSoundbank(url);
    } catch (RIFFInvalidFormatException e) {
        return null;
    } catch(IOException ioe) {
        return null;
    }
}
项目:OpenJSharp    文件:DLSSoundbankReader.java   
public Soundbank getSoundbank(InputStream stream)
        throws InvalidMidiDataException, IOException {
    try {
        stream.mark(512);
        return new DLSSoundbank(stream);
    } catch (RIFFInvalidFormatException e) {
        stream.reset();
        return null;
    }
}
项目:OpenJSharp    文件:DLSSoundbankReader.java   
public Soundbank getSoundbank(File file)
        throws InvalidMidiDataException, IOException {
    try {
        return new DLSSoundbank(file);
    } catch (RIFFInvalidFormatException e) {
        return null;
    }
}
项目:openjdk-jdk10    文件:DLSSoundbankReader.java   
@Override
public Soundbank getSoundbank(InputStream stream)
        throws InvalidMidiDataException, IOException {
    try {
        stream.mark(512);
        return new DLSSoundbank(stream);
    } catch (RIFFInvalidFormatException e) {
        stream.reset();
        return null;
    }
}
项目:jdk8u-jdk    文件:JavaSoundAudioClip.java   
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;
    }
项目:jdk8u-jdk    文件:SF2SoundbankReader.java   
public Soundbank getSoundbank(URL url)
        throws InvalidMidiDataException, IOException {
    try {
        return new SF2Soundbank(url);
    } catch (RIFFInvalidFormatException e) {
        return null;
    } catch(IOException ioe) {
        return null;
    }
}
项目:jdk8u-jdk    文件:SF2SoundbankReader.java   
public Soundbank getSoundbank(InputStream stream)
        throws InvalidMidiDataException, IOException {
    try {
        stream.mark(512);
        return new SF2Soundbank(stream);
    } catch (RIFFInvalidFormatException e) {
        stream.reset();
        return null;
    }
}
项目:jdk8u-jdk    文件:SF2SoundbankReader.java   
public Soundbank getSoundbank(File file)
        throws InvalidMidiDataException, IOException {
    try {
        return new SF2Soundbank(file);
    } catch (RIFFInvalidFormatException e) {
        return null;
    }
}
项目:jdk8u-jdk    文件:StandardMidiFileReader.java   
public MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException {
    InputStream urlStream = url.openStream(); // throws IOException
    BufferedInputStream bis = new BufferedInputStream( urlStream, bisBufferSize );
    MidiFileFormat fileFormat = null;
    try {
        fileFormat = getMidiFileFormat( bis ); // throws InvalidMidiDataException
    } finally {
        bis.close();
    }
    return fileFormat;
}
项目:jdk8u-jdk    文件:DLSSoundbankReader.java   
public Soundbank getSoundbank(URL url)
        throws InvalidMidiDataException, IOException {
    try {
        return new DLSSoundbank(url);
    } catch (RIFFInvalidFormatException e) {
        return null;
    } catch(IOException ioe) {
        return null;
    }
}
项目:jdk8u-jdk    文件:DLSSoundbankReader.java   
public Soundbank getSoundbank(File file)
        throws InvalidMidiDataException, IOException {
    try {
        return new DLSSoundbank(file);
    } catch (RIFFInvalidFormatException e) {
        return null;
    }
}