88942bd027af8be1e570154d5e471d67f555c8a0
[ardour.git] / scripts / template_band.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Live Band",
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 suggested tracks.
8
9 You may rename each track, and you may choose whether it is mono (default) or stereo.
10
11 Optionally, tracks may be assigned to sensible Groups ( vocals, guitars, drums )
12
13 Each track will be pre-assigned a color corresponding to its group.
14
15 Optionally, tracks may be assigned Gates and other plugins.
16
17 This script is developed in Lua, and can be duplicated and/or modified to meet your needs.
18 ]]
19 }
20
21 function session_setup ()
22         return true
23 end
24
25 function route_setup ()
26         return
27         {
28                 ['Insert_at'] = ARDOUR.PresentationInfo.max_order
29         }
30 end
31
32 function factory (params) return function ()
33
34    --at session load, params will be empty.  in this case we can do things that we -only- want to do if this is a new session
35         if (not params) then
36            Editor:set_toggleaction ("Rulers", "toggle-tempo-ruler", 1)
37            Editor:set_toggleaction ("Rulers", "toggle-meter-ruler", 1)
38
39            Editor:set_toggleaction ("Transport", "primary-clock-bbt", 1)
40            Editor:set_toggleaction ("Transport", "secondary-clock-off", 1)
41
42            Editor:set_toggleaction ("Rulers", "toggle-minsec-ruler", 0)
43            Editor:set_toggleaction ("Rulers", "toggle-samples-ruler", 0)
44            Editor:set_toggleaction ("Rulers", "toggle-bbt-ruler", 1)
45         end
46
47
48         local p         = params or route_setup ()
49         local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order
50
51         --prompt the user for the tracks they'd like to instantiate
52         local dialog_options = {
53                 { type = "heading", title = "Track Type: ", col=0, align = "left", colspan = 1},
54                 { type = "heading", title = "Track Name:", align = "left", col=1, colspan = 1 },
55                 { type = "heading", title = "Stereo?", align = "left", col=2, colspan = 1 },
56
57                 { type = "checkbox", key = "check-ldvox",  default = false,        title = "Lead Vocal", col=0 },
58                 { type = "entry",    key = "name-ldvox",   default = "Ld Vox", title = "", col=1 },
59                 { type = "checkbox", key = "stereo-ldvox", default = false,        title = "", col=2 },
60
61                 { type = "checkbox", key = "check-bass", default = false, title = "Bass", col=0 },
62                 { type = "entry",    key = "name-bass",   default = "Bass", title = "", col=1 },
63                 { type = "checkbox", key = "stereo-bass", default = false,        title = "", col=2 },
64
65                 { type = "checkbox", key = "check-piano", default = false, title = "Piano", col=0 },
66                 { type = "entry",    key = "name-piano",   default = "Piano", title = "", col=1 },
67                 { type = "checkbox", key = "stereo-piano", default = false,        title = "", col=2 },
68
69                 { type = "checkbox", key = "check-electric-piano", default = false, title = "Electric Piano", col=0 },
70                 { type = "entry",    key = "name-electric-piano",   default = "E Piano", title = "", col=1 },
71                 { type = "checkbox", key = "stereo-electric-piano", default = false,        title = "", col=2 },
72
73                 { type = "checkbox", key = "check-organ", default = false, title = "Organ", col=0 },
74                 { type = "entry",    key = "name-organ",   default = "Organ", title = "", col=1 },
75                 { type = "checkbox", key = "stereo-organ", default = false,        title = "", col=2 },
76
77                 { type = "checkbox", key = "check-electric-guitar", default = false, title = "Electric Guitar", col=0 },
78                 { type = "entry",    key = "name-electric-guitar",   default = "E Gtr", title = "", col=1 },
79                 { type = "checkbox", key = "stereo-electric-guitar", default = false,        title = "", col=2 },
80
81                 { type = "checkbox", key = "check-solo-guitar", default = false, title = "Lead Guitar", col=0 },
82                 { type = "entry",    key = "name-solo-guitar",   default = "Ld Gtr", title = "", col=1 },
83                 { type = "checkbox", key = "stereo-solo-guitar", default = false,        title = "", col=2 },
84
85                 { type = "checkbox", key = "check-accoustic-guitar", default = false, title = "Acoustic Guitar", col=0 },
86                 { type = "entry",    key = "name-accoustic-guitar",   default = "Ac Gtr", title = "", col=1 },
87                 { type = "checkbox", key = "stereo-accoustic-guitar", default = false,        title = "", col=2 },
88
89                 { type = "checkbox", key = "check-bgvox", default = false, title = "Background Vocals", col=0 },
90                 { type = "label",  title = "BGV1, BGV2, BGV3", col=1, colspan = 1, align = "left"},
91                 { type = "checkbox", key = "stereo-bgvox", default = false,        title = "", col=2 },
92
93                 { type = "checkbox", key = "check-overhead", default = false, title = "Drum Overheads", col=0 },
94                 { type = "label",  title = "OH {OH L, OH R}", col=1, colspan = 1, align = "left"},
95                 { type = "checkbox", key = "stereo-overhead", default = false,        title = "", col=2 },
96
97                 { type = "checkbox", key = "check-room", default = false, title = "Drum Room", col=0 },
98                 { type = "label",  title = "Room {Rm L, Rm R}", col=1, colspan = 1, align = "left"},
99                 { type = "checkbox", key = "stereo-room", default = false,        title = "", col=2 },
100
101                 { type = "checkbox", key = "check-basic-kit", default = false, title = "Basic Drum Mics", col=0 },
102                 { type = "label",  title = "Kick, Snare", col=1, colspan = 1, align = "left"},
103
104                 { type = "checkbox", key = "check-full-kit", default = false, title = "Full Drum Mics", col=0 },
105                 { type = "label",  title = "Hi-Hat, Hi-tom, Mid-Tom, Fl-Tom", col=1, colspan = 1, align = "left"},
106
107                 { type = "checkbox", key = "check-overkill-kit", default = false, title = "Overkill Drum Mics", col=0 },
108                 { type = "label",  title = "Kick Beater, Snare Btm", col=1, colspan = 1, align = "left"},
109
110                 { type = "hseparator", title="", col=0, colspan = 3},
111
112                 { type = "checkbox", key = "group", default = false, title = "Group Track(s)?", col=0 },
113         }
114
115         --- check for available plugins
116         -- gates
117         local xt_eg = not ARDOUR.LuaAPI.new_plugin_info ("XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2):isnil ()
118         local xt_tg = not ARDOUR.LuaAPI.new_plugin_info ("XT-TG Tom Gate (Mono", ARDOUR.PluginType.LV2):isnil ()
119         -- char
120         local xt_tg = not ARDOUR.LuaAPI.new_plugin_info ("XT-BC Bass Character (Mono)", ARDOUR.PluginType.LV2):isnil ()
121         local xt_vc = not ARDOUR.LuaAPI.new_plugin_info ("XT-VC Vocal Character (Mono)", ARDOUR.PluginType.LV2):isnil ()
122
123         if (xt_eg and xt_tg) then
124                 table.insert (dialog_options,
125                 { type = "checkbox", key = "gates", default = false, title = "Add Gate(s)?", col=0 }
126                 )
127         end
128         if (xt_tg and xt_vc) then
129                 table.insert (dialog_options,
130                 { type = "checkbox", key = "char", default = false, title = "Add Character Plugin(s)?", col=0 }
131                 )
132         end
133
134
135
136         local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
137         local rv = dlg:run()
138         if (not rv) then
139                 return
140         end
141
142         -- helper function to reference processors
143         function processor(t, s) --takes a track (t) and a string (s) as arguments
144                 local i = 0
145                 local proc = t:nth_processor(i)
146                         repeat
147                                 if ( proc:display_name() == s ) then
148                                         return proc
149                                 else
150                                         i = i + 1
151                                 end
152                                 proc = t:nth_processor(i)
153                         until proc:isnil()
154                 end
155
156         --INSTANTIATING MIDI TRACKS IS TOO DAMN HARD
157         function create_midi_track(name, chan_count) -- call this function with a name argument and output channel count
158                 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)
159                 return true
160         end
161
162         function add_lv2_plugin (track, pluginname, position)
163                 local p = ARDOUR.LuaAPI.new_plugin(Session, pluginname, ARDOUR.PluginType.LV2, "")
164                 if not p:isnil () then
165                         track:add_processor_by_index(p, position, nil, true)
166                 end
167         end
168
169
170         local drum_group, bass_group, guitar_group, key_group, vox_group
171
172         if rv['group'] then
173                 drum_group = Session:new_route_group("Drums")
174                 drum_group:set_rgba(0x425CADff)
175                 bass_group = Session:new_route_group("Bass")
176                 bass_group:set_rgba(0x1AE54Eff)
177                 guitar_group = Session:new_route_group("Guitars")
178                 guitar_group:set_rgba(0xB475CBff)
179                 key_group = Session:new_route_group("Keys")
180                 key_group:set_rgba(0xDA8032ff)
181                 vox_group = Session:new_route_group("Vox")
182                 vox_group:set_rgba(0xC54249ff)
183         end
184
185         local channel_count = 0
186
187         if rv['check-basic-kit'] then
188                 local names = {"Kick", "Snare"}
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                                         add_lv2_plugin (track, "XT-EG Expander Gate (Mono)", 0)
196                                 end
197                         end
198                 end
199                 channel_count = channel_count + #names
200         end
201
202         if rv['check-full-kit'] then
203                 local names = {"Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
204                 for i = 1, #names do
205                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
206                         for track in tl:iter() do
207                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
208                                 if rv['group'] then drum_group:add(track) end
209                                 if rv['gates'] then
210                                         if string.find(track:name(), '-tom') then
211                                                 add_lv2_plugin (track, "XT-TG Tom Gate (Mono)", 0)
212                                         else
213                                                 add_lv2_plugin (track, "XT-EG Expander Gate (Mono)", 0)
214                                         end
215                                 end
216                         end
217                 end
218                 channel_count = channel_count + #names
219         end
220
221         if rv['check-overkill-kit'] then
222                 local names = {"Kick Beater", "Snare Btm"}
223                 for i = 1, #names do
224                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
225                         for track in tl:iter() do
226                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
227                                 if rv['group'] then drum_group:add(track) end
228                                 if rv['gates'] then
229                                         if string.find(track:name(), '-tom') then
230                                                 add_lv2_plugin (track, "XT-TG Tom Gate (Mono)", 0)
231                                         else
232                                                 add_lv2_plugin (track, "XT-EG Expander Gate (Mono)", 0)
233                                         end
234                                 end
235                         end
236                 end
237                 channel_count = channel_count + #names
238         end
239
240         if rv['check-overhead'] then
241                 local names = { "OH" }
242                 local ch = 1
243                 if rv["stereo-overhead"] 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
255         if rv['check-room'] then
256                 local names = { "Drum Room" }
257                 local ch = 1
258                 if rv["stereo-room"] then ch = 2 end --stereo
259                 for i = 1, #names do
260                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
261                         for track in tl:iter() do
262                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
263                                 if rv['group'] then drum_group:add(track) end
264                         end
265                 end
266                 channel_count = channel_count + ch
267         end
268
269         if rv['check-bass'] then
270                 local names = { rv["name-bass"] }
271                 local ch = 1
272                 if rv["stereo-bass"] then ch = 2 end --stereo
273                 for i = 1, #names do
274                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
275                         for track in tl:iter() do
276                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
277                                 if rv['group'] then bass_group:add(track) end
278                                 if rv['char'] then
279                                         add_lv2_plugin (track, "XT-BC Bass Character (Mono)", 0)
280                                 end
281                         end
282                 end
283                 channel_count = channel_count + ch
284         end
285
286         if rv['check-electric-guitar'] then
287                 local names = { rv["name-electric-guitar"] }
288                 local ch = 1
289                 if rv["stereo-electric-guitar"] then ch = 2 end --stereo
290                 for i = 1, #names do
291                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
292                         for track in tl:iter() do
293                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
294                                 if rv['group'] then guitar_group:add(track) end
295                         end
296                 end
297                 channel_count = channel_count + ch
298         end
299
300         if rv['check-solo-guitar'] then
301                 local names = { rv["name-solo-guitar"] }
302                 local ch = 1
303                 if rv["stereo-solo-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-acoustic-guitar'] then
316                 local names = { rv["name-acoustic-guitar"] }
317                 local ch = 1
318                 if rv["stereo-acoustic-guitar"] 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 guitar_group:add(track) end
324                         end
325                 end
326
327                 channel_count = channel_count + ch
328         end
329
330         if rv['check-piano'] then
331                 local names = { rv["name-piano"] }
332                 local ch = 1
333                 if rv["stereo-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
342                 channel_count = channel_count + ch
343         end
344
345         if rv['check-electric-piano'] then
346                 local names = { rv["name-electric-piano"] }
347                 local ch = 1
348                 if rv["stereo-electric-piano"] then ch = 2 end --stereo
349                 for i = 1, #names do
350                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
351                         for track in tl:iter() do
352                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
353                                 if rv['group'] then key_group:add(track) end
354                         end
355                 end
356                 channel_count = channel_count + ch
357         end
358
359         if rv['check-organ'] then
360                 local names = { rv["name-organ"] }
361                 local ch = 1
362                 if rv["stereo-organ"] then ch = 2 end --stereo
363                 for i = 1, #names do
364                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
365                         for track in tl:iter() do
366                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
367                                 if rv['group'] then key_group:add(track) end
368                         end
369                 end
370                 channel_count = channel_count + ch
371         end
372
373         if rv['check-ldvox'] then
374                 local names = { rv["name-ldvox"] }
375                 local ch = 1
376                 if rv["stereo-ldvox"] then ch = 2 end --stereo
377                 for i = 1, #names do
378                         local tl = Session:new_audio_track ( ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
379                         for track in tl:iter() do
380                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
381                                 if rv['group'] then vox_group:add(track) end
382                                 if rv['char']  then
383                                         add_lv2_plugin (track, "XT-VC Vocal Character (Mono)", 0)
384                                 end
385                         end
386                 end
387                 channel_count = channel_count + ch
388         end
389
390         if rv['check-bgvox'] then
391                 local names = { rv["name-bgvox"] }
392                 local ch = 1
393                 if rv["stereo-bgvox"] then ch = 2 end --stereo
394                 for i = 1, #names do
395                         local tl = Session:new_audio_track (ch, ch, nil, 1, names[i],  insert_at, ARDOUR.TrackMode.Normal)
396                         for track in tl:iter() do
397                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
398                                 if rv['group'] then vox_group:add(track) end
399                         end
400                 end
401                 channel_count = channel_count + ch
402         end
403
404         --fit all tracks on the screen
405         Editor:access_action("Editor","fit_all_tracks")
406
407         Session:save_state("")
408
409         -- determine the number of channels we can record
410         local e = Session:engine()
411         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"
412         local num_inputs = t[4]:size() -- table 't' holds argument references. t[4] is the C.StringVector (return value)
413
414         if num_inputs < channel_count then
415                 -- warn the user if there are less physical inputs than created tracks
416                 LuaDialog.Message ("Session Creation",
417                         "Created more tracks than there are physical inputs on the soundcard",
418                         LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
419         end
420
421 end end