From 3c3a204ad32cfa167efa193b472a7b8103734613 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 17 Aug 2006 02:12:20 +0000 Subject: further optimizations for multiple-track-at-once addition. as in "whoah!" git-svn-id: svn://localhost/ardour2/trunk@836 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.cc | 34 +++---- gtk2_ardour/ardour_ui.h | 4 +- gtk2_ardour/ardour_ui_ed.cc | 2 +- gtk2_ardour/editor.h | 2 +- gtk2_ardour/editor_audio_import.cc | 4 +- gtk2_ardour/editor_route_list.cc | 108 +++++++++++----------- gtk2_ardour/mixer_ui.cc | 62 ++++++------- gtk2_ardour/mixer_ui.h | 2 +- gtk2_ardour/route_params_ui.cc | 35 ++++---- gtk2_ardour/route_params_ui.h | 2 +- gtk2_ardour/route_ui.cc | 1 - libs/ardour/ardour/session.h | 8 +- libs/ardour/audioengine.cc | 2 - libs/ardour/session.cc | 177 +++++++++++++++++++++---------------- libs/ardour/session_state.cc | 5 +- 15 files changed, 243 insertions(+), 205 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 345f715d39..66374ff417 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -874,21 +874,21 @@ ARDOUR_UI::session_add_midi_track () } void -ARDOUR_UI::session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many) +ARDOUR_UI::session_add_audio_route (bool track, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many) { - boost::shared_ptr route; - vector > routes; + list > tracks; + Session::RouteList routes; if (session == 0) { - warning << _("You cannot add a track without a session already loaded.") << endmsg; + warning << _("You cannot add a track or bus without a session already loaded.") << endmsg; return; } try { - if (disk) { - routes = session->new_audio_track (input_channels, output_channels, mode, how_many); + if (track) { + tracks = session->new_audio_track (input_channels, output_channels, mode, how_many); - if (routes.size() != how_many) { + if (tracks.size() != how_many) { if (how_many == 1) { error << _("could not create a new audio track") << endmsg; } else { @@ -897,8 +897,15 @@ ARDOUR_UI::session_add_audio_route (bool disk, int32_t input_channels, int32_t o } } else { - if ((route = session->new_audio_route (input_channels, output_channels)) == 0) { - error << _("could not create new audio bus") << endmsg; + + routes = session->new_audio_route (input_channels, output_channels, how_many); + + if (routes.size() != how_many) { + if (how_many == 1) { + error << _("could not create a new audio track") << endmsg; + } else { + error << string_compose (_("could not create %1 new audio tracks"), how_many) << endmsg; + } } } @@ -2086,14 +2093,7 @@ ARDOUR_UI::add_route () if (track) { session_add_audio_track (input_chan, output_chan, add_route_dialog->mode(), count); } else { - while (count) { - session_add_audio_bus (input_chan, output_chan); - } - --count; - - while (Main::events_pending()) { - Main::iteration (); - } + session_add_audio_bus (input_chan, output_chan, count); } } diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index ebb5c76838..cafa335bf2 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -193,8 +193,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI session_add_audio_route (true, input_channels, output_channels, mode, how_many); } - void session_add_audio_bus (int input_channels, int32_t output_channels) { - session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, 1); + void session_add_audio_bus (int input_channels, int32_t output_channels, uint32_t how_many) { + session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, how_many); } void session_add_midi_track (); diff --git a/gtk2_ardour/ardour_ui_ed.cc b/gtk2_ardour/ardour_ui_ed.cc index 3d8e99ad6e..7b461b1d5c 100644 --- a/gtk2_ardour/ardour_ui_ed.cc +++ b/gtk2_ardour/ardour_ui_ed.cc @@ -196,7 +196,7 @@ ARDOUR_UI::install_actions () act = ActionManager::register_action (common_actions, X_("AddAudioTrack"), _("Add Audio Track"), bind (mem_fun(*this, &ARDOUR_UI::session_add_audio_track), 1, 1, ARDOUR::Normal, 1)); ActionManager::session_sensitive_actions.push_back (act); - act = ActionManager::register_action (common_actions, X_("AddAudioBus"), _("Add Audio Bus"), bind (mem_fun(*this, &ARDOUR_UI::session_add_audio_bus), 1, 1)); + act = ActionManager::register_action (common_actions, X_("AddAudioBus"), _("Add Audio Bus"), bind (mem_fun(*this, &ARDOUR_UI::session_add_audio_bus), 1, 1, 1)); ActionManager::session_sensitive_actions.push_back (act); act = ActionManager::register_action (common_actions, X_("Save"), _("Save"), bind (mem_fun(*this, &ARDOUR_UI::save_state), string(""))); ActionManager::session_sensitive_actions.push_back (act); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 5ddb2b0d2e..dd62a4dd75 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -466,7 +466,7 @@ class Editor : public PublicEditor void add_crossfade_context_items (AudioStreamView*, ARDOUR::Crossfade*, Gtk::Menu_Helpers::MenuList&, bool many); void add_selection_context_items (Gtk::Menu_Helpers::MenuList&); - void handle_new_route (boost::shared_ptr); + void handle_new_route (ARDOUR::Session::RouteList&); void remove_route (TimeAxisView *); bool route_removal; diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 4128348e3a..71e28c9a1d 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -332,7 +332,7 @@ Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32 case ImportAsTrack: { - vector > at (session->new_audio_track (in_chans, out_chans, Normal, 1)); + list > at (session->new_audio_track (in_chans, out_chans, Normal, 1)); if (!at.empty()) { copy = new AudioRegion (region); at.front()->diskstream()->playlist()->add_region (*copy, pos); @@ -342,7 +342,7 @@ Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32 case ImportAsTapeTrack: { - vector > at (session->new_audio_track (in_chans, out_chans, Destructive)); + list > at (session->new_audio_track (in_chans, out_chans, Destructive)); if (!at.empty()) { copy = new AudioRegion (region); at.front()->diskstream()->playlist()->add_region (*copy, pos); diff --git a/gtk2_ardour/editor_route_list.cc b/gtk2_ardour/editor_route_list.cc index c93cf9aba2..573dec0fd5 100644 --- a/gtk2_ardour/editor_route_list.cc +++ b/gtk2_ardour/editor_route_list.cc @@ -39,72 +39,76 @@ using namespace PBD; using namespace Gtk; void -Editor::handle_new_route (boost::shared_ptr route) +Editor::handle_new_route (Session::RouteList& routes) { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), route)); + ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes)); TimeAxisView *tv; AudioTimeAxisView *atv; TreeModel::Row parent; TreeModel::Row row; - if (route->hidden()) { - return; - } - - tv = new AudioTimeAxisView (*this, *session, route, track_canvas); + for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) { + boost::shared_ptr route = (*x); + if (route->hidden()) { + return; + } + + tv = new AudioTimeAxisView (*this, *session, route, track_canvas); + #if 0 - if (route_display_model->children().size() == 0) { + if (route_display_model->children().size() == 0) { + + /* set up basic entries */ + + TreeModel::Row row; + + row = *(route_display_model->append()); // path = "0" + row[route_display_columns.text] = _("Busses"); + row[route_display_columns.tv] = 0; + row = *(route_display_model->append()); // path = "1" + row[route_display_columns.text] = _("Tracks"); + row[route_display_columns.tv] = 0; + + } - /* set up basic entries */ - - TreeModel::Row row; + if (dynamic_cast(route.get()) != 0) { + TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks + parent = *iter; + } else { + TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses + parent = *iter; + } - row = *(route_display_model->append()); // path = "0" - row[route_display_columns.text] = _("Busses"); - row[route_display_columns.tv] = 0; - row = *(route_display_model->append()); // path = "1" - row[route_display_columns.text] = _("Tracks"); - row[route_display_columns.tv] = 0; - - } - - if (dynamic_cast(route.get()) != 0) { - TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks - parent = *iter; - } else { - TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses - parent = *iter; - } - - - row = *(route_display_model->append (parent.children())); + + row = *(route_display_model->append (parent.children())); #else - row = *(route_display_model->append ()); + row = *(route_display_model->append ()); #endif - - row[route_display_columns.text] = route->name(); - row[route_display_columns.visible] = tv->marked_for_display(); - row[route_display_columns.tv] = tv; - - track_views.push_back (tv); - - ignore_route_list_reorder = true; - - if ((atv = dynamic_cast (tv)) != 0) { - /* added a new fresh one at the end */ - if (atv->route()->order_key(N_("editor")) == -1) { - atv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1); + + row[route_display_columns.text] = route->name(); + row[route_display_columns.visible] = tv->marked_for_display(); + row[route_display_columns.tv] = tv; + + track_views.push_back (tv); + + ignore_route_list_reorder = true; + + if ((atv = dynamic_cast (tv)) != 0) { + /* added a new fresh one at the end */ + if (atv->route()->order_key(N_("editor")) == -1) { + atv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1); + } } + + ignore_route_list_reorder = false; + + route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes)); + + tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv)); } - ignore_route_list_reorder = false; - - route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes)); - - tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv)); - editor_mixer_button.set_sensitive(true); } @@ -491,9 +495,7 @@ Editor::initial_route_list_display () route_display_model->clear (); - for (Session::RouteList::iterator i = r.begin(); i != r.end(); ++i) { - handle_new_route (*i); - } + handle_new_route (r); no_route_list_redisplay = false; diff --git a/gtk2_ardour/mixer_ui.cc b/gtk2_ardour/mixer_ui.cc index c2eb588b2f..84fade5472 100644 --- a/gtk2_ardour/mixer_ui.cc +++ b/gtk2_ardour/mixer_ui.cc @@ -251,38 +251,42 @@ Mixer_UI::show_window () } void -Mixer_UI::add_strip (boost::shared_ptr route) +Mixer_UI::add_strip (Session::RouteList& routes) { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &Mixer_UI::add_strip), route)); + ENSURE_GUI_THREAD(bind (mem_fun(*this, &Mixer_UI::add_strip), routes)); MixerStrip* strip; - if (route->hidden()) { - return; - } - - strip = new MixerStrip (*this, *session, route); - strips.push_back (strip); - - strip->set_width (_strip_width); - show_strip (strip); - - no_track_list_redisplay = true; - - TreeModel::Row row = *(track_model->append()); - row[track_columns.text] = route->name(); - - row[track_columns.visible] = true; - row[track_columns.route] = route; - row[track_columns.strip] = strip; - - no_track_list_redisplay = false; - redisplay_track_list (); - - route->name_changed.connect (bind (mem_fun(*this, &Mixer_UI::strip_name_changed), strip)); - strip->GoingAway.connect (bind (mem_fun(*this, &Mixer_UI::remove_strip), strip)); + for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) { + boost::shared_ptr route = (*x); - strip->signal_button_release_event().connect (bind (mem_fun(*this, &Mixer_UI::strip_button_release_event), strip)); + if (route->hidden()) { + return; + } + + strip = new MixerStrip (*this, *session, route); + strips.push_back (strip); + + strip->set_width (_strip_width); + show_strip (strip); + + no_track_list_redisplay = true; + + TreeModel::Row row = *(track_model->append()); + row[track_columns.text] = route->name(); + + row[track_columns.visible] = true; + row[track_columns.route] = route; + row[track_columns.strip] = strip; + + no_track_list_redisplay = false; + redisplay_track_list (); + + route->name_changed.connect (bind (mem_fun(*this, &Mixer_UI::strip_name_changed), strip)); + strip->GoingAway.connect (bind (mem_fun(*this, &Mixer_UI::remove_strip), strip)); + + strip->signal_button_release_event().connect (bind (mem_fun(*this, &Mixer_UI::strip_button_release_event), strip)); + } } void @@ -623,9 +627,7 @@ Mixer_UI::initial_track_display () track_model->clear (); - for (Session::RouteList::iterator i = copy.begin(); i != copy.end(); ++i) { - add_strip (*i); - } + add_strip (copy); no_track_list_redisplay = false; diff --git a/gtk2_ardour/mixer_ui.h b/gtk2_ardour/mixer_ui.h index 6fe4120427..77021dc8fe 100644 --- a/gtk2_ardour/mixer_ui.h +++ b/gtk2_ardour/mixer_ui.h @@ -111,7 +111,7 @@ class Mixer_UI : public Gtk::Window bool strip_scroller_button_release (GdkEventButton*); - void add_strip (boost::shared_ptr); + void add_strip (ARDOUR::Session::RouteList&); void remove_strip (MixerStrip *); void hide_all_strips (bool with_select); diff --git a/gtk2_ardour/route_params_ui.cc b/gtk2_ardour/route_params_ui.cc index 8d8efad8a2..c23ed272e1 100644 --- a/gtk2_ardour/route_params_ui.cc +++ b/gtk2_ardour/route_params_ui.cc @@ -159,22 +159,26 @@ RouteParams_UI::~RouteParams_UI () } void -RouteParams_UI::add_route (boost::shared_ptr route) +RouteParams_UI::add_routes (Session::RouteList& routes) { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::add_route), route)); + ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::add_routes), routes)); - if (route->hidden()) { - return; - } - - TreeModel::Row row = *(route_display_model->append()); - row[route_display_columns.text] = route->name(); - row[route_display_columns.route] = route; + for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) { + boost::shared_ptr route = (*x); - //route_select_list.rows().back().select (); - - route->name_changed.connect (bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route)); - route->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::route_removed), route)); + if (route->hidden()) { + return; + } + + TreeModel::Row row = *(route_display_model->append()); + row[route_display_columns.text] = route->name(); + row[route_display_columns.route] = route; + + //route_select_list.rows().back().select (); + + route->name_changed.connect (bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route)); + route->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::route_removed), route)); + } } @@ -355,9 +359,10 @@ RouteParams_UI::set_session (Session *sess) route_display_model->clear(); if (session) { - session->foreach_route (this, &RouteParams_UI::add_route); + boost::shared_ptr r = session->get_routes(); + add_routes (*r); session->going_away.connect (mem_fun(*this, &ArdourDialog::session_gone)); - session->RouteAdded.connect (mem_fun(*this, &RouteParams_UI::add_route)); + session->RouteAdded.connect (mem_fun(*this, &RouteParams_UI::add_routes)); start_updating (); } else { stop_updating (); diff --git a/gtk2_ardour/route_params_ui.h b/gtk2_ardour/route_params_ui.h index 5f487d6e5c..eff31023f7 100644 --- a/gtk2_ardour/route_params_ui.h +++ b/gtk2_ardour/route_params_ui.h @@ -159,7 +159,7 @@ class RouteParams_UI : public ArdourDialog Glib::RefPtr route_display_model; - void add_route (boost::shared_ptr); + void add_routes (ARDOUR::Session::RouteList&); void route_name_changed (void *src, boost::shared_ptr route); void route_removed (boost::shared_ptr route); diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index b2fdcaf7d4..2b95ff9cfb 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -733,7 +733,6 @@ void RouteUI::route_removed () { ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::route_removed)); - cerr << "Route UI @ " << this << " destroyed by impending end of route\n"; delete this; } diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 757d13f79b..78f6011369 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -345,7 +345,7 @@ class Session : public sigc::trackable, public Stateful sigc::signal DurationChanged; sigc::signal HaltOnXrun; - sigc::signal > RouteAdded; + sigc::signal RouteAdded; void request_roll (); void request_bounded_roll (jack_nframes_t start, jack_nframes_t end); @@ -536,8 +536,8 @@ class Session : public sigc::trackable, public Stateful /* fundamental operations. duh. */ - std::vector > new_audio_track (int input_channels, int output_channels, TrackMode mode = Normal, uint32_t how_many = 1); - boost::shared_ptr new_audio_route (int input_channels, int output_channels); + std::list > new_audio_track (int input_channels, int output_channels, TrackMode mode = Normal, uint32_t how_many = 1); + RouteList new_audio_route (int input_channels, int output_channels, uint32_t how_many); void remove_route (boost::shared_ptr); @@ -1517,7 +1517,7 @@ class Session : public sigc::trackable, public Stateful SerializedRCUManager routes; - void add_route (boost::shared_ptr, bool save = true); + void add_routes (RouteList&, bool save = true); uint32_t destructive_index; int load_routes (const XMLNode&); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 5f86f21762..14593d9712 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -760,7 +760,6 @@ AudioEngine::get_physical_inputs (vector& ins) for (i = 0; ports[i]; ++i) { ins.push_back (ports[i]); } - cerr << "got " << ins.size() << " physical ins\n"; free (ports); } } @@ -783,7 +782,6 @@ AudioEngine::get_physical_outputs (vector& outs) for (i = 0; ports[i]; ++i) { outs.push_back (ports[i]); } - cerr << "got " << outs.size() << " physical outs\n"; free (ports); } } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index dfa7468725..43311e77e4 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -327,13 +327,17 @@ Session::Session (AudioEngine &eng, if (control_out_channels) { shared_ptr r (new Route (*this, _("monitor"), -1, control_out_channels, -1, control_out_channels, Route::ControlOut)); - add_route (r); + RouteList rl; + rl.push_back (r); + add_routes (rl); _control_out = r; } if (master_out_channels) { shared_ptr r (new Route (*this, _("master"), -1, master_out_channels, -1, master_out_channels, Route::MasterOut)); - add_route (r); + RouteList rl; + rl.push_back (r); + add_routes (rl); _master_out = r; } else { /* prohibit auto-connect to master, because there isn't one */ @@ -1669,7 +1673,7 @@ Session::resort_routes_using (shared_ptr r) } -vector > +list > Session::new_audio_track (int input_channels, int output_channels, TrackMode mode, uint32_t how_many) { char track_name[32]; @@ -1677,7 +1681,8 @@ Session::new_audio_track (int input_channels, int output_channels, TrackMode mod uint32_t n = 0; uint32_t channels_used = 0; string port; - vector > ret; + RouteList new_routes; + list > ret; /* count existing audio tracks */ @@ -1791,6 +1796,7 @@ Session::new_audio_track (int input_channels, int output_channels, TrackMode mod track->DiskstreamChanged.connect (mem_fun (this, &Session::resort_routes)); track->set_remote_control_id (ntracks()); + new_routes.push_back (track); ret.push_back (track); } @@ -1804,23 +1810,22 @@ Session::new_audio_track (int input_channels, int output_channels, TrackMode mod --how_many; } - if (!ret.empty()) { - for (vector >::iterator x = ret.begin(); x != ret.end(); ++x) { - add_route ((*x), false); - } - + if (!new_routes.empty()) { + add_routes (new_routes, false); save_state (_current_snapshot_name); } return ret; } -shared_ptr -Session::new_audio_route (int input_channels, int output_channels) +Session::RouteList +Session::new_audio_route (int input_channels, int output_channels, uint32_t how_many) { char bus_name[32]; + uint32_t bus_id = 1; uint32_t n = 0; string port; + RouteList ret; /* count existing audio busses */ @@ -1830,101 +1835,125 @@ Session::new_audio_route (int input_channels, int output_channels) for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { if (dynamic_cast((*i).get()) == 0) { if (!(*i)->hidden()) { - n++; + bus_id++; } } } } - do { - snprintf (bus_name, sizeof(bus_name), "Bus %" PRIu32, n+1); - if (route_by_name (bus_name) == 0) { - break; - } - n++; + vector physinputs; + vector physoutputs; - } while (n < (UINT_MAX-1)); + _engine.get_physical_outputs (physoutputs); + _engine.get_physical_inputs (physinputs); - try { - shared_ptr bus (new Route (*this, bus_name, -1, -1, -1, -1, Route::Flag(0), DataType::AUDIO)); + while (how_many) { - if (bus->ensure_io (input_channels, output_channels, false, this)) { - error << string_compose (_("cannot configure %1 in/%2 out configuration for new audio track"), - input_channels, output_channels) - << endmsg; - } + do { + ++bus_id; - for (uint32_t x = 0; x < bus->n_inputs(); ++x) { - - port = ""; + snprintf (bus_name, sizeof(bus_name), "Bus %" PRIu32, bus_id); - if (input_auto_connect & AutoConnectPhysical) { - port = _engine.get_nth_physical_input ((n+x)%n_physical_inputs); - } - - if (port.length() && bus->connect_input (bus->input (x), port, this)) { + if (route_by_name (bus_name) == 0) { break; } - } - for (uint32_t x = 0; x < bus->n_outputs(); ++x) { - - port = ""; + } while (bus_id < (UINT_MAX-1)); - if (output_auto_connect & AutoConnectPhysical) { - port = _engine.get_nth_physical_input ((n+x)%n_physical_outputs); - } else if (output_auto_connect & AutoConnectMaster) { - if (_master_out) { - port = _master_out->input (x%_master_out->n_inputs())->name(); + try { + shared_ptr bus (new Route (*this, bus_name, -1, -1, -1, -1, Route::Flag(0), DataType::AUDIO)); + + if (bus->ensure_io (input_channels, output_channels, false, this)) { + error << string_compose (_("cannot configure %1 in/%2 out configuration for new audio track"), + input_channels, output_channels) + << endmsg; + } + + for (uint32_t x = 0; x < bus->n_inputs(); ++x) { + + port = ""; + + if (input_auto_connect & AutoConnectPhysical) { + port = physinputs[((n+x)%n_physical_inputs)]; + } + + if (port.length() && bus->connect_input (bus->input (x), port, this)) { + break; } } - - if (port.length() && bus->connect_output (bus->output (x), port, this)) { - break; + + for (uint32_t x = 0; x < bus->n_outputs(); ++x) { + + port = ""; + + if (output_auto_connect & AutoConnectPhysical) { + port = physoutputs[((n+x)%n_physical_outputs)]; + } else if (output_auto_connect & AutoConnectMaster) { + if (_master_out) { + port = _master_out->input (x%_master_out->n_inputs())->name(); + } + } + + if (port.length() && bus->connect_output (bus->output (x), port, this)) { + break; + } + } + + if (_control_out) { + vector cports; + uint32_t ni = _control_out->n_inputs(); + + for (uint32_t n = 0; n < ni; ++n) { + cports.push_back (_control_out->input(n)->name()); + } + bus->set_control_outs (cports); } - } - if (_control_out) { - vector cports; - uint32_t ni = _control_out->n_inputs(); + ret.push_back (bus); + } + - for (uint32_t n = 0; n < ni; ++n) { - cports.push_back (_control_out->input(n)->name()); - } - bus->set_control_outs (cports); + catch (failed_constructor &err) { + error << _("Session: could not create new audio route.") << endmsg; + ret.clear (); + return ret; } - - add_route (bus); - return bus; + + --how_many; } - catch (failed_constructor &err) { - error << _("Session: could not create new audio route.") << endmsg; - return shared_ptr ((Route*) 0); + if (!ret.empty()) { + add_routes (ret, false); + save_state (_current_snapshot_name); } + + return ret; + } void -Session::add_route (boost::shared_ptr route, bool save) +Session::add_routes (RouteList& new_routes, bool save) { { RCUWriter writer (routes); shared_ptr r = writer.get_copy (); - r->push_front (route); + r->insert (r->end(), new_routes.begin(), new_routes.end()); resort_routes_using (r); } - route->solo_changed.connect (sigc::bind (mem_fun (*this, &Session::route_solo_changed), route)); - route->mute_changed.connect (mem_fun (*this, &Session::route_mute_changed)); - route->output_changed.connect (mem_fun (*this, &Session::set_worst_io_latencies_x)); - route->redirects_changed.connect (mem_fun (*this, &Session::update_latency_compensation_proxy)); - - if (route->master()) { - _master_out = route; - } - - if (route->control()) { - _control_out = route; + for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) { + (*x)->solo_changed.connect (sigc::bind (mem_fun (*this, &Session::route_solo_changed), (*x))); + (*x)->mute_changed.connect (mem_fun (*this, &Session::route_mute_changed)); + (*x)->output_changed.connect (mem_fun (*this, &Session::set_worst_io_latencies_x)); + (*x)->redirects_changed.connect (mem_fun (*this, &Session::update_latency_compensation_proxy)); + + if ((*x)->master()) { + _master_out = (*x); + } + + if ((*x)->control()) { + _control_out = (*x); + } } set_dirty(); @@ -1933,7 +1962,7 @@ Session::add_route (boost::shared_ptr route, bool save) save_state (_current_snapshot_name); } - RouteAdded (route); /* EMIT SIGNAL */ + RouteAdded (new_routes); /* EMIT SIGNAL */ } void diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 6770428c65..6f2ad965b4 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1707,6 +1707,7 @@ Session::load_routes (const XMLNode& node) { XMLNodeList nlist; XMLNodeConstIterator niter; + RouteList new_routes; nlist = node.children(); @@ -1721,9 +1722,11 @@ Session::load_routes (const XMLNode& node) return -1; } - add_route (route); + new_routes.push_back (route); } + add_routes (new_routes); + return 0; } -- cgit v1.2.3