From 0cade3f4cb11cb8d4d7f41f43bfd0b0be9ed3083 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 23 Dec 2017 23:48:45 +0000 Subject: [PATCH] Added the ability to configure the selected device id for SndioOut via preferences. --- src/plugins/sndioout/SndioOut.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/sndioout/SndioOut.cpp b/src/plugins/sndioout/SndioOut.cpp index eb8bcc25c..3a3b2228d 100644 --- a/src/plugins/sndioout/SndioOut.cpp +++ b/src/plugins/sndioout/SndioOut.cpp @@ -35,6 +35,7 @@ #include "SndioOut.h" #include +#include #include #include #include @@ -43,10 +44,23 @@ #define ERROR(str) std::cerr << "SndioOut Error: " << str << "\n"; #define INFO(str) std::cerr << "SndioOut Info: " << str << "\n"; #define LOCK() std::unique_lock lock(this->mutex); - +#define PREF_DEVICE_ID "device_id" using namespace musik::core::sdk; +static char* deviceId = nullptr; + +extern "C" void SetPreferences(musik::core::sdk::IPreferences* prefs) { + size_t len = prefs->GetString(PREF_DEVICE_ID, nullptr, 0, ""); + if (len > 1) { + delete[] deviceId; + deviceId = new char[len]; + prefs->GetString(PREF_DEVICE_ID, deviceId, len, ""); + prefs->Save(); + INFO("setting deviceId to " + std::string(deviceId)); + } +} + SndioOut::SndioOut() { this->volume = 1.0f; this->state = StateStopped; @@ -144,7 +158,9 @@ IDevice* SndioOut::GetDefaultDevice() { } bool SndioOut::InitDevice(IBuffer *buffer) { - this->handle = sio_open(nullptr, SIO_PLAY, 0); + const char* device = (::deviceId && strlen(::deviceId)) ? deviceId : nullptr; + + this->handle = sio_open(device, SIO_PLAY, 0); if (this->handle == nullptr) { return false;