summaryrefslogtreecommitdiff
path: root/scripts/_vca_slave_assign.lua
blob: 62055b55cb0b602933f088997db594850806987a (plain)
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
ardour { ["type"] = "Snippet", name = "VCA Slave Examples",
	license     = "MIT",
	author      = "Ardour Team",
}

function factory () return function ()
	-- find possible masters & slave, allow selection in dropdown menu
	local targets = {}
	local sources = {}
	local have_masters = false
	local have_slaves = false

	for v in Session:vca_manager ():vcas() :iter () do -- for each VCA
		sources [v:name ()] = v
		have_masters = true
	end

	for s in Session:get_stripables ():iter () do -- for every track/bus/vca
		if s:is_monitor () or s:is_auditioner () then goto nextroute end -- skip special routes
		targets [s:name ()] = s
		have_slaves = true;
		::nextroute::
	end

	-- bail out if there are no parameters
	if not have_slaves then
		LuaDialog.Message ("VCA Slave Example", "No Slavables found", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
		sources = nil
		collectgarbage ()
		return
	end
	if not have_masters then
		LuaDialog.Message ("VCA Slave Example", "No VCA masters found", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
		targets = nil
		collectgarbage ()
		return
	end

	-- create a dialog, ask user which master to assign to which slave
	local dialog_options = {
		{ type = "dropdown", key = "master", title = "Control Master", values = sources },
		{ type = "dropdown", key = "slave", title = "Control Slave", values = targets }
	}
	local rv = LuaDialog.Dialog ("Select VCA assignment", dialog_options):run ()

	targets = nil -- drop references (the table holds shared-pointer references to all strips)
	collectgarbage () -- and release the references immediately

	if not rv then return end -- user canceled the operation

	-- parse user response
	local mst = rv["master"]
	local slv = rv["slave"]
	assert (not slv:to_slavable ():isnil ())

	-- test if mst is already controlled by slv (directly or indirectly)
	-- if so, don't allow the connection
	if (not slv:to_slavable ():assigned_to (Session:vca_manager(), mst)) then
		-- if slv is a VCA and is controlled by master, disconnect it
		if (not slv:to_vca ():isnil () and slv:to_vca ():slaved_to (mst)) then
			slv:to_slavable ():unassign (mst)
		else
			slv:to_slavable ():assign (mst)
		end
	else
		LuaDialog.Message ("VCA Slave Example", "Recursive VCA assignment ignored", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
	end

	-- drop references
	mst = nil slv = nil
	collectgarbage ()
end end