Convert a com.sun.media.sound.FastShortMessage object to a MIDI ShortMessage object. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiMessage

Description

Convert a com.sun.media.sound.FastShortMessage object to a MIDI ShortMessage object.

Demo Code

/*//from w ww  .  j  a  v a  2  s.c o m
 * Copyright 2004 Hiroo Hayashi
 *
 * This file is part of JSynthLib.
 *
 * JSynthLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or(at your option) any later version.
 *
 * JSynthLib is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JSynthLib; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
//package com.java2s;

import javax.sound.midi.*;

public class Main {
    /**
     * Convert a <code>com.sun.media.sound.FastShortMessage</code>
     * object to a <code>ShortMessage</code> object.
     */
    private static ShortMessage conv(MidiMessage mm)
            throws InvalidMidiDataException {
        ShortMessage m = (ShortMessage) mm;
        ShortMessage msg = new ShortMessage();
        int c = m.getStatus();
        switch (c < 0xf0 ? c & 0xf0 : c) {
        case 0x80:
        case 0x90:
        case 0xa0:
        case 0xb0:
        case 0xe0:
        case 0xf2:
            msg.setMessage(c, m.getData1(), m.getData2());
            break;
        case 0xc0:
        case 0xd0:
        case 0xf1:
        case 0xf3:
            msg.setMessage(c, m.getData1(), 0);
            break;
        case 0xf4:
        case 0xf5:
        case 0xf6:
        case 0xf7:
        case 0xf8:
        case 0xf9:
        case 0xfa:
        case 0xfb:
        case 0xfc:
        case 0xfd:
        case 0xfe:
        case 0xff:
            msg.setMessage(c);
            break;
        default:
            throw new InvalidMidiDataException();
        }
        return msg;
    }
}

Related Tutorials