RtMidi.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /**********************************************************************/
  2. /*! \class RtMidi
  3. \brief An abstract base class for realtime MIDI input/output.
  4. This class implements some common functionality for the realtime
  5. MIDI input/output subclasses RtMidiIn and RtMidiOut.
  6. RtMidi GitHub site: https://github.com/thestk/rtmidi
  7. RtMidi WWW site: http://www.music.mcgill.ca/~gary/rtmidi/
  8. RtMidi: realtime MIDI i/o C++ classes
  9. Copyright (c) 2003-2019 Gary P. Scavone
  10. Permission is hereby granted, free of charge, to any person
  11. obtaining a copy of this software and associated documentation files
  12. (the "Software"), to deal in the Software without restriction,
  13. including without limitation the rights to use, copy, modify, merge,
  14. publish, distribute, sublicense, and/or sell copies of the Software,
  15. and to permit persons to whom the Software is furnished to do so,
  16. subject to the following conditions:
  17. The above copyright notice and this permission notice shall be
  18. included in all copies or substantial portions of the Software.
  19. Any person wishing to distribute modifications to the Software is
  20. asked to send the modifications to the original developer so that
  21. they can be incorporated into the canonical version. This is,
  22. however, not a binding provision of this license.
  23. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  27. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  28. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. */
  31. /**********************************************************************/
  32. /*!
  33. \file RtMidi.h
  34. */
  35. #ifndef RTMIDI_H
  36. #define RTMIDI_H
  37. #if defined _WIN32 || defined __CYGWIN__
  38. #if defined(RTMIDI_EXPORT)
  39. #define RTMIDI_DLL_PUBLIC __declspec(dllexport)
  40. #else
  41. #define RTMIDI_DLL_PUBLIC
  42. #endif
  43. #else
  44. #if __GNUC__ >= 4
  45. #define RTMIDI_DLL_PUBLIC __attribute__( (visibility( "default" )) )
  46. #else
  47. #define RTMIDI_DLL_PUBLIC
  48. #endif
  49. #endif
  50. #define RTMIDI_VERSION "4.0.0"
  51. #include <exception>
  52. #include <iostream>
  53. #include <string>
  54. #include <vector>
  55. /************************************************************************/
  56. /*! \class RtMidiError
  57. \brief Exception handling class for RtMidi.
  58. The RtMidiError class is quite simple but it does allow errors to be
  59. "caught" by RtMidiError::Type. See the RtMidi documentation to know
  60. which methods can throw an RtMidiError.
  61. */
  62. /************************************************************************/
  63. class RTMIDI_DLL_PUBLIC RtMidiError : public std::exception
  64. {
  65. public:
  66. //! Defined RtMidiError types.
  67. enum Type {
  68. WARNING, /*!< A non-critical error. */
  69. DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
  70. UNSPECIFIED, /*!< The default, unspecified error type. */
  71. NO_DEVICES_FOUND, /*!< No devices found on system. */
  72. INVALID_DEVICE, /*!< An invalid device ID was specified. */
  73. MEMORY_ERROR, /*!< An error occured during memory allocation. */
  74. INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
  75. INVALID_USE, /*!< The function was called incorrectly. */
  76. DRIVER_ERROR, /*!< A system driver error occured. */
  77. SYSTEM_ERROR, /*!< A system error occured. */
  78. THREAD_ERROR /*!< A thread error occured. */
  79. };
  80. //! The constructor.
  81. RtMidiError( const std::string& message, Type type = RtMidiError::UNSPECIFIED ) throw()
  82. : message_(message), type_(type) {}
  83. //! The destructor.
  84. virtual ~RtMidiError( void ) throw() {}
  85. //! Prints thrown error message to stderr.
  86. virtual void printMessage( void ) const throw() { std::cerr << '\n' << message_ << "\n\n"; }
  87. //! Returns the thrown error message type.
  88. virtual const Type& getType( void ) const throw() { return type_; }
  89. //! Returns the thrown error message string.
  90. virtual const std::string& getMessage( void ) const throw() { return message_; }
  91. //! Returns the thrown error message as a c-style string.
  92. virtual const char* what( void ) const throw() { return message_.c_str(); }
  93. protected:
  94. std::string message_;
  95. Type type_;
  96. };
  97. //! RtMidi error callback function prototype.
  98. /*!
  99. \param type Type of error.
  100. \param errorText Error description.
  101. Note that class behaviour is undefined after a critical error (not
  102. a warning) is reported.
  103. */
  104. typedef void (*RtMidiErrorCallback)( RtMidiError::Type type, const std::string &errorText, void *userData );
  105. class MidiApi;
  106. class RTMIDI_DLL_PUBLIC RtMidi
  107. {
  108. public:
  109. //! MIDI API specifier arguments.
  110. enum Api {
  111. UNSPECIFIED, /*!< Search for a working compiled API. */
  112. MACOSX_CORE, /*!< Macintosh OS-X CoreMIDI API. */
  113. LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
  114. UNIX_JACK, /*!< The JACK Low-Latency MIDI Server API. */
  115. WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
  116. RTMIDI_DUMMY, /*!< A compilable but non-functional API. */
  117. NUM_APIS /*!< Number of values in this enum. */
  118. };
  119. //! A static function to determine the current RtMidi version.
  120. static std::string getVersion( void ) throw();
  121. //! A static function to determine the available compiled MIDI APIs.
  122. /*!
  123. The values returned in the std::vector can be compared against
  124. the enumerated list values. Note that there can be more than one
  125. API compiled for certain operating systems.
  126. */
  127. static void getCompiledApi( std::vector<RtMidi::Api> &apis ) throw();
  128. //! Return the name of a specified compiled MIDI API.
  129. /*!
  130. This obtains a short lower-case name used for identification purposes.
  131. This value is guaranteed to remain identical across library versions.
  132. If the API is unknown, this function will return the empty string.
  133. */
  134. static std::string getApiName( RtMidi::Api api );
  135. //! Return the display name of a specified compiled MIDI API.
  136. /*!
  137. This obtains a long name used for display purposes.
  138. If the API is unknown, this function will return the empty string.
  139. */
  140. static std::string getApiDisplayName( RtMidi::Api api );
  141. //! Return the compiled MIDI API having the given name.
  142. /*!
  143. A case insensitive comparison will check the specified name
  144. against the list of compiled APIs, and return the one which
  145. matches. On failure, the function returns UNSPECIFIED.
  146. */
  147. static RtMidi::Api getCompiledApiByName( const std::string &name );
  148. //! Pure virtual openPort() function.
  149. virtual void openPort( unsigned int portNumber = 0, const std::string &portName = std::string( "RtMidi" ) ) = 0;
  150. //! Pure virtual openVirtualPort() function.
  151. virtual void openVirtualPort( const std::string &portName = std::string( "RtMidi" ) ) = 0;
  152. //! Pure virtual getPortCount() function.
  153. virtual unsigned int getPortCount() = 0;
  154. //! Pure virtual getPortName() function.
  155. virtual std::string getPortName( unsigned int portNumber = 0 ) = 0;
  156. //! Pure virtual closePort() function.
  157. virtual void closePort( void ) = 0;
  158. void setClientName( const std::string &clientName );
  159. void setPortName( const std::string &portName );
  160. //! Returns true if a port is open and false if not.
  161. /*!
  162. Note that this only applies to connections made with the openPort()
  163. function, not to virtual ports.
  164. */
  165. virtual bool isPortOpen( void ) const = 0;
  166. //! Set an error callback function to be invoked when an error has occured.
  167. /*!
  168. The callback function will be called whenever an error has occured. It is best
  169. to set the error callback function before opening a port.
  170. */
  171. virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ) = 0;
  172. protected:
  173. RtMidi();
  174. virtual ~RtMidi();
  175. MidiApi *rtapi_;
  176. };
  177. /**********************************************************************/
  178. /*! \class RtMidiIn
  179. \brief A realtime MIDI input class.
  180. This class provides a common, platform-independent API for
  181. realtime MIDI input. It allows access to a single MIDI input
  182. port. Incoming MIDI messages are either saved to a queue for
  183. retrieval using the getMessage() function or immediately passed to
  184. a user-specified callback function. Create multiple instances of
  185. this class to connect to more than one MIDI device at the same
  186. time. With the OS-X, Linux ALSA, and JACK MIDI APIs, it is also
  187. possible to open a virtual input port to which other MIDI software
  188. clients can connect.
  189. by Gary P. Scavone, 2003-2017.
  190. */
  191. /**********************************************************************/
  192. // **************************************************************** //
  193. //
  194. // RtMidiIn and RtMidiOut class declarations.
  195. //
  196. // RtMidiIn / RtMidiOut are "controllers" used to select an available
  197. // MIDI input or output interface. They present common APIs for the
  198. // user to call but all functionality is implemented by the classes
  199. // MidiInApi, MidiOutApi and their subclasses. RtMidiIn and RtMidiOut
  200. // each create an instance of a MidiInApi or MidiOutApi subclass based
  201. // on the user's API choice. If no choice is made, they attempt to
  202. // make a "logical" API selection.
  203. //
  204. // **************************************************************** //
  205. class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi
  206. {
  207. public:
  208. //! User callback function type definition.
  209. typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData );
  210. //! Default constructor that allows an optional api, client name and queue size.
  211. /*!
  212. An exception will be thrown if a MIDI system initialization
  213. error occurs. The queue size defines the maximum number of
  214. messages that can be held in the MIDI queue (when not using a
  215. callback function). If the queue size limit is reached,
  216. incoming messages will be ignored.
  217. If no API argument is specified and multiple API support has been
  218. compiled, the default order of use is ALSA, JACK (Linux) and CORE,
  219. JACK (OS-X).
  220. \param api An optional API id can be specified.
  221. \param clientName An optional client name can be specified. This
  222. will be used to group the ports that are created
  223. by the application.
  224. \param queueSizeLimit An optional size of the MIDI input queue can be specified.
  225. */
  226. RtMidiIn( RtMidi::Api api=UNSPECIFIED,
  227. const std::string& clientName = "RtMidi Input Client",
  228. unsigned int queueSizeLimit = 100 );
  229. //! If a MIDI connection is still open, it will be closed by the destructor.
  230. ~RtMidiIn ( void ) throw();
  231. //! Returns the MIDI API specifier for the current instance of RtMidiIn.
  232. RtMidi::Api getCurrentApi( void ) throw();
  233. //! Open a MIDI input connection given by enumeration number.
  234. /*!
  235. \param portNumber An optional port number greater than 0 can be specified.
  236. Otherwise, the default or first port found is opened.
  237. \param portName An optional name for the application port that is used to connect to portId can be specified.
  238. */
  239. void openPort( unsigned int portNumber = 0, const std::string &portName = std::string( "RtMidi Input" ) );
  240. //! Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only).
  241. /*!
  242. This function creates a virtual MIDI input port to which other
  243. software applications can connect. This type of functionality
  244. is currently only supported by the Macintosh OS-X, any JACK,
  245. and Linux ALSA APIs (the function returns an error for the other APIs).
  246. \param portName An optional name for the application port that is
  247. used to connect to portId can be specified.
  248. */
  249. void openVirtualPort( const std::string &portName = std::string( "RtMidi Input" ) );
  250. //! Set a callback function to be invoked for incoming MIDI messages.
  251. /*!
  252. The callback function will be called whenever an incoming MIDI
  253. message is received. While not absolutely necessary, it is best
  254. to set the callback function before opening a MIDI port to avoid
  255. leaving some messages in the queue.
  256. \param callback A callback function must be given.
  257. \param userData Optionally, a pointer to additional data can be
  258. passed to the callback function whenever it is called.
  259. */
  260. void setCallback( RtMidiCallback callback, void *userData = 0 );
  261. //! Cancel use of the current callback function (if one exists).
  262. /*!
  263. Subsequent incoming MIDI messages will be written to the queue
  264. and can be retrieved with the \e getMessage function.
  265. */
  266. void cancelCallback();
  267. //! Close an open MIDI connection (if one exists).
  268. void closePort( void );
  269. //! Returns true if a port is open and false if not.
  270. /*!
  271. Note that this only applies to connections made with the openPort()
  272. function, not to virtual ports.
  273. */
  274. virtual bool isPortOpen() const;
  275. //! Return the number of available MIDI input ports.
  276. /*!
  277. \return This function returns the number of MIDI ports of the selected API.
  278. */
  279. unsigned int getPortCount();
  280. //! Return a string identifier for the specified MIDI input port number.
  281. /*!
  282. \return The name of the port with the given Id is returned.
  283. \retval An empty string is returned if an invalid port specifier
  284. is provided. User code should assume a UTF-8 encoding.
  285. */
  286. std::string getPortName( unsigned int portNumber = 0 );
  287. //! Specify whether certain MIDI message types should be queued or ignored during input.
  288. /*!
  289. By default, MIDI timing and active sensing messages are ignored
  290. during message input because of their relative high data rates.
  291. MIDI sysex messages are ignored by default as well. Variable
  292. values of "true" imply that the respective message type will be
  293. ignored.
  294. */
  295. void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
  296. //! 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.
  297. /*!
  298. This function returns immediately whether a new message is
  299. available or not. A valid message is indicated by a non-zero
  300. vector size. An exception is thrown if an error occurs during
  301. message retrieval or an input connection was not previously
  302. established.
  303. */
  304. double getMessage( std::vector<unsigned char> *message );
  305. //! Set an error callback function to be invoked when an error has occured.
  306. /*!
  307. The callback function will be called whenever an error has occured. It is best
  308. to set the error callback function before opening a port.
  309. */
  310. virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
  311. protected:
  312. void openMidiApi( RtMidi::Api api, const std::string &clientName, unsigned int queueSizeLimit );
  313. };
  314. /**********************************************************************/
  315. /*! \class RtMidiOut
  316. \brief A realtime MIDI output class.
  317. This class provides a common, platform-independent API for MIDI
  318. output. It allows one to probe available MIDI output ports, to
  319. connect to one such port, and to send MIDI bytes immediately over
  320. the connection. Create multiple instances of this class to
  321. connect to more than one MIDI device at the same time. With the
  322. OS-X, Linux ALSA and JACK MIDI APIs, it is also possible to open a
  323. virtual port to which other MIDI software clients can connect.
  324. by Gary P. Scavone, 2003-2017.
  325. */
  326. /**********************************************************************/
  327. class RTMIDI_DLL_PUBLIC RtMidiOut : public RtMidi
  328. {
  329. public:
  330. //! Default constructor that allows an optional client name.
  331. /*!
  332. An exception will be thrown if a MIDI system initialization error occurs.
  333. If no API argument is specified and multiple API support has been
  334. compiled, the default order of use is ALSA, JACK (Linux) and CORE,
  335. JACK (OS-X).
  336. */
  337. RtMidiOut( RtMidi::Api api=UNSPECIFIED,
  338. const std::string& clientName = "RtMidi Output Client" );
  339. //! The destructor closes any open MIDI connections.
  340. ~RtMidiOut( void ) throw();
  341. //! Returns the MIDI API specifier for the current instance of RtMidiOut.
  342. RtMidi::Api getCurrentApi( void ) throw();
  343. //! Open a MIDI output connection.
  344. /*!
  345. An optional port number greater than 0 can be specified.
  346. Otherwise, the default or first port found is opened. An
  347. exception is thrown if an error occurs while attempting to make
  348. the port connection.
  349. */
  350. void openPort( unsigned int portNumber = 0, const std::string &portName = std::string( "RtMidi Output" ) );
  351. //! Close an open MIDI connection (if one exists).
  352. void closePort( void );
  353. //! Returns true if a port is open and false if not.
  354. /*!
  355. Note that this only applies to connections made with the openPort()
  356. function, not to virtual ports.
  357. */
  358. virtual bool isPortOpen() const;
  359. //! Create a virtual output port, with optional name, to allow software connections (OS X, JACK and ALSA only).
  360. /*!
  361. This function creates a virtual MIDI output port to which other
  362. software applications can connect. This type of functionality
  363. is currently only supported by the Macintosh OS-X, Linux ALSA
  364. and JACK APIs (the function does nothing with the other APIs).
  365. An exception is thrown if an error occurs while attempting to
  366. create the virtual port.
  367. */
  368. void openVirtualPort( const std::string &portName = std::string( "RtMidi Output" ) );
  369. //! Return the number of available MIDI output ports.
  370. unsigned int getPortCount( void );
  371. //! Return a string identifier for the specified MIDI port type and number.
  372. /*!
  373. \return The name of the port with the given Id is returned.
  374. \retval An empty string is returned if an invalid port specifier
  375. is provided. User code should assume a UTF-8 encoding.
  376. */
  377. std::string getPortName( unsigned int portNumber = 0 );
  378. //! Immediately send a single message out an open MIDI output port.
  379. /*!
  380. An exception is thrown if an error occurs during output or an
  381. output connection was not previously established.
  382. */
  383. void sendMessage( const std::vector<unsigned char> *message );
  384. //! Immediately send a single message out an open MIDI output port.
  385. /*!
  386. An exception is thrown if an error occurs during output or an
  387. output connection was not previously established.
  388. \param message A pointer to the MIDI message as raw bytes
  389. \param size Length of the MIDI message in bytes
  390. */
  391. void sendMessage( const unsigned char *message, size_t size );
  392. //! Set an error callback function to be invoked when an error has occured.
  393. /*!
  394. The callback function will be called whenever an error has occured. It is best
  395. to set the error callback function before opening a port.
  396. */
  397. virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
  398. protected:
  399. void openMidiApi( RtMidi::Api api, const std::string &clientName );
  400. };
  401. // **************************************************************** //
  402. //
  403. // MidiInApi / MidiOutApi class declarations.
  404. //
  405. // Subclasses of MidiInApi and MidiOutApi contain all API- and
  406. // OS-specific code necessary to fully implement the RtMidi API.
  407. //
  408. // Note that MidiInApi and MidiOutApi are abstract base classes and
  409. // cannot be explicitly instantiated. RtMidiIn and RtMidiOut will
  410. // create instances of a MidiInApi or MidiOutApi subclass.
  411. //
  412. // **************************************************************** //
  413. class RTMIDI_DLL_PUBLIC MidiApi
  414. {
  415. public:
  416. MidiApi();
  417. virtual ~MidiApi();
  418. virtual RtMidi::Api getCurrentApi( void ) = 0;
  419. virtual void openPort( unsigned int portNumber, const std::string &portName ) = 0;
  420. virtual void openVirtualPort( const std::string &portName ) = 0;
  421. virtual void closePort( void ) = 0;
  422. virtual void setClientName( const std::string &clientName ) = 0;
  423. virtual void setPortName( const std::string &portName ) = 0;
  424. virtual unsigned int getPortCount( void ) = 0;
  425. virtual std::string getPortName( unsigned int portNumber ) = 0;
  426. inline bool isPortOpen() const { return connected_; }
  427. void setErrorCallback( RtMidiErrorCallback errorCallback, void *userData );
  428. //! A basic error reporting function for RtMidi classes.
  429. void error( RtMidiError::Type type, std::string errorString );
  430. protected:
  431. virtual void initialize( const std::string& clientName ) = 0;
  432. void *apiData_;
  433. bool connected_;
  434. std::string errorString_;
  435. RtMidiErrorCallback errorCallback_;
  436. bool firstErrorOccurred_;
  437. void *errorCallbackUserData_;
  438. };
  439. class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi
  440. {
  441. public:
  442. MidiInApi( unsigned int queueSizeLimit );
  443. virtual ~MidiInApi( void );
  444. void setCallback( RtMidiIn::RtMidiCallback callback, void *userData );
  445. void cancelCallback( void );
  446. virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
  447. double getMessage( std::vector<unsigned char> *message );
  448. // A MIDI structure used internally by the class to store incoming
  449. // messages. Each message represents one and only one MIDI message.
  450. struct MidiMessage {
  451. std::vector<unsigned char> bytes;
  452. //! Time in seconds elapsed since the previous message
  453. double timeStamp;
  454. // Default constructor.
  455. MidiMessage()
  456. : bytes(0), timeStamp(0.0) {}
  457. };
  458. struct MidiQueue {
  459. unsigned int front;
  460. unsigned int back;
  461. unsigned int ringSize;
  462. MidiMessage *ring;
  463. // Default constructor.
  464. MidiQueue()
  465. : front(0), back(0), ringSize(0), ring(0) {}
  466. bool push( const MidiMessage& );
  467. bool pop( std::vector<unsigned char>*, double* );
  468. unsigned int size( unsigned int *back=0, unsigned int *front=0 );
  469. };
  470. // The RtMidiInData structure is used to pass private class data to
  471. // the MIDI input handling function or thread.
  472. struct RtMidiInData {
  473. MidiQueue queue;
  474. MidiMessage message;
  475. unsigned char ignoreFlags;
  476. bool doInput;
  477. bool firstMessage;
  478. void *apiData;
  479. bool usingCallback;
  480. RtMidiIn::RtMidiCallback userCallback;
  481. void *userData;
  482. bool continueSysex;
  483. // Default constructor.
  484. RtMidiInData()
  485. : ignoreFlags(7), doInput(false), firstMessage(true), apiData(0), usingCallback(false),
  486. userCallback(0), userData(0), continueSysex(false) {}
  487. };
  488. protected:
  489. RtMidiInData inputData_;
  490. };
  491. class RTMIDI_DLL_PUBLIC MidiOutApi : public MidiApi
  492. {
  493. public:
  494. MidiOutApi( void );
  495. virtual ~MidiOutApi( void );
  496. virtual void sendMessage( const unsigned char *message, size_t size ) = 0;
  497. };
  498. // **************************************************************** //
  499. //
  500. // Inline RtMidiIn and RtMidiOut definitions.
  501. //
  502. // **************************************************************** //
  503. inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
  504. inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
  505. inline void RtMidiIn :: openVirtualPort( const std::string &portName ) { rtapi_->openVirtualPort( portName ); }
  506. inline void RtMidiIn :: closePort( void ) { rtapi_->closePort(); }
  507. inline bool RtMidiIn :: isPortOpen() const { return rtapi_->isPortOpen(); }
  508. inline void RtMidiIn :: setCallback( RtMidiCallback callback, void *userData ) { static_cast<MidiInApi *>(rtapi_)->setCallback( callback, userData ); }
  509. inline void RtMidiIn :: cancelCallback( void ) { static_cast<MidiInApi *>(rtapi_)->cancelCallback(); }
  510. inline unsigned int RtMidiIn :: getPortCount( void ) { return rtapi_->getPortCount(); }
  511. inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
  512. inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { static_cast<MidiInApi *>(rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); }
  513. inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return static_cast<MidiInApi *>(rtapi_)->getMessage( message ); }
  514. inline void RtMidiIn :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
  515. inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
  516. inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
  517. inline void RtMidiOut :: openVirtualPort( const std::string &portName ) { rtapi_->openVirtualPort( portName ); }
  518. inline void RtMidiOut :: closePort( void ) { rtapi_->closePort(); }
  519. inline bool RtMidiOut :: isPortOpen() const { return rtapi_->isPortOpen(); }
  520. inline unsigned int RtMidiOut :: getPortCount( void ) { return rtapi_->getPortCount(); }
  521. inline std::string RtMidiOut :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
  522. inline void RtMidiOut :: sendMessage( const std::vector<unsigned char> *message ) { static_cast<MidiOutApi *>(rtapi_)->sendMessage( &message->at(0), message->size() ); }
  523. inline void RtMidiOut :: sendMessage( const unsigned char *message, size_t size ) { static_cast<MidiOutApi *>(rtapi_)->sendMessage( message, size ); }
  524. inline void RtMidiOut :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
  525. #endif