summaryrefslogtreecommitdiff
path: root/scripts/_dialog_test.lua
blob: cc02f82a466b20bc1754e8e14033f785da94d633 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
ardour { ["type"] = "Snippet", name = "Dialog Test" }

function factory () return function ()
	local md = LuaDialog.Message ("title", "hello", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close)
	print (md:run())

	md = nil
	collectgarbage ()

	-----------------------------------------------------------------
	function basic_serialize (o)
		if type(o) == "number" then
			return tostring(o)
		else
			return string.format("%q", o)
		end
	end

	function serialize (name, value)
		local rv = name .. ' = '
		collectgarbage()
		if type(value) == "number" or type(value) == "string" or type(value) == "nil" or type (value) == "boolean" then
			return rv .. basic_serialize(value) .. ' '
		elseif type(value) == "table" then
			rv = rv .. '{} '
			for k,v in pairs(value) do
				local fieldname = string.format("%s[%s]", name, basic_serialize(k))
				rv = rv .. serialize(fieldname, v) .. ' '
			end
			return rv
		elseif type(value) == "function" then
			--return rv .. string.format("%q", string.dump(value, true))
			return rv .. "(function)"
		else
			error('cannot serialize a ' .. type(value))
		end
	end
	-----------------------------------------------------------------

	function func () print "Hello" end

	local dialog_options = {
		{ type = "checkbox", key = "onoff", default = true, title = "OnOff" },

		{ type = "entry", key = "text", default = "changeme", title = "Text Entry" },

		{
			type = "radio", key = "select", title = "RadioBtn", values =
			{
				["Option 1"] = 1, ["Option 2"] = "2", ["Option A"] = 'A'
			},
			default = "Option 1"
		},

		{
			type = "dropdown", key = "dropdown", title = "Menu", values =
			{
				["Option 1"] = 1, ["Option 2"] = "2", ["Callback"] = func,
				["Option 4"] =
				{
					["Option 4a"] = "test", ["Option 4b"] = 4.2
				}
			},
			default = "Option 2"
		},

		{ type = "fader", key = "gain", title = "Level",  default = -10 }, -- unit = 'dB"

		{
			type = "slider", key = "freq", title = "Frequency", min = 20, max = 20000, scalepoints =
			{
				[20] = "20", [200] = "nice", [2000] = "2k", [10000] = "too much"
			},
			default = 500
		},

		{ type = "heading", title = "Heading" },

		{ type = "number", key = "number", title = "Whatever",  min = 0, max = 10, step = 1, digits = 2 },

		{ type = "file", key = "file", title = "Select a File",  path = ARDOUR.LuaAPI.build_filename (Session:path (), Session:name () .. ".ardour") },

		{ type = "folder", key = "folder", title = "Select a Folder",  path = Session:path() }
	}

	local od = LuaDialog.Dialog ("title", dialog_options)
	local rv = od:run()
	if (rv) then
		print (serialize ("dialog", rv))
	end

	od = nil
	collectgarbage ()

end end