node/software-dsp: Port Node ObjectManager to SimpleEventHook
Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
This commit is contained in:
@@ -11,10 +11,6 @@ config = {}
|
|||||||
config.rules = Conf.get_section_as_json("node.software-dsp.rules", Json.Array{})
|
config.rules = Conf.get_section_as_json("node.software-dsp.rules", Json.Array{})
|
||||||
|
|
||||||
-- TODO: port from Obj Manager to Hooks
|
-- TODO: port from Obj Manager to Hooks
|
||||||
nodes_om = ObjectManager {
|
|
||||||
Interest { type = "node" },
|
|
||||||
}
|
|
||||||
|
|
||||||
clients_om = ObjectManager {
|
clients_om = ObjectManager {
|
||||||
Interest { type = "client" }
|
Interest { type = "client" }
|
||||||
}
|
}
|
||||||
@@ -22,36 +18,54 @@ clients_om = ObjectManager {
|
|||||||
filter_nodes = {}
|
filter_nodes = {}
|
||||||
hidden_nodes = {}
|
hidden_nodes = {}
|
||||||
|
|
||||||
nodes_om:connect("object-added", function (om, node)
|
SimpleEventHook {
|
||||||
JsonUtils.match_rules (config.rules, node.properties, function (action, value)
|
name = "node/dsp/create-dsp-node",
|
||||||
if action == "create-filter" then
|
interests = {
|
||||||
log:debug("DSP rule found for " .. node.properties["node.name"])
|
EventInterest {
|
||||||
local props = value:parse (1)
|
Constraint { "event.type", "=", "node-added" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
execute = function(event)
|
||||||
|
local node = event:get_subject()
|
||||||
|
JsonUtils.match_rules (config.rules, node.properties, function (action, value)
|
||||||
|
if action == "create-filter" then
|
||||||
|
local props = value:parse (1)
|
||||||
|
log:debug("DSP rule found for " .. node.properties["node.name"])
|
||||||
|
|
||||||
if props["filter-graph"] then
|
if props["filter-graph"] then
|
||||||
log:debug("Loading filter graph for " .. node.properties["node.name"])
|
log:debug("Loading filter graph for " .. node.properties["node.name"])
|
||||||
filter_nodes[node.properties["object.id"]] = LocalModule("libpipewire-module-filter-chain", props["filter-graph"], {})
|
filter_nodes[node.properties["object.id"]] = LocalModule("libpipewire-module-filter-chain", props["filter-graph"], {})
|
||||||
end
|
|
||||||
|
|
||||||
if props["hide-parent"] then
|
|
||||||
log:debug("Setting permissions to '-' on " .. node.properties["node.name"] .. " for open clients")
|
|
||||||
for client in clients_om:iterate{ type = "client" } do
|
|
||||||
if not client["properties"]["wireplumber.daemon"] then
|
|
||||||
client:update_permissions{ [node["bound-id"]] = "-" }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
hidden_nodes[node["bound-id"]] = node.properties["object.id"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
nodes_om:connect("object-removed", function (om, node)
|
if props["hide-parent"] then
|
||||||
if filter_nodes[node.properties["object.id"]] then
|
log:debug("Setting permissions to '-' on " .. node.properties["node.name"] .. " for open clients")
|
||||||
log:debug("Freeing filter graph on disconnected node " .. node.properties["node.name"])
|
for client in clients_om:iterate{ type = "client" } do
|
||||||
filter_nodes[node.properties["object.id"]] = nil
|
if not client["properties"]["wireplumber.daemon"] then
|
||||||
|
client:update_permissions{ [node["bound-id"]] = "-" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
hidden_nodes[node["bound-id"]] = node.properties["object.id"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end)
|
}:register()
|
||||||
|
|
||||||
|
SimpleEventHook {
|
||||||
|
name = "node/dsp/free-dsp-node",
|
||||||
|
interests = {
|
||||||
|
EventInterest {
|
||||||
|
Constraint { "event.type", "=", "node-removed" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
execute = function(event)
|
||||||
|
local node = event:get_subject()
|
||||||
|
if filter_nodes[node.properties["object.id"]] then
|
||||||
|
log:debug("Freeing filter graph on disconnected node " .. node.properties["node.name"])
|
||||||
|
filter_nodes[node.properties["object.id"]] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}:register()
|
||||||
|
|
||||||
clients_om:connect("object-added", function (om, client)
|
clients_om:connect("object-added", function (om, client)
|
||||||
for id, _ in pairs(hidden_nodes) do
|
for id, _ in pairs(hidden_nodes) do
|
||||||
@@ -61,5 +75,4 @@ clients_om:connect("object-added", function (om, client)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
nodes_om:activate()
|
|
||||||
clients_om:activate()
|
clients_om:activate()
|
||||||
|
Reference in New Issue
Block a user