X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=RtAudio.cpp;h=7b7c8efd3701a76aece071013885a43d96cb5dc6;hb=3d054aec68641b049c102d20632a1eb618355a6f;hp=a51608da9e3719ccd2205aa00b6f4d2ea3c3afda;hpb=1de9bea0c135090aca4c41f7752eda47c9e2959d;p=rtaudio-cdist.git diff --git a/RtAudio.cpp b/RtAudio.cpp index a51608d..7b7c8ef 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -98,39 +98,91 @@ std::string RtAudio :: getVersion( void ) return RTAUDIO_VERSION; } -void RtAudio :: getCompiledApi( std::vector &apis ) -{ - apis.clear(); - - // The order here will control the order of RtAudio's API search in - // the constructor. +// Define API names. +// TODO: replace with initializer list in C++11. +// The order here will control the order of RtAudio's API search in +// the constructor. +// Have to maintain a separate list of API enum identifiers since map +// doesn't preserve insertion order. +static std::pair< RtAudio::ApiNameMap, std::vector > init_ApiNames() +{ + RtAudio::ApiNameMap names; + std::vector apis; #if defined(__UNIX_JACK__) - apis.push_back( UNIX_JACK ); + names["jack"] = std::pair(RtAudio::UNIX_JACK, "Jack"); + apis.push_back(RtAudio::UNIX_JACK); #endif #if defined(__LINUX_PULSE__) - apis.push_back( LINUX_PULSE ); + names["pulse"] = std::pair(RtAudio::LINUX_PULSE, "Pulse"); + apis.push_back(RtAudio::LINUX_PULSE); #endif #if defined(__LINUX_ALSA__) - apis.push_back( LINUX_ALSA ); + names["alsa"] = std::pair(RtAudio::LINUX_ALSA, "ALSA"); + apis.push_back(RtAudio::LINUX_ALSA); #endif #if defined(__LINUX_OSS__) - apis.push_back( LINUX_OSS ); + names["oss"] = std::pair(RtAudio::LINUX_OSS, "OSS"); + apis.push_back(RtAudio::LINUX_OSS); #endif #if defined(__WINDOWS_ASIO__) - apis.push_back( WINDOWS_ASIO ); + names["asio"] = std::pair(RtAudio::WINDOWS_ASIO, "ASIO"); + apis.push_back(RtAudio::WINDOWS_ASIO); #endif #if defined(__WINDOWS_WASAPI__) - apis.push_back( WINDOWS_WASAPI ); + names["wasapi"] = std::pair(RtAudio::WINDOWS_WASAPI, "WASAPI"); + apis.push_back(RtAudio::WINDOWS_WASAPI); #endif #if defined(__WINDOWS_DS__) - apis.push_back( WINDOWS_DS ); + names["ds"] = std::pair(RtAudio::WINDOWS_DS, "DirectSound"); + apis.push_back(RtAudio::WINDOWS_DS); #endif #if defined(__MACOSX_CORE__) - apis.push_back( MACOSX_CORE ); + names["core"] = std::pair(RtAudio::MACOSX_CORE, "CoreAudio"); + apis.push_back(RtAudio::MACOSX_CORE); #endif #if defined(__RTAUDIO_DUMMY__) - apis.push_back( RTAUDIO_DUMMY ); + names["dummy"] = std::pair(RtAudio::RTAUDIO_DUMMY, "Dummy"); + apis.push_back(RtAudio::RTAUDIO_DUMMY); #endif + return std::make_pair(names, apis); +} + +const RtAudio::ApiNameMap RtAudio::apiNames(init_ApiNames().first); +const std::vector RtAudio::compiledApis(init_ApiNames().second); + +void RtAudio :: getCompiledApi( std::vector &apis ) +{ + apis = compiledApis; +} + +const std::vector& RtAudio :: getCompiledApi() +{ + return compiledApis; +} + +const std::string RtAudio :: getCompiledApiName( RtAudio::Api api ) +{ + ApiNameMap::const_iterator it; + for (it = apiNames.begin(); it != apiNames.end(); it++) + if (it->second.first == api) + return it->first; + return ""; +} + +const std::string RtAudio :: getCompiledApiDisplayName( RtAudio::Api api ) +{ + ApiNameMap::const_iterator it; + for (it = apiNames.begin(); it != apiNames.end(); it++) + if (it->second.first == api) + return it->second.second; + return "Unknown"; +} + +RtAudio::Api RtAudio :: getCompiledApiByName( const std::string &name ) +{ + if (apiNames.find(name) == apiNames.end()) + return RtAudio::UNSPECIFIED; + return apiNames.at(name).first; } void RtAudio :: openRtApi( RtAudio::Api api )