-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavexlrfix.lua
195 lines (163 loc) · 6.05 KB
/
wavexlrfix.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
-- This script creates a virtual sink to link Wave XLR source (mirophone input) to.
-- After the link is estabilished it creates Wave XLR sink (playback output).
log = Log.open_topic("s-wavexlrfix")
waveXlrSourceOm = ObjectManager {
Interest {
type = "node",
Constraint { "node.name", "matches", "wavexlr-source" },
}
}
linkOm = ObjectManager {
Interest {
type = "link",
}
}
devicesOm = ObjectManager {
Interest {
type = "device",
}
}
waveXlrSinkNode = nil
nullSinkForWaveXlrSource = nil
nullSinkLink = nil
function createLinkForWaveXlrSource(waveXlrSourceNode)
local outPort = nil
local inPort = nil
local outInterest = Interest {
type = "port",
Constraint { "node.id", "equals", waveXlrSourceNode.properties["object.id"] },
Constraint { "port.direction", "equals", "out" }
}
local inInterest = Interest {
type = "port",
Constraint { "node.id", "equals", nullSinkForWaveXlrSource.properties["object.id"] },
Constraint { "port.direction", "equals", "in" }
}
local portOm = ObjectManager {
Interest {
type = "port",
}
}
function onPortAdded()
if not nullSinkLink then
for port in portOm:iterate(outInterest) do
outPort = port
end
for port in portOm:iterate(inInterest) do
inPort = port
end
if inPort and outPort and inPort.properties["object.id"] and outPort.properties["object.id"] then
local args = {
["link.input.node"] = waveXlrSourceNode.properties["object.id"],
["link.input.port"] = inPort.properties["object.id"],
["link.output.node"] = nullSinkForWaveXlrSource.properties["object.id"],
["link.output.port"] = outPort.properties["object.id"],
}
log:notice("Creating link between null sink and WaveXLR source. Ports: " ..
args["link.input.port"] .. " -> " .. args["link.output.port"])
nullSinkLink = Link("link-factory", args)
nullSinkLink:activate(Feature.Proxy.BOUND)
end
end
end
portOm:connect("object-added", onPortAdded)
portOm:activate()
end
function onLinkCreated(_, link)
if nullSinkLink and link.properties["object.id"] == nullSinkLink.properties["object.id"] then
for node in waveXlrSourceOm:iterate() do
createWaveXlrSink(node)
end
end
end
function createWaveXlrSink(sourceNode)
local deviceInterest = Interest {
type = "device",
Constraint { "object.id", "equals", sourceNode.properties["device.id"] }
}
for device in devicesOm:iterate(deviceInterest) do
local sinkNodeProperties = {
["device.id"] = sourceNode.properties["device.id"],
["factory.name"] = "api.alsa.pcm.sink",
["node.name"] = "wavexlr-sink",
["node.description"] = "WaveXLR Sink",
["node.nick"] = "WaveXLR Sink",
["media.class"] = "Audio/Sink",
["api.alsa.path"] = sourceNode.properties["api.alsa.path"],
["api.alsa.pcm.card"] = sourceNode.properties["api.alsa.pcm.card"],
["api.alsa.pcm.stream"] = "playback",
["alsa.resolution_bits"] = "24",
["audio.channels"] = "2",
["audio.position"] = "FL,FR",
["priority.driver"] = "1000",
["priority.session"] = "1000",
["node.pause-on-idle"] = "false",
}
for k, v in pairs(device.properties) do
if k:find("^api%.alsa%.card%..*") then
sinkNodeProperties[k] = v
end
end
log:notice("Creating custom WaveXLR sink. api.alsa.path: " .. sourceNode.properties["api.alsa.path"])
waveXlrSinkNode = Node("adapter", sinkNodeProperties)
waveXlrSinkNode:activate(Feature.Proxy.BOUND, function(n, err)
if err then
log:warning("Failed to create " .. sinkNodeProperties["node.name"]
.. ": " .. tostring(err))
waveXlrSinkNode = nil
else
log:notice("Created custom WaveXLR sink. object.id: " .. n.properties["object.id"])
end
end)
end
end
function onWaveXlrSourceAdded(_, node)
createLinkForWaveXlrSource(node)
end
function createNullSink()
local properties = {
["factory.name"] = "support.null-audio-sink",
["node.name"] = "null-sink-for-wavexlr-source",
["node.description"] = "Null Sink For WaveXLR Source - do not use",
["node.nick"] = "Null Sink For WaveXLR Source - do not use",
["media.class"] = "Audio/Sink",
["monitor.channel-volumes"] = "true",
["monitor.passthrough"] = "true",
["audio.channels"] = "1",
["audio.position"] = "MONO",
["node.passive"] = "false"
}
log:notice("Creating custom null sink for WaveXLR Source")
local node = Node("adapter", properties)
node:activate(Feature.Proxy.BOUND, function(n, err)
if err then
log:warning("Failed to create " .. properties["node.name"]
.. ": " .. tostring(err))
node = nil
else
log:notice("Created null sink for WaveXLR source. object.id: " ..
n.properties["object.id"])
end
end)
return node
end
function onWaveXlrSourceRemoved()
if waveXlrSinkNode then
log:notice("Removing custom WaveXLR sink");
waveXlrSinkNode:request_destroy()
waveXlrSinkNode = nil
end
if nullSinkLink then
log:notice("Removing null sink link");
nullSinkLink:request_destroy()
nullSinkLink = nil
end
end
nullSinkForWaveXlrSource = createNullSink();
devicesOm:activate()
linkOm:activate()
linkOm:connect("object-added", onLinkCreated)
waveXlrSourceOm:connect("object-added", onWaveXlrSourceAdded)
waveXlrSourceOm:connect("object-removed", onWaveXlrSourceRemoved)
waveXlrSourceOm:activate()
log:notice("script initialized")