Skip to content

Commit

Permalink
[Ref] openmpt123: Return device lists as vector instead of plain text.
Browse files Browse the repository at this point in the history
[Ref] openmpt123: Move version information into audio backends.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21746 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Sep 25, 2024
1 parent 4e419d5 commit 473e52b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 61 deletions.
59 changes: 38 additions & 21 deletions openmpt123/openmpt123.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,26 +223,13 @@ class realtime_audio_stream : public write_buffers_interface {
public:
static void show_versions( [[maybe_unused]] concat_stream<mpt::ustring> & log ) {
#ifdef MPT_WITH_SDL2
log << MPT_USTRING(" libSDL2 ");
SDL_version sdlver;
std::memset( &sdlver, 0, sizeof( SDL_version ) );
SDL_GetVersion( &sdlver );
log << static_cast<int>( sdlver.major ) << MPT_USTRING(".") << static_cast<int>( sdlver.minor ) << MPT_USTRING(".") << static_cast<int>( sdlver.patch );
const char * revision = SDL_GetRevision();
if ( revision ) {
log << MPT_USTRING(" (") << mpt::transcode<mpt::ustring>( sdl2_encoding, revision ) << MPT_USTRING(")");
}
log << MPT_USTRING(", ");
std::memset( &sdlver, 0, sizeof( SDL_version ) );
SDL_VERSION( &sdlver );
log << MPT_USTRING("API: ") << static_cast<int>( sdlver.major ) << MPT_USTRING(".") << static_cast<int>( sdlver.minor ) << MPT_USTRING(".") << static_cast<int>( sdlver.patch );
log << MPT_USTRING(" <https://libsdl.org/>") << lf;
log << MPT_USTRING(" ") << show_sdl2_version() << lf;
#endif
#ifdef MPT_WITH_PULSEAUDIO
log << MPT_USTRING(" ") << MPT_USTRING("libpulse, libpulse-simple") << MPT_USTRING(" (headers ") << mpt::transcode<mpt::ustring>( pulseaudio_encoding, pa_get_headers_version() ) << MPT_USTRING(", API ") << PA_API_VERSION << MPT_USTRING(", PROTOCOL ") << PA_PROTOCOL_VERSION << MPT_USTRING(", library ") << mpt::transcode<mpt::ustring>( pulseaudio_encoding, ( pa_get_library_version() ? pa_get_library_version() : "unknown" ) ) << MPT_USTRING(") <https://www.freedesktop.org/wiki/Software/PulseAudio/>") << lf;
log << MPT_USTRING(" ") << show_pulseaudio_version() << lf;
#endif
#ifdef MPT_WITH_PORTAUDIO
log << MPT_USTRING(" ") << mpt::transcode<mpt::ustring>( portaudio_encoding, Pa_GetVersionText() ) << MPT_USTRING(" (") << Pa_GetVersion() << MPT_USTRING(") <http://portaudio.com/>") << lf;
log << MPT_USTRING(" ") << show_portaudio_version() << lf;
#endif
}
static void show_drivers( concat_stream<mpt::ustring> & drivers ) {
Expand All @@ -268,19 +255,49 @@ class realtime_audio_stream : public write_buffers_interface {
devices << MPT_USTRING(" Available devices:") << lf;
devices << MPT_USTRING(" default: default") << lf;
#if defined( MPT_WITH_PULSEAUDIO )
devices << show_pulseaudio_devices( log );
devices << MPT_USTRING(" pulseaudio:") << lf;
{
auto devs = show_pulseaudio_devices( log );
for ( const auto & dev : devs ) {
devices << MPT_USTRING(" ") << dev << lf;
}
}
#endif
#if defined( MPT_WITH_SDL2 )
devices << show_sdl2_devices( log );
devices << MPT_USTRING(" SDL2:") << lf;
{
auto devs = show_sdl2_devices( log );
for ( const auto & dev : devs ) {
devices << MPT_USTRING(" ") << dev << lf;
}
}
#endif
#if defined( MPT_WITH_PORTAUDIO )
devices << show_portaudio_devices( log );
devices << MPT_USTRING(" portaudio:") << lf;
{
auto devs = show_portaudio_devices( log );
for ( const auto & dev : devs ) {
devices << MPT_USTRING(" ") << dev << lf;
}
}
#endif
#if MPT_OS_WINDOWS && !MPT_OS_WINDOWS_WINRT
devices << show_waveout_devices( log );
devices << MPT_USTRING(" waveout:") << lf;
{
auto devs = show_waveout_devices( log );
for ( const auto & dev : devs ) {
devices << MPT_USTRING(" ") << dev << lf;
}
}
#endif
#if defined( MPT_WITH_ALLEGRO42 )
devices << show_allegro42_devices( log );
devices << MPT_USTRING(" allegro42:") << lf;
{
auto devs = show_allegro42_devices( log );
for ( const auto & dev : devs ) {
devices << MPT_USTRING(" ") << dev << lf;
}
}
#endif
}
public:
Expand Down
9 changes: 4 additions & 5 deletions openmpt123/openmpt123_allegro42.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@ class allegro42_stream_raii : public write_buffers_polling_wrapper_int {
}
};

static mpt::ustring show_allegro42_devices( concat_stream<mpt::ustring> & /* log */ ) {
string_concat_stream<mpt::ustring> devices;
devices << MPT_USTRING(" allegro42:") << lf;
devices << MPT_USTRING(" ") << MPT_USTRING("0") << MPT_USTRING(": Default Device") << lf;
return devices.str();
inline std::vector<mpt::ustring> show_allegro42_devices( concat_stream<mpt::ustring> & /* log */ ) {
string_concat_stream<mpt::ustring> device;
device << MPT_USTRING("0") << MPT_USTRING(": Default Device");
return { device.str() };
}

} // namespace openmpt123
Expand Down
40 changes: 23 additions & 17 deletions openmpt123/openmpt123_portaudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,38 +258,44 @@ class portaudio_stream_blocking_raii : public portaudio_raii, public write_buffe

#define portaudio_stream_raii portaudio_stream_blocking_raii

static mpt::ustring show_portaudio_devices( concat_stream<mpt::ustring> & log ) {
string_concat_stream<mpt::ustring> devices;
devices << MPT_USTRING(" portaudio:") << lf;
inline std::vector<mpt::ustring> show_portaudio_devices( concat_stream<mpt::ustring> & log ) {
std::vector<mpt::ustring> devices;
portaudio_raii portaudio( false, log );
for ( PaDeviceIndex i = 0; i < Pa_GetDeviceCount(); ++i ) {
if ( Pa_GetDeviceInfo( i ) && Pa_GetDeviceInfo( i )->maxOutputChannels > 0 ) {
devices << MPT_USTRING(" ") << i << MPT_USTRING(": ");
string_concat_stream<mpt::ustring> device;
device << i << MPT_USTRING(": ");
if ( Pa_GetHostApiInfo( Pa_GetDeviceInfo( i )->hostApi ) && Pa_GetHostApiInfo( Pa_GetDeviceInfo( i )->hostApi )->name ) {
devices << mpt::transcode<mpt::ustring>( portaudio_encoding, Pa_GetHostApiInfo( Pa_GetDeviceInfo( i )->hostApi )->name );
device << mpt::transcode<mpt::ustring>( portaudio_encoding, Pa_GetHostApiInfo( Pa_GetDeviceInfo( i )->hostApi )->name );
} else {
devices << MPT_USTRING("Host API ") << Pa_GetDeviceInfo( i )->hostApi;
device << MPT_USTRING("Host API ") << Pa_GetDeviceInfo( i )->hostApi;
}
if ( Pa_GetHostApiInfo( Pa_GetDeviceInfo( i )->hostApi ) ) {
if ( i == Pa_GetHostApiInfo( Pa_GetDeviceInfo( i )->hostApi )->defaultOutputDevice ) {
devices << MPT_USTRING(" (default)");
device << MPT_USTRING(" (default)");
}
}
devices << MPT_USTRING(" - ");
device << MPT_USTRING(" - ");
if ( Pa_GetDeviceInfo( i )->name ) {
devices << mpt::transcode<mpt::ustring>( portaudio_encoding, Pa_GetDeviceInfo( i )->name );
device << mpt::transcode<mpt::ustring>( portaudio_encoding, Pa_GetDeviceInfo( i )->name );
} else {
devices << MPT_USTRING("Device ") << i;
device << MPT_USTRING("Device ") << i;
}
devices << MPT_USTRING(" (");
devices << MPT_USTRING("high latency: ") << Pa_GetDeviceInfo( i )->defaultHighOutputLatency;
devices << MPT_USTRING(", ");
devices << MPT_USTRING("low latency: ") << Pa_GetDeviceInfo( i )->defaultLowOutputLatency;
devices << MPT_USTRING(")");
devices << lf;
device << MPT_USTRING(" (");
device << MPT_USTRING("high latency: ") << Pa_GetDeviceInfo( i )->defaultHighOutputLatency;
device << MPT_USTRING(", ");
device << MPT_USTRING("low latency: ") << Pa_GetDeviceInfo( i )->defaultLowOutputLatency;
device << MPT_USTRING(")");
devices.push_back( device.str() );
}
}
return devices.str();
return devices;
}

inline mpt::ustring show_portaudio_version() {
string_concat_stream<mpt::ustring> log;
log << mpt::transcode<mpt::ustring>( portaudio_encoding, Pa_GetVersionText() ) << MPT_USTRING(" (") << Pa_GetVersion() << MPT_USTRING(") <http://portaudio.com/>");
return log.str();
}

} // namespace openmpt123
Expand Down
15 changes: 10 additions & 5 deletions openmpt123/openmpt123_pulseaudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,16 @@ class pulseaudio_stream_raii : public write_buffers_interface {
}
};

static mpt::ustring show_pulseaudio_devices( concat_stream<mpt::ustring> & /* log */ ) {
string_concat_stream<mpt::ustring> devices;
devices << MPT_USTRING(" pulseaudio:") << lf;
devices << MPT_USTRING(" ") << MPT_USTRING("0") << MPT_USTRING(": Default Device") << lf;
return devices.str();
inline std::vector<mpt::ustring> show_pulseaudio_devices( concat_stream<mpt::ustring> & /* log */ ) {
string_concat_stream<mpt::ustring> device;
device << MPT_USTRING("0") << MPT_USTRING(": Default Device");
return { device.str() };
}

inline mpt::ustring show_pulseaudio_version() {
string_concat_stream<mpt::ustring> log;
log << MPT_USTRING("libpulse, libpulse-simple") << MPT_USTRING(" (headers ") << mpt::transcode<mpt::ustring>( pulseaudio_encoding, pa_get_headers_version() ) << MPT_USTRING(", API ") << PA_API_VERSION << MPT_USTRING(", PROTOCOL ") << PA_PROTOCOL_VERSION << MPT_USTRING(", library ") << mpt::transcode<mpt::ustring>( pulseaudio_encoding, ( pa_get_library_version() ? pa_get_library_version() : "unknown" ) ) << MPT_USTRING(") <https://www.freedesktop.org/wiki/Software/PulseAudio/>");
return log.str();
}

} // namespace openmpt123
Expand Down
30 changes: 25 additions & 5 deletions openmpt123/openmpt123_sdl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ class sdl2_stream_raii : public write_buffers_interface {
}
};

static mpt::ustring show_sdl2_devices( concat_stream<mpt::ustring> & /* log */ ) {
string_concat_stream<mpt::ustring> devices;
inline std::vector<mpt::ustring> show_sdl2_devices( concat_stream<mpt::ustring> & /* log */ ) {
std::vector<mpt::ustring> devices;
std::size_t device_index = 0;
devices << MPT_USTRING(" SDL2:") << lf;
sdl2_raii sdl2( SDL_INIT_NOPARACHUTE | SDL_INIT_AUDIO );
for ( int driver = 0; driver < SDL_GetNumAudioDrivers(); ++driver ) {
const char * driver_name = SDL_GetAudioDriver( driver );
Expand All @@ -206,19 +205,40 @@ static mpt::ustring show_sdl2_devices( concat_stream<mpt::ustring> & /* log */ )
continue;
}
for ( int device = 0; device < SDL_GetNumAudioDevices( 0 ); ++device ) {
string_concat_stream<mpt::ustring> dev;
const char * device_name = SDL_GetAudioDeviceName( device, 0 );
if ( !device_name ) {
continue;
}
if ( std::string( device_name ).empty() ) {
continue;
}
devices << MPT_USTRING(" ") << device_index << MPT_USTRING(": ") << mpt::transcode<mpt::ustring>( sdl2_encoding, driver_name ) << MPT_USTRING(" - ") << mpt::transcode<mpt::ustring>( sdl2_encoding, device_name ) << lf;
dev << device_index << MPT_USTRING(": ") << mpt::transcode<mpt::ustring>( sdl2_encoding, driver_name ) << MPT_USTRING(" - ") << mpt::transcode<mpt::ustring>( sdl2_encoding, device_name );
device_index++;
devices.push_back( dev.str() );
}
SDL_AudioQuit();
}
return devices.str();
return devices;
}

inline mpt::ustring show_sdl2_version() {
string_concat_stream<mpt::ustring> log;
log << MPT_USTRING("libSDL2 ");
SDL_version sdlver;
std::memset(&sdlver, 0, sizeof(SDL_version));
SDL_GetVersion(&sdlver);
log << static_cast<int>(sdlver.major) << MPT_USTRING(".") << static_cast<int>(sdlver.minor) << MPT_USTRING(".") << static_cast<int>(sdlver.patch);
const char* revision = SDL_GetRevision();
if (revision) {
log << MPT_USTRING(" (") << mpt::transcode<mpt::ustring>(sdl2_encoding, revision) << MPT_USTRING(")");
}
log << MPT_USTRING(", ");
std::memset(&sdlver, 0, sizeof(SDL_version));
SDL_VERSION(&sdlver);
log << MPT_USTRING("API: ") << static_cast<int>(sdlver.major) << MPT_USTRING(".") << static_cast<int>(sdlver.minor) << MPT_USTRING(".") << static_cast<int>(sdlver.patch);
log << MPT_USTRING(" <https://libsdl.org/>");
return log.str();
}

} // namespace openmpt123
Expand Down
16 changes: 8 additions & 8 deletions openmpt123/openmpt123_waveout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,22 @@ class waveout_stream_raii : public write_buffers_interface {
}
};

static mpt::ustring show_waveout_devices( concat_stream<mpt::ustring> & /*log*/ ) {
string_concat_stream<mpt::ustring> devices;
devices << MPT_USTRING(" waveout:") << lf;
inline std::vector<mpt::ustring> show_waveout_devices( concat_stream<mpt::ustring> & /*log*/ ) {
std::vector<mpt::ustring> devices;
for ( UINT i = 0; i < waveOutGetNumDevs(); ++i ) {
devices << MPT_USTRING(" ") << i << MPT_USTRING(": ");
string_concat_stream<mpt::ustring> device;
device << i << MPT_USTRING(": ");
WAVEOUTCAPS caps;
ZeroMemory( &caps, sizeof( caps ) );
waveOutGetDevCaps( i, &caps, sizeof( caps ) );
#if defined(UNICODE)
devices << mpt::transcode<mpt::ustring>( caps.szPname );
device << mpt::transcode<mpt::ustring>( caps.szPname );
#else
devices << mpt::transcode<mpt::ustring>( mpt::logical_encoding::locale, caps.szPname );
device << mpt::transcode<mpt::ustring>( mpt::logical_encoding::locale, caps.szPname );
#endif
devices << lf;
devices.push_back( device.str() );
}
return devices.str();
return devices;
}

} // namespace openmpt123
Expand Down

0 comments on commit 473e52b

Please sign in to comment.