+int
+Session::ensure_engine (uint32_t desired_sample_rate)
+{
+ if (_engine.current_backend() == 0) {
+ /* backend is unknown ... */
+ boost::optional<int> r = AudioEngineSetupRequired (desired_sample_rate);
+ if (r.get_value_or (-1) != 0) {
+ return -1;
+ }
+ } else if (_engine.setup_required()) {
+ /* backend is known, but setup is needed */
+ boost::optional<int> r = AudioEngineSetupRequired (desired_sample_rate);
+ if (r.get_value_or (-1) != 0) {
+ return -1;
+ }
+ } else if (!_engine.running()) {
+ if (_engine.start()) {
+ return -1;
+ }
+ }
+
+ /* at this point the engine should be running
+ */
+
+ if (!_engine.running()) {
+ return -1;
+ }
+
+ return immediately_post_engine ();
+
+}
+
+int
+Session::immediately_post_engine ()
+{
+ /* Do various initializations that should take place directly after we
+ * know that the engine is running, but before we either create a
+ * session or set state for an existing one.
+ */
+
+ 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));
+ }
+
+ /* every time we reconnect, recompute worst case output latencies */
+
+ _engine.Running.connect_same_thread (*this, boost::bind (&Session::initialize_latencies, this));
+
+ if (synced_to_engine()) {
+ _engine.transport_stop ();
+ }
+
+ if (config.get_jack_time_master()) {
+ _engine.transport_locate (_transport_frame);
+ }
+
+ try {
+ BootMessage (_("Set up LTC"));
+ setup_ltc ();
+ BootMessage (_("Set up Click"));
+ setup_click ();
+ BootMessage (_("Set up standard connections"));
+ setup_bundles ();
+ }
+
+ catch (failed_constructor& err) {
+ return -1;
+ }
+
+ return 0;
+}
+