summaryrefslogtreecommitdiff
path: root/scripts/_osc_hook_example.lua
blob: fdcda4b44fdac5c61fe904592eb0fd8a7b25b70a (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
ardour {
	["type"]    = "EditorHook",
	name        = "OSC Callback Example",
	author      = "Ardour Lua Task Force",
	description = "Send OSC messages",
}

function action_params ()
	return
	{
		["uri"] = { title = "OSC URI ", default = "osc.udp://localhost:7890"},
	}
end


function signals ()
	s = LuaSignal.Set()
	s:add (
		{
			[LuaSignal.SoloActive] = true,
			[LuaSignal.RegionPropertyChanged] = true,
			[LuaSignal.Exported] = true,
			[LuaSignal.TransportStateChange] = true
		}
	)
	return s
end

function factory (params)
	return function (signal, ref, ...)
		local uri = params["unique"] or "osc.udp://localhost:7890"
		local tx = ARDOUR.LuaOSC.Address (uri)
		-- debug print (stdout)
		-- print (signal, ref, ...)

		if (signal == LuaSignal.Exported) then
			tx:send ("/session/exported", "ss", ...)
		elseif (signal == LuaSignal.SoloActive) then
			tx:send ("/session/solo_changed", "")
		elseif (signal == LuaSignal.TransportStateChange) then
			tx:send ("/session/transport", "if",
				Session:transport_frame(), Session:transport_speed())
		elseif (signal == LuaSignal.RegionPropertyChanged) then
			obj,pch = ...
			tx:send ("/region_property_changed", "sTTiii",
				obj:name (),
				(pch:containsFramePos (ARDOUR.Properties.Start)),
				(pch:containsFramePos (ARDOUR.Properties.Length)),
				obj:position (), obj:start (), obj:length ())
		end
	end
end