Commit 38394419 authored by Julian Bouzas's avatar Julian Bouzas
Browse files

src: scripts: add mini.lua monitor

parent 6283a805
Pipeline #365260 passed with stages
in 1 minute and 20 seconds
......@@ -19,6 +19,7 @@
#define G_LOG_DOMAIN "wp-file-monitor"
#include <errno.h>
#include <sys/inotify.h>
#include <spa/utils/defs.h>
......
......@@ -12,4 +12,6 @@ function alsa_monitor.enable()
properties = alsa_monitor.properties,
rules = alsa_monitor.rules,
})
load_monitor("midi", {})
end
-- WirePlumber
--
-- Copyright © 2021 Collabora Ltd.
-- @author Julian Bouzas <julian.bouzas@collabora.com>
--
-- SPDX-License-Identifier: MIT
SND_PATH = "/dev/snd"
SEQ_NAME = "seq"
SND_SEQ_PATH = SND_PATH .. "/" .. SEQ_NAME
function CreateMidiNode ()
-- Midi properties
local props = {}
props["factory.name"] = "api.alsa.seq.bridge"
props["node.name"] = "Midi-Bridge"
-- create the midi node
local node = Node("spa-node-factory", props)
node:activate(Feature.Proxy.BOUND, function (n)
Log.info ("activated Midi bridge")
end)
return node;
end
midi_node = nil
fm = FileMonitor()
if GLib.access (SND_SEQ_PATH, "rw") then
midi_node = CreateMidiNode ()
else
-- listen for changed events
fm:connect ("changed", function (o, name, wd, mask, cookie)
-- files changed
if mask & FileMonitorFlag.IN.ATTRIB then
if name ~= SEQ_NAME then
return
end
if midi_node == nil and GLib.access (SND_SEQ_PATH, "rw") then
midi_node = CreateMidiNode ()
Core.idle_add (function (c) fm:close() end)
end
end
-- directory was deleted or moved
if mask & (FileMonitorFlag.IN.DELETE_SELF | FileMonitorFlag.IN.MOVE_SELF) then
Core.idle_add (function (c) fm:close() end)
end
end)
-- open and add watch
if fm:open(FileMonitorFlag.IO.IN | FileMonitorFlag.IO.ERR) then
fm:add_watch (SND_PATH,
FileMonitorFlag.IN.ATTRIB | FileMonitorFlag.IN.CLOSE_WRITE |
FileMonitorFlag.IN.DELETE_SELF | FileMonitorFlag.IN.MOVE_SELF)
else
Log.warning ("Failed to open file monitor");
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment