blob: cf274e60975deb0f92c9a9555c6864d6d8b46169 (
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
84
85
86
87
88
89
90
91
92
93
|
<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>miditime.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// miditime.cpp</span>
00002 <span class="comment">//</span>
00003 <span class="comment">// Simple program to output MIDI to the 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 -o miditime miditime.cpp RtMidi.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="classRtMidi.html">RtMidi</a> midi( RtMidi::ABSOLUTE_TIME );
00021
00022 <span class="keywordflow">if</span> ( midi.getPortCount( RtMidi::MIDI_OUTPUT ) < 1 ) {
00023 cout << <span class="stringliteral">"\nThere are no MIDI output destinations available!\n"</span>;
00024 exit(0);
00025 }
00026
00027 <span class="keywordflow">try</span> {
00028 midi.openPort( RtMidi::MIDI_OUTPUT );
00029 }
00030 <span class="keywordflow">catch</span> ( <a class="code" href="classRtError.html">RtError</a> & ) {
00031 <span class="comment">// You might want to do something more useful here.</span>
00032 cout << <span class="stringliteral">"\nAborting program!\n"</span>;
00033 midi.closePort();
00034 exit(0);
00035 }
00036
00037 <span class="comment">// Install an interrupt handler function.</span>
00038 (void) signal(SIGINT, finish);
00039
00040 RtMidi::MidiMessage message;
00041 message.bytes.push_back( 144 );
00042 message.bytes.push_back( 64 );
00043 message.bytes.push_back( 80 );
00044
00045 cout << <span class="stringliteral">"Scheduling for 1 second later ..."</span> << endl;
00046 timeval tvTime;
00047 <span class="keywordflow">if</span> ( gettimeofday( &tvTime, NULL ) == 0 ) {
00048 message.timeStamp = (double) tvTime.tv_sec + 1.0;
00049 message.timeStamp += (double) (tvTime.tv_usec * 0.000001);
00050 }
00051 <span class="comment">//message.timeStamp = 1.0;</span>
00052 midi.sendMessage( &message );
00053
00054 <span class="comment">// Sleep for 0.5 seconds.</span>
00055 usleep( 1000000 );
00056
00057 cout << <span class="stringliteral">"1 second has passed ..."</span> << endl;
00058
00059 <span class="comment">// Sleep another 1.0 seconds.</span>
00060 usleep( 1000000 );
00061
00062 cout << <span class="stringliteral">"Turning note off ... "</span>;
00063
00064 <span class="comment">// Turn the note off.</span>
00065 message.timeStamp = 0.0;
00066 message.bytes[2] = 0;
00067 midi.sendMessage( &message );
00068
00069 midi.closePort();
00070
00071 cout << <span class="stringliteral">"Goodbye!"</span> << endl;
00072 <span class="keywordflow">return</span> 0;
00073 }
</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>
|