Fix session-open after selecting new, template, then back
[ardour.git] / gtk2_ardour / editor_regions.cc
index 845e56fdec5cb00e852a04b61123c0dde6f089bb..0372e1f3d89220c35179f11c9ec0b4dfb7078599 100644 (file)
 #include "ardour/session.h"
 #include "ardour/profile.h"
 
-#include "gtkmm2ext/choice.h"
 #include "gtkmm2ext/treeutils.h"
 #include "gtkmm2ext/utils.h"
 
+#include "widgets/choice.h"
+#include "widgets/tooltips.h"
+
 #include "audio_clock.h"
 #include "editor.h"
 #include "editing.h"
+#include "editing_convert.h"
 #include "keyboard.h"
 #include "ardour_ui.h"
 #include "gui_thread.h"
 #include "editor_regions.h"
 #include "editor_drag.h"
 #include "main_clock.h"
-#include "tooltips.h"
 #include "ui_config.h"
 
 #include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ArdourWidgets;
 using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Gtk;
@@ -64,9 +67,9 @@ using namespace Editing;
 using Gtkmm2ext::Keyboard;
 
 struct ColumnInfo {
-    int         index;
-    const char* label;
-    const char* tooltip;
+       int         index;
+       const char* label;
+       const char* tooltip;
 };
 
 EditorRegions::EditorRegions (Editor* e)
@@ -77,7 +80,7 @@ EditorRegions::EditorRegions (Editor* e)
        , _show_automatic_regions (true)
        , ignore_region_list_selection_change (false)
        , ignore_selected_region_change (false)
-       , _no_redisplay (false)
+       , _no_redisplay (false)
        , _sort_type ((Editing::RegionListSortType) 0)
        , expanded (false)
 {
@@ -96,14 +99,11 @@ EditorRegions::EditorRegions (Editor* e)
        _model->set_sort_column (0, SORT_ASCENDING);
 
        /* column widths */
-       int bbt_width, sync_width, check_width, height;
+       int bbt_width, check_width, height;
 
        Glib::RefPtr<Pango::Layout> layout = _display.create_pango_layout (X_("000|000|000"));
        Gtkmm2ext::get_pixel_size (layout, bbt_width, height);
 
-       layout = _display.create_pango_layout (X_("Start "));
-       Gtkmm2ext::get_pixel_size (layout, sync_width, height);
-
        check_width = 20;
 
        TreeViewColumn* col_name = manage (new TreeViewColumn ("", _columns.name));
@@ -119,7 +119,7 @@ EditorRegions::EditorRegions (Editor* e)
        col_length->set_fixed_width (bbt_width);
        col_length->set_sizing (TREE_VIEW_COLUMN_FIXED);
        TreeViewColumn* col_sync = manage (new TreeViewColumn ("", _columns.sync));
-       col_sync->set_fixed_width (sync_width);
+       col_sync->set_fixed_width (bbt_width);
        col_sync->set_sizing (TREE_VIEW_COLUMN_FIXED);
        TreeViewColumn* col_fadein = manage (new TreeViewColumn ("", _columns.fadein));
        col_fadein->set_fixed_width (bbt_width);
@@ -497,13 +497,13 @@ EditorRegions::remove_unused_regions ()
                return;
        }
 
-       prompt  = _("Do you really want to remove unused regions?"
-                   "\n(This is destructive and cannot be undone)");
+       prompt = _("Do you really want to remove unused regions?"
+                  "\n(This is destructive and cannot be undone)");
 
        choices.push_back (_("No, do nothing."));
        choices.push_back (_("Yes, remove."));
 
-       Gtkmm2ext::Choice prompter (_("Remove unused regions"), prompt, choices);
+       ArdourWidgets::Choice prompter (_("Remove unused regions"), prompt, choices);
 
        if (prompter.run () == 1) {
                _no_redisplay = true;
@@ -522,6 +522,7 @@ EditorRegions::region_changed (boost::shared_ptr<Region> r, const PropertyChange
        our_interests.add (ARDOUR::Properties::position);
        our_interests.add (ARDOUR::Properties::length);
        our_interests.add (ARDOUR::Properties::start);
+       our_interests.add (ARDOUR::Properties::sync_position);
        our_interests.add (ARDOUR::Properties::locked);
        our_interests.add (ARDOUR::Properties::position_lock_style);
        our_interests.add (ARDOUR::Properties::muted);
@@ -800,7 +801,7 @@ EditorRegions::populate_row (boost::shared_ptr<Region> region, TreeModel::Row co
        if (all || what_changed.contains (Properties::position)) {
                populate_row_position (region, row, used);
        }
-       if (all || what_changed.contains (Properties::start)) {
+       if (all || what_changed.contains (Properties::start) || what_changed.contains (Properties::sync_position)) {
                populate_row_sync (region, row, used);
        }
        if (all || what_changed.contains (Properties::fade_in)) {
@@ -1032,7 +1033,7 @@ EditorRegions::populate_row_name (boost::shared_ptr<Region> region, TreeModel::R
 void
 EditorRegions::populate_row_source (boost::shared_ptr<Region> region, TreeModel::Row const &row)
 {
-        if (boost::dynamic_pointer_cast<SilentFileSource>(region->source())) {
+       if (boost::dynamic_pointer_cast<SilentFileSource>(region->source())) {
                row[_columns.path] = _("MISSING ") + Gtkmm2ext::markup_escape_text (region->source()->name());
        } else {
                row[_columns.path] = Gtkmm2ext::markup_escape_text (region->source()->name());
@@ -1057,10 +1058,10 @@ EditorRegions::set_full (bool f)
 {
        if (f) {
                _display.expand_all ();
-                expanded = true;
+               expanded = true;
        } else {
                _display.collapse_all ();
-                expanded = false;
+               expanded = false;
        }
 }
 
@@ -1304,9 +1305,9 @@ EditorRegions::selection_mapover (sigc::slot<void,boost::shared_ptr<Region> > sl
 
 void
 EditorRegions::drag_data_received (const RefPtr<Gdk::DragContext>& context,
-                                  int x, int y,
-                                  const SelectionData& data,
-                                  guint info, guint time)
+                                   int x, int y,
+                                   const SelectionData& data,
+                                   guint info, guint time)
 {
        vector<string> paths;
 
@@ -1322,7 +1323,8 @@ EditorRegions::drag_data_received (const RefPtr<Gdk::DragContext>& context,
                bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
 
                if (UIConfiguration::instance().get_only_copy_imported_files() || copy) {
-                       _editor->do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsRegion, SrcBest, pos);
+                       _editor->do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsRegion,
+                                           SrcBest, SMFTrackName, SMFTempoIgnore, pos);
                } else {
                        _editor->do_embed (paths, Editing::ImportDistinctFiles, ImportAsRegion, pos);
                }
@@ -1530,13 +1532,13 @@ EditorRegions::get_state () const
 {
        XMLNode* node = new XMLNode (X_("RegionList"));
 
-       node->add_property (X_("sort-type"), enum_2_string (_sort_type));
+       node->set_property (X_("sort-type"), _sort_type);
 
        RefPtr<Action> act = ActionManager::get_action (X_("RegionList"), X_("SortAscending"));
        bool const ascending = RefPtr<RadioAction>::cast_dynamic(act)->get_active ();
-       node->add_property (X_("sort-ascending"), ascending ? "yes" : "no");
-       node->add_property (X_("show-all"), toggle_full_action()->get_active() ? "yes" : "no");
-       node->add_property (X_("show-automatic-regions"), _show_automatic_regions ? "yes" : "no");
+       node->set_property (X_("sort-ascending"), ascending);
+       node->set_property (X_("show-all"), toggle_full_action()->get_active());
+       node->set_property (X_("show-automatic-regions"), _show_automatic_regions);
 
        return *node;
 }
@@ -1550,10 +1552,8 @@ EditorRegions::set_state (const XMLNode & node)
                return;
        }
 
-       XMLProperty const * p = node.property (X_("sort-type"));
-
-       if (p) {
-               Editing::RegionListSortType const t = static_cast<Editing::RegionListSortType> (string_2_enum (p->value(), _sort_type));
+       Editing::RegionListSortType t;
+       if (node.get_property (X_("sort-type"), t)) {
 
                if (_sort_type != t) {
                        changed = true;
@@ -1564,10 +1564,8 @@ EditorRegions::set_state (const XMLNode & node)
                ract->set_active ();
        }
 
-       p = node.property (X_("sort-ascending"));
-
-       if (p) {
-               bool const yn = string_is_affirmative (p->value ());
+       bool yn;
+       if (node.get_property (X_("sort-ascending"), yn)) {
                SortType old_sort_type;
                int old_sort_column;
 
@@ -1589,10 +1587,7 @@ EditorRegions::set_state (const XMLNode & node)
                RefPtr<RadioAction>::cast_dynamic(act)->set_active ();
        }
 
-       p = node.property (X_("show-all"));
-       if (p) {
-               bool const yn = string_is_affirmative (p->value ());
-
+       if (node.get_property (X_("show-all"), yn)) {
                if (expanded != yn) {
                        changed = true;
                }
@@ -1601,10 +1596,7 @@ EditorRegions::set_state (const XMLNode & node)
                toggle_full_action()->set_active (yn);
        }
 
-       p = node.property (X_("show-automatic-regions"));
-       if (p) {
-               bool const yn = string_is_affirmative (p->value ());
-
+       if (node.get_property (X_("show-automatic-regions"), yn)) {
                if (yn != _show_automatic_regions) {
                        _show_automatic_regions = yn;
                        toggle_show_auto_regions_action()->set_active (yn);