diff --git a/src/config/main.lua.d/00-functions.lua b/src/config/main.lua.d/00-functions.lua deleted file mode 120000 index 8334af3b..00000000 --- a/src/config/main.lua.d/00-functions.lua +++ /dev/null @@ -1 +0,0 @@ -../common/00-functions.lua \ No newline at end of file diff --git a/src/config/main.lua.d/40-stream-defaults.lua b/src/config/main.lua.d/40-stream-defaults.lua deleted file mode 100644 index b869099b..00000000 --- a/src/config/main.lua.d/40-stream-defaults.lua +++ /dev/null @@ -1,42 +0,0 @@ -stream_defaults = {} -stream_defaults.enabled = true - -stream_defaults.properties = { - -- whether to restore the last stream properties or not - ["restore-props"] = true, - - -- whether to restore the last stream target or not - ["restore-target"] = true, - - -- the default channel volume for new streams whose props were never saved - -- previously. This is only used if "restore-props" is set to true. - ["default-channel-volume"] = 1.0, -} - -stream_defaults.rules = { - -- Rules to override settings per node - -- { - -- matches = { - -- { - -- { "application.name", "matches", "pw-play" }, - -- }, - -- }, - -- apply_properties = { - -- ["state.restore-props"] = false, - -- ["state.restore-target"] = false, - -- ["state.default-channel-volume"] = 0.5, - -- }, - -- }, -} - -function stream_defaults.enable() - if stream_defaults.enabled == false then - return - end - - -- Save and restore stream-specific properties - load_script("restore-stream.lua", { - properties = stream_defaults.properties, - rules = stream_defaults.rules, - }) -end diff --git a/src/config/main.lua.d/90-enable-all.lua b/src/config/main.lua.d/90-enable-all.lua deleted file mode 100644 index a42c5a37..00000000 --- a/src/config/main.lua.d/90-enable-all.lua +++ /dev/null @@ -1,12 +0,0 @@ --- Provide the "default" pw_metadata, which stores --- dynamic properties of pipewire objects in RAM -load_module("metadata") - --- Track/store/restore user choices about streams -stream_defaults.enable() - --- Link nodes by stream role and device intended role -load_script("intended-roles.lua") - --- Automatically suspends idle nodes after 3 seconds -load_script("suspend-node.lua") diff --git a/src/config/wireplumber.conf b/src/config/wireplumber.conf index 15a9885a..a3c862b7 100644 --- a/src/config/wireplumber.conf +++ b/src/config/wireplumber.conf @@ -85,9 +85,18 @@ wireplumber.components = [ # The lua scripting engine { name = libwireplumber-module-lua-scripting, type = module } + # Provide the "default" pw_metadata, which stores + # dynamic properties of pipewire objects in RAM + { name = libwireplumber-module-metadata, type = module } + + # Link nodes by stream role and device intended role + { name = intended-roles.lua, type = script/lua } + + # Automatically suspends idle nodes after 3 seconds + { name = suspend-node.lua, type = script/lua } + # The lua configuration file(s) # Other components are loaded from there - { name = main.lua, type = config/lua } { name = policy.lua, type = config/lua } { name = bluetooth.lua, type = config/lua } ] diff --git a/src/config/wireplumber.conf.d/stream-settings.conf b/src/config/wireplumber.conf.d/stream-settings.conf index c449162f..46faaae1 100644 --- a/src/config/wireplumber.conf.d/stream-settings.conf +++ b/src/config/wireplumber.conf.d/stream-settings.conf @@ -1,20 +1,31 @@ # Settings to Track/store/restore user choices about streams +wireplumber.components = [ + # Save and restore stream-specific properties + { name = restore-stream.lua, type = script/lua } +] wireplumber.settings = { stream_default.restore-props = true stream_default.restore-target = true + + ## The default channel volume for new streams whose props were never saved + ## previously. This is only used if "restore-props" is set to true. + # stream.default-channel-volume = 1.0, + stream_default = [ + # Rules to override settings per application/node { - matches = [ - # Matches all devices - { application.name = "pw-play" } - ] - actions = { - update-props = { - state.restore-props = false - state.restore-target = false - } - } + # matches = [ + # # Matches all devices + # { application.name = "pw-play" } + # ] + # actions = { + # update-props = { + # state.restore-props = false + # state.restore-target = false + # state.default-channel-volume = 1.0 + # } + # } } ] } diff --git a/src/scripts/monitors/alsa.lua b/src/scripts/monitors/alsa.lua index 76d288d3..8450bc2b 100644 --- a/src/scripts/monitors/alsa.lua +++ b/src/scripts/monitors/alsa.lua @@ -26,6 +26,7 @@ local config_settings = { device_names_table = nil node_names_table = nil +-- applies rules from alsa-settings.conf when asked to function rulesApplyProperties(properties) local matched, mprops = Settings.apply_rule ("alsa_monitor", properties) diff --git a/src/scripts/monitors/bluez.lua b/src/scripts/monitors/bluez.lua index 4924ae00..357c1a08 100644 --- a/src/scripts/monitors/bluez.lua +++ b/src/scripts/monitors/bluez.lua @@ -37,7 +37,7 @@ for _, r in ipairs(config.rules or {}) do r.matches = nil end --- applies properties from config.rules when asked to +-- applies rules from bluez-settings.conf when asked to function rulesApplyProperties(properties) for _, r in ipairs(config.rules or {}) do if r.apply_properties then diff --git a/src/scripts/restore-stream.lua b/src/scripts/restore-stream.lua index 06867d42..ff1d2bf6 100644 --- a/src/scripts/restore-stream.lua +++ b/src/scripts/restore-stream.lua @@ -9,40 +9,23 @@ -- SPDX-License-Identifier: MIT -- Receive script arguments from config.lua -local config = ... or {} -config.properties = config.properties or {} -config_restore_props = config.properties["restore-props"] or false -config_restore_target = config.properties["restore-target"] or false -config_default_channel_volume = config.properties["default-channel-volume"] or 1.0 +config_restore_props = Settings.get_boolean ("stream_default.restore-props") + or false +config_restore_target = Settings.get_boolean ("stream_default.restore-target") + or false +config_default_channel_volume = Settings.get_float ("stream.default-channel-volume") + or 1.0 --- preprocess rules and create Interest objects -for _, r in ipairs(config.rules or {}) do - r.interests = {} - for _, i in ipairs(r.matches) do - local interest_desc = { type = "properties" } - for _, c in ipairs(i) do - c.type = "pw" - table.insert(interest_desc, Constraint(c)) - end - local interest = Interest(interest_desc) - table.insert(r.interests, interest) - end - r.matches = nil -end - --- applies properties from config.rules when asked to +-- applies rules from stream-settings.conf when asked to function rulesApplyProperties(properties) - for _, r in ipairs(config.rules or {}) do - if r.apply_properties then - for _, interest in ipairs(r.interests) do - if interest:matches(properties) then - for k, v in pairs(r.apply_properties) do - properties[k] = v - end - end - end + local matched, mprops = Settings.apply_rule ("stream_default", properties) + + if (matched and mprops) then + for k, v in pairs(mprops) do + properties[k] = v end end + end -- the state storage @@ -140,7 +123,7 @@ function saveTarget(subject, target_key, type, value) local stream_props = node.properties rulesApplyProperties(stream_props) - if stream_props["state.restore-target"] == false then + if stream_props["state.restore-target"] == "false" then return end @@ -288,7 +271,7 @@ function saveStream(node) local stream_props = node.properties rulesApplyProperties(stream_props) - if config_restore_props and stream_props["state.restore-props"] ~= false then + if config_restore_props and stream_props["state.restore-props"] ~= "false" then local key_base = findSuitableKey(stream_props) if not key_base then return @@ -357,7 +340,7 @@ function restoreStream(node) return end - if config_restore_props and stream_props["state.restore-props"] ~= false then + if config_restore_props and stream_props["state.restore-props"] ~= "false" then local props = { "Spa:Pod:Object:Param:Props", "Props" } local str = state_table[key_base .. ":volume"] @@ -389,7 +372,7 @@ function restoreStream(node) node:set_param("Props", param) end - if config_restore_target and stream_props["state.restore-target"] ~= false then + if config_restore_target and stream_props["state.restore-target"] ~= "false" then local str = state_table[key_base .. ":target"] if str then restoreTarget(node, str)