Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / sound / midi / SysexMessage.java
blob7ab60f4b6af64971eec54618fd00e27e42985dab
1 /* SysexMessage.java -- System Exclusive MIDI message.
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.sound.midi;
41 /**
42 * A system exclusive MIDI message.
44 * @author Anthony Green (green@redhat.com)
45 * @since 1.3
48 public class SysexMessage extends MidiMessage
50 public static final int SYSTEM_EXCLUSIVE = 0xF0;
52 public static final int SPECIAL_SYSTEM_EXCLUSIVE = 0xF7;
54 /**
55 * Create a default valid system exclusive message.
57 * The official specs don't specify what message is to be
58 * created. Our implementation creates an empty
59 * system exclusive message.
61 public SysexMessage()
63 super(new byte[2]);
64 data[0] = (byte) SYSTEM_EXCLUSIVE;
65 data[1] = (byte) ShortMessage.END_OF_EXCLUSIVE;
68 /**
69 * Create a SysexMessage object.
70 * @param data a complete system exclusive message
72 public SysexMessage(byte[] data)
74 super(data);
77 /**
78 * Set the sysex message. The first data byte (status) must be
79 * 0xF0 or 0xF7.
81 * @param data the message data
82 * @param length the length of the message data
83 * @throws InvalidMidiDataException if the status byte is not 0xF0 or 0xF7
85 public void setMessage(byte[] data, int length)
86 throws InvalidMidiDataException
88 if (data[0] != SYSTEM_EXCLUSIVE
89 || data[0] != SPECIAL_SYSTEM_EXCLUSIVE)
90 throw new InvalidMidiDataException("Sysex message starts with 0x"
91 + Integer.toHexString(data[0])
92 + " instead of 0xF0 or 0xF7");
93 super.setMessage(data, length);
96 /**
97 * Set the sysex message. status must be either 0xF0 or 0xF7.
99 * @param status the sysex statys byte (0xF0 or 0xF7)
100 * @param data the message data
101 * @param length the length of the message data
102 * @throws InvalidMidiDataException if status is not 0xF0 or 0xF7
104 public void setMessage(int status, byte[] data, int length)
105 throws InvalidMidiDataException
107 if (status != SYSTEM_EXCLUSIVE
108 || status != SPECIAL_SYSTEM_EXCLUSIVE)
109 throw new InvalidMidiDataException("Sysex message starts with 0x"
110 + Integer.toHexString(status)
111 + " instead of 0xF0 or 0xF7");
112 this.data = new byte[length+1];
113 this.data[0] = (byte) status;
114 System.arraycopy(data, 0, this.data, 1, length);
115 this.length = length+1;
119 * Get the data for this message, not including the status byte.
120 * @return the message data, not including the status byte
122 public byte[] getData()
124 byte[] result = new byte[length - 1];
125 System.arraycopy(data, 1, result, 0, length - 1);
126 return result;
129 /* Create a deep-copy clone of this object.
130 * @see java.lang.Object#clone()
132 public Object clone()
134 byte message[] = new byte[length];
135 System.arraycopy(data, 0, message, 0, length);
136 return new SysexMessage(message);