Persist volume
This commit is contained in:
parent
609a195452
commit
d314ad7dd9
1 changed files with 23 additions and 2 deletions
|
|
@ -1517,6 +1517,11 @@ void Client::Impl::AutoSave() {
|
|||
node_obj["channels"] = sd.channels;
|
||||
node_obj["loopback"] = sd.loopback;
|
||||
node_obj["target_node"] = sd.target_node;
|
||||
auto volIt = volume_states.find(entry.first);
|
||||
if (volIt != volume_states.end()) {
|
||||
node_obj["volume"] = volIt->second.volume;
|
||||
node_obj["mute"] = volIt->second.mute;
|
||||
}
|
||||
nodes_array.push_back(std::move(node_obj));
|
||||
}
|
||||
}
|
||||
|
|
@ -2012,6 +2017,7 @@ Status Client::SetNodeVolume(NodeId node, float volume, bool mute) {
|
|||
}
|
||||
|
||||
pw_thread_loop_unlock(impl_->thread_loop);
|
||||
impl_->AutoSave();
|
||||
return Status::Ok();
|
||||
}
|
||||
|
||||
|
|
@ -2628,6 +2634,11 @@ Status Client::SaveConfig(std::string_view path) {
|
|||
node_obj["channels"] = sd.channels;
|
||||
node_obj["loopback"] = sd.loopback;
|
||||
node_obj["target_node"] = sd.target_node;
|
||||
auto volIt = impl_->volume_states.find(entry.first);
|
||||
if (volIt != impl_->volume_states.end()) {
|
||||
node_obj["volume"] = volIt->second.volume;
|
||||
node_obj["mute"] = volIt->second.mute;
|
||||
}
|
||||
nodes_array.push_back(std::move(node_obj));
|
||||
}
|
||||
|
||||
|
|
@ -2809,10 +2820,20 @@ Status Client::LoadConfig(std::string_view path) {
|
|||
opts.behavior = VirtualBehavior::kLoopback;
|
||||
opts.target_node = target;
|
||||
}
|
||||
Result<uint32_t> result;
|
||||
if (is_source) {
|
||||
CreateVirtualSource(name, opts);
|
||||
auto r = CreateVirtualSource(name, opts);
|
||||
result = {r.status, r.ok() ? r.value.node.value : 0};
|
||||
} else {
|
||||
CreateVirtualSink(name, opts);
|
||||
auto r = CreateVirtualSink(name, opts);
|
||||
result = {r.status, r.ok() ? r.value.node.value : 0};
|
||||
}
|
||||
if (result.ok() && result.value != 0) {
|
||||
float vol = node_obj.value("volume", 1.0f);
|
||||
bool muted = node_obj.value("mute", false);
|
||||
if (vol != 1.0f || muted) {
|
||||
SetNodeVolume(NodeId{result.value}, vol, muted);
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue