From af895ef50d80bae4f5bb63ee563604804eeb2fb2 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 26 Sep 2007 14:36:49 +0000 Subject: [PATCH] GUI control over saved and in-memory history depth git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2486 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/option_editor.cc | 115 ++++++++++++++++++++++-- gtk2_ardour/option_editor.h | 20 ++++- libs/ardour/ardour/configuration_vars.h | 5 +- libs/ardour/session_state.cc | 15 ++-- libs/pbd/pbd/undo.h | 8 +- libs/pbd/undo.cc | 15 ++-- 6 files changed, 150 insertions(+), 28 deletions(-) diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index 862b22850c..c328532f6a 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -64,12 +64,18 @@ OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui) /* Paths */ path_table (11, 2), - /* Fades */ + /* misc */ short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0), short_xfade_slider (short_xfade_adjustment), destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0), destructo_xfade_slider (destructo_xfade_adjustment), + history_depth (20, -1, 100, 1.0, 10.0), + saved_history_depth (20, 0, 100, 1.0, 10.0), + history_depth_spinner (history_depth), + saved_history_depth_spinner (saved_history_depth), + limit_history_button (_("Limit undo history")), + save_history_button (_("Save undo history")), /* Sync */ @@ -131,7 +137,7 @@ OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui) setup_sync_options(); setup_path_options(); - setup_fade_options (); + setup_misc_options (); setup_keyboard_options (); setup_auditioner_editor (); @@ -140,7 +146,7 @@ OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui) notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse"))); notebook.pages().push_back (TabElem (click_packer, _("Click"))); notebook.pages().push_back (TabElem (audition_packer, _("Audition"))); - notebook.pages().push_back (TabElem (fade_packer, _("Layers & Fades"))); + notebook.pages().push_back (TabElem (misc_packer, _("Misc"))); setup_midi_options (); notebook.pages().push_back (TabElem (midi_packer, _("MIDI"))); @@ -244,7 +250,7 @@ OptionEditor::add_session_paths () } void -OptionEditor::setup_fade_options () +OptionEditor::setup_misc_options () { Gtk::HBox* hbox; @@ -256,7 +262,7 @@ OptionEditor::setup_fade_options () hbox->set_spacing (10); hbox->pack_start (*label, false, false); hbox->pack_start (short_xfade_slider, true, true); - fade_packer.pack_start (*hbox, false, false); + misc_packer.pack_start (*hbox, false, false); short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed)); @@ -268,16 +274,94 @@ OptionEditor::setup_fade_options () hbox->set_spacing (10); hbox->pack_start (*label, false, false); hbox->pack_start (destructo_xfade_slider, true, true); - fade_packer.pack_start (*hbox, false, false); + misc_packer.pack_start (*hbox, false, false); + destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed)); + hbox = manage (new HBox); + hbox->set_border_width (5); + hbox->set_spacing (10); + hbox->pack_start (limit_history_button, false, false); + misc_packer.pack_start (*hbox, false, false); + + label = manage (new Label (_("History depth (commands)"))); + label->set_name ("OptionsLabel"); + + hbox = manage (new HBox); + hbox->set_border_width (5); + hbox->set_spacing (10); + hbox->pack_start (*label, false, false); + hbox->pack_start (history_depth_spinner, false, false); + misc_packer.pack_start (*hbox, false, false); + + history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::history_depth_changed)); + saved_history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::saved_history_depth_changed)); + save_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::save_history_toggled)); + limit_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::limit_history_toggled)); + + hbox = manage (new HBox); + hbox->set_border_width (5); + hbox->set_spacing (10); + hbox->pack_start (save_history_button, false, false); + misc_packer.pack_start (*hbox, false, false); + + label = manage (new Label (_("Saved history depth (commands)"))); + label->set_name ("OptionsLabel"); + + hbox = manage (new HBox); + hbox->set_border_width (5); + hbox->set_spacing (10); + hbox->pack_start (*label, false, false); + hbox->pack_start (saved_history_depth_spinner, false, false); + misc_packer.pack_start (*hbox, false, false); + short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS); destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS); destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs()); - fade_packer.show_all (); + misc_packer.show_all (); +} + +void +OptionEditor::limit_history_toggled () +{ + bool x = limit_history_button.get_active(); + + if (!x) { + Config->set_history_depth (0); + history_depth_spinner.set_sensitive (false); + } else { + if (Config->get_history_depth() == 0) { + /* get back to a sane default */ + Config->set_history_depth (20); + } + history_depth_spinner.set_sensitive (true); + } +} + +void +OptionEditor::save_history_toggled () +{ + bool x = save_history_button.get_active(); + + if (x != Config->get_save_history()) { + Config->set_save_history (x); + saved_history_depth_spinner.set_sensitive (x); + } +} + +void +OptionEditor::history_depth_changed() +{ + Config->set_history_depth ((int32_t) floor (history_depth.get_value())); +} + +void +OptionEditor::saved_history_depth_changed() +{ + Config->set_saved_history_depth ((int32_t) floor (saved_history_depth.get_value())); } void @@ -1188,5 +1272,22 @@ OptionEditor::parameter_changed (const char* parameter_name) if (PARAM_IS ("timecode-source-is-synced")) { synced_timecode_button.set_active (Config->get_timecode_source_is_synced()); + } else if (PARAM_IS ("history-depth")) { + int32_t depth = Config->get_history_depth(); + + history_depth.set_value (depth); + history_depth_spinner.set_sensitive (depth != 0); + limit_history_button.set_active (depth != 0); + + } else if (PARAM_IS ("saved-history-depth")) { + + saved_history_depth.set_value (Config->get_saved_history_depth()); + + } else if (PARAM_IS ("save-history")) { + + bool x = Config->get_save_history(); + + save_history_button.set_active (x); + saved_history_depth_spinner.set_sensitive (x); } } diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h index 3881687d5c..82bb4db79b 100644 --- a/gtk2_ardour/option_editor.h +++ b/gtk2_ardour/option_editor.h @@ -78,18 +78,32 @@ class OptionEditor : public ArdourDialog void remove_session_paths (); void raid_path_changed (); - /* fades */ + /* misc */ + + Gtk::VBox misc_packer; - Gtk::VBox fade_packer; Gtk::Adjustment short_xfade_adjustment; Gtk::HScale short_xfade_slider; Gtk::Adjustment destructo_xfade_adjustment; Gtk::HScale destructo_xfade_slider; - void setup_fade_options(); + void setup_misc_options(); + void short_xfade_adjustment_changed (); void destructo_xfade_adjustment_changed (); + Gtk::Adjustment history_depth; + Gtk::Adjustment saved_history_depth; + Gtk::SpinButton history_depth_spinner; + Gtk::SpinButton saved_history_depth_spinner; + Gtk::CheckButton limit_history_button; + Gtk::CheckButton save_history_button; + + void history_depth_changed(); + void saved_history_depth_changed(); + void save_history_toggled (); + void limit_history_toggled (); + /* Sync */ Gtk::VBox sync_packer; diff --git a/libs/ardour/ardour/configuration_vars.h b/libs/ardour/ardour/configuration_vars.h index 4bbfe89bdc..8473f0f4d0 100644 --- a/libs/ardour/ardour/configuration_vars.h +++ b/libs/ardour/ardour/configuration_vars.h @@ -138,8 +138,9 @@ CONFIG_VARIABLE (bool, verify_remove_last_capture, "verify-remove-last-capture", CONFIG_VARIABLE (bool, no_new_session_dialog, "no-new-session-dialog", false) CONFIG_VARIABLE (bool, use_vst, "use-vst", true) CONFIG_VARIABLE (uint32_t, subframes_per_frame, "subframes-per-frame", 100) -CONFIG_VARIABLE (uint32_t, saved_history_depth, "save-history-depth", 20) -CONFIG_VARIABLE (uint32_t, history_depth, "history-depth", 20) +CONFIG_VARIABLE (bool, save_history, "save-history", true) +CONFIG_VARIABLE (int32_t, saved_history_depth, "save-history-depth", 20) +CONFIG_VARIABLE (int32_t, history_depth, "history-depth", 20) CONFIG_VARIABLE (bool, use_overlap_equivalency, "use-overlap-equivalency", false) CONFIG_VARIABLE (bool, periodic_safety_backups, "periodic-safety-backups", true) CONFIG_VARIABLE (uint32_t, periodic_safety_backup_interval, "periodic-safety-backup-interval", 120) diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 8067ae581b..f704bbad5f 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2989,8 +2989,6 @@ Session::save_history (string snapshot_name) string xml_path; string bak_path; - tree.set_root (&_history.get_state (Config->get_saved_history_depth())); - if (snapshot_name.empty()) { snapshot_name = _current_snapshot_name; } @@ -2999,13 +2997,17 @@ Session::save_history (string snapshot_name) bak_path = xml_path + ".bak"; - if ((access (xml_path.c_str(), F_OK) == 0) && - (rename (xml_path.c_str(), bak_path.c_str()))) - { + if (Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS) && ::rename (xml_path.c_str(), bak_path.c_str())) { error << _("could not backup old history file, current history not saved.") << endmsg; return -1; } + if (!Config->get_save_history() || Config->get_saved_history_depth() < 0) { + return 0; + } + + tree.set_root (&_history.get_state (Config->get_saved_history_depth())); + if (!tree.write (xml_path)) { error << string_compose (_("history could not be saved to %1"), xml_path) << endmsg; @@ -3043,8 +3045,7 @@ Session::restore_history (string snapshot_name) xmlpath = _path + snapshot_name + ".history"; cerr << string_compose(_("Loading history from '%1'."), xmlpath) << endmsg; - if (access (xmlpath.c_str(), F_OK)) { - info << string_compose (_("%1: no history file \"%2\" for this session."), _name, xmlpath) << endmsg; + if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) { return 1; } diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h index 3f4a1c5e9d..fa53648b24 100644 --- a/libs/pbd/pbd/undo.h +++ b/libs/pbd/pbd/undo.h @@ -93,17 +93,17 @@ class UndoHistory : public sigc::trackable void clear_undo (); void clear_redo (); - XMLNode &get_state(uint32_t depth = 0); + XMLNode &get_state(int32_t depth = 0); void save_state(); - void set_depth (uint32_t); - uint32_t get_depth() const { return _depth; } + void set_depth (int32_t); + int32_t get_depth() const { return _depth; } sigc::signal Changed; private: bool _clearing; - uint32_t _depth; + int32_t _depth; std::list UndoList; std::list RedoList; diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc index d54c6b0fff..f59228082d 100644 --- a/libs/pbd/undo.cc +++ b/libs/pbd/undo.cc @@ -152,11 +152,11 @@ UndoHistory::UndoHistory () } void -UndoHistory::set_depth (uint32_t d) +UndoHistory::set_depth (int32_t d) { _depth = d; - while (_depth > 0 && UndoList.size() > _depth) { + while (_depth > 0 && UndoList.size() > (uint32_t) _depth) { UndoList.pop_front (); } } @@ -166,7 +166,7 @@ UndoHistory::add (UndoTransaction* const ut) { ut->GoingAway.connect (bind (mem_fun (*this, &UndoHistory::remove), ut)); - while (_depth > 0 && UndoList.size() > _depth) { + while (_depth > 0 && UndoList.size() > (uint32_t) _depth) { UndoList.pop_front (); } @@ -253,17 +253,22 @@ UndoHistory::clear () } XMLNode& -UndoHistory::get_state (uint32_t depth) +UndoHistory::get_state (int32_t depth) { XMLNode *node = new XMLNode ("UndoHistory"); if (depth == 0) { + + return (*node); + + } else if (depth < 0) { + /* everything */ for (list::iterator it = UndoList.begin(); it != UndoList.end(); ++it) { node->add_child_nocopy((*it)->get_state()); } - + } else { /* just the last "depth" transactions */