Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Public Types | Public Member Functions | List of all members
RtMidiIn Class Reference

A realtime MIDI input class. More...

#include <RtMidi.h>

Inheritance diagram for RtMidiIn:
RtMidi

Public Types

typedef void(* RtMidiCallback )(double timeStamp, std::vector< unsigned char > *message, void *userData)
 User callback function type definition.
 
- Public Types inherited from RtMidi
enum  Api {
  UNSPECIFIED, MACOSX_CORE, LINUX_ALSA, UNIX_JACK,
  WINDOWS_MM, RTMIDI_DUMMY
}
 MIDI API specifier arguments. More...
 

Public Member Functions

 RtMidiIn (RtMidi::Api api=UNSPECIFIED, const std::string clientName=std::string("RtMidi Input Client"), unsigned int queueSizeLimit=100)
 Default constructor that allows an optional api, client name and queue size. More...
 
 ~RtMidiIn (void) throw ()
 If a MIDI connection is still open, it will be closed by the destructor.
 
RtMidi::Api getCurrentApi (void) throw ()
 Returns the MIDI API specifier for the current instance of RtMidiIn.
 
void openPort (unsigned int portNumber=0, const std::string portName=std::string("RtMidi Input"))
 Open a MIDI input connection given by enumeration number. More...
 
void openVirtualPort (const std::string portName=std::string("RtMidi Input"))
 Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only). More...
 
void setCallback (RtMidiCallback callback, void *userData=0)
 Set a callback function to be invoked for incoming MIDI messages. More...
 
void cancelCallback ()
 Cancel use of the current callback function (if one exists). More...
 
void closePort (void)
 Close an open MIDI connection (if one exists).
 
virtual bool isPortOpen () const
 Returns true if a port is open and false if not.
 
unsigned int getPortCount ()
 Return the number of available MIDI input ports. More...
 
std::string getPortName (unsigned int portNumber=0)
 Return a string identifier for the specified MIDI input port number. More...
 
void ignoreTypes (bool midiSysex=true, bool midiTime=true, bool midiSense=true)
 Specify whether certain MIDI message types should be queued or ignored during input. More...
 
double getMessage (std::vector< unsigned char > *message)
 Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds. More...
 
virtual void setErrorCallback (RtMidiErrorCallback errorCallback=NULL)
 Set an error callback function to be invoked when an error has occured. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RtMidi
static std::string getVersion (void) throw ()
 A static function to determine the current RtMidi version.
 
static void getCompiledApi (std::vector< RtMidi::Api > &apis) throw ()
 A static function to determine the available compiled MIDI APIs. More...
 

Detailed Description

A realtime MIDI input class.

This class provides a common, platform-independent API for realtime MIDI input. It allows access to a single MIDI input port. Incoming MIDI messages are either saved to a queue for retrieval using the getMessage() function or immediately passed to a user-specified callback function. Create multiple instances of this class to connect to more than one MIDI device at the same time. With the OS-X, Linux ALSA, and JACK MIDI APIs, it is also possible to open a virtual input port to which other MIDI software clients can connect.

by Gary P. Scavone, 2003-2014.

Constructor & Destructor Documentation

RtMidiIn::RtMidiIn ( RtMidi::Api  api = UNSPECIFIED,
const std::string  clientName = std::string("RtMidi Input Client"),
unsigned int  queueSizeLimit = 100 
)

Default constructor that allows an optional api, client name and queue size.

An exception will be thrown if a MIDI system initialization error occurs. The queue size defines the maximum number of messages that can be held in the MIDI queue (when not using a callback function). If the queue size limit is reached, incoming messages will be ignored.

If no API argument is specified and multiple API support has been compiled, the default order of use is ALSA, JACK (Linux) and CORE, JACK (OS-X).

Parameters
apiAn optional API id can be specified.
clientNameAn optional client name can be specified. This will be used to group the ports that are created by the application.
queueSizeLimitAn optional size of the MIDI input queue can be specified.

Member Function Documentation

void RtMidiIn::openPort ( unsigned int  portNumber = 0,
const std::string  portName = std::string( "RtMidi Input" ) 
)
inlinevirtual

Open a MIDI input connection given by enumeration number.

Parameters
portNumberAn optional port number greater than 0 can be specified. Otherwise, the default or first port found is opened.
portNameAn optional name for the application port that is used to connect to portId can be specified.

Implements RtMidi.

540 { rtapi_->openPort( portNumber, portName ); }
void RtMidiIn::openVirtualPort ( const std::string  portName = std::string( "RtMidi Input" ))
inlinevirtual

Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only).

This function creates a virtual MIDI input port to which other software applications can connect. This type of functionality is currently only supported by the Macintosh OS-X, any JACK, and Linux ALSA APIs (the function returns an error for the other APIs).

Parameters
portNameAn optional name for the application port that is used to connect to portId can be specified.

Implements RtMidi.

541 { rtapi_->openVirtualPort( portName ); }
void RtMidiIn::setCallback ( RtMidiCallback  callback,
void *  userData = 0 
)
inline

Set a callback function to be invoked for incoming MIDI messages.

The callback function will be called whenever an incoming MIDI message is received. While not absolutely necessary, it is best to set the callback function before opening a MIDI port to avoid leaving some messages in the queue.

Parameters
callbackA callback function must be given.
userDataOptionally, a pointer to additional data can be passed to the callback function whenever it is called.
544 { ((MidiInApi *)rtapi_)->setCallback( callback, userData ); }
void RtMidiIn::cancelCallback ( void  )
inline

Cancel use of the current callback function (if one exists).

Subsequent incoming MIDI messages will be written to the queue and can be retrieved with the getMessage function.

545 { ((MidiInApi *)rtapi_)->cancelCallback(); }
unsigned int RtMidiIn::getPortCount ( void  )
inlinevirtual

Return the number of available MIDI input ports.

Returns
This function returns the number of MIDI ports of the selected API.

Implements RtMidi.

546 { return rtapi_->getPortCount(); }
std::string RtMidiIn::getPortName ( unsigned int  portNumber = 0)
inlinevirtual

Return a string identifier for the specified MIDI input port number.

Returns
The name of the port with the given Id is returned.
Return values
Anempty string is returned if an invalid port specifier is provided.

Implements RtMidi.

547 { return rtapi_->getPortName( portNumber ); }
void RtMidiIn::ignoreTypes ( bool  midiSysex = true,
bool  midiTime = true,
bool  midiSense = true 
)
inline

Specify whether certain MIDI message types should be queued or ignored during input.

By default, MIDI timing and active sensing messages are ignored during message input because of their relative high data rates. MIDI sysex messages are ignored by default as well. Variable values of "true" imply that the respective message type will be ignored.

548 { ((MidiInApi *)rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); }
double RtMidiIn::getMessage ( std::vector< unsigned char > *  message)
inline

Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds.

This function returns immediately whether a new message is available or not. A valid message is indicated by a non-zero vector size. An exception is thrown if an error occurs during message retrieval or an input connection was not previously established.

549 { return ((MidiInApi *)rtapi_)->getMessage( message ); }
void RtMidiIn::setErrorCallback ( RtMidiErrorCallback  errorCallback = NULL)
inlinevirtual

Set an error callback function to be invoked when an error has occured.

The callback function will be called whenever an error has occured. It is best to set the error callback function before opening a port.

Implements RtMidi.

550 { rtapi_->setErrorCallback(errorCallback); }

The documentation for this class was generated from the following file:

The Synthesis ToolKit in C++ (STK)
©1995--2014 Perry R. Cook and Gary P. Scavone. All Rights Reserved.