javax.sound.midi

Class MidiMessage

  • All Implemented Interfaces:
    Cloneable
    Direct Known Subclasses:
    MetaMessage, ShortMessage, SysexMessage

    public abstract class MidiMessage
    extends Object
    implements Cloneable
    MidiMessage is the base class for MIDI messages. They include not only the standard MIDI messages that a synthesizer can respond to, but also "meta-events" that can be used by sequencer programs. There are meta-events for such information as lyrics, copyrights, tempo indications, time and key signatures, markers, etc. For more information, see the Standard MIDI Files 1.0 specification, which is part of the Complete MIDI 1.0 Detailed Specification published by the MIDI Manufacturer's Association (http://www.midi.org).

    The base MidiMessage class provides access to three types of information about a MIDI message:

    • The messages's status byte
    • The total length of the message in bytes (the status byte plus any data bytes)
    • A byte array containing the complete message
    MidiMessage includes methods to get, but not set, these values. Setting them is a subclass responsibility.

    The MIDI standard expresses MIDI data in bytes. However, because JavaTM uses signed bytes, the Java Sound API uses integers instead of bytes when expressing MIDI data. For example, the getStatus() method of MidiMessage returns MIDI status bytes as integers. If you are processing MIDI data that originated outside Java Sound and now is encoded as signed bytes, the bytes can can be converted to integers using this conversion:

    int i = (int)(byte & 0xFF)

    If you simply need to pass a known MIDI byte value as a method parameter, it can be expressed directly as an integer, using (for example) decimal or hexidecimal notation. For instance, to pass the "active sensing" status byte as the first argument to ShortMessage's setMessage(int) method, you can express it as 254 or 0xFE.

    See Also:
    Track, Sequence, Receiver
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected byte[] data
      The MIDI message data.
      protected int length
      The number of bytes in the MIDI message, including the status byte and any data bytes.

        

    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected MidiMessage(byte[] data)
      Constructs a new MidiMessage.

        

    • Method Summary

      Methods 
      Modifier and Type Method and Description
      abstract Object clone()
      Creates a new object of the same class and with the same contents as this object.
      int getLength()
      Obtains the total length of the MIDI message in bytes.
      byte[] getMessage()
      Obtains the MIDI message data.
      int getStatus()
      Obtains the status byte for the MIDI message.
      protected void setMessage(byte[] data, int length)
      Sets the data for the MIDI message.

        

    • Field Detail

      • data

        protected byte[] data
        The MIDI message data. The first byte is the status byte for the message; subsequent bytes up to the length of the message are data bytes for this message.
        See Also:
        getLength()
      • length

        protected int length
        The number of bytes in the MIDI message, including the status byte and any data bytes.
        See Also:
        getLength()
    • Constructor Detail

      • MidiMessage

        protected MidiMessage(byte[] data)
        Constructs a new MidiMessage. This protected constructor is called by concrete subclasses, which should ensure that the data array specifies a complete, valid MIDI message.
        Parameters:
        data - an array of bytes containing the complete message. The message data may be changed using the setMessage method.
        See Also:
        setMessage(byte[], int)
    • Method Detail

      • setMessage

        protected void setMessage(byte[] data,
                      int length)
                           throws InvalidMidiDataException
        Sets the data for the MIDI message. This protected method is called by concrete subclasses, which should ensure that the data array specifies a complete, valid MIDI message.
        Throws:
        InvalidMidiDataException
      • getMessage

        public byte[] getMessage()
        Obtains the MIDI message data. The first byte of the returned byte array is the status byte of the message. Any subsequent bytes up to the length of the message are data bytes. The byte array may have a length which is greater than that of the actual message; the total length of the message in bytes is reported by the getLength() method.
        Returns:
        the byte array containing the complete MidiMessage data
      • getStatus

        public int getStatus()
        Obtains the status byte for the MIDI message. The status "byte" is represented as an integer; see the discussion in the MidiMessage class description.
        Returns:
        the integer representation of this event's status byte
      • getLength

        public int getLength()
        Obtains the total length of the MIDI message in bytes. A MIDI message consists of one status byte and zero or more data bytes. The return value ranges from 1 for system real-time messages, to 2 or 3 for channel messages, to any value for meta and system exclusive messages.
        Returns:
        the length of the message in bytes
      • clone

        public abstract Object clone()
        Creates a new object of the same class and with the same contents as this object.
        Overrides:
        clone in class Object
        Returns:
        a clone of this instance.
        See Also:
        Cloneable

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

22/12/2024 10:34:11 Cette version de la page est en cache (à la date du 22/12/2024 10:34:11) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.

Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/sound/midi/MidiMessage.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, MidiMessage

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut