For now, only use the multi-threaded process code if we are
[ardour.git] / libs / ardour / session.cc
index ef0a6c2a48636bbfc2cd379d43517404094194f5..f2343e1013af059a50a7a03fffd07df3b940da2a 100644 (file)
@@ -153,7 +153,6 @@ Session::Session (AudioEngine &eng,
        , _post_transport_work (0)
        , _send_timecode_update (false)
        , _all_route_group (new RouteGroup (*this, "all"))
-       , _process_graph (new Graph (*this))
        , routes (new RouteList)
        , _total_free_4k_blocks (0)
        , _bundles (new BundleList)
@@ -169,6 +168,13 @@ Session::Session (AudioEngine &eng,
 {
        _locations = new Locations (*this);
 
+       if (how_many_dsp_threads () > 1) {
+               /* For now, only create the graph if we are using >1 DSP threads, as
+                  it is a bit slower than the old code with 1 thread.
+               */
+               _process_graph.reset (new Graph (*this));
+       }
+
        playlists.reset (new SessionPlaylists);
 
        _all_route_group->set_active (true, this);
@@ -624,7 +630,7 @@ Session::remove_monitor_section ()
                        } else if ((*x)->is_master()) {
                                /* relax */
                        } else {
-                               (*x)->drop_listen (_monitor_out);
+                               (*x)->remove_aux_or_listen (_monitor_out);
                        }
                }
        }
@@ -1384,8 +1390,6 @@ Session::resort_routes ()
                /* writer goes out of scope and forces update */
        }
 
-       //_process_graph->dump(1);
-
 #ifndef NDEBUG
        boost::shared_ptr<RouteList> rl = routes.reader ();
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
@@ -1460,7 +1464,10 @@ Session::resort_routes_using (boost::shared_ptr<RouteList> r)
                   Note: the process graph rechain does not require a
                   topologically-sorted list, but hey ho.
                */
-               _process_graph->rechain (sorted_routes, edges);
+               if (_process_graph) {
+                       _process_graph->rechain (sorted_routes, edges);
+               }
+               
                _current_route_graph = edges;
 
                /* Complete the building of the routes' lists of what directly
@@ -2143,13 +2150,17 @@ Session::add_routes (RouteList& new_routes, bool auto_connect, bool save)
 
        if (_monitor_out && IO::connecting_legal) {
 
-               for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) {
-                       if ((*x)->is_monitor()) {
-                               /* relax */
-                       } else if ((*x)->is_master()) {
-                               /* relax */
-                       } else {
-                               (*x)->enable_monitor_send ();
+               {
+                       Glib::Mutex::Lock lm (_engine.process_lock());          
+                       
+                       for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) {
+                               if ((*x)->is_monitor()) {
+                                       /* relax */
+                               } else if ((*x)->is_master()) {
+                                       /* relax */
+                               } else {
+                                       (*x)->enable_monitor_send ();
+                               }
                        }
                }
 
@@ -2233,13 +2244,14 @@ Session::add_internal_sends (boost::shared_ptr<Route> dest, Placement p, boost::
                dest->add_internal_return();
        }
 
+       
        for (RouteList::iterator i = senders->begin(); i != senders->end(); ++i) {
-
+               
                if ((*i)->is_monitor() || (*i)->is_master() || (*i) == dest) {
                        continue;
                }
-
-               (*i)->listen_via (dest, p);
+               
+               (*i)->add_aux_send (dest, p);
        }
 
        graph_reordered ();
@@ -2310,7 +2322,9 @@ Session::remove_route (boost::shared_ptr<Route> route)
         */
 
        resort_routes ();
-       _process_graph->clear_other_chain ();
+       if (_process_graph) {
+               _process_graph->clear_other_chain ();
+       }
 
        /* get rid of it from the dead wood collection in the route list manager */
 
@@ -3621,6 +3635,26 @@ Session::next_send_id ()
        }
 }
 
+uint32_t
+Session::next_aux_send_id ()
+{
+       /* this doesn't really loop forever. just think about it */
+
+       while (true) {
+               for (boost::dynamic_bitset<uint32_t>::size_type n = 0; n < aux_send_bitset.size(); ++n) {
+                       if (!aux_send_bitset[n]) {
+                               aux_send_bitset[n] = true;
+                               return n;
+
+                       }
+               }
+
+               /* none available, so resize and try again */
+
+               aux_send_bitset.resize (aux_send_bitset.size() + 16, false);
+       }
+}
+
 uint32_t
 Session::next_return_id ()
 {
@@ -3653,6 +3687,18 @@ Session::mark_send_id (uint32_t id)
        send_bitset[id] = true;
 }
 
+void
+Session::mark_aux_send_id (uint32_t id)
+{
+       if (id >= aux_send_bitset.size()) {
+               aux_send_bitset.resize (id+16, false);
+       }
+       if (aux_send_bitset[id]) {
+               warning << string_compose (_("aux send ID %1 appears to be in use already"), id) << endmsg;
+       }
+       aux_send_bitset[id] = true;
+}
+
 void
 Session::mark_return_id (uint32_t id)
 {
@@ -3685,6 +3731,14 @@ Session::unmark_send_id (uint32_t id)
        }
 }
 
+void
+Session::unmark_aux_send_id (uint32_t id)
+{
+       if (id < aux_send_bitset.size()) {
+               aux_send_bitset[id] = false;
+       }
+}
+
 void
 Session::unmark_return_id (uint32_t id)
 {