Java examples for javax.sound.midi:MidiMessage
Convert MIDI SysexMessage into a hex-dump string.
/*/* w ww .ja va 2s. com*/ * 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 */ import java.io.File; import javax.sound.midi.*; import java.util.*; public class Main{ private static MidiUtil.SysexInputQueue[] sysexInputQueue; /** * Convert <code>SysexMessage</code> into a hexa-dump string. * * @param m a <code>SysexMessage</code> value * @param bytes number of bytes per line. If equal or less than * 0, no newlines are inserted. * @return a <code>String</code> value */ public static String sysexMessageToString(SysexMessage m, int bytes) { byte[] d = m.getMessage(); return Utility.hexDump(d, 0, -1, bytes); } /** * Convert <code>SysexMessage</code> into a hexa-dump string. If * the length is longer than 16bytes, bytes of middle of the array * are not ignored. * * @param m a <code>SysexMessage</code> value * @return a <code>String</code> value * @exception InvalidMidiDataException if an error occurs */ public static String sysexMessageToString(SysexMessage m) throws InvalidMidiDataException { byte[] d = m.getMessage(); return Utility.hexDumpOneLine(d, 0, -1, 16); } /** * get Sysex Message from MIDI input queue. * @see #getInputMidiDeviceInfo() * @see #clearSysexInputQueue */ static MidiMessage getMessage(int port, long timeout) throws MidiUtil.TimeoutException, InvalidMidiDataException { return sysexInputQueue[port].getMessage(timeout); } }