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