diff --git a/src/config/wireplumber.conf.d.examples/device.conf b/src/config/wireplumber.conf.d.examples/device.conf index 79599eb0..2059063b 100644 --- a/src/config/wireplumber.conf.d.examples/device.conf +++ b/src/config/wireplumber.conf.d.examples/device.conf @@ -4,17 +4,13 @@ wireplumber.settings = { ## Enables storing/restoring preferences to the file system at startup; ## when set to false, default nodes and routes are selected based on ## their priorities and any runtime changes do not persist after restart - # device.use-persistent-storage = true + # device.restore-profile = true + + # device.restore-routes = true ## device default volume level - # device.default-volume = 0.064 + # device.routes.default-sink-volume = 0.064 ## device default input volume - # device.default-input-volume = 1.0 - - ## The persistent save interval in milliseconds when a change happens - # device.save-interval-ms = 1000 - - ## The device discovery time out(in milli sec) between V4L2 and libcamera. - # device.camera-discovery-timeout = 100 + # device.routes.default-source-volume = 1.0 } diff --git a/src/scripts/default-nodes/state-default-nodes.lua b/src/scripts/default-nodes/state-default-nodes.lua index 92f777bc..5a45156f 100644 --- a/src/scripts/default-nodes/state-default-nodes.lua +++ b/src/scripts/default-nodes/state-default-nodes.lua @@ -11,7 +11,7 @@ -- node out of the user preferences cutils = require ("common-utils") -settings = require ("settings-device") +settings = require ("settings-node") log = Log.open_topic ("s-default-nodes") -- the state storage @@ -178,7 +178,7 @@ function updateStored (def_node_type, stored) cutils.storeAfterTimeout (state, state_table) end -function handlePersistentSetting (enable) +function toggleState (enable) if enable and not state then state = State ("default-nodes") state_table = state:load () @@ -194,5 +194,5 @@ function handlePersistentSetting (enable) end end -settings:subscribe ("use-persistent-storage", handlePersistentSetting) -handlePersistentSetting (settings.use_persistent_storage) +settings:subscribe ("restore-default-targets", toggleState) +toggleState (settings ["restore-default-targets"]) diff --git a/src/scripts/device/apply-routes.lua b/src/scripts/device/apply-routes.lua index 460f8666..13f6fbed 100644 --- a/src/scripts/device/apply-routes.lua +++ b/src/scripts/device/apply-routes.lua @@ -57,7 +57,8 @@ AsyncEventHook { local is_input = (route.direction == "Input") props.mute = props.mute or false props.channelVolumes = props.channelVolumes or - { is_input and settings.default_input_volume or settings.default_volume } + { is_input and settings ["routes.default-source-volume"] + or settings ["routes.default-sink-volume"] } -- prefix the props with correct IDs to create a Pod.Object table.insert (props, 1, "Spa:Pod:Object:Param:Props") diff --git a/src/scripts/device/state-profile.lua b/src/scripts/device/state-profile.lua index a32613a0..b85a05b4 100644 --- a/src/scripts/device/state-profile.lua +++ b/src/scripts/device/state-profile.lua @@ -126,7 +126,7 @@ function updateStoredProfile (device, profile) profile.name, index, dev_name)) end -function handlePersistentSetting (enable) +function toggleState (enable) if enable and not state then state = State ("default-profile") state_table = state:load () @@ -140,5 +140,5 @@ function handlePersistentSetting (enable) end end -settings:subscribe ("use-persistent-storage", handlePersistentSetting) -handlePersistentSetting (settings.use_persistent_storage) +settings:subscribe ("restore-profile", toggleState) +toggleState (settings.restore_profile) diff --git a/src/scripts/device/state-routes.lua b/src/scripts/device/state-routes.lua index f19821b4..0ea6e3bc 100644 --- a/src/scripts/device/state-routes.lua +++ b/src/scripts/device/state-routes.lua @@ -303,7 +303,7 @@ function getStoredProfileRoutes (dev_info, profile_name) return str and cutils.parseArray (str) or {} end -function handlePersistentSetting (enable) +function toggleState (enable) if enable and not state then state = State ("default-routes") state_table = state:load () @@ -319,5 +319,5 @@ function handlePersistentSetting (enable) end end -settings:subscribe ("use-persistent-storage", handlePersistentSetting) -handlePersistentSetting (settings.use_persistent_storage) +settings:subscribe ("restore-routes", toggleState) +toggleState (settings.restore_routes) diff --git a/src/scripts/lib/monitor-utils.lua b/src/scripts/lib/monitor-utils.lua index 1065ef61..65c2f037 100644 --- a/src/scripts/lib/monitor-utils.lua +++ b/src/scripts/lib/monitor-utils.lua @@ -7,9 +7,8 @@ -- Script is a Lua Module of monitor Lua utility functions -settings = require ("settings-device") +settings = require ("settings-monitor") log = Log.open_topic ("s-monitors-utils") -d_timeout = settings["camera-discovery-timeout"] local mutils = { cam_data = {} @@ -104,7 +103,7 @@ function mutils.register_cam_node (self, parent, id, factory, properties) local other_api = api == "v4l2" and "libcamera" or "v4l2" if cam_api_data.enum_status and not cam_data[other_api].enum_status then log:trace (string.format ("\"%s\" armed a timer for %d", api, dev_num)) - cam_data.source = Core.timeout_add (d_timeout, function() + cam_data.source = Core.timeout_add (settings["camera-discovery-timeout"], function() log:trace (string.format ("\"%s\" armed timer expired for %d", api, dev_num)) self:create_cam_node (dev_num) cam_data.source = nil diff --git a/src/scripts/lib/settings-device.lua b/src/scripts/lib/settings-device.lua index f8dfa092..1bc0efb5 100644 --- a/src/scripts/lib/settings-device.lua +++ b/src/scripts/lib/settings-device.lua @@ -9,10 +9,10 @@ local settings_manager = require ("settings-manager") local defaults = { - ["use-persistent-storage"] = true, - ["default-volume"] = 0.4 ^ 3, - ["default-input-volume"] = 1.0, - ["camera-discovery-timeout"] = 100, + ["restore-profile"] = true, + ["restore-routes"] = true, + ["routes.default-sink-volume"] = 0.4 ^ 3, + ["routes.default-source-volume"] = 1.0, } return settings_manager.new ("device.", defaults) diff --git a/src/scripts/lib/settings-monitor.lua b/src/scripts/lib/settings-monitor.lua new file mode 100644 index 00000000..a1b5f703 --- /dev/null +++ b/src/scripts/lib/settings-monitor.lua @@ -0,0 +1,15 @@ +-- WirePlumber +-- +-- Copyright © 2023 Collabora Ltd. +-- +-- SPDX-License-Identifier: MIT + +-- Monitors settings manager + +local settings_manager = require ("settings-manager") + +local defaults = { + ["camera-discovery-timeout"] = 100, +} + +return settings_manager.new ("monitor.", defaults) diff --git a/src/scripts/lib/settings-node.lua b/src/scripts/lib/settings-node.lua index 71b6d84b..481c841c 100644 --- a/src/scripts/lib/settings-node.lua +++ b/src/scripts/lib/settings-node.lua @@ -17,6 +17,8 @@ local defaults = { ["stream.restore-target"] = true, ["stream.default-playback-volume"] = 1.0, ["stream.default-capture-volume"] = 1.0, + + ["restore-default-targets"] = true, } return settings_manager.new ("node.", defaults)