diff options
| author | JP Cimalando <jp-dev@inbox.ru> | 2018-05-07 17:30:27 +0200 |
|---|---|---|
| committer | JP Cimalando <jp-dev@inbox.ru> | 2018-05-07 19:20:23 +0200 |
| commit | f7b624ba819036b9ebfb3f4d0517fd45e01919b2 (patch) | |
| tree | 5f31ce4d7ec0b8f6c90a85a3de0e533691d94104 /RtAudio.cpp | |
| parent | 4a7ca4f1d42fff04eb085d85a3b298df2c937a34 (diff) | |
API names, and conversion from/to API identifier
Diffstat (limited to 'RtAudio.cpp')
| -rw-r--r-- | RtAudio.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/RtAudio.cpp b/RtAudio.cpp index b091e15..db3b7cb 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -45,6 +45,7 @@ #include <cstdlib> #include <cstring> #include <climits> +#include <cctype> #include <cmath> #include <algorithm> @@ -133,6 +134,92 @@ void RtAudio :: getCompiledApi( std::vector<RtAudio::Api> &apis ) #endif } +const std::string &RtAudio :: getCompiledApiName( RtAudio::Api api ) +{ +#if defined(__UNIX_JACK__) + if ( api == UNIX_JACK ) { + static std::string name( "JACK" ); + return name; + } +#endif +#if defined(__LINUX_PULSE__) + if ( api == LINUX_PULSE ) { + static std::string name( "PulseAudio" ); + return name; + } +#endif +#if defined(__LINUX_ALSA__) + if ( api == LINUX_ALSA ) { + static std::string name( "ALSA" ); + return name; + } +#endif +#if defined(__LINUX_OSS__) + if ( api == LINUX_OSS ) { + static std::string name( "OSS" ); + return name; + } +#endif +#if defined(__WINDOWS_ASIO__) + if ( api == WINDOWS_ASIO ) { + static std::string name( "ASIO" ); + return name; + } +#endif +#if defined(__WINDOWS_WASAPI__) + if ( api == WINDOWS_WASAPI ) { + static std::string name( "WASAPI" ); + return name; + } +#endif +#if defined(__WINDOWS_DS__) + if ( api == WINDOWS_DS ) { + static std::string name( "DirectSound" ); + return name; + } +#endif +#if defined(__MACOSX_CORE__) + if ( api == MACOSX_CORE ) { + static std::string name( "CoreAudio" ); + return name; + } +#endif +#if defined(__RTAUDIO_DUMMY__) + if ( api == RTAUDIO_DUMMY ) { + static std::string name( "Dummy" ); + return name; + } +#endif + static std::string name; + return name; +} + +RtAudio::Api RtAudio :: getCompiledApiByName( const std::string &name ) +{ + unsigned int api_number = RtAudio::UNSPECIFIED; + size_t nameLength = name.size(); + + if ( nameLength == 0 ) + return RtAudio::UNSPECIFIED; + + while ( api_number <= RtAudio::RTAUDIO_DUMMY ) { + const std::string &otherName = + getCompiledApiName((RtAudio::Api)api_number); + + bool equal = nameLength == otherName.size(); + for ( size_t i = 0; equal && i < nameLength; ++i ) + equal = tolower((unsigned char)name[i]) == + tolower((unsigned char)otherName[i]); + + if ( equal ) + return (RtAudio::Api)api_number; + + ++api_number; + } + + return RtAudio::UNSPECIFIED; +} + void RtAudio :: openRtApi( RtAudio::Api api ) { if ( rtapi_ ) |
