AU: mark preset dirty when parameter changes
[ardour.git] / scripts / _rgh_midi_track_trick.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Rob's 16 MIDI Trick Pony",
4         description = [[clearly broken approach to go about things]]
5 }
6
7 function route_setup ()
8         return {
9                 ['Insert_at'] = ARDOUR.PresentationInfo.max_order,
10                 ['name'] = 'Sweet16',
11                 ['group'] = false, -- return value will be a RouteGroup* or nil
12         }
13 end
14
15 function factory (p) return function ()
16         local name      = "Sweet16"
17         local insert_at = ARDOUR.PresentationInfo.max_order
18         local group     = nil
19
20         -- check for "MIDI Channel Map" LV2 from x42 midifilters.lv2
21         if ARDOUR.LuaAPI.new_plugin_info ("http://gareus.org/oss/lv2/midifilter#channelmap", ARDOUR.PluginType.LV2):isnil () then
22                 LuaDialog.Message ("16 MIDI Tracks", "Error: Plugin 'MIDI Simple Channel Map' was not found.", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
23                 return
24         end
25
26         if type (p) == 'table' and p['how_many'] ~= nil then
27                 -- used from the AddRouteDialog (or w/action_params)
28                 name      = p["name"] or 'Sweet16'
29                 insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
30                 group     = p["group"] or nil
31         else
32                 -- used standalone, prompt for name and insert position
33                 local dialog_options = {
34                         { type = "entry", key = "name", default = 'Sweet16', title = "Name Prefix" },
35                         { type = "entry", key = "group", default = '', title = "Group (empty for none)" },
36                         { type = "dropdown", key = "insertpos", title = "Position", default = "Last", values =
37                                 {
38                                         ["First"]            = ArdourUI.InsertAt.First,
39                                         ["Before Selection"] = ArdourUI.InsertAt.BeforeSelection,
40                                         ["After Selection"]  = ArdourUI.InsertAt.AfterSelection,
41                                         ["Last"]             = ArdourUI.InsertAt.Last
42                                 }
43                         }
44                 }
45
46                 local od = LuaDialog.Dialog ("16 MIDI Tracks", dialog_options)
47                 local rv = od:run()
48                 if (not rv) then return end
49                 name = rv['name'] or 'Sweet16'
50                 if rv['insertpos'] then
51                         insert_at = ArdourUI.translate_order (rv['insertpos'])
52                 end
53                 if rv['group'] and rv['group'] ~= '' then
54                         group = Session:new_route_group (rv['group'])
55                 end
56         end
57         collectgarbage ()
58
59         -- all systems go
60
61         local tl = Session:new_midi_track (
62                 ARDOUR.ChanCount(ARDOUR.DataType ("midi"), 1),
63                 ARDOUR.ChanCount(ARDOUR.DataType ("midi"), 1),
64                 true, -- strict i/o
65                 ARDOUR.PluginInfo(), nil, -- no instrument, no instrument preset
66                 group,
67                 16, -- how many
68                 name, insert_at, ARDOUR.TrackMode.Normal)
69
70         local i = 1
71         for track in tl:iter() do
72                 local p = ARDOUR.LuaAPI.new_plugin(Session, "http://gareus.org/oss/lv2/midifilter#channelmap", ARDOUR.PluginType.LV2, "")
73                 assert (not p:isnil ())
74                 track:add_processor_by_index(p, 0, nil, true)
75                 for j = 1, 16 do
76                         ARDOUR.LuaAPI.set_processor_param (p, j, i)
77                 end
78                 i = i + 1
79         end
80         collectgarbage () -- drop references to tracks.
81 end end