mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-02 11:58:27 +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 "SndioOut.h"
|
||||||
|
|
||||||
#include <core/sdk/constants.h>
|
#include <core/sdk/constants.h>
|
||||||
|
#include <core/sdk/IPreferences.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -43,10 +44,23 @@
|
|||||||
#define ERROR(str) std::cerr << "SndioOut Error: " << str << "\n";
|
#define ERROR(str) std::cerr << "SndioOut Error: " << str << "\n";
|
||||||
#define INFO(str) std::cerr << "SndioOut Info: " << str << "\n";
|
#define INFO(str) std::cerr << "SndioOut Info: " << str << "\n";
|
||||||
#define LOCK() std::unique_lock<std::recursive_mutex> lock(this->mutex);
|
#define LOCK() std::unique_lock<std::recursive_mutex> lock(this->mutex);
|
||||||
|
#define PREF_DEVICE_ID "device_id"
|
||||||
|
|
||||||
using namespace musik::core::sdk;
|
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() {
|
SndioOut::SndioOut() {
|
||||||
this->volume = 1.0f;
|
this->volume = 1.0f;
|
||||||
this->state = StateStopped;
|
this->state = StateStopped;
|
||||||
@ -144,7 +158,9 @@ IDevice* SndioOut::GetDefaultDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SndioOut::InitDevice(IBuffer *buffer) {
|
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) {
|
if (this->handle == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user