You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RtMidi.h 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. */
  190. /**********************************************************************/
  191. // **************************************************************** //
  192. //
  193. // RtMidiIn and RtMidiOut class declarations.
  194. //
  195. // RtMidiIn / RtMidiOut are "controllers" used to select an available
  196. // MIDI input or output interface. They present common APIs for the
  197. // user to call but all functionality is implemented by the classes
  198. // MidiInApi, MidiOutApi and their subclasses. RtMidiIn and RtMidiOut
  199. // each create an instance of a MidiInApi or MidiOutApi subclass based
  200. // on the user's API choice. If no choice is made, they attempt to
  201. // make a "logical" API selection.
  202. //
  203. // **************************************************************** //
  204. class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi
  205. {
  206. public:
  207. //! User callback function type definition.
  208. typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData );
  209. //! Default constructor that allows an optional api, client name and queue size.
  210. /*!
  211. An exception will be thrown if a MIDI system initialization
  212. error occurs. The queue size defines the maximum number of
  213. messages that can be held in the MIDI queue (when not using a
  214. callback function). If the queue size limit is reached,
  215. incoming messages will be ignored.
  216. If no API argument is specified and multiple API support has been
  217. compiled, the default order of use is ALSA, JACK (Linux) and CORE,
  218. JACK (OS-X).
  219. \param api An optional API id can be specified.
  220. \param clientName An optional client name can be specified. This
  221. will be used to group the ports that are created
  222. by the application.
  223. \param queueSizeLimit An optional size of the MIDI input queue can be specified.
  224. */
  225. RtMidiIn( RtMidi::Api api=UNSPECIFIED,
  226. const std::string& clientName = "RtMidi Input Client",
  227. unsigned int queueSizeLimit = 100 );
  228. //! If a MIDI connection is still open, it will be closed by the destructor.
  229. ~RtMidiIn ( void ) throw();
  230. //! Returns the MIDI API specifier for the current instance of RtMidiIn.
  231. RtMidi::Api getCurrentApi( void ) throw();
  232. //! Open a MIDI input connection given by enumeration number.
  233. /*!
  234. \param portNumber An optional port number greater than 0 can be specified.
  235. Otherwise, the default or first port found is opened.
  236. \param portName An optional name for the application port that is used to connect to portId can be specified.
  237. */
  238. void openPort( unsigned int portNumber = 0, const std::string &portName = std::string( "RtMidi Input" ) );
  239. //! Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only).
  240. /*!
  241. This function creates a virtual MIDI input port to which other
  242. software applications can connect. This type of functionality
  243. is currently only supported by the Macintosh OS-X, any JACK,
  244. and Linux ALSA APIs (the function returns an error for the other APIs).
  245. \param portName An optional name for the application port that is
  246. used to connect to portId can be specified.
  247. */
  248. void openVirtualPort( const std::string &portName = std::string( "RtMidi Input" ) );
  249. //! Set a callback function to be invoked for incoming MIDI messages.
  250. /*!
  251. The callback function will be called whenever an incoming MIDI
  252. message is received. While not absolutely necessary, it is best
  253. to set the callback function before opening a MIDI port to avoid
  254. leaving some messages in the queue.
  255. \param callback A callback function must be given.
  256. \param userData Optionally, a pointer to additional data can be
  257. passed to the callback function whenever it is called.
  258. */
  259. void setCallback( RtMidiCallback callback, void *userData = 0 );
  260. //! Cancel use of the current callback function (if one exists).
  261. /*!
  262. Subsequent incoming MIDI messages will be written to the queue
  263. and can be retrieved with the \e getMessage function.
  264. */
  265. void cancelCallback();
  266. //! Close an open MIDI connection (if one exists).
  267. void closePort( void );
  268. //! Returns true if a port is open and false if not.
  269. /*!
  270. Note that this only applies to connections made with the openPort()
  271. function, not to virtual ports.
  272. */
  273. virtual bool isPortOpen() const;
  274. //! Return the number of available MIDI input ports.
  275. /*!
  276. \return This function returns the number of MIDI ports of the selected API.
  277. */
  278. unsigned int getPortCount();
  279. //! Return a string identifier for the specified MIDI input port number.
  280. /*!
  281. \return The name of the port with the given Id is returned.
  282. \retval An empty string is returned if an invalid port specifier
  283. is provided. User code should assume a UTF-8 encoding.
  284. */
  285. std::string getPortName( unsigned int portNumber = 0 );
  286. //! Specify whether certain MIDI message types should be queued or ignored during input.
  287. /*!
  288. By default, MIDI timing and active sensing messages are ignored
  289. during message input because of their relative high data rates.
  290. MIDI sysex messages are ignored by default as well. Variable
  291. values of "true" imply that the respective message type will be
  292. ignored.
  293. */
  294. void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
  295. //! 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.
  296. /*!
  297. This function returns immediately whether a new message is
  298. available or not. A valid message is indicated by a non-zero
  299. vector size. An exception is thrown if an error occurs during
  300. message retrieval or an input connection was not previously
  301. established.
  302. */
  303. double getMessage( std::vector<unsigned char> *message );
  304. //! Set an error callback function to be invoked when an error has occured.
  305. /*!
  306. The callback function will be called whenever an error has occured. It is best
  307. to set the error callback function before opening a port.
  308. */
  309. virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
  310. protected:
  311. void openMidiApi( RtMidi::Api api, const std::string &clientName, unsigned int queueSizeLimit );
  312. };
  313. /**********************************************************************/
  314. /*! \class RtMidiOut
  315. \brief A realtime MIDI output class.
  316. This class provides a common, platform-independent API for MIDI
  317. output. It allows one to probe available MIDI output ports, to
  318. connect to one such port, and to send MIDI bytes immediately over
  319. the connection. Create multiple instances of this class to
  320. connect to more than one MIDI device at the same time. With the
  321. OS-X, Linux ALSA and JACK MIDI APIs, it is also possible to open a
  322. virtual port to which other MIDI software clients can connect.
  323. */
  324. /**********************************************************************/
  325. class RTMIDI_DLL_PUBLIC RtMidiOut : public RtMidi
  326. {
  327. public:
  328. //! Default constructor that allows an optional client name.
  329. /*!
  330. An exception will be thrown if a MIDI system initialization error occurs.
  331. If no API argument is specified and multiple API support has been
  332. compiled, the default order of use is ALSA, JACK (Linux) and CORE,
  333. JACK (OS-X).
  334. */
  335. RtMidiOut( RtMidi::Api api=UNSPECIFIED,
  336. const std::string& clientName = "RtMidi Output Client" );
  337. //! The destructor closes any open MIDI connections.
  338. ~RtMidiOut( void ) throw();
  339. //! Returns the MIDI API specifier for the current instance of RtMidiOut.
  340. RtMidi::Api getCurrentApi( void ) throw();
  341. //! Open a MIDI output connection.
  342. /*!
  343. An optional port number greater than 0 can be specified.
  344. Otherwise, the default or first port found is opened. An
  345. exception is thrown if an error occurs while attempting to make
  346. the port connection.
  347. */
  348. void openPort( unsigned int portNumber = 0, const std::string &portName = std::string( "RtMidi Output" ) );
  349. //! Close an open MIDI connection (if one exists).
  350. void closePort( void );
  351. //! Returns true if a port is open and false if not.
  352. /*!
  353. Note that this only applies to connections made with the openPort()
  354. function, not to virtual ports.
  355. */
  356. virtual bool isPortOpen() const;
  357. //! Create a virtual output port, with optional name, to allow software connections (OS X, JACK and ALSA only).
  358. /*!
  359. This function creates a virtual MIDI output port to which other
  360. software applications can connect. This type of functionality
  361. is currently only supported by the Macintosh OS-X, Linux ALSA
  362. and JACK APIs (the function does nothing with the other APIs).
  363. An exception is thrown if an error occurs while attempting to
  364. create the virtual port.
  365. */
  366. void openVirtualPort( const std::string &portName = std::string( "RtMidi Output" ) );
  367. //! Return the number of available MIDI output ports.
  368. unsigned int getPortCount( void );
  369. //! Return a string identifier for the specified MIDI port type and number.
  370. /*!
  371. \return The name of the port with the given Id is returned.
  372. \retval An empty string is returned if an invalid port specifier
  373. is provided. User code should assume a UTF-8 encoding.
  374. */
  375. std::string getPortName( unsigned int portNumber = 0 );
  376. //! Immediately send a single message out an open MIDI output port.
  377. /*!
  378. An exception is thrown if an error occurs during output or an
  379. output connection was not previously established.
  380. */
  381. void sendMessage( const std::vector<unsigned char> *message );
  382. //! Immediately send a single message out an open MIDI output port.
  383. /*!
  384. An exception is thrown if an error occurs during output or an
  385. output connection was not previously established.
  386. \param message A pointer to the MIDI message as raw bytes
  387. \param size Length of the MIDI message in bytes
  388. */
  389. void sendMessage( const unsigned char *message, size_t size );
  390. //! Set an error callback function to be invoked when an error has occured.
  391. /*!
  392. The callback function will be called whenever an error has occured. It is best
  393. to set the error callback function before opening a port.
  394. */
  395. virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
  396. protected:
  397. void openMidiApi( RtMidi::Api api, const std::string &clientName );
  398. };
  399. // **************************************************************** //
  400. //
  401. // MidiInApi / MidiOutApi class declarations.
  402. //
  403. // Subclasses of MidiInApi and MidiOutApi contain all API- and
  404. // OS-specific code necessary to fully implement the RtMidi API.
  405. //
  406. // Note that MidiInApi and MidiOutApi are abstract base classes and
  407. // cannot be explicitly instantiated. RtMidiIn and RtMidiOut will
  408. // create instances of a MidiInApi or MidiOutApi subclass.
  409. //
  410. // **************************************************************** //
  411. class RTMIDI_DLL_PUBLIC MidiApi
  412. {
  413. public:
  414. MidiApi();
  415. virtual ~MidiApi();
  416. virtual RtMidi::Api getCurrentApi( void ) = 0;
  417. virtual void openPort( unsigned int portNumber, const std::string &portName ) = 0;
  418. virtual void openVirtualPort( const std::string &portName ) = 0;
  419. virtual void closePort( void ) = 0;
  420. virtual void setClientName( const std::string &clientName ) = 0;
  421. virtual void setPortName( const std::string &portName ) = 0;
  422. virtual unsigned int getPortCount( void ) = 0;
  423. virtual std::string getPortName( unsigned int portNumber ) = 0;
  424. inline bool isPortOpen() const { return connected_; }
  425. void setErrorCallback( RtMidiErrorCallback errorCallback, void *userData );
  426. //! A basic error reporting function for RtMidi classes.
  427. void error( RtMidiError::Type type, std::string errorString );
  428. protected:
  429. virtual void initialize( const std::string& clientName ) = 0;
  430. void *apiData_;
  431. bool connected_;
  432. std::string errorString_;
  433. RtMidiErrorCallback errorCallback_;
  434. bool firstErrorOccurred_;
  435. void *errorCallbackUserData_;
  436. };
  437. class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi
  438. {
  439. public:
  440. MidiInApi( unsigned int queueSizeLimit );
  441. virtual ~MidiInApi( void );
  442. void setCallback( RtMidiIn::RtMidiCallback callback, void *userData );
  443. void cancelCallback( void );
  444. virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
  445. double getMessage( std::vector<unsigned char> *message );
  446. // A MIDI structure used internally by the class to store incoming
  447. // messages. Each message represents one and only one MIDI message.
  448. struct MidiMessage {
  449. std::vector<unsigned char> bytes;
  450. //! Time in seconds elapsed since the previous message
  451. double timeStamp;
  452. // Default constructor.
  453. MidiMessage()
  454. : bytes(0), timeStamp(0.0) {}
  455. };
  456. struct MidiQueue {
  457. unsigned int front;
  458. unsigned int back;
  459. unsigned int ringSize;
  460. MidiMessage *ring;
  461. // Default constructor.
  462. MidiQueue()
  463. : front(0), back(0), ringSize(0), ring(0) {}
  464. bool push( const MidiMessage& );
  465. bool pop( std::vector<unsigned char>*, double* );
  466. unsigned int size( unsigned int *back=0, unsigned int *front=0 );
  467. };
  468. // The RtMidiInData structure is used to pass private class data to
  469. // the MIDI input handling function or thread.
  470. struct RtMidiInData {
  471. MidiQueue queue;
  472. MidiMessage message;
  473. unsigned char ignoreFlags;
  474. bool doInput;
  475. bool firstMessage;
  476. void *apiData;
  477. bool usingCallback;
  478. RtMidiIn::RtMidiCallback userCallback;
  479. void *userData;
  480. bool continueSysex;
  481. // Default constructor.
  482. RtMidiInData()
  483. : ignoreFlags(7), doInput(false), firstMessage(true), apiData(0), usingCallback(false),
  484. userCallback(0), userData(0), continueSysex(false) {}
  485. };
  486. protected:
  487. RtMidiInData inputData_;
  488. };
  489. class RTMIDI_DLL_PUBLIC MidiOutApi : public MidiApi
  490. {
  491. public:
  492. MidiOutApi( void );
  493. virtual ~MidiOutApi( void );
  494. virtual void sendMessage( const unsigned char *message, size_t size ) = 0;
  495. };
  496. // **************************************************************** //
  497. //
  498. // Inline RtMidiIn and RtMidiOut definitions.
  499. //
  500. // **************************************************************** //
  501. inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
  502. inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
  503. inline void RtMidiIn :: openVirtualPort( const std::string &portName ) { rtapi_->openVirtualPort( portName ); }
  504. inline void RtMidiIn :: closePort( void ) { rtapi_->closePort(); }
  505. inline bool RtMidiIn :: isPortOpen() const { return rtapi_->isPortOpen(); }
  506. inline void RtMidiIn :: setCallback( RtMidiCallback callback, void *userData ) { static_cast<MidiInApi *>(rtapi_)->setCallback( callback, userData ); }
  507. inline void RtMidiIn :: cancelCallback( void ) { static_cast<MidiInApi *>(rtapi_)->cancelCallback(); }
  508. inline unsigned int RtMidiIn :: getPortCount( void ) { return rtapi_->getPortCount(); }
  509. inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
  510. inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { static_cast<MidiInApi *>(rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); }
  511. inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return static_cast<MidiInApi *>(rtapi_)->getMessage( message ); }
  512. inline void RtMidiIn :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
  513. inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
  514. inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
  515. inline void RtMidiOut :: openVirtualPort( const std::string &portName ) { rtapi_->openVirtualPort( portName ); }
  516. inline void RtMidiOut :: closePort( void ) { rtapi_->closePort(); }
  517. inline bool RtMidiOut :: isPortOpen() const { return rtapi_->isPortOpen(); }
  518. inline unsigned int RtMidiOut :: getPortCount( void ) { return rtapi_->getPortCount(); }
  519. inline std::string RtMidiOut :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
  520. inline void RtMidiOut :: sendMessage( const std::vector<unsigned char> *message ) { static_cast<MidiOutApi *>(rtapi_)->sendMessage( &message->at(0), message->size() ); }
  521. inline void RtMidiOut :: sendMessage( const unsigned char *message, size_t size ) { static_cast<MidiOutApi *>(rtapi_)->sendMessage( message, size ); }
  522. inline void RtMidiOut :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
  523. #endif