Audio plugin host https://kx.studio/carla
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.

678 lines
24KB

  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-2012 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. // RtMidi: Version 2.0.1
  35. #ifndef RTMIDI_H
  36. #define RTMIDI_H
  37. #include "CarlaDefines.hpp"
  38. #include "RtError.h"
  39. #include <string>
  40. #include <vector>
  41. class RtMidi
  42. {
  43. public:
  44. //! MIDI API specifier arguments.
  45. enum Api {
  46. UNSPECIFIED, /*!< Search for a working compiled API. */
  47. MACOSX_CORE, /*!< Macintosh OS-X Core Midi API. */
  48. LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
  49. UNIX_JACK, /*!< The Jack Low-Latency MIDI Server API. */
  50. WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
  51. WINDOWS_KS, /*!< The Microsoft Kernel Streaming MIDI API. */
  52. RTMIDI_DUMMY /*!< A compilable but non-functional API. */
  53. };
  54. //! A static function to determine the available compiled MIDI APIs.
  55. /*!
  56. The values returned in the std::vector can be compared against
  57. the enumerated list values. Note that there can be more than one
  58. API compiled for certain operating systems.
  59. */
  60. static void getCompiledApi( std::vector<RtMidi::Api> &apis ) throw();
  61. //! Pure virtual openPort() function.
  62. virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0;
  63. //! Pure virtual openVirtualPort() function.
  64. virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0;
  65. //! Pure virtual getPortCount() function.
  66. virtual unsigned int getPortCount() = 0;
  67. //! Pure virtual getPortName() function.
  68. virtual std::string getPortName( unsigned int portNumber = 0 ) = 0;
  69. //! Pure virtual closePort() function.
  70. virtual void closePort( void ) = 0;
  71. //! A basic error reporting function for RtMidi classes.
  72. static void error( RtError::Type type, std::string errorString );
  73. protected:
  74. RtMidi() {};
  75. virtual ~RtMidi() {};
  76. };
  77. /**********************************************************************/
  78. /*! \class RtMidiIn
  79. \brief A realtime MIDI input class.
  80. This class provides a common, platform-independent API for
  81. realtime MIDI input. It allows access to a single MIDI input
  82. port. Incoming MIDI messages are either saved to a queue for
  83. retrieval using the getMessage() function or immediately passed to
  84. a user-specified callback function. Create multiple instances of
  85. this class to connect to more than one MIDI device at the same
  86. time. With the OS-X and Linux ALSA MIDI APIs, it is also possible
  87. to open a virtual input port to which other MIDI software clients
  88. can connect.
  89. by Gary P. Scavone, 2003-2012.
  90. */
  91. /**********************************************************************/
  92. // **************************************************************** //
  93. //
  94. // RtMidiIn and RtMidiOut class declarations.
  95. //
  96. // RtMidiIn / RtMidiOut are "controllers" used to select an available
  97. // MIDI input or output interface. They present common APIs for the
  98. // user to call but all functionality is implemented by the classes
  99. // MidiInApi, MidiOutApi and their subclasses. RtMidiIn and RtMidiOut
  100. // each create an instance of a MidiInApi or MidiOutApi subclass based
  101. // on the user's API choice. If no choice is made, they attempt to
  102. // make a "logical" API selection.
  103. //
  104. // **************************************************************** //
  105. class MidiInApi;
  106. class MidiOutApi;
  107. class RtMidiIn : public RtMidi
  108. {
  109. public:
  110. //! User callback function type definition.
  111. typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData);
  112. //! Default constructor that allows an optional api, client name and queue size.
  113. /*!
  114. An exception will be thrown if a MIDI system initialization
  115. error occurs. The queue size defines the maximum number of
  116. messages that can be held in the MIDI queue (when not using a
  117. callback function). If the queue size limit is reached,
  118. incoming messages will be ignored.
  119. If no API argument is specified and multiple API support has been
  120. compiled, the default order of use is JACK, ALSA (Linux) and CORE,
  121. Jack (OS-X).
  122. */
  123. RtMidiIn( RtMidi::Api api=UNSPECIFIED,
  124. const std::string clientName = std::string( "RtMidi Input Client"),
  125. unsigned int queueSizeLimit = 100 );
  126. //! If a MIDI connection is still open, it will be closed by the destructor.
  127. ~RtMidiIn ( void ) throw();
  128. //! Returns the MIDI API specifier for the current instance of RtMidiIn.
  129. RtMidi::Api getCurrentApi( void ) throw();
  130. //! Open a MIDI input connection.
  131. /*!
  132. An optional port number greater than 0 can be specified.
  133. Otherwise, the default or first port found is opened.
  134. */
  135. void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Input" ) );
  136. //! Create a virtual input port, with optional name, to allow software connections (OS X and ALSA only).
  137. /*!
  138. This function creates a virtual MIDI input port to which other
  139. software applications can connect. This type of functionality
  140. is currently only supported by the Macintosh OS-X and Linux ALSA
  141. APIs (the function does nothing for the other APIs).
  142. */
  143. void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) );
  144. //! Set a callback function to be invoked for incoming MIDI messages.
  145. /*!
  146. The callback function will be called whenever an incoming MIDI
  147. message is received. While not absolutely necessary, it is best
  148. to set the callback function before opening a MIDI port to avoid
  149. leaving some messages in the queue.
  150. */
  151. void setCallback( RtMidiCallback callback, void *userData = 0 );
  152. //! Cancel use of the current callback function (if one exists).
  153. /*!
  154. Subsequent incoming MIDI messages will be written to the queue
  155. and can be retrieved with the \e getMessage function.
  156. */
  157. void cancelCallback();
  158. //! Close an open MIDI connection (if one exists).
  159. void closePort( void );
  160. //! Return the number of available MIDI input ports.
  161. unsigned int getPortCount();
  162. //! Return a string identifier for the specified MIDI input port number.
  163. /*!
  164. An empty string is returned if an invalid port specifier is provided.
  165. */
  166. std::string getPortName( unsigned int portNumber = 0 );
  167. //! Specify whether certain MIDI message types should be queued or ignored during input.
  168. /*!
  169. o By default, MIDI timing and active sensing messages are ignored
  170. during message input because of their relative high data rates.
  171. MIDI sysex messages are ignored by default as well. Variable
  172. values of "true" imply that the respective message type will be
  173. ignored.
  174. */
  175. void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
  176. //! 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.
  177. /*!
  178. This function returns immediately whether a new message is
  179. available or not. A valid message is indicated by a non-zero
  180. vector size. An exception is thrown if an error occurs during
  181. message retrieval or an input connection was not previously
  182. established.
  183. */
  184. double getMessage( std::vector<unsigned char> *message );
  185. protected:
  186. void openMidiApi( RtMidi::Api api, const std::string clientName, unsigned int queueSizeLimit );
  187. MidiInApi *rtapi_;
  188. };
  189. /**********************************************************************/
  190. /*! \class RtMidiOut
  191. \brief A realtime MIDI output class.
  192. This class provides a common, platform-independent API for MIDI
  193. output. It allows one to probe available MIDI output ports, to
  194. connect to one such port, and to send MIDI bytes immediately over
  195. the connection. Create multiple instances of this class to
  196. connect to more than one MIDI device at the same time. With the
  197. OS-X and Linux ALSA MIDI APIs, it is also possible to open a
  198. virtual port to which other MIDI software clients can connect.
  199. by Gary P. Scavone, 2003-2012.
  200. */
  201. /**********************************************************************/
  202. class RtMidiOut : public RtMidi
  203. {
  204. public:
  205. //! Default constructor that allows an optional client name.
  206. /*!
  207. An exception will be thrown if a MIDI system initialization error occurs.
  208. If no API argument is specified and multiple API support has been
  209. compiled, the default order of use is JACK, ALSA (Linux) and CORE,
  210. Jack (OS-X).
  211. */
  212. RtMidiOut( RtMidi::Api api=UNSPECIFIED,
  213. const std::string clientName = std::string( "RtMidi Output Client") );
  214. //! The destructor closes any open MIDI connections.
  215. ~RtMidiOut( void ) throw();
  216. //! Returns the MIDI API specifier for the current instance of RtMidiOut.
  217. RtMidi::Api getCurrentApi( void ) throw();
  218. //! Open a MIDI output connection.
  219. /*!
  220. An optional port number greater than 0 can be specified.
  221. Otherwise, the default or first port found is opened. An
  222. exception is thrown if an error occurs while attempting to make
  223. the port connection.
  224. */
  225. void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) );
  226. //! Close an open MIDI connection (if one exists).
  227. void closePort( void );
  228. //! Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only).
  229. /*!
  230. This function creates a virtual MIDI output port to which other
  231. software applications can connect. This type of functionality
  232. is currently only supported by the Macintosh OS-X and Linux ALSA
  233. APIs (the function does nothing with the other APIs). An
  234. exception is thrown if an error occurs while attempting to create
  235. the virtual port.
  236. */
  237. void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
  238. //! Return the number of available MIDI output ports.
  239. unsigned int getPortCount( void );
  240. //! Return a string identifier for the specified MIDI port type and number.
  241. /*!
  242. An empty string is returned if an invalid port specifier is provided.
  243. */
  244. std::string getPortName( unsigned int portNumber = 0 );
  245. //! Immediately send a single message out an open MIDI output port.
  246. /*!
  247. An exception is thrown if an error occurs during output or an
  248. output connection was not previously established.
  249. */
  250. void sendMessage( std::vector<unsigned char> *message );
  251. protected:
  252. void openMidiApi( RtMidi::Api api, const std::string clientName );
  253. MidiOutApi *rtapi_;
  254. };
  255. // **************************************************************** //
  256. //
  257. // MidiInApi / MidiOutApi class declarations.
  258. //
  259. // Subclasses of MidiInApi and MidiOutApi contain all API- and
  260. // OS-specific code necessary to fully implement the RtMidi API.
  261. //
  262. // Note that MidiInApi and MidiOutApi are abstract base classes and
  263. // cannot be explicitly instantiated. RtMidiIn and RtMidiOut will
  264. // create instances of a MidiInApi or MidiOutApi subclass.
  265. //
  266. // **************************************************************** //
  267. class MidiInApi
  268. {
  269. public:
  270. MidiInApi( unsigned int queueSizeLimit );
  271. virtual ~MidiInApi( void );
  272. virtual RtMidi::Api getCurrentApi( void ) = 0;
  273. virtual void openPort( unsigned int portNumber, const std::string portName ) = 0;
  274. virtual void openVirtualPort( const std::string portName ) = 0;
  275. virtual void closePort( void ) = 0;
  276. void setCallback( RtMidiIn::RtMidiCallback callback, void *userData );
  277. void cancelCallback( void );
  278. virtual unsigned int getPortCount( void ) = 0;
  279. virtual std::string getPortName( unsigned int portNumber ) = 0;
  280. virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
  281. double getMessage( std::vector<unsigned char> *message );
  282. // A MIDI structure used internally by the class to store incoming
  283. // messages. Each message represents one and only one MIDI message.
  284. struct MidiMessage {
  285. std::vector<unsigned char> bytes;
  286. double timeStamp;
  287. // Default constructor.
  288. MidiMessage()
  289. :bytes(0), timeStamp(0.0) {}
  290. };
  291. struct MidiQueue {
  292. unsigned int front;
  293. unsigned int back;
  294. unsigned int size;
  295. unsigned int ringSize;
  296. MidiMessage *ring;
  297. // Default constructor.
  298. MidiQueue()
  299. :front(0), back(0), size(0), ringSize(0) {}
  300. };
  301. // The RtMidiInData structure is used to pass private class data to
  302. // the MIDI input handling function or thread.
  303. struct RtMidiInData {
  304. MidiQueue queue;
  305. MidiMessage message;
  306. unsigned char ignoreFlags;
  307. bool doInput;
  308. bool firstMessage;
  309. void *apiData;
  310. bool usingCallback;
  311. void *userCallback;
  312. void *userData;
  313. bool continueSysex;
  314. // Default constructor.
  315. RtMidiInData()
  316. : ignoreFlags(7), doInput(false), firstMessage(true),
  317. apiData(nullptr), usingCallback(false), userCallback(nullptr), userData(nullptr),
  318. continueSysex(false) {}
  319. };
  320. protected:
  321. virtual void initialize( const std::string& clientName ) = 0;
  322. RtMidiInData inputData_;
  323. void *apiData_;
  324. bool connected_;
  325. std::string errorString_;
  326. };
  327. class MidiOutApi
  328. {
  329. public:
  330. MidiOutApi( void );
  331. virtual ~MidiOutApi( void );
  332. virtual RtMidi::Api getCurrentApi( void ) = 0;
  333. virtual void openPort( unsigned int portNumber, const std::string portName ) = 0;
  334. virtual void openVirtualPort( const std::string portName ) = 0;
  335. virtual void closePort( void ) = 0;
  336. virtual unsigned int getPortCount( void ) = 0;
  337. virtual std::string getPortName( unsigned int portNumber ) = 0;
  338. virtual void sendMessage( std::vector<unsigned char> *message ) = 0;
  339. protected:
  340. virtual void initialize( const std::string& clientName ) = 0;
  341. void *apiData_;
  342. bool connected_;
  343. std::string errorString_;
  344. };
  345. // **************************************************************** //
  346. //
  347. // Inline RtMidiIn and RtMidiOut definitions.
  348. //
  349. // **************************************************************** //
  350. inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
  351. inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); }
  352. inline void RtMidiIn :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); }
  353. inline void RtMidiIn :: closePort( void ) { return rtapi_->closePort(); }
  354. inline void RtMidiIn :: setCallback( RtMidiCallback callback, void *userData ) { return rtapi_->setCallback( callback, userData ); }
  355. inline void RtMidiIn :: cancelCallback( void ) { return rtapi_->cancelCallback(); }
  356. inline unsigned int RtMidiIn :: getPortCount( void ) { return rtapi_->getPortCount(); }
  357. inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
  358. inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { return rtapi_->ignoreTypes( midiSysex, midiTime, midiSense ); }
  359. inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return rtapi_->getMessage( message ); }
  360. inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
  361. inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); }
  362. inline void RtMidiOut :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); }
  363. inline void RtMidiOut :: closePort( void ) { return rtapi_->closePort(); }
  364. inline unsigned int RtMidiOut :: getPortCount( void ) { return rtapi_->getPortCount(); }
  365. inline std::string RtMidiOut :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
  366. inline void RtMidiOut :: sendMessage( std::vector<unsigned char> *message ) { return rtapi_->sendMessage( message ); }
  367. // **************************************************************** //
  368. //
  369. // MidiInApi and MidiOutApi subclass prototypes.
  370. //
  371. // **************************************************************** //
  372. #if !defined(__LINUX_ALSA__) && !defined(__UNIX_JACK__) && !defined(__MACOSX_CORE__) && !defined(__WINDOWS_MM__) && !defined(__WINDOWS_KS__)
  373. #define __RTMIDI_DUMMY__
  374. #endif
  375. #if defined(__MACOSX_CORE__)
  376. class MidiInCore: public MidiInApi
  377. {
  378. public:
  379. MidiInCore( const std::string clientName, unsigned int queueSizeLimit );
  380. ~MidiInCore( void );
  381. RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; };
  382. void openPort( unsigned int portNumber, const std::string portName );
  383. void openVirtualPort( const std::string portName );
  384. void closePort( void );
  385. unsigned int getPortCount( void );
  386. std::string getPortName( unsigned int portNumber );
  387. protected:
  388. void initialize( const std::string& clientName );
  389. };
  390. class MidiOutCore: public MidiOutApi
  391. {
  392. public:
  393. MidiOutCore( const std::string clientName );
  394. ~MidiOutCore( void );
  395. RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; };
  396. void openPort( unsigned int portNumber, const std::string portName );
  397. void openVirtualPort( const std::string portName );
  398. void closePort( void );
  399. unsigned int getPortCount( void );
  400. std::string getPortName( unsigned int portNumber );
  401. void sendMessage( std::vector<unsigned char> *message );
  402. protected:
  403. void initialize( const std::string& clientName );
  404. };
  405. #endif
  406. #if defined(__UNIX_JACK__)
  407. class MidiInJack: public MidiInApi
  408. {
  409. public:
  410. MidiInJack( const std::string clientName, unsigned int queueSizeLimit );
  411. ~MidiInJack( void );
  412. RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; };
  413. void openPort( unsigned int portNumber, const std::string portName );
  414. void openVirtualPort( const std::string portName );
  415. void closePort( void );
  416. unsigned int getPortCount( void );
  417. std::string getPortName( unsigned int portNumber );
  418. protected:
  419. void initialize( const std::string& clientName );
  420. };
  421. class MidiOutJack: public MidiOutApi
  422. {
  423. public:
  424. MidiOutJack( const std::string clientName );
  425. ~MidiOutJack( void );
  426. RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; };
  427. void openPort( unsigned int portNumber, const std::string portName );
  428. void openVirtualPort( const std::string portName );
  429. void closePort( void );
  430. unsigned int getPortCount( void );
  431. std::string getPortName( unsigned int portNumber );
  432. void sendMessage( std::vector<unsigned char> *message );
  433. protected:
  434. void initialize( const std::string& clientName );
  435. };
  436. #endif
  437. #if defined(__LINUX_ALSA__)
  438. class MidiInAlsa: public MidiInApi
  439. {
  440. public:
  441. MidiInAlsa( const std::string clientName, unsigned int queueSizeLimit );
  442. ~MidiInAlsa( void );
  443. RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; };
  444. void openPort( unsigned int portNumber, const std::string portName );
  445. void openVirtualPort( const std::string portName );
  446. void closePort( void );
  447. unsigned int getPortCount( void );
  448. std::string getPortName( unsigned int portNumber );
  449. protected:
  450. void initialize( const std::string& clientName );
  451. };
  452. class MidiOutAlsa: public MidiOutApi
  453. {
  454. public:
  455. MidiOutAlsa( const std::string clientName );
  456. ~MidiOutAlsa( void );
  457. RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; };
  458. void openPort( unsigned int portNumber, const std::string portName );
  459. void openVirtualPort( const std::string portName );
  460. void closePort( void );
  461. unsigned int getPortCount( void );
  462. std::string getPortName( unsigned int portNumber );
  463. void sendMessage( std::vector<unsigned char> *message );
  464. protected:
  465. void initialize( const std::string& clientName );
  466. };
  467. #endif
  468. #if defined(__WINDOWS_MM__)
  469. class MidiInWinMM: public MidiInApi
  470. {
  471. public:
  472. MidiInWinMM( const std::string clientName, unsigned int queueSizeLimit );
  473. ~MidiInWinMM( void );
  474. RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; };
  475. void openPort( unsigned int portNumber, const std::string portName );
  476. void openVirtualPort( const std::string portName );
  477. void closePort( void );
  478. unsigned int getPortCount( void );
  479. std::string getPortName( unsigned int portNumber );
  480. protected:
  481. void initialize( const std::string& clientName );
  482. };
  483. class MidiOutWinMM: public MidiOutApi
  484. {
  485. public:
  486. MidiOutWinMM( const std::string clientName );
  487. ~MidiOutWinMM( void );
  488. RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; };
  489. void openPort( unsigned int portNumber, const std::string portName );
  490. void openVirtualPort( const std::string portName );
  491. void closePort( void );
  492. unsigned int getPortCount( void );
  493. std::string getPortName( unsigned int portNumber );
  494. void sendMessage( std::vector<unsigned char> *message );
  495. protected:
  496. void initialize( const std::string& clientName );
  497. };
  498. #endif
  499. #if defined(__WINDOWS_KS__)
  500. class MidiInWinKS: public MidiInApi
  501. {
  502. public:
  503. MidiInWinKS( const std::string clientName, unsigned int queueSizeLimit );
  504. ~MidiInWinKS( void );
  505. RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_KS; };
  506. void openPort( unsigned int portNumber, const std::string portName );
  507. void openVirtualPort( const std::string portName );
  508. void closePort( void );
  509. unsigned int getPortCount( void );
  510. std::string getPortName( unsigned int portNumber );
  511. protected:
  512. void initialize( const std::string& clientName );
  513. };
  514. class MidiOutWinKS: public MidiOutApi
  515. {
  516. public:
  517. MidiOutWinKS( const std::string clientName );
  518. ~MidiOutWinKS( void );
  519. RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_KS; };
  520. void openPort( unsigned int portNumber, const std::string portName );
  521. void openVirtualPort( const std::string portName );
  522. void closePort( void );
  523. unsigned int getPortCount( void );
  524. std::string getPortName( unsigned int portNumber );
  525. void sendMessage( std::vector<unsigned char> *message );
  526. protected:
  527. void initialize( const std::string& clientName );
  528. };
  529. #endif
  530. #if defined(__RTMIDI_DUMMY__)
  531. class MidiInDummy: public MidiInApi
  532. {
  533. public:
  534. MidiInDummy( const std::string clientName, unsigned int queueSizeLimit ) : MidiInApi( queueSizeLimit ) { errorString_ = "MidiInDummy: This class provides no functionality."; RtMidi::error( RtError::WARNING, errorString_ ); };
  535. RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; };
  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 ) { return 0; };
  540. std::string getPortName( unsigned int portNumber ) { return ""; };
  541. protected:
  542. void initialize( const std::string& clientName ) {};
  543. };
  544. class MidiOutDummy: public MidiOutApi
  545. {
  546. public:
  547. MidiOutDummy( const std::string clientName ) { errorString_ = "MidiOutDummy: This class provides no functionality."; RtMidi::error( RtError::WARNING, errorString_ ); };
  548. RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; };
  549. void openPort( unsigned int portNumber, const std::string portName ) {};
  550. void openVirtualPort( const std::string portName ) {};
  551. void closePort( void ) {};
  552. unsigned int getPortCount( void ) { return 0; };
  553. std::string getPortName( unsigned int portNumber ) { return ""; };
  554. void sendMessage( std::vector<unsigned char> *message ) {};
  555. protected:
  556. void initialize( const std::string& clientName ) {};
  557. };
  558. #endif
  559. #endif