Cont'd work on route-templates
authorRobin Gareus <robin@gareus.org>
Sat, 19 Aug 2017 22:18:58 +0000 (00:18 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 19 Aug 2017 22:18:58 +0000 (00:18 +0200)
gtk2_ardour/add_route_dialog.cc
gtk2_ardour/session_dialog.cc
scripts/_route_template_example.lua [deleted file]
scripts/_route_template_generic_audio.lua [new file with mode: 0644]
scripts/_route_template_generic_midi.lua [new file with mode: 0644]
scripts/_route_template_interactive_audio.lua [deleted file]
scripts/route_template_interactive_audio.lua [new file with mode: 0644]

index 383039c55b86c96e1fcf48974c7406ab656781a7..05df3c71e36d1e50f1624a3aefb3e95dbfa3276a 100644 (file)
@@ -302,7 +302,7 @@ AddRouteDialog::trk_template_row_selected ()
                        trk_template_desc.set_sensitive (true);
 
                        manual_label.set_sensitive (false);
-                       add_label.set_sensitive (false);
+                       add_label.set_sensitive (rs.find ("how_many") != rs.end ());
                        type_label.set_sensitive (false);
 
                        name_label.set_sensitive (rs.find ("name") != rs.end());
@@ -329,7 +329,9 @@ AddRouteDialog::trk_template_row_selected ()
                        }
 
                        if ((it = rs.find ("how_many")) != rs.end()) {
-                               routes_adjustment.set_value (atoi (it->second.c_str()));
+                               if (atoi (it->second.c_str()) > 0) {
+                                       routes_adjustment.set_value (atoi (it->second.c_str()));
+                               }
                        }
 
                        if ((it = rs.find ("track_mode")) != rs.end()) {
@@ -342,6 +344,8 @@ AddRouteDialog::trk_template_row_selected ()
                                                        mode_combo.set_active_text (_("Tape"));
                                                }
                                                break;
+                                       default: // "NonLayered" enum is still present for session-format compat
+                                               break;
                                }
                        }
 
@@ -368,7 +372,7 @@ AddRouteDialog::trk_template_row_selected ()
                        trk_template_desc.set_sensitive (true);
 
                        manual_label.set_sensitive (false);
-                       add_label.set_sensitive (false);
+                       add_label.set_sensitive (true);
                        type_label.set_sensitive (false);
                        name_label.set_sensitive (true);
                        group_label.set_sensitive (false);
@@ -743,6 +747,7 @@ AddRouteDialog::refill_channel_setups ()
        }
 
        trk_template_model->clear();
+       bool selected_default = false;
 
        /* Add any Lua scripts (factory templates) found in the scripts folder */
        LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction));
@@ -751,7 +756,8 @@ AddRouteDialog::refill_channel_setups ()
                        continue;
                }
                TreeModel::Row row;
-               if ( (*s)->name == "Add tracks") {  //somewhat-special, most-used template
+               if ( (*s)->name == "Create Audio Tracks Interactively" && Profile->get_mixbus ()) {
+                       // somewhat-special, Ben says: "most-used template"
                        row = *(trk_template_model->prepend ());
                } else {
                        row = *(trk_template_model->append ());
@@ -761,8 +767,9 @@ AddRouteDialog::refill_channel_setups ()
                row[track_template_columns.description] = (*s)->description;
                row[track_template_columns.created_with] = _("{Factory Template}");
 
-               if ( (*s)->name == "Add tracks") {  //somewhat-special, most-used template
+               if ((*s)->name == "Create Audio Tracks Interactively" && Profile->get_mixbus ()) {
                        trk_template_chooser.get_selection()->select(row);
+                       selected_default = true;
                }
        }
 
@@ -785,6 +792,10 @@ AddRouteDialog::refill_channel_setups ()
        row[track_template_columns.description] = _("Use the controls, below, to add tracks.");
        row[track_template_columns.created_with] = "";
 
+       if (!selected_default) {
+               trk_template_chooser.get_selection()->select(row);
+       }
+
        set_popdown_strings (channel_combo, channel_combo_strings);
 
        if (!channel_current_choice.empty()) {
index 6741984d7f925d8be14a75dc79c996ba2a32b400..b73514c1aab4910cc0976938d6b0c0b923281e4f 100644 (file)
@@ -568,7 +568,7 @@ SessionDialog::populate_session_templates ()
        LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit));
        for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) {
                TreeModel::Row row = *(template_model->append ());
-               row[session_template_columns.name] = "Meta: " + (*s)->name;
+               row[session_template_columns.name] = (*s)->name;
                row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
                row[session_template_columns.description] = (*s)->description;
                row[session_template_columns.created_with_short] = _("{Factory Template}");
diff --git a/scripts/_route_template_example.lua b/scripts/_route_template_example.lua
deleted file mode 100644 (file)
index a3642bf..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-ardour {
-       ["type"]    = "EditorAction",
-       name        = "Generic Audio Track",
-       description = [[Example ]]
-}
-
--- If a route_setup function is present in an Editor Action Script
--- the script is also listed in the "add track/bus" dialog as meta-template
---
--- The function is expected to return a Lua table. The table may be empty.
-function route_setup ()
-       local e = Session:engine()
-       local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
-       return
-       {
-               -- keys control which AddRouteDialog controls are made sensitive.
-               -- The following keys accept a default value to pre-seed the dialog.
-               ['how_many'] = t[4]:size(),
-               ['name'] = 'Audio',
-               ['channels'] = 2,
-               ['track_mode'] = ARDOUR.TrackMode.Normal,
-               ['strict_io'] = true,
-               -- these keys just need to be set (to something other than nil)
-               -- in order to set the control sensitives
-               ['insert_at'] = ARDOUR.PresentationInfo.max_order,
-               ['group'] = false, -- return value will be a RouteGroup*
-               ['instrument'] = nil, -- return value will be a PluginInfoPtr
-       }
-end
-
--- The Script can be used as EditorAction in which case it can
--- optionally provide instantiation parmaters
-function action_params ()
-       return
-       {
-               ['how_many'] = { title = "How Many tracks to add", default = "1" },
-               ["name"]     = { title = "Track Name Prefix", default = "Audio" },
-       }
-end
-
-
-function factory (params) return function ()
-       -- When called from the AddRouteDialog, 'params' will be a table with
-       -- keys as described in route_setup() above.
-
-       local p         = params or route_setup ()
-       local name      = p["name"] or 'Audio'
-       local how_many  = p["how_many"] or 1
-       local channels  = p["channels"] or 1
-       local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
-       local group     = p["group"] or nil
-       local mode      = p["track_mode"] or ARDOUR.TrackMode.Normal
-       local strict_io = p["strict_io"] or false
-       local chan_out  = 0
-
-       if ARDOUR.config():get_output_auto_connect() == ARDOUR.AutoConnectOption.AutoConnectMaster then
-               if not Session:master_out():isnil() then
-                       chan_out = Session:master_out():n_inputs ():n_audio ()
-               end
-       end
-
-       if chan_out == 0 then
-               chan_out = channels;
-       end
-
-       local tl = Session:new_audio_track (channels, chan_out, group, how_many, name, insert_at, mode)
-
-       if strict_io then
-               for t in tl:iter() do
-                       t:set_strict_io (true)
-               end
-       end
-
-end end
diff --git a/scripts/_route_template_generic_audio.lua b/scripts/_route_template_generic_audio.lua
new file mode 100644 (file)
index 0000000..a3642bf
--- /dev/null
@@ -0,0 +1,74 @@
+ardour {
+       ["type"]    = "EditorAction",
+       name        = "Generic Audio Track",
+       description = [[Example ]]
+}
+
+-- If a route_setup function is present in an Editor Action Script
+-- the script is also listed in the "add track/bus" dialog as meta-template
+--
+-- The function is expected to return a Lua table. The table may be empty.
+function route_setup ()
+       local e = Session:engine()
+       local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
+       return
+       {
+               -- keys control which AddRouteDialog controls are made sensitive.
+               -- The following keys accept a default value to pre-seed the dialog.
+               ['how_many'] = t[4]:size(),
+               ['name'] = 'Audio',
+               ['channels'] = 2,
+               ['track_mode'] = ARDOUR.TrackMode.Normal,
+               ['strict_io'] = true,
+               -- these keys just need to be set (to something other than nil)
+               -- in order to set the control sensitives
+               ['insert_at'] = ARDOUR.PresentationInfo.max_order,
+               ['group'] = false, -- return value will be a RouteGroup*
+               ['instrument'] = nil, -- return value will be a PluginInfoPtr
+       }
+end
+
+-- The Script can be used as EditorAction in which case it can
+-- optionally provide instantiation parmaters
+function action_params ()
+       return
+       {
+               ['how_many'] = { title = "How Many tracks to add", default = "1" },
+               ["name"]     = { title = "Track Name Prefix", default = "Audio" },
+       }
+end
+
+
+function factory (params) return function ()
+       -- When called from the AddRouteDialog, 'params' will be a table with
+       -- keys as described in route_setup() above.
+
+       local p         = params or route_setup ()
+       local name      = p["name"] or 'Audio'
+       local how_many  = p["how_many"] or 1
+       local channels  = p["channels"] or 1
+       local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
+       local group     = p["group"] or nil
+       local mode      = p["track_mode"] or ARDOUR.TrackMode.Normal
+       local strict_io = p["strict_io"] or false
+       local chan_out  = 0
+
+       if ARDOUR.config():get_output_auto_connect() == ARDOUR.AutoConnectOption.AutoConnectMaster then
+               if not Session:master_out():isnil() then
+                       chan_out = Session:master_out():n_inputs ():n_audio ()
+               end
+       end
+
+       if chan_out == 0 then
+               chan_out = channels;
+       end
+
+       local tl = Session:new_audio_track (channels, chan_out, group, how_many, name, insert_at, mode)
+
+       if strict_io then
+               for t in tl:iter() do
+                       t:set_strict_io (true)
+               end
+       end
+
+end end
diff --git a/scripts/_route_template_generic_midi.lua b/scripts/_route_template_generic_midi.lua
new file mode 100644 (file)
index 0000000..a62197d
--- /dev/null
@@ -0,0 +1,78 @@
+ardour {
+       ["type"]    = "EditorAction",
+       name        = "Generic MIDI Track",
+       description = [[Example]]
+}
+
+-- If a route_setup function is present in an Editor Action Script
+-- the script is also listed in the "add track/bus" dialog as meta-template
+--
+-- The function is expected to return a Lua table. The table may be empty.
+function route_setup ()
+       return
+       {
+               -- keys control which AddRouteDialog controls are made sensitive.
+               -- The following keys accept a default value to pre-seed the dialog.
+               ['how_many'] = 1,
+               ['name'] = 'MIDI',
+               ['channels'] = nil,
+               ['track_mode'] = nil,
+               ['strict_io'] = true,
+               -- these keys just need to be set (to something other than nil)
+               -- in order to set the control sensitives
+               ['insert_at'] = ARDOUR.PresentationInfo.max_order,
+               ['group'] = false, -- return value will be a RouteGroup*
+               ['instrument'] = true, -- return value will be a PluginInfoPtr
+       }
+end
+
+-- The Script can be used as EditorAction in which case it can
+-- optionally provide instantiation parmaters
+function action_params ()
+       return
+       {
+               ['how_many']   = { title = "How Many tracks to add", default = "1" },
+               ["name"]       = { title = "Track Name Prefix", default = "MIDI" },
+               ["instrument"] = { title = "Add Instrument", default = "true" },
+       }
+end
+
+
+function factory (params) return function ()
+       -- When called from the AddRouteDialog, 'params' will be a table with
+       -- keys as described in route_setup() above.
+
+       local p          = params or route_setup ()
+       local name       = p["name"] or 'Audio'
+       local how_many   = p["how_many"] or 1
+       local insert_at  = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
+       local group      = p["group"] or nil
+       local strict_io  = p["strict_io"] or false
+       local instrument = p["instrument"] or nil
+
+       -- used in 'action-script mode'
+       if instrument == "true" then
+               instrument = ARDOUR.LuaAPI.new_plugin_info ("http://gareus.org/oss/lv2/gmsynth", ARDOUR.PluginType.LV2) -- general midi synth
+               if instrument:isnil () then
+                       instrument = ARDOUR.LuaAPI.new_plugin_info ("https://community.ardour.org/node/7596", ARDOUR.PluginType.LV2) -- reasonable synth
+               end
+               if instrument:isnil () then
+                       LuaDialog.Message ("MIDI track add", "Cannot find instrument plugin",
+                               LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
+                       return
+               end
+       end
+
+       -- add no instrument
+       if type (instrument) ~= "userdata" then
+               instrument = ARDOUR.PluginInfo ()
+       end
+
+       Session:new_midi_track(
+               ARDOUR.ChanCount(ARDOUR.DataType ("midi"), 1),
+               ARDOUR.ChanCount(ARDOUR.DataType ("audio"), 2),
+               strict_io,
+               instrument, nil,
+               group, how_many, name, insert_at, ARDOUR.TrackMode.Normal)
+
+end end
diff --git a/scripts/_route_template_interactive_audio.lua b/scripts/_route_template_interactive_audio.lua
deleted file mode 100644 (file)
index e53eab4..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-ardour {
-       ["type"]    = "EditorAction",
-       name        = "Create Audio Tracks interactively",
-       description = [[
-This template creates audio tracks.
-
-You will be prompted for:
-... the number of tracks to add
-... the name of the tracks ( default: Audio %d )
-... whether they are mono or stereo (default mono)
-... whether to record-arm the tracks (default: no)
-]]
-}
-
-function route_setup ()
-       return
-       {
-               ['Insert_at'] = ARDOUR.PresentationInfo.max_order;
-       }
-end
-
-function factory (params) return function ()
-       local p         = params or route_setup ()
-       local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
-
-       local e = Session:engine()
-       -- from the engine's POV readable/capture ports are "outputs"
-       local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
-       -- table 't' holds argument references. t[4] is the C.StringVector (return value)
-       local tracks = t[4]:size();
-
-       local dialog_options = {
-               { type = "number", key = "tracks", title = "Create Tracks",  min = 1, max = 128, step = 1, digits = 0, default = tracks },
-               { type = "checkbox", key = "recarm", default = false, title = "Record Arm Tracks" },
-       }
-
-       local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
-       local rv = dlg:run()
-       if (not rv or rv['tracks'] == 0) then
-               return
-       end
-
-       -- create tracks
-       local tl = Session:new_audio_track (1, 1, nil, rv['tracks'], "", insert_at, ARDOUR.TrackMode.Normal)
-       -- and optionally record-arm them
-       if rv['recarm'] then
-               for track in tl:iter() do
-                       track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
-               end
-       end
-end end
diff --git a/scripts/route_template_interactive_audio.lua b/scripts/route_template_interactive_audio.lua
new file mode 100644 (file)
index 0000000..99cdf7f
--- /dev/null
@@ -0,0 +1,51 @@
+ardour {
+       ["type"]    = "EditorAction",
+       name        = "Create Audio Tracks Interactively",
+       description = [[
+This template creates audio tracks.
+
+You will be prompted for:
+... the number of tracks to add
+... the name of the tracks ( default: Audio %d )
+... whether they are mono or stereo (default mono)
+... whether to record-arm the tracks (default: no)
+]]
+}
+
+function route_setup ()
+       return
+       {
+               ['Insert_at'] = ARDOUR.PresentationInfo.max_order;
+       }
+end
+
+function factory (params) return function ()
+       local p         = params or route_setup ()
+       local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
+
+       local e = Session:engine()
+       -- from the engine's POV readable/capture ports are "outputs"
+       local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
+       -- table 't' holds argument references. t[4] is the C.StringVector (return value)
+       local tracks = t[4]:size();
+
+       local dialog_options = {
+               { type = "number", key = "tracks", title = "Create Tracks",  min = 1, max = 128, step = 1, digits = 0, default = tracks },
+               { type = "checkbox", key = "recarm", default = false, title = "Record Arm Tracks" },
+       }
+
+       local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
+       local rv = dlg:run()
+       if (not rv or rv['tracks'] == 0) then
+               return
+       end
+
+       -- create tracks
+       local tl = Session:new_audio_track (1, 1, nil, rv['tracks'], "", insert_at, ARDOUR.TrackMode.Normal)
+       -- and optionally record-arm them
+       if rv['recarm'] then
+               for track in tl:iter() do
+                       track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
+               end
+       end
+end end