diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 146ac56e0b..69830ade65 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -2284,6 +2284,18 @@ ARDOUR_UI::screen_lock_is_allowed() const return false; } +bool +ARDOUR_UI::session_auto_save_is_allowed() const +{ + if(!_session) + return false; + + if( (_session->record_status() == Session::Recording) && (ARDOUR_UI::config()->get_auto_save_timer () != 0) ) + return true; + else + return false; +} + /** Ask the user for the name of a new snapshot and then take it. */ diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 4ca03a62eb..8911d2e5e0 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -316,6 +316,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr void on_lock_button_pressed (); PBD::Signal0 lock_button_was_pressed; + bool session_auto_save_is_allowed() const; + protected: friend class PublicEditor; diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 7acc29fc57..1a370dab90 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1129,20 +1129,20 @@ Editor::on_realize () signal_event().connect (sigc::mem_fun (*this, &Editor::generic_event_handler)); } -// Update lock time +// Update lock time and auto_save time void Editor::on_ardour_ui_config_changed(const std::string& param) { if (param=="auto-lock-timer" && ARDOUR_UI::instance()->screen_lock_is_allowed()) - { start_lock_event_timing(); - } + + if (param=="auto-save-timer" && ARDOUR_UI::instance()->session_auto_save_is_allowed()) + start_session_auto_save_event_timing(); } void Editor::start_lock_event_timing () -{ - +{ ARDOUR_UI* ardour_ui = ARDOUR_UI::instance(); timeout_connection.disconnect(); @@ -1154,6 +1154,69 @@ Editor::start_lock_event_timing () timeout_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::lock_timeout_callback), 1 * 1000); } +bool +Editor::lock_timeout_callback () +{ + struct timeval now, delta; + + gettimeofday (&now, 0); + + timersub (&now, &last_event_time, &delta); + + if( !ARDOUR_UI::instance()->screen_lock_is_allowed() ) + return false; // Returning false will effectively disconnect us from the timer callback. + + if (delta.tv_sec >= 60 * ARDOUR_UI::config()->get_auto_lock_timer ()) + { + lock (); + /* don't call again. Returning false will effectively + disconnect us from the timer callback. + + unlock() will call start_lock_event_timing() to get things + started again. + */ + return false; + } + + return true; +} + +void +Editor::start_session_auto_save_event_timing () +{ + ARDOUR_UI* ardour_ui = ARDOUR_UI::instance(); + + _session_auto_save_timeout_connection.disconnect(); + + if( !ardour_ui->session_auto_save_is_allowed() ) + return; + + gettimeofday(&_start_recording_time, 0); + + _session_auto_save_timeout_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::session_auto_save_timeout_callback), 1 * 1000); +} + +bool +Editor::session_auto_save_timeout_callback () +{ + struct timeval now, delta; + + gettimeofday (&now, 0); + + timersub (&now, &_start_recording_time, &delta); + + if( !ARDOUR_UI::instance()->session_auto_save_is_allowed() ) + return false; // Returning false will effectively disconnect us from the timer callback. + + if (delta.tv_sec >= 60 * ARDOUR_UI::config()->get_auto_save_timer ()) + { + ARDOUR_UI::instance()->save_state(); + gettimeofday(&_start_recording_time, 0); + } + + return true; +} + bool Editor::generic_event_handler (GdkEvent* ev) { @@ -1171,33 +1234,6 @@ Editor::generic_event_handler (GdkEvent* ev) return false; } -bool -Editor::lock_timeout_callback () -{ - struct timeval now, delta; - - gettimeofday (&now, 0); - - timersub (&now, &last_event_time, &delta); - - if( !ARDOUR_UI::instance()->screen_lock_is_allowed() ) - return false; // Returning false will effectively disconnect us from the timer callback. - - if (delta.tv_sec >= 60 * ARDOUR_UI::config()->get_auto_lock_timer ()) - { - lock (); - /* don't call again. Returning false will effectively - disconnect us from the timer callback. - - unlock() will call start_lock_event_timing() to get things - started again. - */ - return false; - } - - return true; -} - void Editor::map_position_change (framepos_t frame) { @@ -1358,6 +1394,7 @@ Editor::set_session (Session *t) _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::refresh_location_display, this), gui_context()); _session->history().Changed.connect (_session_connections, invalidator (*this), boost::bind (&Editor::history_changed, this), gui_context()); _session->RecordStateChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&Editor::start_lock_event_timing, this), gui_context()); + _session->RecordStateChanged.connect (_session_connections, invalidator (*this), boost::bind (&Editor::start_session_auto_save_event_timing, this), gui_context()); playhead_cursor->show (); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index ffe5471966..64e412b8b2 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1367,6 +1367,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD sigc::connection timeout_connection; bool lock_timeout_callback (); void start_lock_event_timing (); + + // Session auto save staff + struct timeval _start_recording_time; + sigc::connection _session_auto_save_timeout_connection; + bool session_auto_save_timeout_callback(); + void start_session_auto_save_event_timing (); + void on_ardour_ui_config_changed (const std::string&); Gtk::Menu fade_context_menu;