Class Routing

java.lang.Object
eu.bandm.music.midi.Routing

public class Routing extends Object
Contains methods and classes for networks which process MIDI messages and MIDI events. It contains additional wrappers which lift some deficient classes from java.sound.midi to the modern Collection and functional interfaces.

The basic data structures defined by the JRE infrastructure are

   +----- MidiEvent---+
   |  long tick       |
   | +--MidiMessage-+ |
   | |              | |
   | +--------------+ |
   +------------------*
  
  

(The time stamps in Midi Events, coming from a midi standard file, and those coming with MidiMessages (as separate method parameters) may have different scaling and meaning.)

  • Field Details

    • NO_TIME_INFO

      public static final int NO_TIME_INFO
      To be used when time values are not significant. The API doc of Receiver says:
      »If time-stamping is not supported by this receiver, the time-stamp value should be -1.«
      See Also:
    • isChannelMessage

      public static Pattern<Integer> isChannelMessage
      A pattern matching the command codes which are acoompanied by a channel number.
    • content

      public static Motif<MidiMessage,MidiEvent> content
    • any

      protected static Pattern<Integer> any
    • anyE

      protected static Pattern<MidiEvent> anyE
  • Constructor Details

    • Routing

      public Routing()
  • Method Details

    • checkParameterValue

      @Opt public static @Opt PreMessage checkParameterValue(int i, String text)
      Checks whether the given value is allowed as a parameter for one MIDI data byte.
      Parameters:
      i - signed parameter value, must be in the range 0..127 (incl.)
      text - the role of the parameter as contained in the error message.
      Returns:
      an error message or null for success.
    • extractCommand

      public static int extractCommand(int m)
      Extract the command code from the first byte (="status byte") of a midi message.
      Parameters:
      m - the int value of an encoded MidiMessage status byte.
      Returns:
      the int value of the MIDI command, based on zero, ie. from midiStatusCommand.noteOn.ordinal() to midiStatusCommand.systemMessage.ordinal(), as defined in this file.
    • extractChannel

      public static int extractChannel(int m)
      Extract the channel number from the first byte (="status byte") of a midi message.
      Parameters:
      m - the int value of a MidiMessage status byte.
      Returns:
      the int value of the adressed channel, from 0 to 15
    • extract14bits

      public static int extract14bits(ShortMessage message)
      Extract the 14 bits from the second and third byte of a short message, as high bits and low bits. These make up the value of a pitch bend message.
      Parameters:
      message - a complete MIDI message.
      Returns:
      the int value when concatenating the 7 lower bits of the two data byes, high byte first.
    • packStatus

      public static int packStatus(int code, int channel)
      Encode a command code and a channel number into the status byte of a MIDI message.
      Parameters:
      code - the int value of the command, packed into the higher nibble. (May by based on zero or eight, since hi bit will be set anyhow.)
      channel - value packed into the lower nibble.
      Returns:
      the int value of the status byte, high bit always set
    • extractKeyNumber

      public static int extractKeyNumber(MidiMessage m)
      Extract a keyboard key number from the second byte of a short message. This method does only make sense when a key value is really part of the message, i.e. the commands from "midi_note_off" to "midi_polyphonic_aftertouch". In case of "midi_program_change" and "midi_control_change" it can be used to get the data byte, but this is an abuse w.r.t. the name of this method.

      (Java bytes are signed and must be converted to int to get their midi meaning, wich is unsigned.)

      Parameters:
      m - a complete MIDI message.
      Returns:
      the int value of the second byte, which for most short messages indicates the keyboard key number.
    • rangeIncluded

      public static Pattern<Integer> rangeIncluded(int from, int to)
      A pattern which matches any Integer in the range between the two bounds, with both included.
    • range

      public static Pattern<Integer> range(int from, int to)
      A pattern which matches any Integer in the range between the two bounds. The lower limit is included, the upper not.
    • statusByte

      public static Pattern<Integer> statusByte(Pattern<Integer> command, Pattern<Integer> channel)
      Constructs a Pattern for an integer which represents a status byte.
    • status

      public static Pattern<MidiMessage> status(Pattern<Integer> statusByte)
    • statusByteM

      public static Pattern<MidiMessage> statusByteM(Pattern<Integer> command, Pattern<Integer> channel)
      Replace by content( statusByte(..,..))
    • statusByteE

      public static Pattern<MidiEvent> statusByteE(Pattern<Integer> command, Pattern<Integer> channel)
    • system

      public static Pattern<Integer> system(Pattern<Integer> systemMessage)
    • metaType

      public static Pattern<MidiMessage> metaType(int mt)
    • systemM

      public static Pattern<MidiMessage> systemM(Pattern<Integer> systemMessage)
    • systemE

      public static Pattern<MidiEvent> systemE(Pattern<Integer> systemMessage)
    • keyM

      public static Pattern<MidiMessage> keyM(Pattern<Integer> keyNumber)
    • rec

      public static Receiver rec(Consumer<MidiMessage> c)
    • main

      public static void main(String[] args) throws InvalidMidiDataException, IOException
      Throws:
      InvalidMidiDataException
      IOException