Skip to content

Instantly share code, notes, and snippets.

@mattsp1290
Created September 18, 2022 03:34
Show Gist options
  • Save mattsp1290/35123a6dbd0e6ec8c0cfb2432b159e6c to your computer and use it in GitHub Desktop.
Save mattsp1290/35123a6dbd0e6ec8c0cfb2432b159e6c to your computer and use it in GitHub Desktop.
Touch OSC Global Fader

Touch OSC Global Fader

Add the contents of globalFader.lua to your global fader. Each child fader will need the childFader.lua script and their name prefixed with the faderPrefix found in globalFader.lua The default is childFader

local receiveValue = 'x'
function onReceiveNotify(key, value)
if (key == 'globalFader') then
self.values[receiveValue] = value
end
end
local allNodes = {}
local childNodes = {}
local sendValue = 'x'
local faderPrefix = 'childFader'
function traverseTree(group)
local nodes = {}
for i=1, #group.children do
if group.children[i].type == ControlType.GROUP -- when a subgroup is found
or group.children[i].type == ControlType.PAGER then
local children = traverseTree(group.children[i]) -- recursion with the current subgroup
for j=1, #children do
table.insert(nodes, children[j])
end
end
table.insert(nodes, group.children[i])
end
return nodes
end
function notifyNodes(nodes)
for i=1, #nodes do
local node = nodes[i]
node:notify('globalFader', self.values[sendValue])
end
end
function init()
allNodes = traverseTree(root)
local childCount = 0
for i=1, #allNodes do
local node = allNodes[i]
if ((node.name ~= nil) and (node.name:find(faderPrefix, 1, true) == 1)) then
childCount = childCount + 1
childNodes[childCount] = node
end
end
notifyNodes(childNodes)
end
function onValueChanged(key)
if (key == sendValue) then
notifyNodes(childNodes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment