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.

180 lines
17KB

  1. <HTML>
  2. <HEAD>
  3. <TITLE>The RtMidi Tutorial</TITLE>
  4. <LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
  5. </HEAD>
  6. <BODY BGCOLOR="#FFFFFF">
  7. <CENTER>
  8. <a class="qindex" href="index.html">Tutorial</a> &nbsp; <a class="qindex" href="annotated.html">Class/Enum List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </CENTER>
  9. <HR>
  10. <!-- Generated by Doxygen 1.5.8 -->
  11. <h1>RtMidi.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/**********************************************************************/</span>
  12. <a name="l00036"></a>00036 <span class="comment">/**********************************************************************/</span>
  13. <a name="l00037"></a>00037
  14. <a name="l00038"></a>00038 <span class="comment">// RtMidi: Version 1.0.11</span>
  15. <a name="l00039"></a>00039
  16. <a name="l00040"></a>00040 <span class="preprocessor">#ifndef RTMIDI_H</span>
  17. <a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define RTMIDI_H</span>
  18. <a name="l00042"></a>00042 <span class="preprocessor"></span>
  19. <a name="l00043"></a>00043 <span class="preprocessor">#include "RtError.h"</span>
  20. <a name="l00044"></a>00044 <span class="preprocessor">#include &lt;string&gt;</span>
  21. <a name="l00045"></a>00045
  22. <a name="l00046"></a><a class="code" href="classRtMidi.html">00046</a> <span class="keyword">class </span><a class="code" href="classRtMidi.html" title="An abstract base class for realtime MIDI input/output.">RtMidi</a>
  23. <a name="l00047"></a>00047 {
  24. <a name="l00048"></a>00048 <span class="keyword">public</span>:
  25. <a name="l00049"></a>00049
  26. <a name="l00051"></a>00051 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classRtMidi.html#d9e30a89638f93193cb40edebaa536f5" title="Pure virtual openPort() function.">openPort</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> portNumber = 0, <span class="keyword">const</span> std::string portName = std::string( <span class="stringliteral">"RtMidi"</span> ) ) = 0;
  27. <a name="l00052"></a>00052
  28. <a name="l00054"></a>00054 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classRtMidi.html#9200cde4f5337c0bc421d20bd4fcf654" title="Pure virtual openVirtualPort() function.">openVirtualPort</a>( <span class="keyword">const</span> std::string portName = std::string( <span class="stringliteral">"RtMidi"</span> ) ) = 0;
  29. <a name="l00055"></a>00055
  30. <a name="l00057"></a>00057 <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classRtMidi.html#9a49ef73a1e6007444019a7ae095e195" title="Pure virtual getPortCount() function.">getPortCount</a>() = 0;
  31. <a name="l00058"></a>00058
  32. <a name="l00060"></a>00060 <span class="keyword">virtual</span> std::string <a class="code" href="classRtMidi.html#799e2b9f4df39b298518f2b394db3391" title="Pure virtual getPortName() function.">getPortName</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> portNumber = 0 ) = 0;
  33. <a name="l00061"></a>00061
  34. <a name="l00063"></a>00063 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classRtMidi.html#36125c4fa16550345b57f4a4927f5b4a" title="Pure virtual closePort() function.">closePort</a>( <span class="keywordtype">void</span> ) = 0;
  35. <a name="l00064"></a>00064
  36. <a name="l00065"></a>00065 <span class="keyword">protected</span>:
  37. <a name="l00066"></a>00066
  38. <a name="l00067"></a>00067 <a class="code" href="classRtMidi.html" title="An abstract base class for realtime MIDI input/output.">RtMidi</a>();
  39. <a name="l00068"></a>00068 <span class="keyword">virtual</span> ~<a class="code" href="classRtMidi.html" title="An abstract base class for realtime MIDI input/output.">RtMidi</a>() {};
  40. <a name="l00069"></a>00069
  41. <a name="l00070"></a>00070 <span class="comment">// A basic error reporting function for internal use in the RtMidi</span>
  42. <a name="l00071"></a>00071 <span class="comment">// subclasses. The behavior of this function can be modified to</span>
  43. <a name="l00072"></a>00072 <span class="comment">// suit specific needs.</span>
  44. <a name="l00073"></a>00073 <span class="keywordtype">void</span> error( <a class="code" href="classRtError.html#b04667aae01bffc354a9ac6bda6903ac" title="Defined RtError types.">RtError::Type</a> type );
  45. <a name="l00074"></a>00074
  46. <a name="l00075"></a>00075 <span class="keywordtype">void</span> *apiData_;
  47. <a name="l00076"></a>00076 <span class="keywordtype">bool</span> connected_;
  48. <a name="l00077"></a>00077 std::string errorString_;
  49. <a name="l00078"></a>00078 };
  50. <a name="l00079"></a>00079
  51. <a name="l00080"></a>00080 <span class="comment">/**********************************************************************/</span>
  52. <a name="l00096"></a>00096 <span class="comment">/**********************************************************************/</span>
  53. <a name="l00097"></a>00097
  54. <a name="l00098"></a>00098 <span class="preprocessor">#include &lt;vector&gt;</span>
  55. <a name="l00099"></a>00099 <span class="preprocessor">#include &lt;queue&gt;</span>
  56. <a name="l00100"></a>00100
  57. <a name="l00101"></a><a class="code" href="classRtMidiIn.html">00101</a> <span class="keyword">class </span><a class="code" href="classRtMidiIn.html" title="A realtime MIDI input class.">RtMidiIn</a> : <span class="keyword">public</span> <a class="code" href="classRtMidi.html" title="An abstract base class for realtime MIDI input/output.">RtMidi</a>
  58. <a name="l00102"></a>00102 {
  59. <a name="l00103"></a>00103 <span class="keyword">public</span>:
  60. <a name="l00104"></a>00104
  61. <a name="l00106"></a>00106 <span class="keyword">typedef</span> void (*<a class="code" href="classRtMidiIn.html#297d2eb3c3420b437970a6fc59d89cbf" title="User callback function type definition.">RtMidiCallback</a>)( <span class="keywordtype">double</span> timeStamp, std::vector&lt;unsigned char&gt; *message, <span class="keywordtype">void</span> *userData);
  62. <a name="l00107"></a>00107
  63. <a name="l00109"></a>00109
  64. <a name="l00112"></a>00112 <a class="code" href="classRtMidiIn.html#31abb996e5fdc4a8f9dc5a50848e2ee5" title="Default constructor that allows an optional client name.">RtMidiIn</a>( <span class="keyword">const</span> std::string clientName = std::string( <span class="stringliteral">"RtMidi Input Client"</span>) );
  65. <a name="l00113"></a>00113
  66. <a name="l00115"></a>00115 <a class="code" href="classRtMidiIn.html#f865d88c154b6fdadc640da5dc278d40" title="If a MIDI connection is still open, it will be closed by the destructor.">~RtMidiIn</a>();
  67. <a name="l00116"></a>00116
  68. <a name="l00118"></a>00118
  69. <a name="l00122"></a>00122 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#7e853661b1056083e07318d67c51f6fd" title="Open a MIDI input connection.">openPort</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> portNumber = 0, <span class="keyword">const</span> std::string Portname = std::string( <span class="stringliteral">"RtMidi Input"</span> ) );
  70. <a name="l00123"></a>00123
  71. <a name="l00125"></a>00125
  72. <a name="l00131"></a>00131 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#245261b3f12ce727faed18fcfeef18c2" title="Create a virtual input port, with optional name, to allow software connections (OS...">openVirtualPort</a>( <span class="keyword">const</span> std::string portName = std::string( <span class="stringliteral">"RtMidi Input"</span> ) );
  73. <a name="l00132"></a>00132
  74. <a name="l00134"></a>00134
  75. <a name="l00140"></a>00140 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#7590563461c7467608a4b3806406b32d" title="Set a callback function to be invoked for incoming MIDI messages.">setCallback</a>( <a class="code" href="classRtMidiIn.html#297d2eb3c3420b437970a6fc59d89cbf" title="User callback function type definition.">RtMidiCallback</a> callback, <span class="keywordtype">void</span> *userData = 0 );
  76. <a name="l00141"></a>00141
  77. <a name="l00143"></a>00143
  78. <a name="l00147"></a>00147 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#de23832a66c1ed56965c26325602543e" title="Cancel use of the current callback function (if one exists).">cancelCallback</a>();
  79. <a name="l00148"></a>00148
  80. <a name="l00150"></a>00150 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#55bacf0d228fd8e3be6a79d12fd1dc39" title="Close an open MIDI connection (if one exists).">closePort</a>( <span class="keywordtype">void</span> );
  81. <a name="l00151"></a>00151
  82. <a name="l00153"></a>00153 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classRtMidiIn.html#62b1b38aa8e5f11cd66f03d59228f4e4" title="Return the number of available MIDI input ports.">getPortCount</a>();
  83. <a name="l00154"></a>00154
  84. <a name="l00156"></a>00156
  85. <a name="l00159"></a>00159 std::string <a class="code" href="classRtMidiIn.html#f2961fff09fa01a3d5bc0f0c5a042aaf" title="Return a string identifier for the specified MIDI input port number.">getPortName</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> portNumber = 0 );
  86. <a name="l00160"></a>00160
  87. <a name="l00162"></a>00162
  88. <a name="l00166"></a>00166 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#2e15868916737039e0a34d47bffdf188" title="Set the maximum number of MIDI messages to be saved in the queue.">setQueueSizeLimit</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> queueSize );
  89. <a name="l00167"></a>00167
  90. <a name="l00169"></a>00169
  91. <a name="l00176"></a>00176 <span class="keywordtype">void</span> <a class="code" href="classRtMidiIn.html#f9507125aaa42276ccc01df576fc3533" title="Specify whether certain MIDI message types should be queued or ignored during input...">ignoreTypes</a>( <span class="keywordtype">bool</span> midiSysex = <span class="keyword">true</span>, <span class="keywordtype">bool</span> midiTime = <span class="keyword">true</span>, <span class="keywordtype">bool</span> midiSense = <span class="keyword">true</span> );
  92. <a name="l00177"></a>00177
  93. <a name="l00179"></a>00179
  94. <a name="l00186"></a>00186 <span class="keywordtype">double</span> <a class="code" href="classRtMidiIn.html#1ba10ecd276b30a8579c7d60a9c890eb" title="Fill the user-provided vector with the data bytes for the next available MIDI message...">getMessage</a>( std::vector&lt;unsigned char&gt; *message );
  95. <a name="l00187"></a>00187
  96. <a name="l00188"></a>00188 <span class="comment">// A MIDI structure used internally by the class to store incoming</span>
  97. <a name="l00189"></a>00189 <span class="comment">// messages. Each message represents one and only one MIDI message.</span>
  98. <a name="l00190"></a>00190 <span class="keyword">struct </span>MidiMessage {
  99. <a name="l00191"></a>00191 std::vector&lt;unsigned char&gt; bytes;
  100. <a name="l00192"></a>00192 <span class="keywordtype">double</span> timeStamp;
  101. <a name="l00193"></a>00193
  102. <a name="l00194"></a>00194 <span class="comment">// Default constructor.</span>
  103. <a name="l00195"></a>00195 MidiMessage()
  104. <a name="l00196"></a>00196 :bytes(3), timeStamp(0.0) {}
  105. <a name="l00197"></a>00197 };
  106. <a name="l00198"></a>00198
  107. <a name="l00199"></a>00199 <span class="comment">// The RtMidiInData structure is used to pass private class data to</span>
  108. <a name="l00200"></a>00200 <span class="comment">// the MIDI input handling function or thread.</span>
  109. <a name="l00201"></a>00201 <span class="keyword">struct </span>RtMidiInData {
  110. <a name="l00202"></a>00202 std::queue&lt;MidiMessage&gt; queue;
  111. <a name="l00203"></a>00203 MidiMessage message;
  112. <a name="l00204"></a>00204 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> queueLimit;
  113. <a name="l00205"></a>00205 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ignoreFlags;
  114. <a name="l00206"></a>00206 <span class="keywordtype">bool</span> doInput;
  115. <a name="l00207"></a>00207 <span class="keywordtype">bool</span> firstMessage;
  116. <a name="l00208"></a>00208 <span class="keywordtype">void</span> *apiData;
  117. <a name="l00209"></a>00209 <span class="keywordtype">bool</span> usingCallback;
  118. <a name="l00210"></a>00210 <span class="keywordtype">void</span> *userCallback;
  119. <a name="l00211"></a>00211 <span class="keywordtype">void</span> *userData;
  120. <a name="l00212"></a>00212 <span class="keywordtype">bool</span> continueSysex;
  121. <a name="l00213"></a>00213
  122. <a name="l00214"></a>00214 <span class="comment">// Default constructor.</span>
  123. <a name="l00215"></a>00215 RtMidiInData()
  124. <a name="l00216"></a>00216 : queueLimit(1024), ignoreFlags(7), doInput(<span class="keyword">false</span>), firstMessage(<span class="keyword">true</span>),
  125. <a name="l00217"></a>00217 apiData(0), usingCallback(<span class="keyword">false</span>), userCallback(0), userData(0),
  126. <a name="l00218"></a>00218 continueSysex(<span class="keyword">false</span>) {}
  127. <a name="l00219"></a>00219 };
  128. <a name="l00220"></a>00220
  129. <a name="l00221"></a>00221 <span class="keyword">private</span>:
  130. <a name="l00222"></a>00222
  131. <a name="l00223"></a>00223 <span class="keywordtype">void</span> initialize( <span class="keyword">const</span> std::string&amp; clientName );
  132. <a name="l00224"></a>00224 RtMidiInData inputData_;
  133. <a name="l00225"></a>00225
  134. <a name="l00226"></a>00226 };
  135. <a name="l00227"></a>00227
  136. <a name="l00228"></a>00228 <span class="comment">/**********************************************************************/</span>
  137. <a name="l00240"></a>00240 <span class="comment">/**********************************************************************/</span>
  138. <a name="l00241"></a>00241
  139. <a name="l00242"></a><a class="code" href="classRtMidiOut.html">00242</a> <span class="keyword">class </span><a class="code" href="classRtMidiOut.html" title="A realtime MIDI output class.">RtMidiOut</a> : <span class="keyword">public</span> <a class="code" href="classRtMidi.html" title="An abstract base class for realtime MIDI input/output.">RtMidi</a>
  140. <a name="l00243"></a>00243 {
  141. <a name="l00244"></a>00244 <span class="keyword">public</span>:
  142. <a name="l00245"></a>00245
  143. <a name="l00247"></a>00247
  144. <a name="l00250"></a>00250 <a class="code" href="classRtMidiOut.html#8ed1b492900f3410bf91ad53203b9db3" title="Default constructor that allows an optional client name.">RtMidiOut</a>( <span class="keyword">const</span> std::string clientName = std::string( <span class="stringliteral">"RtMidi Output Client"</span> ) );
  145. <a name="l00251"></a>00251
  146. <a name="l00253"></a>00253 <a class="code" href="classRtMidiOut.html#b776c431bd84193febb2f78fb8c7e792" title="The destructor closes any open MIDI connections.">~RtMidiOut</a>();
  147. <a name="l00254"></a>00254
  148. <a name="l00256"></a>00256
  149. <a name="l00262"></a>00262 <span class="keywordtype">void</span> <a class="code" href="classRtMidiOut.html#1b280d67317cd473a8816aeb2fe6c186" title="Open a MIDI output connection.">openPort</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> portNumber = 0, <span class="keyword">const</span> std::string portName = std::string( <span class="stringliteral">"RtMidi Output"</span> ) );
  150. <a name="l00263"></a>00263
  151. <a name="l00265"></a>00265 <span class="keywordtype">void</span> <a class="code" href="classRtMidiOut.html#3092e53a8aed2d3b163fcaa05fafd041" title="Close an open MIDI connection (if one exists).">closePort</a>();
  152. <a name="l00266"></a>00266
  153. <a name="l00268"></a>00268
  154. <a name="l00276"></a>00276 <span class="keywordtype">void</span> <a class="code" href="classRtMidiOut.html#47068e1c076d91fd89587c0ccdeddc7a" title="Create a virtual output port, with optional name, to allow software connections (OS...">openVirtualPort</a>( <span class="keyword">const</span> std::string portName = std::string( <span class="stringliteral">"RtMidi Output"</span> ) );
  155. <a name="l00277"></a>00277
  156. <a name="l00279"></a>00279 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classRtMidiOut.html#d6cddbcc7faa20a7be229f765ade0877" title="Return the number of available MIDI output ports.">getPortCount</a>();
  157. <a name="l00280"></a>00280
  158. <a name="l00282"></a>00282
  159. <a name="l00285"></a>00285 std::string <a class="code" href="classRtMidiOut.html#cc4ae0ab71a49ae7629075d5a9cd837c" title="Return a string identifier for the specified MIDI port type and number.">getPortName</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> portNumber = 0 );
  160. <a name="l00286"></a>00286
  161. <a name="l00288"></a>00288
  162. <a name="l00292"></a>00292 <span class="keywordtype">void</span> <a class="code" href="classRtMidiOut.html#0bd8972ef8ac4e8d37ccc4b5d51c2eb3" title="Immediately send a single message out an open MIDI output port.">sendMessage</a>( std::vector&lt;unsigned char&gt; *message );
  163. <a name="l00293"></a>00293
  164. <a name="l00294"></a>00294 <span class="keyword">private</span>:
  165. <a name="l00295"></a>00295
  166. <a name="l00296"></a>00296 <span class="keywordtype">void</span> initialize( <span class="keyword">const</span> std::string&amp; clientName );
  167. <a name="l00297"></a>00297 };
  168. <a name="l00298"></a>00298
  169. <a name="l00299"></a>00299 <span class="preprocessor">#endif</span>
  170. </pre></div></div>
  171. <HR>
  172. <table><tr><td><img src="../images/mcgill.gif" width=165></td>
  173. <td>&copy;2003-2009 Gary P. Scavone, McGill University. All Rights Reserved.<br>
  174. Maintained by Gary P. Scavone, gary at music.mcgill.ca</td></tr>
  175. </table>
  176. </BODY>
  177. </HTML>