Track Templates: shorten some of the track names.
[ardour.git] / scripts / _tracks_band.lua
1 ardour {
2         ["type"]    = "TrackSetup",
3         name        = "Live Band Recording Session",
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
19     --prompt the user for the tracks they'd like to instantiate
20         local dialog_options = {
21                 { type = "heading", title = "Select the tracks you'd like\n to add to your session: " },
22
23                 { type = "checkbox", key = "ldvox", default = false, title = "Lead Vocal" },
24
25                 { type = "checkbox", key = "bass", default = false, title = "Bass" },
26
27                 { type = "checkbox", key = "piano", default = false, title = "Piano" },
28                 { type = "checkbox", key = "electric-piano", default = false, title = "Electric Piano" },
29                 { type = "checkbox", key = "organ", default = false, title = "Organ" },
30
31                 { type = "checkbox", key = "electric-guitar", default = false, title = "Electric Guitar" },
32                 { type = "checkbox", key = "solo-guitar", default = false, title = "Lead Guitar" },
33                 { type = "checkbox", key = "accoustic-guitar", default = false, title = "Acoustic Guitar" },
34
35                 { type = "checkbox", key = "basic-kit", default = false, title = "Basic Drum Mics (Kick + Snare)" },
36                 { type = "checkbox", key = "full-kit", default = false, title = "Full Drum Mics (Kick, Snare, HiHat, 3 Toms)" },
37                 { type = "checkbox", key = "overkill-kit", default = false, title = "Overkill Drum Mics (Kick (2x), Snare(2x), HiHat, 3 Toms)" },
38
39                 { type = "checkbox", key = "overhead-mono", default = false, title = "Drum OH (2 mono)" },
40                 { type = "checkbox", key = "overhead-stereo", default = false, title = "Drum OH (Stereo)" },
41
42                 { type = "checkbox", key = "room-mono", default = false, title = "Drum Room (Mono)" },
43                 { type = "checkbox", key = "room-stereo", default = false, title = "Drum Room (Stereo)" },
44
45                 { type = "checkbox", key = "bgvox", default = false, title = "Background Vocals (3x)" },
46
47                 { type = "heading", title = "-------------------" },
48
49                 { type = "checkbox", key = "group", default = false, title = "Group Track(s)?" },
50                 { type = "checkbox", key = "gates", default = false, title = "Add Gate(s)?" },
51                 { type = "checkbox", key = "char", default = false, title = "Add Character Plugin(s)?" },
52         }
53
54         local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
55         local rv = dlg:run()
56         if (not rv) then
57                 return
58         end
59
60         -- helper function to reference processors
61         function processor(t, s) --takes a track (t) and a string (s) as arguments
62                 local i = 0
63                 local proc = t:nth_processor(i)
64                         repeat
65                                 if ( proc:display_name() == s ) then
66                                         return proc
67                                 else
68                                         i = i + 1
69                                 end
70                                 proc = t:nth_processor(i)
71                         until proc:isnil()
72                 end
73
74         --INSTANTIATING MIDI TRACKS IS TOO DAMN HARD
75         function create_midi_track(name, chan_count) -- call this function with a name argument and output channel count
76                 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)
77                 return true
78         end
79
80         if rv['group'] then
81                 drum_group = Session:new_route_group("Drums")
82                 drum_group:set_rgba(0x425CADff)
83                 bass_group = Session:new_route_group("Bass")
84                 bass_group:set_rgba(0x1AE54Eff)
85                 guitar_group = Session:new_route_group("Guitars")
86                 guitar_group:set_rgba(0xB475CBff)
87                 key_group = Session:new_route_group("Keys")
88                 key_group:set_rgba(0xDA8032ff)
89                 vox_group = Session:new_route_group("Vox")
90                 vox_group:set_rgba(0xC54249ff)
91         end
92
93         local track_count = 0;
94         if rv['basic-kit'] then
95                 local names = {"Kick", "Snare"}
96                 for i = 1, #names do
97                 local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
98                         for track in tl:iter() do
99                                 local gate = ARDOUR.LuaAPI.new_plugin(Session, "XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2, "")
100                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
101                                 if rv['group'] then drum_group:add(track) end
102                                 if rv['gates'] then track:add_processor_by_index(eg, 0, nil, true) end
103                         end
104                 end
105
106                 track_count = track_count+2
107         end
108
109         if rv['full-kit'] then
110                 local names = {"Kick", "Snare", "Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
111                 for i = 1, #names do
112                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
113                         for track in tl:iter() do
114                                 local eg = ARDOUR.LuaAPI.new_plugin(Session, "XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2, "")
115                                 local tg = ARDOUR.LuaAPI.new_plugin(Session, "XT-TG Tom Gate (Mono)",      ARDOUR.PluginType.LV2, "")
116                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
117                                 if rv['group'] then drum_group:add(track) end
118                                 if rv['gates'] then
119                                         if string.find(track:name(), '-tom') then
120                                                 track:add_processor_by_index(tg, 0, nil, true)
121                                         else
122                                                 track:add_processor_by_index(eg, 0, nil, true)
123                                         end
124                                 end
125                         end
126                 end
127
128                 track_count = track_count+6
129         end
130
131         if rv['overkill-kit'] then
132                 local names = {"Kick In", "Kick Out", "Snare Top", "Snare Btm", "Hi-Hat", "Hi-tom", "Mid-tom", "Fl-tom"}
133                 for i = 1, #names do
134                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
135                         for track in tl:iter() do
136                                 local eg = ARDOUR.LuaAPI.new_plugin(Session, "XT-EG Expander Gate (Mono)", ARDOUR.PluginType.LV2, "")
137                                 local tg = ARDOUR.LuaAPI.new_plugin(Session, "XT-TG Tom Gate (Mono)",      ARDOUR.PluginType.LV2, "")
138                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
139                                 if rv['group'] then drum_group:add(track) end
140                                 if rv['gates'] then
141                                         if string.find(track:name(), '-tom') then
142                                                 track:add_processor_by_index(tg, 0, nil, true)
143                                         else
144                                                 track:add_processor_by_index(eg, 0, nil, true)
145                                         end
146                                 end
147                         end
148                 end
149
150                 track_count = track_count+8
151         end
152
153         if rv['overhead-mono'] then
154                 local names = {"Drum OHL", "Drum OHR"}
155                 for i = 1, #names do
156                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
157                         for track in tl:iter() do
158                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
159                                 if rv['group'] then drum_group:add(track) end
160                         end
161                 end
162
163                 track_count = track_count+2
164         end
165
166         if rv['overhead-stereo'] then
167                 local names = {"Drum OH (st)"}
168                 for i = 1, #names do
169                         local tl = Session:new_audio_track (2, 2, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
170                         for track in tl:iter() do
171                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
172                                 if rv['group'] then drum_group:add(track) end
173                         end
174                 end
175
176                 track_count = track_count+2
177         end
178
179         if rv['room-mono'] then
180                 local names = {"Drum Room"}
181                 for i = 1, #names do
182                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
183                         for track in tl:iter() do
184                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
185                                 if rv['group'] then drum_group:add(track) end
186                         end
187                 end
188
189                 track_count = track_count+1
190         end
191
192         if rv['room-stereo'] then
193                 local names = {"Drum Room (st)"}
194                 for i = 1, #names do
195                         local tl = Session:new_audio_track (2, 2, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
196                         for track in tl:iter() do
197                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
198                                 if rv['group'] then drum_group:add(track) end
199                         end
200                 end
201
202                 track_count = track_count+2
203         end
204
205         if rv['bass'] then
206                 local names = {"Bass"}
207                 for i = 1, #names do
208                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
209                         for track in tl:iter() do
210                                 local bc = ARDOUR.LuaAPI.new_plugin(Session, "XT-BC Bass Character (Mono)", ARDOUR.PluginType.LV2, "")
211                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
212                                 if rv['group'] then bass_group:add(track) end
213                                 if rv['char'] then track:add_processor_by_index(bc, 0, nil, true) end
214                         end
215                 end
216
217                 track_count = track_count+1
218         end
219
220         if rv['electric-guitar'] then
221                 local names = {"El Guitar"}
222                 for i = 1, #names do
223                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
224                         for track in tl:iter() do
225                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
226                                 if rv['group'] then guitar_group:add(track) end
227                         end
228                 end
229
230                 track_count = track_count+1
231         end
232
233         if rv['solo-guitar'] then
234                 local names = {"Ld Guitar"}
235                 for i = 1, #names do
236                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
237                         for track in tl:iter() do
238                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
239                                 if rv['group'] then guitar_group:add(track) end
240                         end
241                 end
242
243                 track_count = track_count+1
244         end
245
246         if rv['accoustic-guitar'] then
247                 local names = {"Ac Guitar"}
248                 for i = 1, #names do
249                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
250                         for track in tl:iter() do
251                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
252                                 if rv['group'] then guitar_group:add(track) end
253                         end
254                 end
255
256                 track_count = track_count+1
257         end
258
259         if rv['piano'] then
260                 local names = {"Piano"}
261                 for i = 1, #names do
262                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
263                         for track in tl:iter() do
264                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
265                                 if rv['group'] then key_group:add(track) end
266                         end
267                 end
268
269                 track_count = track_count+1
270         end
271
272         if rv['electric-piano'] then
273                 local names = {"E Piano"}
274                 for i = 1, #names do
275                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
276                         for track in tl:iter() do
277                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
278                                 if rv['group'] then key_group:add(track) end
279                         end
280                 end
281
282                 track_count = track_count+1
283         end
284
285         if rv['organ'] then
286                 local names = {"Organ"}
287                 for i = 1, #names do
288                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
289                         for track in tl:iter() do
290                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
291                                 if rv['group'] then key_group:add(track) end
292                         end
293                 end
294
295                 track_count = track_count+1
296         end
297
298         if rv['ldvox'] then
299                 local names = {"Vox"}
300                 for i = 1, #names do
301                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
302                         for track in tl:iter() do
303                                 local vc = ARDOUR.LuaAPI.new_plugin(Session, "XT-VC Vocal Character (Mono)", ARDOUR.PluginType.LV2, "")
304                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
305                                 if rv['group'] then vox_group:add(track) end
306                                 if rv['char']  then track:add_processor_by_index(vc, 0, nil, true) end
307                         end
308                 end
309
310                 track_count = track_count+1
311         end
312
313         if rv['bgvox'] then
314                 local names = {"Bg. Vox 1", "Bg. Vox 2", "Bg. Vox 3"}
315                 for i = 1, #names do
316                         local tl = Session:new_audio_track (1, 1, nil, 1, names[i],  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
317                         for track in tl:iter() do
318                                 --track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
319                                 if rv['group'] then vox_group:add(track) end
320                         end
321                 end
322
323                 track_count = track_count+1
324         end
325
326     --determine the number of tracks we can record
327         local e = Session:engine()
328         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"
329         local num_inputs = t[4]:size();  -- table 't' holds argument references. t[4] is the C.StringVector (return value)
330
331     --ToDo:  if track_count > num_inputs, we should warn the user to check their routing.
332
333     --fit all tracks on the screen
334     Editor:access_action("Editor","fit_all_tracks")
335
336         Session:save_state("");
337 end