Java Code Examples for javax.sound.midi.SysexMessage#setMessage()

The following examples show how to use javax.sound.midi.SysexMessage#setMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DavidMusicModule.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
private static void sendSysexMessage(Receiver receiver, byte... message) {
 SysexMessage msg = new SysexMessage();
 try {
        msg.setMessage(message, message.length);
    } catch (InvalidMidiDataException ex) {
        throw new RuntimeException(ex);
    }
    receiver.send(msg, -1);
}
 
Example 2
Source File: FinnwMusicModule.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
private void addSysExMessage(int status, byte... data) {
    try {
        SysexMessage msg = new SysexMessage();
        msg.setMessage(status, data, data.length);
        messages.add(msg);
    } catch (InvalidMidiDataException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 3
Source File: StandardMidiFileReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void readTrack(Track track) throws IOException, InvalidMidiDataException {
    try {
        // reset current tick to 0
        long tick = 0;

        // reset current status byte to 0 (invalid value).
        // this should cause us to throw an InvalidMidiDataException if we don't
        // get a valid status byte from the beginning of the track.
        int status = 0;
        boolean endOfTrackFound = false;

        while (!trackFinished() && !endOfTrackFound) {
            MidiMessage message;

            int data1 = -1;         // initialize to invalid value
            int data2 = 0;

            // each event has a tick delay and then the event data.

            // first read the delay (a variable-length int) and update our tick value
            tick += readVarInt();

            // check for new status
            int byteValue = readUnsigned();

            if (byteValue >= 0x80) {
                status = byteValue;
            } else {
                data1 = byteValue;
            }

            switch (status & 0xF0) {
            case 0x80:
            case 0x90:
            case 0xA0:
            case 0xB0:
            case 0xE0:
                // two data bytes
                if (data1 == -1) {
                    data1 = readUnsigned();
                }
                data2 = readUnsigned();
                message = new FastShortMessage(status | (data1 << 8) | (data2 << 16));
                break;
            case 0xC0:
            case 0xD0:
                // one data byte
                if (data1 == -1) {
                    data1 = readUnsigned();
                }
                message = new FastShortMessage(status | (data1 << 8));
                break;
            case 0xF0:
                // sys-ex or meta
                switch(status) {
                case 0xF0:
                case 0xF7:
                    // sys ex
                    int sysexLength = (int) readVarInt();
                    byte[] sysexData = new byte[sysexLength];
                    read(sysexData);

                    SysexMessage sysexMessage = new SysexMessage();
                    sysexMessage.setMessage(status, sysexData, sysexLength);
                    message = sysexMessage;
                    break;

                case 0xFF:
                    // meta
                    int metaType = readUnsigned();
                    int metaLength = (int) readVarInt();

                    byte[] metaData = new byte[metaLength];
                    read(metaData);

                    MetaMessage metaMessage = new MetaMessage();
                    metaMessage.setMessage(metaType, metaData, metaLength);
                    message = metaMessage;
                    if (metaType == 0x2F) {
                        // end of track means it!
                        endOfTrackFound = true;
                    }
                    break;
                default:
                    throw new InvalidMidiDataException("Invalid status byte: " + status);
                } // switch sys-ex or meta
                break;
            default:
                throw new InvalidMidiDataException("Invalid status byte: " + status);
            } // switch
            track.add(new MidiEvent(message, tick));
        } // while
    } catch (ArrayIndexOutOfBoundsException e) {
        if (DEBUG) e.printStackTrace();
        // fix for 4834374
        throw new EOFException("invalid MIDI file");
    }
}
 
Example 4
Source File: StandardMidiFileReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void readTrack(Track track) throws IOException, InvalidMidiDataException {
    try {
        // reset current tick to 0
        long tick = 0;

        // reset current status byte to 0 (invalid value).
        // this should cause us to throw an InvalidMidiDataException if we don't
        // get a valid status byte from the beginning of the track.
        int status = 0;
        boolean endOfTrackFound = false;

        while (!trackFinished() && !endOfTrackFound) {
            MidiMessage message;

            int data1 = -1;         // initialize to invalid value
            int data2 = 0;

            // each event has a tick delay and then the event data.

            // first read the delay (a variable-length int) and update our tick value
            tick += readVarInt();

            // check for new status
            int byteValue = readUnsigned();

            if (byteValue >= 0x80) {
                status = byteValue;
            } else {
                data1 = byteValue;
            }

            switch (status & 0xF0) {
            case 0x80:
            case 0x90:
            case 0xA0:
            case 0xB0:
            case 0xE0:
                // two data bytes
                if (data1 == -1) {
                    data1 = readUnsigned();
                }
                data2 = readUnsigned();
                message = new FastShortMessage(status | (data1 << 8) | (data2 << 16));
                break;
            case 0xC0:
            case 0xD0:
                // one data byte
                if (data1 == -1) {
                    data1 = readUnsigned();
                }
                message = new FastShortMessage(status | (data1 << 8));
                break;
            case 0xF0:
                // sys-ex or meta
                switch(status) {
                case 0xF0:
                case 0xF7:
                    // sys ex
                    int sysexLength = (int) readVarInt();
                    byte[] sysexData = new byte[sysexLength];
                    read(sysexData);

                    SysexMessage sysexMessage = new SysexMessage();
                    sysexMessage.setMessage(status, sysexData, sysexLength);
                    message = sysexMessage;
                    break;

                case 0xFF:
                    // meta
                    int metaType = readUnsigned();
                    int metaLength = (int) readVarInt();

                    byte[] metaData = new byte[metaLength];
                    read(metaData);

                    MetaMessage metaMessage = new MetaMessage();
                    metaMessage.setMessage(metaType, metaData, metaLength);
                    message = metaMessage;
                    if (metaType == 0x2F) {
                        // end of track means it!
                        endOfTrackFound = true;
                    }
                    break;
                default:
                    throw new InvalidMidiDataException("Invalid status byte: " + status);
                } // switch sys-ex or meta
                break;
            default:
                throw new InvalidMidiDataException("Invalid status byte: " + status);
            } // switch
            track.add(new MidiEvent(message, tick));
        } // while
    } catch (ArrayIndexOutOfBoundsException e) {
        if (DEBUG) e.printStackTrace();
        // fix for 4834374
        throw new EOFException("invalid MIDI file");
    }
}