26 #if CONFIG_ENABLE_RTMIDI
31 #include "../../system/log.h"
55 try {
mRtMidi.reset(
new RtMidiIn()); }
56 catch (
const RtMidiError &error)
LogE(
"%s", error.getMessage().c_str());
86 LogW(
"Midi has not been initialized");
91 try { cnt = mRtMidi->getPortCount(); }
92 catch (
const RtMidiError &error)
LogE(
"%s", error.getMessage().c_str());
109 std::stringstream ss;
112 if (i<0 or i>=static_cast<int>(
mRtMidi->getPortCount()))
113 ss <<
"Midi input port #" << i <<
" not available.";
114 else ss << i <<
mRtMidi->getPortName(i);
116 catch (
const RtMidiError &error)
LogE(
"%s", error.getMessage().c_str());
133 LogW(
"Midi has not been initialized");
134 return std::string();
137 std::stringstream ss;
140 if (mRtMidi->getPortCount()==0)
return "No Midi input ports available.";
141 for (
int i=0; i<static_cast<int>(mRtMidi->getPortCount()); i++)
142 ss <<
"Midi input port #" << i <<
": " << mRtMidi->getPortName(i) <<
'\n';
144 catch (
const RtMidiError &error)
LogE(
"%s", error.getMessage().c_str());
164 if (i<0 or i>=static_cast<int>(
mRtMidi->getPortCount()))
166 LogW (
"Invalid port number");
177 catch (
const RtMidiError &error)
LogE(
"%s", error.getMessage().c_str());
199 if (n>0)
return OpenPort(n-1,AppName);
223 std::vector<unsigned char> message;
229 for (
int i=0; i<256; ++i)
231 std::this_thread::sleep_for(
232 std::chrono::microseconds(2));
234 if (message.size()>0) clearing=
true;
237 while (clearing and --timeout>0);
239 catch (
const RtMidiError &error)
LogE(
"%s", error.getMessage().c_str());
263 std::vector< unsigned char > *message,
268 if (message->size()==3)
270 int byte0 = (*message)[0];
273 data.
byte1 = (*message)[1];
274 data.
byte2 = (*message)[2];
286 #endif // CONFIG_ENABLE_RTMIDI
double deltatime
Time elapsed since the last MIDI event.
RtMidiImplementation()
Constructor without functionality.
int mCurrentPort
The current port that is used or -1 of none.
void init() overridefinal
Initialize RtMidi implementation.
std::unique_ptr< RtMidiIn > mRtMidi
Instance of the third-party MIDI interface.
MidiEvent event
Midi event, encoded by the enumeration MidiEvent.
std::string GetPortName(int i) overridefinal
Get the name of device number i (starting with zero)
Midi event when a key is pressed.
void send(Data &data)
Send new MIDI data to the messaging system.
Interface for reading an externally connected MIDI keyboard.
std::string GetPortNames() overridefinal
Get a list of all available input devices.
static void StaticCallback(double deltatime, std::vector< unsigned char > *message, void *)
Static callback function (private)
int byte1
Data byte, usually representing the MIDI key index.
void exit() overridefinal
Shut down RtMidi implementation.
Midi event when a key is released.
static MidiEvent byteToEvent(int byte)
Convert MIDI code to MidiEvent.
int GetNumberOfPorts() overridefinal
Get the number of available MIDI input ports.
Adapter class for reading an externally connected MIDI keyboard.
bool OpenPort(int i, std::string AppName="") overridefinal
Open MIDI input device number i.
int byte2
Data byte, usually representing the keystroke intensity.
void ClearQueue()
Clear the MIDI input queue.
Structure of the data associated with a MIDI event.