RtMidi.h 27 KB

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