Newer
Older
/**********************************************************************/
/*! \class RtMidi
\brief An abstract base class for realtime MIDI input/output.
This class implements some common functionality for the realtime
MIDI input/output subclasses RtMidiIn and RtMidiOut.
RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/
RtMidi: realtime MIDI i/o C++ classes
Copyright (c) 2003-2014 Gary P. Scavone
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
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
Any person wishing to distribute modifications to the Software is
asked to send the modifications to the original developer so that
they can be incorporated into the canonical version. This is,
however, not a binding provision of this license.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**********************************************************************/
#include "RtMidi.h"
#include <sstream>
//*********************************************************************//
// RtMidi Definitions
//*********************************************************************//
RtMidi :: RtMidi()
: rtapi_(0)
{
}
RtMidi :: ~RtMidi()
{
if ( rtapi_ )
delete rtapi_;
rtapi_ = 0;
}
std::string RtMidi :: getVersion( void ) throw()
{
return std::string( RTMIDI_VERSION );
}
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
void RtMidi :: getCompiledApi( std::vector<RtMidi::Api> &apis ) throw()
{
apis.clear();
// The order here will control the order of RtMidi's API search in
// the constructor.
#if defined(__MACOSX_CORE__)
apis.push_back( MACOSX_CORE );
#endif
#if defined(__LINUX_ALSA__)
apis.push_back( LINUX_ALSA );
#endif
#if defined(__UNIX_JACK__)
apis.push_back( UNIX_JACK );
#endif
#if defined(__WINDOWS_MM__)
apis.push_back( WINDOWS_MM );
#endif
#if defined(__RTMIDI_DUMMY__)
apis.push_back( RTMIDI_DUMMY );
#endif
}
//*********************************************************************//
// RtMidiIn Definitions
//*********************************************************************//
void RtMidiIn :: openMidiApi( RtMidi::Api api, const std::string clientName, unsigned int queueSizeLimit )
{
if ( rtapi_ )
delete rtapi_;
rtapi_ = 0;
#if defined(__UNIX_JACK__)
if ( api == UNIX_JACK )
rtapi_ = new MidiInJack( clientName, queueSizeLimit );
#endif
#if defined(__LINUX_ALSA__)
if ( api == LINUX_ALSA )
rtapi_ = new MidiInAlsa( clientName, queueSizeLimit );
#endif
#if defined(__WINDOWS_MM__)
if ( api == WINDOWS_MM )
rtapi_ = new MidiInWinMM( clientName, queueSizeLimit );
#endif
#if defined(__MACOSX_CORE__)
if ( api == MACOSX_CORE )
rtapi_ = new MidiInCore( clientName, queueSizeLimit );
#endif
#if defined(__RTMIDI_DUMMY__)
if ( api == RTMIDI_DUMMY )
rtapi_ = new MidiInDummy( clientName, queueSizeLimit );
#endif
}
RtMidiIn :: RtMidiIn( RtMidi::Api api, const std::string clientName, unsigned int queueSizeLimit )
: RtMidi()
{
if ( api != UNSPECIFIED ) {
// Attempt to open the specified API.
openMidiApi( api, clientName, queueSizeLimit );
if ( rtapi_ ) return;
// No compiled support for specified API value. Issue a warning
// and continue as if no API was specified.
std::cerr << "\nRtMidiIn: no compiled support for specified API argument!\n\n" << std::endl;
}
// Iterate through the compiled APIs and return as soon as we find
// one with at least one port or we reach the end of the list.
std::vector< RtMidi::Api > apis;
getCompiledApi( apis );
for ( unsigned int i=0; i<apis.size(); i++ ) {
openMidiApi( apis[i], clientName, queueSizeLimit );
if ( rtapi_->getPortCount() ) break;
}
if ( rtapi_ ) return;
// It should not be possible to get here because the preprocessor
// definition __RTMIDI_DUMMY__ is automatically defined if no
// API-specific definitions are passed to the compiler. But just in
// case something weird happens, we'll throw an error.
std::string errorText = "RtMidiIn: no compiled API support found ... critical error!!";
throw( RtMidiError( errorText, RtMidiError::UNSPECIFIED ) );
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
}
RtMidiIn :: ~RtMidiIn() throw()
{
}
//*********************************************************************//
// RtMidiOut Definitions
//*********************************************************************//
void RtMidiOut :: openMidiApi( RtMidi::Api api, const std::string clientName )
{
if ( rtapi_ )
delete rtapi_;
rtapi_ = 0;
#if defined(__UNIX_JACK__)
if ( api == UNIX_JACK )
rtapi_ = new MidiOutJack( clientName );
#endif
#if defined(__LINUX_ALSA__)
if ( api == LINUX_ALSA )
rtapi_ = new MidiOutAlsa( clientName );
#endif
#if defined(__WINDOWS_MM__)
if ( api == WINDOWS_MM )
rtapi_ = new MidiOutWinMM( clientName );
#endif
#if defined(__MACOSX_CORE__)
if ( api == MACOSX_CORE )
rtapi_ = new MidiOutCore( clientName );
#endif
#if defined(__RTMIDI_DUMMY__)
if ( api == RTMIDI_DUMMY )
rtapi_ = new MidiOutDummy( clientName );
#endif
}
RtMidiOut :: RtMidiOut( RtMidi::Api api, const std::string clientName )
{
if ( api != UNSPECIFIED ) {
// Attempt to open the specified API.
openMidiApi( api, clientName );
if ( rtapi_ ) return;
// No compiled support for specified API value. Issue a warning
// and continue as if no API was specified.
std::cerr << "\nRtMidiOut: no compiled support for specified API argument!\n\n" << std::endl;
Loading
Loading full blame...