Class MidiProcessor

  • All Implemented Interfaces:
    AutoCloseable, Receiver

    public class MidiProcessor
    extends Object
    implements Receiver
    A Receiver that splits MIDI chords into notes distributed across all MIDI channels before forwarding the new MidiMessages to another Receiver.
    Since:
    2020-03-08
    • Constructor Detail

      • MidiProcessor

        public MidiProcessor​(MidiDevice midiReceiver,
                             boolean debugMode)
                      throws MidiUnavailableException
        Constructs a MidiProcessor using a MidiDevice with the option to run in debugging mode. All MIDI channels are set to available.
        Parameters:
        midiReceiver - the MIDI device to send processed messages to
        debugMode - specifies whether to enable debugging messages
        Throws:
        MidiUnavailableException - if the provided MidiDevice won't supply a receiver
      • MidiProcessor

        public MidiProcessor​(Receiver receiver,
                             boolean debugMode)
        Constructs a MidiProcessor using a Receiver with the option to run in debugging mode. All MIDI channels are set to available.
        Parameters:
        receiver - the MIDI receiver to send processed messages to
        debugMode - specifies whether to enable debugging messages
      • MidiProcessor

        public MidiProcessor​(Receiver receiver)
        Constructs a MidiProcessor using a Receiver without debugging output. All MIDI channels are set to available.
        Parameters:
        receiver - the MIDI receiver to send processed messages to
    • Method Detail

      • send

        public void send​(MidiMessage message,
                         long timeStamp)
        Sends a MIDI message to this receiver, along with an optional timestamp. Set timestamp to -1 if not used.
        Specified by:
        send in interface Receiver
        Parameters:
        message - the message to be received and processed by this MidiProcessor
        timeStamp - the timestamp (in microseconds) of the message
      • close

        public void close()
        Closes this MidiProcessor and releases its resources, specifically the MIDI device assigned with setReceiver or the constructor.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Receiver
      • isRunning

        public boolean isRunning()
        Checks whether or not close has been called on this MidiProcessor.
        Returns:
        false if close has been called; true otherwise
      • setReceiver

        public void setReceiver​(Receiver receiver)
        Sets the Receiver that processed messages are sent to.
        Parameters:
        receiver - the desired MIDI receiver
        See Also:
        setReceiver(MidiDevice)
      • channelAvailable

        public boolean channelAvailable​(int channel)
        Reports whether or not a MIDI channel is currently in use.
        Parameters:
        channel - the channel to check for availability
        Returns:
        true if channel is available; false if channel is out of range or in use
      • leastUsedChannel

        public int leastUsedChannel()
        Finds the MIDI channel with the least amount of uses, returning the lower channel if multiple have an equal number of uses.
        Returns:
        the MIDI channel number of the least used channel
      • translateMessage

        public ShortMessage translateMessage​(ShortMessage message)
        Translates the provided message onto the correct MIDI channel. If it is available, the original channel of message is chosen, otherwise the next available channel from 0 is chosen.
        Parameters:
        message - the message to be translated
        Returns:
        the translated version of message