Class MidiProcessor
- java.lang.Object
-
- com.github.noahr_atc.midisplitter.MidiProcessor
-
- All Implemented Interfaces:
AutoCloseable,Receiver
public class MidiProcessor extends Object implements Receiver
AReceiverthat splits MIDI chords into notes distributed across all MIDI channels before forwarding the newMidiMessages to another Receiver.- Since:
- 2020-03-08
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classMidiProcessor.ChannelStatusRepresents whether or not a MIDI channel is available, as well as how many notes need to be turned off before the will be available.static classMidiProcessor.ExceededMidiChannelsExceptionIndicates that all 16 MIDI channels are in use and the current note cannot be distributed to a unique channel.protected static classMidiProcessor.NoteMappingRepresents an entry in aMidiProcessor's note translation map.
-
Constructor Summary
Constructors Constructor Description MidiProcessor(MidiDevice midiReceiver)Constructs aMidiProcessorusing aMidiDevicewithout debugging output.MidiProcessor(MidiDevice midiReceiver, boolean debugMode)Constructs aMidiProcessorusing aMidiDevicewith the option to run in debugging mode.MidiProcessor(Receiver receiver)Constructs aMidiProcessorusing aReceiverwithout debugging output.MidiProcessor(Receiver receiver, boolean debugMode)Constructs aMidiProcessorusing aReceiverwith the option to run in debugging mode.
-
Method Summary
Modifier and Type Method Description booleanchannelAvailable(int channel)Reports whether or not a MIDI channel is currently in use.voidclose()Closes thisMidiProcessorand releases its resources, specifically the MIDI device assigned with setReceiver or the constructor.intfirstAvailableChannel()Finds the first MIDI channel from 0 that a message hasn't currently been translated to.booleanisRunning()Checks whether or notclosehas been called on thisMidiProcessor.intleastUsedChannel()Finds the MIDI channel with the least amount of uses, returning the lower channel if multiple have an equal number of uses.voidsend(MidiMessage message, long timeStamp)Sends a MIDI message to this receiver, along with an optional timestamp.voidsetReceiver(MidiDevice midiReceiver)Opens a MIDI device and sets it as theReceiverthat processed messages are sent to.voidsetReceiver(Receiver receiver)Sets theReceiverthat processed messages are sent to.ShortMessagetranslateMessage(ShortMessage message)Translates the provided message onto the correct MIDI channel.
-
-
-
Constructor Detail
-
MidiProcessor
public MidiProcessor(MidiDevice midiReceiver, boolean debugMode) throws MidiUnavailableException
Constructs aMidiProcessorusing aMidiDevicewith the option to run in debugging mode. All MIDI channels are set to available.- Parameters:
midiReceiver- the MIDI device to send processed messages todebugMode- specifies whether to enable debugging messages- Throws:
MidiUnavailableException- if the providedMidiDevicewon't supply a receiver
-
MidiProcessor
public MidiProcessor(MidiDevice midiReceiver) throws MidiUnavailableException
Constructs aMidiProcessorusing aMidiDevicewithout debugging output. All MIDI channels are set to available.- Parameters:
midiReceiver- the MIDI device to send processed messages to- Throws:
MidiUnavailableException- if the providedMidiDevicewon't supply a receiver
-
MidiProcessor
public MidiProcessor(Receiver receiver, boolean debugMode)
Constructs aMidiProcessorusing aReceiverwith the option to run in debugging mode. All MIDI channels are set to available.- Parameters:
receiver- the MIDI receiver to send processed messages todebugMode- specifies whether to enable debugging messages
-
-
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.
-
close
public void close()
Closes thisMidiProcessorand releases its resources, specifically the MIDI device assigned with setReceiver or the constructor.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceReceiver
-
isRunning
public boolean isRunning()
Checks whether or notclosehas been called on thisMidiProcessor.- Returns:
falseifclosehas been called;trueotherwise
-
setReceiver
public void setReceiver(MidiDevice midiReceiver) throws MidiUnavailableException, NullPointerException
Opens a MIDI device and sets it as theReceiverthat processed messages are sent to.- Parameters:
midiReceiver- the desired MIDI device to receive messages- Throws:
MidiUnavailableException- if the providedMidiDevicewon't supply a receiverNullPointerException- if the providedMidiDeviceis null- See Also:
setReceiver(Receiver)
-
setReceiver
public void setReceiver(Receiver receiver)
Sets theReceiverthat 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:
trueifchannelis available;falseifchannelis out of range or in use
-
firstAvailableChannel
public int firstAvailableChannel() throws MidiProcessor.ExceededMidiChannelsExceptionFinds the first MIDI channel from 0 that a message hasn't currently been translated to.- Returns:
- the MIDI channel number of the available channel
- Throws:
MidiProcessor.ExceededMidiChannelsException- if all MIDI channels are 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 ofmessageis chosen, otherwise the next available channel from 0 is chosen.- Parameters:
message- the message to be translated- Returns:
- the translated version of
message
-
-