More template re-naming
[ardour.git] / scripts / template_band.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Track Wizard",
4         description = [[
5 This template helps create the tracks for a typical pop/rock band.
6
7 You will be prompted to assemble your session from a list of track types.
8
9 Each track will be pre-assigned with a color.
10
11 Optionally, tracks may be assigned to sensible Groups ( vocals, guitars, drums )
12
13 Optionally, tracks may be assigned Gates and other plugins.
14     ]]
15 }
16
17 function session_setup ()
18         return true;
19 end
20
21 function route_setup ()
22         return
23         {
24                 ['Insert_at'] = ARDOUR.PresentationInfo.max_order;
25         }
26 end
27
28 function factory () return function ()
29
30         local p         = params or route_setup ()
31         local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
32
33     --prompt the user for the tracks they'd like to instantiate
34         local dialog_options = {
35                 { type = "heading", title = "Select the tracks you'd like\nto add to your session: ", col=0, align = "left", colspan = 1},
36                 { type = "heading", title = "Name", col=1, colspan = 1 },
37                 { type = "heading", title = "Stereo?", col=2, colspan = 1 },
38
39                 { type = "checkbox", key = "check-ldvox",  default = false,        title = "Lead Vocal", col=0 },
40                 { type = "entry",    key = "name-ldvox",   default = "Lead Vocal", title = "", col=1 },
41                 { type = "checkbox", key = "stereo-ldvox", default = false,        title = "", col=2 },
42
43                 { type = "checkbox", key = "check-bass", default = false, title = "Bass", col=0 },
44                 { type = "entry",    key = "name-bass",   default = "Bass", title = "", col=1 },
45                 { type = "checkbox", key = "stereo-bass", default = false,        title = "", col=2 },
46
47                 { type = "checkbox", key = "check-piano", default = false, title = "Piano", col=0 },
48                 { type = "entry",    key = "name-piano",   default = "Piano", title = "", col=1 },
49                 { type = "checkbox", key = "stereo-piano", default = false,        title = "", col=2 },
50
51                 { type = "checkbox", key = "check-electric-piano", default = false, title = "Electric Piano", col=0 },
52                 { type = "entry",    key = "name-electric-piano",   default = "E Piano", title = "", col=1 },
53                 { type = "checkbox", key = "stereo-electric-piano", default = false,        title = "", col=2 },
54
55                 { type = "checkbox", key = "check-organ", default = false, title = "Organ", col=0 },
56                 { type = "entry",    key = "name-organ",   default = "Organ", title = "", col=1 },
57                 { type = "checkbox", key = "stereo-organ", default = false,        title = "", col=2 },
58
59                 { type = "checkbox", key = "check-electric-guitar", default = false, title = "Electric Guitar", col=0 },
60                 { type = "entry",    key = "name-electric-guitar",   default = "E Guitar", title = "", col=1 },
61                 { type = "checkbox", key = "stereo-electric-guitar", default = false,        title = "", col=2 },
62
63                 { type = "checkbox", key = "check-solo-guitar", default = false, title = "Lead Guitar", col=0 },
64                 { type = "entry",    key = "name-solo-guitar",   default = "Ld Gtr", title = "", col=1 },
65                 { type = "checkbox", key = "stereo-solo-guitar", default = false,        title = "", col=2 },
66
67                 { type = "checkbox", key = "check-accoustic-guitar", default = false, title = "Acoustic Guitar", col=0 },
68                 { type = "entry",    key = "name-accoustic-guitar",   default = "Ac Gtr", title = "", col=1 },
69                 { type = "checkbox", key = "stereo-accoustic-guitar", default = false,        title = "", col=2 },
70
71                 { type = "checkbox", key = "check-basic-kit", default = false, title = "Basic Drum Mics", col=0 },
72                 { type = "label",  title = "(Kick + Snare)", col=1, colspan = 1, align = "left"},
73 --              { type = "checkbox", key = "stereo-overhead-mono", default = false,        title = "", col=2 },
74
75                 { type = "checkbox", key = "check-full-kit", default = false, title = "Full Drum Mics", col=0 },
76                 { type = "label",  title = "(Kick, Snare, HiHat, 3 Toms)", col=1, colspan = 1, align = "left"},
77 --              { type = "checkbox", key = "stereo-overhead-mono", default = false,        title = "", col=2 },
78
79                 { type = "checkbox", key = "check-overkill-kit", default = false, title = "Overkill Drum Mics", col=0 },
80                 { type = "label",  title = "(Kick (2x), Snare(2x), HiHat, 3 Toms)", col=1, colspan = 1, align = "left"},
81 --              { type = "checkbox", key = "stereo-overhead-mono", default = false,        title = "", col=2 },
82
83                 { type = "checkbox", key = "check-overhead", default = false, title = "Drum Overheads", col=0 },
84 --              { type = "entry",    key = "name-ldvox",   default = "Lead Vocal", title = "", col=1 },
85                 { type = "checkbox", key = "stereo-overhead", default = false,        title = "", col=2 },
86
87                 { type = "checkbox", key = "check-room", default = false, title = "Drum Room", col=0 },
88 --              { type = "entry",    key = "name-ldvox",   default = "Lead Vocal", title = "", col=1 },
89                 { type = "checkbox", key = "stereo-room", default = false,        title = "", col=2 },
90
91                 { type = "checkbox", key = "check-bgvox", default = false, title = "Background Vocals (3x)", col=0 },
92 --              { type = "entry",    key = "name-ldvox",   default = "Lead Vocal", title = "", col=1 },
93                 { type = "checkbox", key = "stereo-bgvox", default = false,        title = "", col=2 },
94
95                 { type = "hseparator", title="", col=0, colspan = 3},
96
97                 { type = "checkbox", key = "group", default = false, title = "Group Track(s)?", col=0 },
98                 { type = "checkbox", key = "gates", default = false, title = "Add Gate(s)?", col=0 },
99                 { type = "checkbox", key = "char", default = false, title = "Add Character Plugin(s)?", col=0 },
100         }
101
102         local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
103         local rv = dlg:run()
104         if (not rv) then
105                 return
106         end
107
108         -- helper function to reference processors
109         function processor(t, s) --takes a track (t) and a string (s) as arguments
110                 local i = 0
111                 local proc = t:nth_processor(i)
112                         repeat
113                                 if ( proc:display_name() == s ) then
114                                         return proc
115                                 else
116                                         i = i + 1
117                                 end
118                                 proc = t:nth_processor(i)
119                         until proc:isnil()
120                 end
121
122         --INSTANTIATING MIDI TRACKS IS TOO DAMN HARD
123         function create_midi_track(name, chan_count) -- call this function with a name argument and output channel count
124                 Session:new_midi_track(ARDOUR.ChanCount(ARDOUR.DataType ("midi"), 1),  ARDOUR.ChanCount(ARDOUR.DataType ("audio"), chan_count), true, ARDOUR.PluginInfo(), nil, nil, 1, name, 1, ARDOUR.TrackMode.Normal)
125                 return true
126         end
127
128         if rv['group'] then
129                 drum_group = Session:new_route_group("Drums")
130                 drum_group:set_rgba(0x425CADff)
131                 bass_group = Session:new_route_group("Bass")
132                 bass_group:set_rgba(0x1AE54Eff)
133                 guitar_group = Session:new_route_group("Guitars")
134                 guitar_group:set_rgba(0xB475CBff)
135                 key_group = Session:new_route_group("Keys")
136                 key_group:set_rgba(0xDA8032ff)
137                 vox_group = Session:new_route_group("Vox")
138                 vox_group:set_rgba(0xC54249ff)
139         end
140
141         local track_count = 0;
142         if rv['check-basic-kit'] then
143                 local names = {"Kick", "Snare"}
144                 for i = 1, #names do
145                 local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
146                         for track in tl:iter() do
147                                 local gate = ARDOUR.LuaAPI.new_plugin(Session, "XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2, "")
148                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
149                                 if rv['group'] then drum_group:add(track) end
150                                 if rv['gates'] then track:add_processor_by_index(eg, 0, nil, true) end
151                         end
152                 end
153
154                 track_count = track_count+2
155         end
156
157         if rv['check-full-kit'] then
158                 local names = {"Kick", "Snare", "Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
159                 for i = 1, #names do
160                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
161                         for track in tl:iter() do
162                                 local eg = ARDOUR.LuaAPI.new_plugin(Session, "XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2, "")
163                                 local tg = ARDOUR.LuaAPI.new_plugin(Session, "XT-TG Tom Gate (Mono)",      ARDOUR.PluginType.LV2, "")
164                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
165                                 if rv['group'] then drum_group:add(track) end
166                                 if rv['gates'] then
167                                         if string.find(track:name(), '-tom') then
168                                                 track:add_processor_by_index(tg, 0, nil, true)
169                                         else
170                                                 track:add_processor_by_index(eg, 0, nil, true)
171                                         end
172                                 end
173                         end
174                 end
175
176                 track_count = track_count+6
177         end
178
179         if rv['check-overkill-kit'] then
180                 local names = {"Kick In", "Kick Out", "Snare Top", "Snare Btm", "Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
181                 for i = 1, #names do
182                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
183                         for track in tl:iter() do
184                                 local eg = ARDOUR.LuaAPI.new_plugin(Session, "XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2, "")
185                                 local tg = ARDOUR.LuaAPI.new_plugin(Session, "XT-TG Tom Gate (Mono)",      ARDOUR.PluginType.LV2, "")
186                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
187                                 if rv['group'] then drum_group:add(track) end
188                                 if rv['gates'] then
189                                         if string.find(track:name(), '-tom') then
190                                                 track:add_processor_by_index(tg, 0, nil, true)
191                                         else
192                                                 track:add_processor_by_index(eg, 0, nil, true)
193                                         end
194                                 end
195                         end
196                 end
197
198                 track_count = track_count+8
199         end
200
201         if rv['check-overhead'] then
202                 local names = { "OH" }
203                 local ch = 1
204                 if rv["stereo-bass"] then ch = 2 end --stereo
205                 for i = 1, #names do
206                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
207                         for track in tl:iter() do
208                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
209                                 if rv['group'] then drum_group:add(track) end
210                         end
211                 end
212
213                 track_count = track_count+ch
214         end
215
216
217         if rv['check-room'] then
218                 local names = { "Drum Room" }
219                 local ch = 1
220                 if rv["stereo-bass"] then ch = 2 end --stereo
221                 for i = 1, #names do
222                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
223                         for track in tl:iter() do
224                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
225                                 if rv['group'] then drum_group:add(track) end
226                         end
227                 end
228
229                 track_count = track_count+ch
230         end
231
232         if rv['check-bass'] then
233                 local names = { rv["name-bass"] }
234                 local ch = 1
235                 if rv["stereo-bass"] then ch = 2 end --stereo
236                 for i = 1, #names do
237                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
238                         for track in tl:iter() do
239                                 local bc = ARDOUR.LuaAPI.new_plugin(Session, "XT-BC Bass Character (Mono)", ARDOUR.PluginType.LV2, "")
240                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
241                                 if rv['group'] then bass_group:add(track) end
242                                 if rv['char'] then track:add_processor_by_index(bc, 0, nil, true) end
243                         end
244                 end
245
246                 track_count = track_count+ch
247         end
248
249         if rv['check-electric-guitar'] then
250                 local names = { rv["name-electric-guitar"] }
251                 local ch = 1
252                 if rv["stereo-electric-guitar"] then ch = 2 end --stereo
253                 for i = 1, #names do
254                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
255                         for track in tl:iter() do
256                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
257                                 if rv['group'] then guitar_group:add(track) end
258                         end
259                 end
260
261                 track_count = track_count+ch
262         end
263
264         if rv['check-solo-guitar'] then
265                 local names = { rv["name-solo-guitar"] }
266                 local ch = 1
267                 if rv["stereo-solo-guitar"] then ch = 2 end --stereo
268                 for i = 1, #names do
269                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
270                         for track in tl:iter() do
271                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
272                                 if rv['group'] then guitar_group:add(track) end
273                         end
274                 end
275
276                 track_count = track_count+ch
277         end
278
279         if rv['check-acoustic-guitar'] then
280                 local names = { rv["name-acoustic-guitar"] }
281                 local ch = 1
282                 if rv["stereo-acoustic-guitar"] then ch = 2 end --stereo
283                 for i = 1, #names do
284                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
285                         for track in tl:iter() do
286                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
287                                 if rv['group'] then guitar_group:add(track) end
288                         end
289                 end
290
291                 track_count = track_count+ch
292         end
293
294         if rv['check-piano'] then
295                 local names = { rv["name-piano"] }
296                 local ch = 1
297                 if rv["stereo-piano"] then ch = 2 end --stereo
298                 for i = 1, #names do
299                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
300                         for track in tl:iter() do
301                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
302                                 if rv['group'] then key_group:add(track) end
303                         end
304                 end
305
306                 track_count = track_count+ch
307         end
308
309         if rv['check-electric-piano'] then
310                 local names = { rv["name-electric-piano"] }
311                 local ch = 1
312                 if rv["stereo-electric-piano"] then ch = 2 end --stereo
313                 for i = 1, #names do
314                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
315                         for track in tl:iter() do
316                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
317                                 if rv['group'] then key_group:add(track) end
318                         end
319                 end
320
321                 track_count = track_count+ch
322         end
323
324         if rv['check-organ'] then
325                 local names = { rv["name-organ"] }
326                 local ch = 1
327                 if rv["stereo-organ"] then ch = 2 end --stereo
328                 for i = 1, #names do
329                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
330                         for track in tl:iter() do
331                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
332                                 if rv['group'] then key_group:add(track) end
333                         end
334                 end
335
336                 track_count = track_count+ch
337         end
338
339         if rv['check-ldvox'] then
340                 local names = { rv["name-ldvox"] }
341                 local ch = 1
342                 if rv["stereo-ldvox"] then ch = 2 end --stereo
343                 for i = 1, #names do
344                         local tl = Session:new_audio_track ( ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
345                         for track in tl:iter() do
346                                 local vc = ARDOUR.LuaAPI.new_plugin(Session, "XT-VC Vocal Character (Mono)", ARDOUR.PluginType.LV2, "")
347                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
348                                 if rv['group'] then vox_group:add(track) end
349                                 if rv['char']  then track:add_processor_by_index(vc, 0, nil, true) end
350                         end
351                 end
352
353                 track_count = track_count+ch
354         end
355
356         if rv['check-bgvox'] then
357                 local names = { rv["name-bgvox"] }
358                 local ch = 1
359                 if rv["stereo-bgvox"] then ch = 2 end --stereo
360                 for i = 1, #names do
361                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
362                         for track in tl:iter() do
363                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
364                                 if rv['group'] then vox_group:add(track) end
365                         end
366                 end
367
368                 track_count = track_count+ch
369         end
370
371     --determine the number of tracks we can record
372         local e = Session:engine()
373         local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())  -- from the engine's POV readable/capture ports are "outputs"
374         local num_inputs = t[4]:size();  -- table 't' holds argument references. t[4] is the C.StringVector (return value)
375
376     --ToDo:  if track_count > num_inputs, we should warn the user to check their routing.
377
378     --fit all tracks on the screen
379     Editor:access_action("Editor","fit_all_tracks")
380
381         Session:save_state("");
382 end end