Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RtMidiImplementation Class Reference

Interface for reading an externally connected MIDI keyboard. More...

#include <RtMidiimplementation.h>

+ Inheritance diagram for RtMidiImplementation:
+ Collaboration diagram for RtMidiImplementation:

Public Member Functions

 RtMidiImplementation ()
 Constructor without functionality. More...
 
 ~RtMidiImplementation ()
 Destructor without functionality. More...
 
void init () overridefinal
 Initialize RtMidi implementation. More...
 
void exit () overridefinal
 Shut down RtMidi implementation. More...
 
int GetNumberOfPorts () overridefinal
 Get the number of available MIDI input ports. More...
 
std::string GetPortName (int i) overridefinal
 Get the name of device number i (starting with zero) More...
 
std::string GetPortNames () overridefinal
 Get a list of all available input devices. More...
 
bool OpenPort (int i, std::string AppName="") overridefinal
 Open MIDI input device number i. More...
 
bool OpenPort (std::string AppName="") overridefinal
 Open MIDI device with the highest port number. More...
 
int getCurrentPort () const overridefinal
 Get the current port number. More...
 
- Public Member Functions inherited from MidiAdapter
 MidiAdapter ()
 Constructor without function. More...
 
 ~MidiAdapter ()
 Destructor without function. More...
 
void send (Data &data)
 Send new MIDI data to the messaging system. More...
 

Private Member Functions

void ClearQueue ()
 Clear the MIDI input queue. More...
 

Static Private Member Functions

static void StaticCallback (double deltatime, std::vector< unsigned char > *message, void *)
 Static callback function (private) More...
 

Private Attributes

std::unique_ptr< RtMidiIn > mRtMidi
 Instance of the third-party MIDI interface. More...
 
int mCurrentPort
 The current port that is used or -1 of none. More...
 

Additional Inherited Members

- Public Types inherited from MidiAdapter
enum  MidiEvent { MIDI_UNDEFINED = 0, MIDI_KEY_PRESS, MIDI_KEY_RELEASE, MIDI_CONTROL_CHANGE }
 Enumeration of the possible MIDI events. More...
 
- Static Public Member Functions inherited from MidiAdapter
static MidiEvent byteToEvent (int byte)
 Convert MIDI code to MidiEvent. More...
 

Detailed Description

Interface for reading an externally connected MIDI keyboard.

This class provides a simplified interface for reading external MIDI keyboards. It uses the third-party software RtMidi 2.1.0 which is published under the same license.

See also
Source: http://www.music.mcgill.ca/~gary/rtmidi/ A documentation of RtMidi is not included here. If you need more information please refer to the above website.

Requirements for Linux: alsa_devel, library asound, #define LINUX_ALSA

Definition at line 52 of file RtMidiimplementation.h.

Constructor & Destructor Documentation

RtMidiImplementation::RtMidiImplementation ( )

Constructor without functionality.

Definition at line 37 of file RtMidiimplementation.cpp.

RtMidiImplementation::~RtMidiImplementation ( )
inline

Destructor without functionality.

Definition at line 56 of file RtMidiimplementation.h.

Member Function Documentation

void RtMidiImplementation::ClearQueue ( )
private

Clear the MIDI input queue.

This functions polls data from the queue until it is empty. Here the timing is crucial.

Details: Clearing the queue in RtMidi requires some effort. The queue is read via getMessage in intervals of 2 us. Unfortunately this function does not really tell us wether the queue is empty, rather it may respond after some time. To circumvent this problem we decalare the queue as empty if 1024 request do not render an event.

Definition at line 219 of file RtMidiimplementation.cpp.

void RtMidiImplementation::exit ( )
finaloverridevirtual

Shut down RtMidi implementation.

Destroys the RtMidi instance, resetting the pointer mRtMidi.

Implements MidiAdapter.

Definition at line 68 of file RtMidiimplementation.cpp.

int RtMidiImplementation::getCurrentPort ( ) const
inlinefinaloverridevirtual

Get the current port number.

Implements MidiAdapter.

Definition at line 66 of file RtMidiimplementation.h.

int RtMidiImplementation::GetNumberOfPorts ( )
finaloverridevirtual

Get the number of available MIDI input ports.

Returns
Number of available MIDI ports (0=none).

Implements MidiAdapter.

Definition at line 82 of file RtMidiimplementation.cpp.

std::string RtMidiImplementation::GetPortName ( int  i)
finaloverridevirtual

Get the name of device number i (starting with zero)

Parameters
i: Number of the port starting with 0
Returns
Name of the MIDI device connected to port i

Implements MidiAdapter.

Definition at line 107 of file RtMidiimplementation.cpp.

std::string RtMidiImplementation::GetPortNames ( )
finaloverridevirtual

Get a list of all available input devices.

Returns
List of all available MIDI devices as a single string

Reimplemented from MidiAdapter.

Definition at line 129 of file RtMidiimplementation.cpp.

void RtMidiImplementation::init ( )
finaloverridevirtual

Initialize RtMidi implementation.

Initializes the RtMidi implementation by trying to create a new instance. Exception errors are caught and converted into conventional error messages.

Implements MidiAdapter.

Definition at line 53 of file RtMidiimplementation.cpp.

bool RtMidiImplementation::OpenPort ( int  i,
std::string  AppName = "" 
)
finaloverridevirtual

Open MIDI input device number i.

Parameters
i: Number of the MIDI port to be opened.
AppName: Name of the application (e.g. Entropy Piano Tuner Midi in). Shows up in the list MIDI input devices.
Returns
True if successful.

Implements MidiAdapter.

Definition at line 160 of file RtMidiimplementation.cpp.

+ Here is the call graph for this function:

bool RtMidiImplementation::OpenPort ( std::string  AppName = "")
finaloverridevirtual

Open MIDI device with the highest port number.

If MIDI devices are connected, this function opens the port with the highest number (usually this is the last one that has been connected to the computer).

Parameters
AppName: Name of the application (e.g. Entropy Piano Tuner Midi in). Shows up in the list MIDI input devices.
Returns
True if successful.

Implements MidiAdapter.

Definition at line 196 of file RtMidiimplementation.cpp.

+ Here is the call graph for this function:

void RtMidiImplementation::StaticCallback ( double  deltatime,
std::vector< unsigned char > *  message,
void *  obj 
)
staticprivate

Static callback function (private)

The RtMidi package does not admit member functions for callback. To circumvent this restriction, we define a static callback function to which all MIDI events are passed. The third user-specific parameter void pointer passes the address of the object. The purpose of the callback function is to send off the received data to the messaging system.

Parameters
deltatime: passes the elapsed time since the last callback
message: Pointer to a vector containing the MIDI event data.
obj: Pointer to the instance of this class. See also: RtMidiImplementation::OpenPort

Definition at line 262 of file RtMidiimplementation.cpp.

+ Here is the call graph for this function:

Member Data Documentation

int RtMidiImplementation::mCurrentPort
private

The current port that is used or -1 of none.

Static callback function, required by RtMidi.

Definition at line 71 of file RtMidiimplementation.h.

std::unique_ptr<RtMidiIn> RtMidiImplementation::mRtMidi
private

Instance of the third-party MIDI interface.

Definition at line 70 of file RtMidiimplementation.h.


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