New versions of RtAudio and RtMidi in preparation for new release.

This commit is contained in:
Gary Scavone
2021-11-16 21:28:04 -05:00
parent 67d573b169
commit 1fd900263b
4 changed files with 1342 additions and 495 deletions

View File

@@ -46,7 +46,7 @@
#ifndef __RTAUDIO_H #ifndef __RTAUDIO_H
#define __RTAUDIO_H #define __RTAUDIO_H
#define RTAUDIO_VERSION "5.1.0" #define RTAUDIO_VERSION "5.2.0"
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
#if defined(RTAUDIO_EXPORT) #if defined(RTAUDIO_EXPORT)
@@ -226,12 +226,12 @@ class RTAUDIO_DLL_PUBLIC RtAudioError : public std::runtime_error
UNSPECIFIED, /*!< The default, unspecified error type. */ UNSPECIFIED, /*!< The default, unspecified error type. */
NO_DEVICES_FOUND, /*!< No devices found on system. */ NO_DEVICES_FOUND, /*!< No devices found on system. */
INVALID_DEVICE, /*!< An invalid device ID was specified. */ INVALID_DEVICE, /*!< An invalid device ID was specified. */
MEMORY_ERROR, /*!< An error occured during memory allocation. */ MEMORY_ERROR, /*!< An error occurred during memory allocation. */
INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */ INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
INVALID_USE, /*!< The function was called incorrectly. */ INVALID_USE, /*!< The function was called incorrectly. */
DRIVER_ERROR, /*!< A system driver error occured. */ DRIVER_ERROR, /*!< A system driver error occurred. */
SYSTEM_ERROR, /*!< A system error occured. */ SYSTEM_ERROR, /*!< A system error occurred. */
THREAD_ERROR /*!< A thread error occured. */ THREAD_ERROR /*!< A thread error occurred. */
}; };
//! The constructor. //! The constructor.
@@ -299,30 +299,21 @@ class RTAUDIO_DLL_PUBLIC RtAudio
struct DeviceInfo { struct DeviceInfo {
bool probed; /*!< true if the device capabilities were successfully probed. */ bool probed; /*!< true if the device capabilities were successfully probed. */
std::string name; /*!< Character string device identifier. */ std::string name; /*!< Character string device identifier. */
unsigned int outputChannels; /*!< Maximum output channels supported by device. */ unsigned int outputChannels{}; /*!< Maximum output channels supported by device. */
unsigned int inputChannels; /*!< Maximum input channels supported by device. */ unsigned int inputChannels{}; /*!< Maximum input channels supported by device. */
unsigned int duplexChannels; /*!< Maximum simultaneous input/output channels supported by device. */ unsigned int duplexChannels{}; /*!< Maximum simultaneous input/output channels supported by device. */
bool isDefaultOutput; /*!< true if this is the default output device. */ bool isDefaultOutput{false}; /*!< true if this is the default output device. */
bool isDefaultInput; /*!< true if this is the default input device. */ bool isDefaultInput{false}; /*!< true if this is the default input device. */
std::vector<unsigned int> sampleRates; /*!< Supported sample rates (queried from list of standard rates). */ std::vector<unsigned int> sampleRates; /*!< Supported sample rates (queried from list of standard rates). */
unsigned int preferredSampleRate; /*!< Preferred sample rate, e.g. for WASAPI the system sample rate. */ unsigned int preferredSampleRate{}; /*!< Preferred sample rate, e.g. for WASAPI the system sample rate. */
RtAudioFormat nativeFormats; /*!< Bit mask of supported data formats. */ RtAudioFormat nativeFormats{}; /*!< Bit mask of supported data formats. */
// Default constructor.
DeviceInfo()
:probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
isDefaultOutput(false), isDefaultInput(false), preferredSampleRate(0), nativeFormats(0) {}
}; };
//! The structure for specifying input or ouput stream parameters. //! The structure for specifying input or output stream parameters.
struct StreamParameters { struct StreamParameters {
unsigned int deviceId; /*!< Device index (0 to getDeviceCount() - 1). */ unsigned int deviceId{}; /*!< Device index (0 to getDeviceCount() - 1). */
unsigned int nChannels; /*!< Number of channels. */ unsigned int nChannels{}; /*!< Number of channels. */
unsigned int firstChannel; /*!< First channel index on device (default = 0). */ unsigned int firstChannel{}; /*!< First channel index on device (default = 0). */
// Default constructor.
StreamParameters()
: deviceId(0), nChannels(0), firstChannel(0) {}
}; };
//! The structure for specifying stream options. //! The structure for specifying stream options.
@@ -383,14 +374,10 @@ class RTAUDIO_DLL_PUBLIC RtAudio
RtAudio with Jack, each instance must have a unique client name. RtAudio with Jack, each instance must have a unique client name.
*/ */
struct StreamOptions { struct StreamOptions {
RtAudioStreamFlags flags; /*!< A bit-mask of stream flags (RTAUDIO_NONINTERLEAVED, RTAUDIO_MINIMIZE_LATENCY, RTAUDIO_HOG_DEVICE, RTAUDIO_ALSA_USE_DEFAULT). */ RtAudioStreamFlags flags{}; /*!< A bit-mask of stream flags (RTAUDIO_NONINTERLEAVED, RTAUDIO_MINIMIZE_LATENCY, RTAUDIO_HOG_DEVICE, RTAUDIO_ALSA_USE_DEFAULT). */
unsigned int numberOfBuffers; /*!< Number of stream buffers. */ unsigned int numberOfBuffers{}; /*!< Number of stream buffers. */
std::string streamName; /*!< A stream name (currently used only in Jack). */ std::string streamName; /*!< A stream name (currently used only in Jack). */
int priority; /*!< Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME). */ int priority{}; /*!< Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME). */
// Default constructor.
StreamOptions()
: flags(0), numberOfBuffers(0), priority(0) {}
}; };
//! A static function to determine the current RtAudio version. //! A static function to determine the current RtAudio version.
@@ -527,7 +514,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio
lowest allowable value is used. The actual value used is lowest allowable value is used. The actual value used is
returned via the structure argument. The parameter is API dependent. returned via the structure argument. The parameter is API dependent.
\param errorCallback A client-defined function that will be invoked \param errorCallback A client-defined function that will be invoked
when an error has occured. when an error has occurred.
*/ */
void openStream( RtAudio::StreamParameters *outputParameters, void openStream( RtAudio::StreamParameters *outputParameters,
RtAudio::StreamParameters *inputParameters, RtAudio::StreamParameters *inputParameters,
@@ -616,7 +603,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio
}; };
// Operating system dependent thread functionality. // Operating system dependent thread functionality.
#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) #if defined(_WIN32) || defined(__CYGWIN__)
#ifndef NOMINMAX #ifndef NOMINMAX
#define NOMINMAX #define NOMINMAX
@@ -628,18 +615,22 @@ class RTAUDIO_DLL_PUBLIC RtAudio
typedef uintptr_t ThreadHandle; typedef uintptr_t ThreadHandle;
typedef CRITICAL_SECTION StreamMutex; typedef CRITICAL_SECTION StreamMutex;
#elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__) #else
// Using pthread library for various flavors of unix. // Using pthread library for various flavors of unix.
#include <pthread.h> #include <pthread.h>
typedef pthread_t ThreadHandle; typedef pthread_t ThreadHandle;
typedef pthread_mutex_t StreamMutex; typedef pthread_mutex_t StreamMutex;
#else // Setup for "dummy" behavior #endif
// Setup for "dummy" behavior if no apis specified.
#if !(defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) \
|| defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) \
|| defined(__LINUX_OSS__) || defined(__MACOSX_CORE__))
#define __RTAUDIO_DUMMY__ #define __RTAUDIO_DUMMY__
typedef int ThreadHandle;
typedef int StreamMutex;
#endif #endif
@@ -647,19 +638,15 @@ class RTAUDIO_DLL_PUBLIC RtAudio
// between the private RtAudio stream structure and global callback // between the private RtAudio stream structure and global callback
// handling functions. // handling functions.
struct CallbackInfo { struct CallbackInfo {
void *object; // Used as a "this" pointer. void *object{}; // Used as a "this" pointer.
ThreadHandle thread; ThreadHandle thread{};
void *callback; void *callback{};
void *userData; void *userData{};
void *errorCallback; void *errorCallback{};
void *apiInfo; // void pointer for API specific callback information void *apiInfo{}; // void pointer for API specific callback information
bool isRunning; bool isRunning{false};
bool doRealtime; bool doRealtime{false};
int priority; int priority{};
// Default constructor.
CallbackInfo()
:object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false), priority(0) {}
}; };
// **************************************************************** // // **************************************************************** //
@@ -686,9 +673,9 @@ class S24 {
S24() {} S24() {}
S24& operator = ( const int& i ) { S24& operator = ( const int& i ) {
c3[0] = (i & 0x000000ff); c3[0] = (unsigned char)(i & 0x000000ff);
c3[1] = (i & 0x0000ff00) >> 8; c3[1] = (unsigned char)((i & 0x0000ff00) >> 8);
c3[2] = (i & 0x00ff0000) >> 16; c3[2] = (unsigned char)((i & 0x00ff0000) >> 16);
return *this; return *this;
} }
@@ -895,20 +882,20 @@ public:
RtApiCore(); RtApiCore();
~RtApiCore(); ~RtApiCore();
RtAudio::Api getCurrentApi( void ) { return RtAudio::MACOSX_CORE; } RtAudio::Api getCurrentApi( void ) override { return RtAudio::MACOSX_CORE; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
unsigned int getDefaultOutputDevice( void ); unsigned int getDefaultOutputDevice( void ) override;
unsigned int getDefaultInputDevice( void ); unsigned int getDefaultInputDevice( void ) override;
void closeStream( void ); void closeStream( void ) override;
void startStream( void ); void startStream( void ) override;
void stopStream( void ); void stopStream( void ) override;
void abortStream( void ); void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
bool callbackEvent( AudioDeviceID deviceId, bool callbackEvent( AudioDeviceID deviceId,
const AudioBufferList *inBufferList, const AudioBufferList *inBufferList,
const AudioBufferList *outBufferList ); const AudioBufferList *outBufferList );
@@ -918,7 +905,7 @@ public:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
static const char* getErrorCode( OSStatus code ); static const char* getErrorCode( OSStatus code );
}; };
@@ -932,18 +919,18 @@ public:
RtApiJack(); RtApiJack();
~RtApiJack(); ~RtApiJack();
RtAudio::Api getCurrentApi( void ) { return RtAudio::UNIX_JACK; } RtAudio::Api getCurrentApi( void ) override { return RtAudio::UNIX_JACK; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ); void closeStream( void ) override;
void startStream( void ); void startStream( void ) override;
void stopStream( void ); void stopStream( void ) override;
void abortStream( void ); void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
bool callbackEvent( unsigned long nframes ); bool callbackEvent( unsigned long nframes );
private: private:
@@ -951,7 +938,7 @@ public:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
bool shouldAutoconnect_; bool shouldAutoconnect_;
}; };
@@ -966,18 +953,20 @@ public:
RtApiAsio(); RtApiAsio();
~RtApiAsio(); ~RtApiAsio();
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_ASIO; } RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_ASIO; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); unsigned int getDefaultOutputDevice( void ) override;
void closeStream( void ); unsigned int getDefaultInputDevice( void ) override;
void startStream( void ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void stopStream( void ); void closeStream( void ) override;
void abortStream( void ); void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
bool callbackEvent( long bufferIndex ); bool callbackEvent( long bufferIndex );
private: private:
@@ -988,7 +977,7 @@ public:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
}; };
#endif #endif
@@ -1001,20 +990,20 @@ public:
RtApiDs(); RtApiDs();
~RtApiDs(); ~RtApiDs();
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_DS; } RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_DS; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
unsigned int getDefaultOutputDevice( void ); unsigned int getDefaultOutputDevice( void ) override;
unsigned int getDefaultInputDevice( void ); unsigned int getDefaultInputDevice( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ); void closeStream( void ) override;
void startStream( void ); void startStream( void ) override;
void stopStream( void ); void stopStream( void ) override;
void abortStream( void ); void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
void callbackEvent( void ); void callbackEvent( void );
private: private:
@@ -1026,7 +1015,7 @@ public:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
}; };
#endif #endif
@@ -1041,15 +1030,13 @@ public:
RtApiWasapi(); RtApiWasapi();
virtual ~RtApiWasapi(); virtual ~RtApiWasapi();
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_WASAPI; } RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_WASAPI; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
unsigned int getDefaultOutputDevice( void ); void closeStream( void ) override;
unsigned int getDefaultInputDevice( void ); void startStream( void ) override;
void closeStream( void ); void stopStream( void ) override;
void startStream( void ); void abortStream( void ) override;
void stopStream( void );
void abortStream( void );
private: private:
bool coInitialized_; bool coInitialized_;
@@ -1058,7 +1045,7 @@ private:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int* bufferSize, RtAudioFormat format, unsigned int* bufferSize,
RtAudio::StreamOptions* options ); RtAudio::StreamOptions* options ) override;
static DWORD WINAPI runWasapiThread( void* wasapiPtr ); static DWORD WINAPI runWasapiThread( void* wasapiPtr );
static DWORD WINAPI stopWasapiThread( void* wasapiPtr ); static DWORD WINAPI stopWasapiThread( void* wasapiPtr );
@@ -1076,18 +1063,18 @@ public:
RtApiAlsa(); RtApiAlsa();
~RtApiAlsa(); ~RtApiAlsa();
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_ALSA; } RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_ALSA; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ); void closeStream( void ) override;
void startStream( void ); void startStream( void ) override;
void stopStream( void ); void stopStream( void ) override;
void abortStream( void ); void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
void callbackEvent( void ); void callbackEvent( void );
private: private:
@@ -1097,7 +1084,7 @@ public:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
}; };
#endif #endif
@@ -1108,28 +1095,27 @@ class RtApiPulse: public RtApi
{ {
public: public:
~RtApiPulse(); ~RtApiPulse();
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_PULSE; } RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_PULSE; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ); void closeStream( void ) override;
void startStream( void ); void startStream( void ) override;
void stopStream( void ); void stopStream( void ) override;
void abortStream( void ); void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
void callbackEvent( void ); void callbackEvent( void );
private: private:
std::vector<RtAudio::DeviceInfo> devices_; void collectDeviceInfo( void );
void saveDeviceInfo( void );
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
}; };
#endif #endif
@@ -1142,18 +1128,18 @@ public:
RtApiOss(); RtApiOss();
~RtApiOss(); ~RtApiOss();
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_OSS; } RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_OSS; }
unsigned int getDeviceCount( void ); unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ); RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ); void closeStream( void ) override;
void startStream( void ); void startStream( void ) override;
void stopStream( void ); void stopStream( void ) override;
void abortStream( void ); void abortStream( void ) override;
// This function is intended for internal use only. It must be // This function is intended for internal use only. It must be
// public because it is called by the internal callback handler, // public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function // which is not a member of RtAudio. External use of this function
// will most likely produce highly undesireable results! // will most likely produce highly undesirable results!
void callbackEvent( void ); void callbackEvent( void );
private: private:
@@ -1161,7 +1147,7 @@ public:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels, bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate, unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize, RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ); RtAudio::StreamOptions *options ) override;
}; };
#endif #endif
@@ -1173,20 +1159,20 @@ class RtApiDummy: public RtApi
public: public:
RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtAudioError::WARNING ); } RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtAudioError::WARNING ); }
RtAudio::Api getCurrentApi( void ) { return RtAudio::RTAUDIO_DUMMY; } RtAudio::Api getCurrentApi( void ) override { return RtAudio::RTAUDIO_DUMMY; }
unsigned int getDeviceCount( void ) { return 0; } unsigned int getDeviceCount( void ) override { return 0; }
RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) { RtAudio::DeviceInfo info; return info; } RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) override { RtAudio::DeviceInfo info; return info; }
void closeStream( void ) {} void closeStream( void ) override {}
void startStream( void ) {} void startStream( void ) override {}
void stopStream( void ) {} void stopStream( void ) override {}
void abortStream( void ) {} void abortStream( void ) override {}
private: private:
bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/, bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/,
unsigned int /*firstChannel*/, unsigned int /*sampleRate*/, unsigned int /*firstChannel*/, unsigned int /*sampleRate*/,
RtAudioFormat /*format*/, unsigned int * /*bufferSize*/, RtAudioFormat /*format*/, unsigned int * /*bufferSize*/,
RtAudio::StreamOptions * /*options*/ ) { return false; } RtAudio::StreamOptions * /*options*/ ) override { return false; }
}; };
#endif #endif

View File

@@ -58,13 +58,14 @@
#endif #endif
#endif #endif
#define RTMIDI_VERSION "4.0.0" #define RTMIDI_VERSION "5.0.0"
#include <exception> #include <exception>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
/************************************************************************/ /************************************************************************/
/*! \class RtMidiError /*! \class RtMidiError
\brief Exception handling class for RtMidi. \brief Exception handling class for RtMidi.
@@ -132,6 +133,8 @@ class MidiApi;
class RTMIDI_DLL_PUBLIC RtMidi class RTMIDI_DLL_PUBLIC RtMidi
{ {
public: public:
RtMidi(RtMidi&& other) noexcept;
//! MIDI API specifier arguments. //! MIDI API specifier arguments.
enum Api { enum Api {
UNSPECIFIED, /*!< Search for a working compiled API. */ UNSPECIFIED, /*!< Search for a working compiled API. */
@@ -140,6 +143,7 @@ class RTMIDI_DLL_PUBLIC RtMidi
UNIX_JACK, /*!< The JACK Low-Latency MIDI Server API. */ UNIX_JACK, /*!< The JACK Low-Latency MIDI Server API. */
WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */ WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
RTMIDI_DUMMY, /*!< A compilable but non-functional API. */ RTMIDI_DUMMY, /*!< A compilable but non-functional API. */
WEB_MIDI_API, /*!< W3C Web MIDI API. */
NUM_APIS /*!< Number of values in this enum. */ NUM_APIS /*!< Number of values in this enum. */
}; };
@@ -213,6 +217,10 @@ class RTMIDI_DLL_PUBLIC RtMidi
RtMidi(); RtMidi();
virtual ~RtMidi(); virtual ~RtMidi();
MidiApi *rtapi_; MidiApi *rtapi_;
/* Make the class non-copyable */
RtMidi(RtMidi& other) = delete;
RtMidi& operator=(RtMidi& other) = delete;
}; };
/**********************************************************************/ /**********************************************************************/
@@ -248,7 +256,6 @@ class RTMIDI_DLL_PUBLIC RtMidi
class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi
{ {
public: public:
//! User callback function type definition. //! User callback function type definition.
typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData ); typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData );
@@ -274,6 +281,8 @@ class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi
const std::string& clientName = "RtMidi Input Client", const std::string& clientName = "RtMidi Input Client",
unsigned int queueSizeLimit = 100 ); unsigned int queueSizeLimit = 100 );
RtMidiIn(RtMidiIn&& other) noexcept : RtMidi(std::move(other)) { }
//! If a MIDI connection is still open, it will be closed by the destructor. //! If a MIDI connection is still open, it will be closed by the destructor.
~RtMidiIn ( void ) throw(); ~RtMidiIn ( void ) throw();
@@ -371,6 +380,19 @@ class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi
*/ */
virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ); virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
//! Set maximum expected incoming message size.
/*!
For APIs that require manual buffer management, it can be useful to set the buffer
size and buffer count when expecting to receive large SysEx messages. Note that
currently this function has no effect when called after openPort(). The default
buffer size is 1024 with a count of 4 buffers, which should be sufficient for most
cases; as mentioned, this does not affect all API backends, since most either support
dynamically scalable buffers or take care of buffer handling themselves. It is
principally intended for users of the Windows MM backend who must support receiving
especially large messages.
*/
virtual void setBufferSize( unsigned int size, unsigned int count );
protected: protected:
void openMidiApi( RtMidi::Api api, const std::string &clientName, unsigned int queueSizeLimit ); void openMidiApi( RtMidi::Api api, const std::string &clientName, unsigned int queueSizeLimit );
}; };
@@ -403,6 +425,8 @@ class RTMIDI_DLL_PUBLIC RtMidiOut : public RtMidi
RtMidiOut( RtMidi::Api api=UNSPECIFIED, RtMidiOut( RtMidi::Api api=UNSPECIFIED,
const std::string& clientName = "RtMidi Output Client" ); const std::string& clientName = "RtMidi Output Client" );
RtMidiOut(RtMidiOut&& other) noexcept : RtMidi(std::move(other)) { }
//! The destructor closes any open MIDI connections. //! The destructor closes any open MIDI connections.
~RtMidiOut( void ) throw(); ~RtMidiOut( void ) throw();
@@ -523,6 +547,7 @@ protected:
RtMidiErrorCallback errorCallback_; RtMidiErrorCallback errorCallback_;
bool firstErrorOccurred_; bool firstErrorOccurred_;
void *errorCallbackUserData_; void *errorCallbackUserData_;
}; };
class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi
@@ -535,6 +560,7 @@ class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi
void cancelCallback( void ); void cancelCallback( void );
virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ); virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
double getMessage( std::vector<unsigned char> *message ); double getMessage( std::vector<unsigned char> *message );
virtual void setBufferSize( unsigned int size, unsigned int count );
// A MIDI structure used internally by the class to store incoming // A MIDI structure used internally by the class to store incoming
// messages. Each message represents one and only one MIDI message. // messages. Each message represents one and only one MIDI message.
@@ -576,11 +602,13 @@ class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi
RtMidiIn::RtMidiCallback userCallback; RtMidiIn::RtMidiCallback userCallback;
void *userData; void *userData;
bool continueSysex; bool continueSysex;
unsigned int bufferSize;
unsigned int bufferCount;
// Default constructor. // Default constructor.
RtMidiInData() RtMidiInData()
: ignoreFlags(7), doInput(false), firstMessage(true), apiData(0), usingCallback(false), : ignoreFlags(7), doInput(false), firstMessage(true), apiData(0), usingCallback(false),
userCallback(0), userData(0), continueSysex(false) {} userCallback(0), userData(0), continueSysex(false), bufferSize(1024), bufferCount(4) {}
}; };
protected: protected:
@@ -614,6 +642,7 @@ inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return r
inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { static_cast<MidiInApi *>(rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); } inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { static_cast<MidiInApi *>(rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); }
inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return static_cast<MidiInApi *>(rtapi_)->getMessage( message ); } inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return static_cast<MidiInApi *>(rtapi_)->getMessage( message ); }
inline void RtMidiIn :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); } inline void RtMidiIn :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
inline void RtMidiIn :: setBufferSize( unsigned int size, unsigned int count ) { static_cast<MidiInApi *>(rtapi_)->setBufferSize(size, count); }
inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); } inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string &portName ) { rtapi_->openPort( portNumber, portName ); } inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff