Only emit InstrumentInfo::Changed() on actual change
[ardour.git] / scripts / _dialog_test.lua
1 ardour { ["type"] = "Snippet", name = "Dialog Test" }
2
3 function factory () return function ()
4         local md = LuaDialog.Message ("title", "hello", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close)
5         print (md:run())
6
7         md = nil
8         collectgarbage ()
9
10         -----------------------------------------------------------------
11         function basic_serialize (o)
12                 if type(o) == "number" then
13                         return tostring(o)
14                 else
15                         return string.format("%q", o)
16                 end
17         end
18
19         function serialize (name, value)
20                 local rv = name .. ' = '
21                 collectgarbage()
22                 if type(value) == "number" or type(value) == "string" or type(value) == "nil" or type (value) == "boolean" then
23                         return rv .. basic_serialize(value) .. ' '
24                 elseif type(value) == "table" then
25                         rv = rv .. '{} '
26                         for k,v in pairs(value) do
27                                 local fieldname = string.format("%s[%s]", name, basic_serialize(k))
28                                 rv = rv .. serialize(fieldname, v) .. ' '
29                         end
30                         return rv
31                 elseif type(value) == "function" then
32                         --return rv .. string.format("%q", string.dump(value, true))
33                         return rv .. "(function)"
34                 else
35                         error('cannot serialize a ' .. type(value))
36                 end
37         end
38         -----------------------------------------------------------------
39
40         function func () print "Hello" end
41
42         local dialog_options = {
43                 { type = "checkbox", key = "onoff", default = true, title = "OnOff" },
44
45                 { type = "entry", key = "text", default = "changeme", title = "Text Entry" },
46
47                 {
48                         type = "radio", key = "select", title = "RadioBtn", values =
49                         {
50                                 ["Option 1"] = 1, ["Option 2"] = "2", ["Option A"] = 'A'
51                         },
52                         default = "Option 1"
53                 },
54
55                 {
56                         type = "dropdown", key = "dropdown", title = "Menu", values =
57                         {
58                                 ["Option 1"] = 1, ["Option 2"] = "2", ["Callback"] = func,
59                                 ["Option 4"] =
60                                 {
61                                         ["Option 4a"] = "test", ["Option 4b"] = 4.2
62                                 }
63                         },
64                         default = "Option 2"
65                 },
66
67                 { type = "fader", key = "gain", title = "Level",  default = -10 }, -- unit = 'dB"
68
69                 {
70                         type = "slider", key = "freq", title = "Frequency", min = 20, max = 20000, scalepoints =
71                         {
72                                 [20] = "20", [200] = "nice", [2000] = "2k", [10000] = "too much"
73                         },
74                         default = 500
75                 },
76
77                 { type = "heading", title = "Heading" },
78
79                 { type = "number", key = "number", title = "Whatever",  min = 0, max = 10, step = 1, digits = 2 },
80
81                 { type = "file", key = "file", title = "Select a File",  path = ARDOUR.LuaAPI.build_filename (Session:path (), Session:name () .. ".ardour") },
82
83                 { type = "folder", key = "folder", title = "Select a Folder",  path = Session:path() }
84         }
85
86         local od = LuaDialog.Dialog ("title", dialog_options)
87         local rv = od:run()
88         if (rv) then
89                 print (serialize ("dialog", rv))
90         end
91
92         od = nil
93         collectgarbage ()
94
95 end end