4203f837d4b9736699ce71610ff774164557a646
[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 (params) 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         }
99
100         --- check for available plugins
101         -- gates
102         local xt_eg = not ARDOUR.LuaAPI.new_plugin_info ("XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2):isnil ()
103         local xt_tg = not ARDOUR.LuaAPI.new_plugin_info ("XT-TG Tom Gate (Mono", ARDOUR.PluginType.LV2):isnil ()
104         -- char
105         local xt_tg = not ARDOUR.LuaAPI.new_plugin_info ("XT-BC Bass Character (Mono)", ARDOUR.PluginType.LV2):isnil ()
106         local xt_vc = not ARDOUR.LuaAPI.new_plugin_info ("XT-VC Vocal Character (Mono)", ARDOUR.PluginType.LV2):isnil ()
107
108         if (xt_eg and xt_tg) then
109                 table.insert (dialog_options,
110                 { type = "checkbox", key = "gates", default = false, title = "Add Gate(s)?", col=0 }
111                 )
112         end
113         if (xt_tg and xt_vc) then
114                 table.insert (dialog_options,
115                 { type = "checkbox", key = "char", default = false, title = "Add Character Plugin(s)?", col=0 }
116                 )
117         end
118
119
120
121         local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
122         local rv = dlg:run()
123         if (not rv) then
124                 return
125         end
126
127         -- helper function to reference processors
128         function processor(t, s) --takes a track (t) and a string (s) as arguments
129                 local i = 0
130                 local proc = t:nth_processor(i)
131                         repeat
132                                 if ( proc:display_name() == s ) then
133                                         return proc
134                                 else
135                                         i = i + 1
136                                 end
137                                 proc = t:nth_processor(i)
138                         until proc:isnil()
139                 end
140
141         --INSTANTIATING MIDI TRACKS IS TOO DAMN HARD
142         function create_midi_track(name, chan_count) -- call this function with a name argument and output channel count
143                 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)
144                 return true
145         end
146
147         function add_lv2_plugin (track, pluginname, position)
148                 local p = ARDOUR.LuaAPI.new_plugin(Session, pluginname, ARDOUR.PluginType.LV2, "")
149                 if not p:isnil () then
150                         track:add_processor_by_index(p, position, nil, true)
151                 end
152         end
153
154
155         local drum_group, bass_group, guitar_group, key_group, vox_group
156
157         if rv['group'] then
158                 drum_group = Session:new_route_group("Drums")
159                 drum_group:set_rgba(0x425CADff)
160                 bass_group = Session:new_route_group("Bass")
161                 bass_group:set_rgba(0x1AE54Eff)
162                 guitar_group = Session:new_route_group("Guitars")
163                 guitar_group:set_rgba(0xB475CBff)
164                 key_group = Session:new_route_group("Keys")
165                 key_group:set_rgba(0xDA8032ff)
166                 vox_group = Session:new_route_group("Vox")
167                 vox_group:set_rgba(0xC54249ff)
168         end
169
170         local channel_count = 0
171
172         if rv['check-basic-kit'] then
173                 local names = {"Kick", "Snare"}
174                 for i = 1, #names do
175                 local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
176                         for track in tl:iter() do
177                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
178                                 if rv['group'] then drum_group:add(track) end
179                                 if rv['gates'] then
180                                         add_lv2_plugin (track, "XT-EG Expander Gate (Mono)", 0)
181                                 end
182                         end
183                 end
184                 channel_count = channel_count + #names
185         end
186
187         if rv['check-full-kit'] then
188                 local names = {"Kick", "Snare", "Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
189                 for i = 1, #names do
190                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
191                         for track in tl:iter() do
192                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
193                                 if rv['group'] then drum_group:add(track) end
194                                 if rv['gates'] then
195                                         if string.find(track:name(), '-tom') then
196                                                 add_lv2_plugin (track, "XT-TG Tom Gate (Mono)", 0)
197                                         else
198                                                 add_lv2_plugin (track, "XT-EG Expander Gate (Mono)", 0)
199                                         end
200                                 end
201                         end
202                 end
203                 channel_count = channel_count + #names
204         end
205
206         if rv['check-overkill-kit'] then
207                 local names = {"Kick In", "Kick Out", "Snare Top", "Snare Btm", "Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
208                 for i = 1, #names do
209                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
210                         for track in tl:iter() do
211                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
212                                 if rv['group'] then drum_group:add(track) end
213                                 if rv['gates'] then
214                                         if string.find(track:name(), '-tom') then
215                                                 add_lv2_plugin (track, "XT-TG Tom Gate (Mono)", 0)
216                                         else
217                                                 add_lv2_plugin (track, "XT-EG Expander Gate (Mono)", 0)
218                                         end
219                                 end
220                         end
221                 end
222                 channel_count = channel_count + #names
223         end
224
225         if rv['check-overhead'] then
226                 local names = { "OH" }
227                 local ch = 1
228                 if rv["stereo-overhead"] then ch = 2 end --stereo
229                 for i = 1, #names do
230                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
231                         for track in tl:iter() do
232                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
233                                 if rv['group'] then drum_group:add(track) end
234                         end
235                 end
236                 channel_count = channel_count + ch
237         end
238
239
240         if rv['check-room'] then
241                 local names = { "Drum Room" }
242                 local ch = 1
243                 if rv["stereo-room"] then ch = 2 end --stereo
244                 for i = 1, #names do
245                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
246                         for track in tl:iter() do
247                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
248                                 if rv['group'] then drum_group:add(track) end
249                         end
250                 end
251                 channel_count = channel_count + ch
252         end
253
254         if rv['check-bass'] then
255                 local names = { rv["name-bass"] }
256                 local ch = 1
257                 if rv["stereo-bass"] then ch = 2 end --stereo
258                 for i = 1, #names do
259                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
260                         for track in tl:iter() do
261                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
262                                 if rv['group'] then bass_group:add(track) end
263                                 if rv['char'] then
264                                         add_lv2_plugin (track, "XT-BC Bass Character (Mono)", 0)
265                                 end
266                         end
267                 end
268                 channel_count = channel_count + ch
269         end
270
271         if rv['check-electric-guitar'] then
272                 local names = { rv["name-electric-guitar"] }
273                 local ch = 1
274                 if rv["stereo-electric-guitar"] then ch = 2 end --stereo
275                 for i = 1, #names do
276                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
277                         for track in tl:iter() do
278                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
279                                 if rv['group'] then guitar_group:add(track) end
280                         end
281                 end
282                 channel_count = channel_count + ch
283         end
284
285         if rv['check-solo-guitar'] then
286                 local names = { rv["name-solo-guitar"] }
287                 local ch = 1
288                 if rv["stereo-solo-guitar"] then ch = 2 end --stereo
289                 for i = 1, #names do
290                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
291                         for track in tl:iter() do
292                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
293                                 if rv['group'] then guitar_group:add(track) end
294                         end
295                 end
296
297                 channel_count = channel_count + ch
298         end
299
300         if rv['check-acoustic-guitar'] then
301                 local names = { rv["name-acoustic-guitar"] }
302                 local ch = 1
303                 if rv["stereo-acoustic-guitar"] then ch = 2 end --stereo
304                 for i = 1, #names do
305                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
306                         for track in tl:iter() do
307                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
308                                 if rv['group'] then guitar_group:add(track) end
309                         end
310                 end
311
312                 channel_count = channel_count + ch
313         end
314
315         if rv['check-piano'] then
316                 local names = { rv["name-piano"] }
317                 local ch = 1
318                 if rv["stereo-piano"] then ch = 2 end --stereo
319                 for i = 1, #names do
320                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
321                         for track in tl:iter() do
322                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
323                                 if rv['group'] then key_group:add(track) end
324                         end
325                 end
326
327                 channel_count = channel_count + ch
328         end
329
330         if rv['check-electric-piano'] then
331                 local names = { rv["name-electric-piano"] }
332                 local ch = 1
333                 if rv["stereo-electric-piano"] then ch = 2 end --stereo
334                 for i = 1, #names do
335                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
336                         for track in tl:iter() do
337                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
338                                 if rv['group'] then key_group:add(track) end
339                         end
340                 end
341                 channel_count = channel_count + ch
342         end
343
344         if rv['check-organ'] then
345                 local names = { rv["name-organ"] }
346                 local ch = 1
347                 if rv["stereo-organ"] then ch = 2 end --stereo
348                 for i = 1, #names do
349                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
350                         for track in tl:iter() do
351                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
352                                 if rv['group'] then key_group:add(track) end
353                         end
354                 end
355                 channel_count = channel_count + ch
356         end
357
358         if rv['check-ldvox'] then
359                 local names = { rv["name-ldvox"] }
360                 local ch = 1
361                 if rv["stereo-ldvox"] then ch = 2 end --stereo
362                 for i = 1, #names do
363                         local tl = Session:new_audio_track ( ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
364                         for track in tl:iter() do
365                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
366                                 if rv['group'] then vox_group:add(track) end
367                                 if rv['char']  then
368                                         add_lv2_plugin (track, "XT-VC Vocal Character (Mono)", 0)
369                                 end
370                         end
371                 end
372                 channel_count = channel_count + ch
373         end
374
375         if rv['check-bgvox'] then
376                 local names = { rv["name-bgvox"] }
377                 local ch = 1
378                 if rv["stereo-bgvox"] then ch = 2 end --stereo
379                 for i = 1, #names do
380                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
381                         for track in tl:iter() do
382                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
383                                 if rv['group'] then vox_group:add(track) end
384                         end
385                 end
386                 channel_count = channel_count + ch
387         end
388
389         --fit all tracks on the screen
390         Editor:access_action("Editor","fit_all_tracks")
391
392         Session:save_state("")
393
394         -- determine the number of channels we can record
395         local e = Session:engine()
396         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"
397         local num_inputs = t[4]:size() -- table 't' holds argument references. t[4] is the C.StringVector (return value)
398
399         if num_inputs < channel_count then
400                 -- warn the user if there are less physical inputs than created tracks
401                 LuaDialog.Message ("Session Creation",
402                         "Created more tracks than there are physical inputs on the soundcard",
403                         LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
404         end
405
406 end end