fix drawing of zero-length notes
[ardour.git] / scripts / _export_plugins_on_save.lua
1 ardour {
2         ["type"]    = "EditorHook",
3         name        = "Save Extra Data (instruments)",
4         author      = "Ardour Lua Task Force",
5         description = "Export custom data when the session is saved",
6 }
7
8 -- subscribe to signals
9 -- http://manual.ardour.org/lua-scripting/class_reference/#LuaSignal.LuaSignal
10 function signals ()
11         s = LuaSignal.Set()
12         s:add ({[LuaSignal.StateSaved] = true})
13         return s
14 end
15
16 -- create callback functions
17 function factory () return function (signal, ...)
18         assert (signal == LuaSignal.StateSaved)
19
20         local all_instruments = {}
21
22         -- iterate over all routes
23         for r in Session:get_routes():iter() do
24                 local proc = r:the_instrument() -- get instrument processor (if any)
25                 if proc:isnil() then goto nextroute end -- skip tracks/busses without instrument
26                 local pi = proc:to_insert() -- check if it's a plugin-insert
27                 if pi:isnil() then goto nextroute end
28
29                 local pp = pi:plugin (0) -- get first instance
30                 all_instruments[r:name()] = string.format ("%s (%s)", proc:name(), pp:unique_id())
31
32                 ::nextroute::
33         end
34
35         if next (all_instruments) ~= nil then -- check if table is not empty
36                 -- write to a file in the session-folder
37                 file = io.open (ARDOUR.LuaAPI.build_filename (Session:path(), Session:name () .. ".instruments.txt"), "w")
38                 for nme, nfo in pairs (all_instruments) do
39                         file:write (nme .. ": " .. nfo)
40                 end
41                 file:close()
42         end
43
44 end end