+
+ set_worst_io_latencies ();
+}
+
+void
+Session::set_worst_io_latencies ()
+{
+ set_worst_playback_latency ();
+ set_worst_capture_latency ();
+}
+
+void
+Session::set_worst_playback_latency ()
+{
+ if (_state_of_the_state & (InitialConnecting|Deletion)) {
+ return;
+ }
+
+ _worst_output_latency = 0;
+
+ if (!_engine.connected()) {
+ return;
+ }
+
+ boost::shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ _worst_output_latency = max (_worst_output_latency, (*i)->output()->latency());
+ }
+
+ DEBUG_TRACE (DEBUG::Latency, string_compose ("Worst output latency: %1\n", _worst_output_latency));
+}
+
+void
+Session::set_worst_capture_latency ()
+{
+ if (_state_of_the_state & (InitialConnecting|Deletion)) {
+ return;
+ }
+
+ _worst_input_latency = 0;
+
+ if (!_engine.connected()) {
+ return;
+ }
+
+ boost::shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ _worst_input_latency = max (_worst_input_latency, (*i)->input()->latency());
+ }
+
+ DEBUG_TRACE (DEBUG::Latency, string_compose ("Worst input latency: %1\n", _worst_input_latency));
+}
+
+void
+Session::update_latency_compensation (bool force_whole_graph)
+{
+ bool some_track_latency_changed = false;
+
+ if (_state_of_the_state & (InitialConnecting|Deletion)) {
+ return;
+ }
+
+ DEBUG_TRACE(DEBUG::Latency, "---------------------------- update latency compensation\n\n");
+
+ _worst_track_latency = 0;
+
+ boost::shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if (!(*i)->is_hidden() && ((*i)->active())) {
+ framecnt_t tl;
+ if ((*i)->signal_latency () != (tl = (*i)->update_signal_latency ())) {
+ some_track_latency_changed = true;
+ }
+ _worst_track_latency = max (tl, _worst_track_latency);
+ }
+ }
+
+ DEBUG_TRACE (DEBUG::Latency, string_compose ("worst signal processing latency: %1 (changed ? %2)\n", _worst_track_latency,
+ (some_track_latency_changed ? "yes" : "no")));
+
+ DEBUG_TRACE(DEBUG::Latency, "---------------------------- DONE update latency compensation\n\n");
+
+ if (some_track_latency_changed || force_whole_graph) {
+ _engine.update_latencies ();
+ }
+
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
+ if (!tr) {
+ continue;
+ }
+ tr->set_capture_offset ();
+ }
+}
+
+char
+Session::session_name_is_legal (const string& path)
+{
+ char illegal_chars[] = { '/', '\\', ':', ';', '\0' };
+
+ for (int i = 0; illegal_chars[i]; ++i) {
+ if (path.find (illegal_chars[i]) != string::npos) {
+ return illegal_chars[i];
+ }
+ }
+
+ return 0;
+}
+
+uint32_t
+Session::next_control_id () const
+{
+ return ntracks() + nbusses() + 1;