blob: 267d6fbfd83bbe6354f8e95630ade8b25364722b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<HTML>
<HEAD>
<TITLE>The Synthesis ToolKit in C++ (STK)</TITLE>
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<img src="princeton.gif"> <img src="ccrma.gif"><P>
<a class="qindex" href="index.html">Home</a> <a class="qindex" href="information.html">Information</a> <a class="qindex" href="classes.html">Classes</a> <a class="qindex" href="download.html">Download</a> <a class="qindex" href="usage.html">Usage</a> <a class="qindex" href="maillist.html">Mail List</a> <a class="qindex" href="system.html">Requirements</a> <a class="qindex" href="links.html">Links</a> <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
<HR>
<!-- Generated by Doxygen 1.3-rc3 -->
<h1>midiin.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// midiin.cpp</span>
00002 <span class="comment">//</span>
00003 <span class="comment">// Simple program to read MIDI input from default port.</span>
00004 <span class="comment">//</span>
00005 <span class="comment">// by Gary Scavone, 2003.</span>
00006 <span class="comment">//</span>
00007 <span class="comment">// compile: g++ -Wall -D__MACOSX_CORE__ -o midiin midiin.cpp RtMidi.cpp Stk.cpp -framework CoreMIDI -framework CoreFoundation -framework CoreAudio</span>
00008
00009 <span class="preprocessor">#include <iostream></span>
00010 <span class="preprocessor">#include <unistd.h></span>
00011 <span class="preprocessor">#include <signal.h></span>
00012 <span class="preprocessor">#include "RtMidi.h"</span>
00013
00014 <span class="keywordtype">bool</span> done;
00015 <span class="keyword">static</span> <span class="keywordtype">void</span> finish(<span class="keywordtype">int</span> ignore){ done = <span class="keyword">true</span>; }
00016
00017 <span class="keywordtype">int</span> main()
00018 {
00019 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
00020 <a class="code" href="classRtMidiIn.html">RtMidiIn</a> midi;
00021 std::vector<unsigned char> message;
00022
00023 <span class="keywordflow">if</span> ( midi.<a class="code" href="classRtMidiIn.html#a5">getPortCount</a>() < 1 ) {
00024 cout << <span class="stringliteral">"\nThere are no MIDI input sources available!\n"</span>;
00025 exit(0);
00026 }
00027
00028 <span class="keywordflow">try</span> {
00029 midi.<a class="code" href="classRtMidiIn.html#a3">openPort</a>();
00030 }
00031 <span class="keywordflow">catch</span> ( <a class="code" href="classRtError.html">RtError</a> & ) {
00032 <span class="comment">// You might want to do something more useful here.</span>
00033 cout << <span class="stringliteral">"\nAborting program!\n"</span>;
00034 <span class="keywordflow">goto</span> cleanup;
00035 }
00036
00037 <span class="comment">// Install an interrupt handler function.</span>
00038 (void) signal(SIGINT, finish);
00039
00040 <span class="keywordtype">int</span> nBytes, i, value;
00041 <span class="keywordtype">double</span> stamp;
00042 done = <span class="keyword">false</span>;
00043 cout << <span class="stringliteral">"Reading MIDI from default port ..."</span> << endl;
00044 <span class="keywordflow">while</span> ( !done ) {
00045 stamp = midi.<a class="code" href="classRtMidiIn.html#a9">getMessage</a>( &message );
00046 nBytes = message.size();
00047 <span class="keywordflow">for</span> ( i=0; i<nBytes; i++ ) {
00048 value = message[i];
00049 cout << <span class="stringliteral">"Byte "</span> << i << <span class="stringliteral">" = "</span> << value << <span class="stringliteral">", "</span>;
00050 }
00051 <span class="keywordflow">if</span> ( nBytes > 0 )
00052 cout << <span class="stringliteral">"stamp = "</span> << stamp << <span class="charliteral">'\n'</span>;
00053
00054 <span class="comment">// Sleep for 10 milliseconds.</span>
00055 usleep( 10000 );
00056 }
00057
00058 cout << <span class="stringliteral">"Goodbye!"</span> << endl;
00059
00060 cleanup:
00061 midi.<a class="code" href="classRtMidiIn.html#a4">closePort</a>();
00062 <span class="keywordflow">return</span> 0;
00063 }
</pre></div><HR>
<table>
<tr><td><A HREF="http://www-ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
<tr><td>©1995-2002 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>
</BODY>
</HTML>
|