mirror of
https://github.com/clangen/musikcube.git
synced 2024-12-30 12:16:00 +00:00
Added the ability to configure the selected device id for SndioOut via preferences.
This commit is contained in:
parent
69ff6058c5
commit
0cade3f4cb
@ -35,6 +35,7 @@
|
||||
#include "SndioOut.h"
|
||||
|
||||
#include <core/sdk/constants.h>
|
||||
#include <core/sdk/IPreferences.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#include <iostream>
|
||||
@ -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<std::recursive_mutex> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user