From 27653eaeba422866e17992237629c2fb0db2dee3 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sun, 21 Dec 2025 16:51:06 +1100 Subject: [PATCH] session: Add new_audio_routes_tracks_bulk() method This allows bulk creating tracks with different name templates. Simply call the bulk method multiple times as required and finally call add_routes() once. --- libs/ardour/ardour/session.h | 16 +++++++++++ libs/ardour/session.cc | 54 ++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 7b89352ceb..ab22ce781a 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -779,6 +779,22 @@ public: bool trigger_visibility = false ); + /* Call this repeatedly with different track name templates and finally call add_routes. + * useful for speeding up imports of various kinds that involve lots of tracks */ + bool new_audio_routes_tracks_bulk ( + RouteList& routes, + std::list >& tracks, + int input_channels, + int output_channels, + std::shared_ptr route_group, + uint32_t how_many, + std::string name_template, + PresentationInfo::order_t order, + TrackMode mode = Normal, + bool input_auto_connect = true, + bool trigger_visibility = false + ); + std::list > new_midi_track ( const ChanCount& input, const ChanCount& output, bool strict_io, std::shared_ptr instrument, diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 40b374512f..0ccb29aab5 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -3004,17 +3004,17 @@ Session::ensure_route_presentation_info_gap (PresentationInfo::order_t first_new /** Caller must not hold process lock * @param name_template string to use for the start of the name, or "" to use "Audio". */ -list< std::shared_ptr > -Session::new_audio_track (int input_channels, int output_channels, std::shared_ptr route_group, - uint32_t how_many, string name_template, PresentationInfo::order_t order, - TrackMode mode, bool input_auto_connect, - bool trigger_visibility) +bool +Session::new_audio_routes_tracks_bulk (RouteList& routes, list< std::shared_ptr >& tracks, + int input_channels, int output_channels, std::shared_ptr route_group, + uint32_t how_many, string name_template, PresentationInfo::order_t order, + TrackMode mode, bool input_auto_connect, + bool trigger_visibility) { string track_name; uint32_t track_id = 0; string port; - RouteList new_routes; - list > ret; + bool ret = true; const string name_pattern = default_track_name_pattern (DataType::AUDIO); bool const use_number = (how_many != 1) || name_template.empty () || (name_template == name_pattern); @@ -3067,8 +3067,8 @@ Session::new_audio_track (int input_channels, int output_channels, std::shared_p track->presentation_info ().set_trigger_track (trigger_visibility); - new_routes.push_back (track); - ret.push_back (track); + routes.push_back (track); + tracks.push_back (track); } catch (failed_constructor &err) { @@ -3085,12 +3085,42 @@ Session::new_audio_track (int input_channels, int output_channels, std::shared_p --how_many; } + return ret; + failed: - if (!new_routes.empty()) { - add_routes (new_routes, input_auto_connect, true, order); + return false; +} + +/** Caller must not hold process lock + * @param name_template string to use for the start of the name, or "" to use "Audio". + */ +list< std::shared_ptr > +Session::new_audio_track (int input_channels, int output_channels, std::shared_ptr route_group, + uint32_t how_many, string name_template, PresentationInfo::order_t order, + TrackMode mode, bool input_auto_connect, + bool trigger_visibility) +{ + RouteList routes; + list > tracks; + + new_audio_routes_tracks_bulk (routes, + tracks, + input_channels, + output_channels, + route_group, + how_many, + name_template, + order, + mode, + input_auto_connect, + trigger_visibility + ); + + if (!routes.empty ()) { + add_routes (routes, input_auto_connect, true, order); } - return ret; + return tracks; } /** Caller must not hold process lock.