mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 06:32:36 +00:00
Fixed "list_outputs" message so it also returns the selected output.
This commit is contained in:
parent
628366a700
commit
f327b63dbc
@ -149,6 +149,36 @@ namespace musik {
|
||||
return output;
|
||||
}
|
||||
|
||||
musik::core::sdk::IOutput* GetUnmanagedSelectedOutput() {
|
||||
IOutput* output = nullptr;
|
||||
|
||||
OutputList plugins = queryOutputs<NullDeleter>();
|
||||
|
||||
if (plugins.size()) {
|
||||
std::shared_ptr<Preferences> prefs =
|
||||
Preferences::ForComponent(components::Playback);
|
||||
|
||||
const std::string name = prefs->GetString(keys::OutputPlugin);
|
||||
|
||||
for (size_t i = 0; i < plugins.size(); i++) {
|
||||
if (plugins[i]->Name() == name) {
|
||||
output = plugins[i].get();
|
||||
plugins.erase(plugins.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!output) {
|
||||
output = plugins[0].get();
|
||||
plugins.erase(plugins.begin());
|
||||
}
|
||||
}
|
||||
|
||||
release(plugins);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Output SelectedOutput() {
|
||||
std::shared_ptr<Preferences> prefs =
|
||||
Preferences::ForComponent(components::Playback);
|
||||
|
@ -46,5 +46,6 @@ namespace musik { namespace core { namespace audio { namespace outputs {
|
||||
size_t GetOutputCount();
|
||||
musik::core::sdk::IOutput* GetUnmanagedOutput(size_t index);
|
||||
musik::core::sdk::IOutput* GetUnmanagedOutput(const std::string& name);
|
||||
musik::core::sdk::IOutput* GetUnmanagedSelectedOutput();
|
||||
|
||||
} } } }
|
||||
|
@ -138,6 +138,10 @@ static class Environment : public IEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
virtual IOutput* GetDefaultOutput() override {
|
||||
return outputs::GetUnmanagedSelectedOutput();
|
||||
}
|
||||
|
||||
virtual void ReindexMetadata() override {
|
||||
if (::library) {
|
||||
::library->Indexer()->Schedule(IIndexer::SyncType::Local);
|
||||
|
@ -60,6 +60,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
virtual void SetPreampGain(float gain) = 0;
|
||||
virtual void ReloadPlaybackOutput() = 0;
|
||||
virtual void SetDefaultOutput(IOutput* output) = 0;
|
||||
virtual IOutput* GetDefaultOutput() = 0;
|
||||
virtual void ReindexMetadata() = 0;
|
||||
virtual void RebuildMetadata() = 0;
|
||||
};
|
||||
|
@ -128,6 +128,8 @@ namespace key {
|
||||
static const std::string sdk_version = "sdk_version";
|
||||
static const std::string api_version = "api_version";
|
||||
static const std::string driver_name = "driver_name";
|
||||
static const std::string all = "all";
|
||||
static const std::string selected = "selected";
|
||||
static const std::string devices = "devices";
|
||||
static const std::string device_name = "device_name";
|
||||
static const std::string device_id = "device_id";
|
||||
|
@ -1158,10 +1158,29 @@ void WebSocketServer::RespondWithRunIndexer(connection_hdl connection, json& req
|
||||
void WebSocketServer::RespondWithListOutputDrivers(connection_hdl connection, json& request) {
|
||||
json outputs = json::array();
|
||||
|
||||
std::string selectedDriverName, selectedDeviceId;
|
||||
|
||||
size_t count = context.environment->GetOutputCount();
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
auto output = context.environment->GetOutputAtIndex(i);
|
||||
auto output = context.environment->GetDefaultOutput();
|
||||
|
||||
if (output) {
|
||||
selectedDriverName = output->Name();
|
||||
auto device = output->GetDefaultDevice();
|
||||
if (device) {
|
||||
selectedDeviceId = device->Id();
|
||||
}
|
||||
output->Release();
|
||||
}
|
||||
|
||||
output = context.environment->GetOutputAtIndex(i);
|
||||
json devices = json::array();
|
||||
|
||||
devices.push_back({
|
||||
{ key::device_name, "default" },
|
||||
{ key::device_id, "" }
|
||||
});
|
||||
|
||||
auto deviceList = output->GetDeviceList();
|
||||
if (deviceList) {
|
||||
for (size_t j = 0; j < deviceList->Count(); j++) {
|
||||
@ -1182,7 +1201,13 @@ void WebSocketServer::RespondWithListOutputDrivers(connection_hdl connection, js
|
||||
output->Release();
|
||||
}
|
||||
|
||||
this->RespondWithOptions(connection, request, { { key::data, outputs } });
|
||||
this->RespondWithOptions(connection, request, {
|
||||
{ key::all, outputs },
|
||||
{ key::selected, {
|
||||
{ key::driver_name, selectedDriverName },
|
||||
{ key::device_id, selectedDeviceId }
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
void WebSocketServer::RespondWithSetDefaultOutputDriver(connection_hdl connection, json& request) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user