[Summary] Session auto save

[Reviewed] GZharun
This commit is contained in:
nikolay 2014-08-13 15:17:51 +03:00
parent 741efb0371
commit 6809921555
4 changed files with 90 additions and 32 deletions

View file

@ -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.
*/

View file

@ -316,6 +316,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
void on_lock_button_pressed ();
PBD::Signal0<void> lock_button_was_pressed;
bool session_auto_save_is_allowed() const;
protected:
friend class PublicEditor;

View file

@ -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 ();

View file

@ -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;