NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
MIDI Processors

MIDI Processors are objects which can manipulate the content of a MIDIMessage.

The abstract class MIDIProcessor defines basically an object which has a bool MIDIProcessor::Process(MIDITimedMessage* msg) method, which takes a pointer to a MIDITimedMessage as argument: it can change or inspect the message and returns an answer yes/no. Some subclasses are already built in the library:

Many classes (see MIDIInDriver, MIDIOutDriver, MIDIThru, MIDISequencer) have a SetProcessor() method that allows the user to "plug in" a processor in their flow of incoming-outcoming messages. This is an example which could be useful for debugging purposes: plugging a MIDIProcessorPrinter to a MIDIInDriver will print all incoming messages.

#include "manager.h" // includes driver.h and timer.h
#include "processor.h"
int main() {
// this is the MIDI IN port 0 in your system
MIDIProcessorPrinter printer; // creates a printer processor
driver->SetProcessor(&printer); // plugs the printer into the driver
driver->OpenPort(); // starts receiving messages
// waits 20 secs: you can play with a MIDI device connected to the port
// and the incoming messages will be printed on stdout
driver->ClosePort(); // closes the port
return 0;
}
Receives MIDI messages from an hardware MIDI in port.
Definition: driver.h:224
virtual void ClosePort()
Closes the hardware out port.
virtual void SetProcessor(MIDIProcessor *proc)
Sets the in processor, which can manipulate all incoming messages (see MIDIProcessor).
virtual void OpenPort()
Opens the hardware in port.
static MIDIInDriver * GetInDriver(unsigned int n)
Returns a pointer to the MIDIInDriver with given port id.
A MIDIProcessor which prints a human-readable description of the processed messages to a std::ostream...
Definition: processor.h:184
static void Wait(unsigned int msecs)
Stops the calling thread for the given number of milliseconds.
Definition: timer.h:105
Contains the definition of the static class MIDIManager.
Contains the definition of the pure virtual MIDIProcessor class and its specializations MIDIMultiProc...

This is another example using the MIDIThru class.

#include "manager.h" // includes driver.h and timer.h
#include "thru.h"
int main() {
MIDIThru thru; // creates a thru object. It receives and sends
// messages on MIDI IN and OUT ports 0 in your system
MIDIProcessorTransposer tr; // creates a transposer processor
thru.SetProcessor(tr); // plugs the transposer into the thru
tr.SetAllTranspose(12); // set transposing up an octave on all channels
MIDIManager::AddMIDITick(&thru); // adds the thru to the MIDIManager queue
thru.Start(); // starts the thru
// waits 20 secs: you can play with a MIDI device connected to the port
// and the notes will sound one octave up
thru.Stop(); // stops the thru
return 0;
}
static void AddMIDITick(MIDITickComponent *tick)
Inserts a MIDITickComponent object into the queue.
A MIDIProcessor which shifts the pitch of MIDI note and polyphonic pressure messages by a given amoun...
Definition: processor.h:118
void SetAllTranspose(int trans)
Sets the same transposing amount (in semitones) for all the channels.
A MIDITickComponent which immediately echoes to an out MIDI port all messages incoming from an in MID...
Definition: thru.h:44
virtual void Stop()
Stops the MIDI thru.
virtual void SetProcessor(MIDIProcessor *proc)
Sets the out processor, which can manipulate messages arrived to the in port before they are sent to ...
virtual void Start()
Starts the MIDI thru.
Contains the definition of the class MIDIThru.

A similar use of the MIDIProcessorPrinter is done in the test_thru.cpp example file.