summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-04-25 05:26:56 +0200
committerRobin Gareus <robin@gareus.org>2017-04-25 14:01:34 +0200
commit72017b6117a9234ed680628f55ef6e20e7c64a90 (patch)
tree5b182f5c4dcec59307782b5ed2c775f6a3f59074 /scripts
parentf5995661d0b652a1907ca440dce6e1fcc2bf3855 (diff)
Add a Lua script to exercise the LuaDialog
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_dialog_test.lua89
1 files changed, 89 insertions, 0 deletions
diff --git a/scripts/_dialog_test.lua b/scripts/_dialog_test.lua
new file mode 100644
index 0000000000..15bb67b4f7
--- /dev/null
+++ b/scripts/_dialog_test.lua
@@ -0,0 +1,89 @@
+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 = "number", key = "number", title = "Whatever", min = 0, max = 10, step = 1, digits = 2 }
+ }
+
+ local od = LuaDialog.Dialog ("title", dialog_options)
+ local rv = od:run()
+ if (rv) then
+ print (serialize ("dialog", rv))
+ end
+
+ od = nil
+ collectgarbage ()
+
+end end