Package eu.bandm.music.midi
Class Routing
java.lang.Object
eu.bandm.music.midi.Routing
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.)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
AReceiver
receives a {link MidiMessage} and a time stamp.static class
A wrapper which takes aReceiver
and adds interfaces and convenience methods.static enum
The midi command code values, as encoded in the top four bit of a status byte.static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Motif
<MidiMessage, MidiEvent> A pattern matching the command codes which are acoompanied by a channel number.static final int
To be used when time values are not significant. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Opt PreMessage
checkParameterValue
(int i, String text) Checks whether the given value is allowed as a parameter for one MIDI data byte.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.static int
extractChannel
(int m) Extract the channel number from the first byte (="status byte") of a midi message.static int
extractCommand
(int m) Extract the command code from the first byte (="status byte") of a midi message.static int
Extract a keyboard key number from the second byte of a short message.static Pattern
<MidiMessage> static void
static Pattern
<MidiMessage> metaType
(int mt) static int
packStatus
(int code, int channel) Encode a command code and a channel number into the status byte of a MIDI message.range
(int from, int to) A pattern which matches any Integer in the range between the two bounds.rangeIncluded
(int from, int to) A pattern which matches any Integer in the range between the two bounds, with both included.static Receiver
rec
(Consumer<MidiMessage> c) static Pattern
<MidiMessage> statusByte
(Pattern<Integer> command, Pattern<Integer> channel) Constructs a Pattern for an integer which represents a status byte.statusByteE
(Pattern<Integer> command, Pattern<Integer> channel) static Pattern
<MidiMessage> statusByteM
(Pattern<Integer> command, Pattern<Integer> channel) Replace by content( statusByte(..,..))static Pattern
<MidiMessage>
-
Field Details
-
NO_TIME_INFO
public static final int NO_TIME_INFOTo be used when time values are not significant. The API doc ofReceiver
says:
»If time-stamping is not supported by this receiver, the time-stamp value should be -1.«- See Also:
-
isChannelMessage
A pattern matching the command codes which are acoompanied by a channel number. -
-
any
-
anyE
-
-
Constructor Details
-
Routing
public Routing()
-
-
Method Details
-
checkParameterValue
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 encodedMidiMessage
status byte.- Returns:
- the int value of the MIDI command, based on zero, ie.
from
midiStatusCommand.noteOn.ordinal()
tomidiStatusCommand.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 aMidiMessage
status byte.- Returns:
- the int value of the adressed channel, from 0 to 15
-
extract14bits
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
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
A pattern which matches any Integer in the range between the two bounds, with both included. -
range
A pattern which matches any Integer in the range between the two bounds. The lower limit is included, the upper not. -
statusByte
Constructs a Pattern for an integer which represents a status byte. -
status
-
statusByteM
Replace by content( statusByte(..,..)) -
statusByteE
-
system
-
metaType
-
systemM
-
systemE
-
keyM
-
rec
-
main
- Throws:
InvalidMidiDataException
IOException
-