remove all trace of SAE from source code.
[ardour.git] / gtk2_ardour / editor_regions.cc
index 672a0c5b8edafe38b4ce7591195323b2ce818d3f..63b96f1e64c3288b56638461842f5cbad8faf752 100644 (file)
 
 #include "ardour/audioregion.h"
 #include "ardour/audiofilesource.h"
+#include "ardour/silentfilesource.h"
 #include "ardour/region_factory.h"
 #include "ardour/session.h"
-#include "ardour/session_playlists.h"
-#include "ardour/silentfilesource.h"
 #include "ardour/profile.h"
 
 #include "gtkmm2ext/choice.h"
 #include "gtkmm2ext/treeutils.h"
+#include "gtkmm2ext/utils.h"
 
 #include "audio_clock.h"
 #include "editor.h"
 #include "utils.h"
 #include "editor_regions.h"
 #include "editor_drag.h"
+#include "main_clock.h"
+#include "tooltips.h"
+#include "ui_config.h"
 
 #include "i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Gtk;
 using namespace Glib;
@@ -79,6 +83,7 @@ EditorRegions::EditorRegions (Editor* e)
 {
        _display.set_size_request (100, -1);
        _display.set_rules_hint (true);
+       _display.set_name ("EditGroupList");
 
        /* Try to prevent single mouse presses from initiating edits.
           This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
@@ -107,31 +112,31 @@ EditorRegions::EditorRegions (Editor* e)
        Gtk::Label* l;
 
        ColumnInfo ci[] = {
-               { 0, _("Region"), _("Region name, with number of channels in []'s") },
-               { 1, _("Position"),  _("Position of start of region") },
-               { 2, _("End"),  _("Position of end of region") },
-               { 3, _("Length"),  _("Length of the region") },
-               { 4, _("Sync"),  _("Position of region sync point, relative to start of the region") },
-               { 5, _("Fade In"),  _("Length of region fade-in (units: secondary clock), () if disabled") },
-               { 6, _("Fade Out"),  _("Length of region fade-out (units: secondary clock), () if dsisabled") },
-               { 7, _("L"),  _("Region position locked?") },
-               { 8, _("G"),  _("Region position glued to Bars|Beats time?") },
-               { 9, _("M"),  _("Region muted?") },
-               { 10, _("O"),  _("Region opaque (blocks regions below it from being heard)?") },
+               { 0,   _("Region"),    _("Region name, with number of channels in []'s") },
+               { 1,   _("Position"),  _("Position of start of region") },
+               { 2,   _("End"),       _("Position of end of region") },
+               { 3,   _("Length"),    _("Length of the region") },
+               { 4,   _("Sync"),      _("Position of region sync point, relative to start of the region") },
+               { 5,   _("Fade In"),   _("Length of region fade-in (units: secondary clock), () if disabled") },
+               { 6,   _("Fade Out"),  _("Length of region fade-out (units: secondary clock), () if disabled") },
+               { 7,  S_("Lock|L"),    _("Region position locked?") },
+               { 8,  S_("Gain|G"),    _("Region position glued to Bars|Beats time?") },
+               { 9,  S_("Mute|M"),    _("Region muted?") },
+               { 10, S_("Opaque|O"),  _("Region opaque (blocks regions below it from being heard)?") },
                { -1, 0, 0 }
        };
-       
+
        for (int i = 0; ci[i].index >= 0; ++i) {
                col = _display.get_column (ci[i].index);
                l = manage (new Label (ci[i].label));
-               ARDOUR_UI::instance()->set_tip (*l, ci[i].tooltip);
+               set_tooltip (*l, ci[i].tooltip);
                col->set_widget (*l);
                l->show ();
 
                if (ci[i].index > 6) {
                        col->set_expand (false);
                        col->set_alignment (ALIGN_CENTER);
-               } 
+               }
        }
 
        _display.set_headers_visible (true);
@@ -183,6 +188,7 @@ EditorRegions::EditorRegions (Editor* e)
 
        _display.get_selection()->set_mode (SELECTION_MULTIPLE);
        _display.add_object_drag (_columns.region.index(), "regions");
+       _display.set_drag_column (_columns.name.index());
 
        /* setup DnD handling */
 
@@ -212,11 +218,11 @@ EditorRegions::EditorRegions (Editor* e)
 
        //ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (sigc::mem_fun(*this, &Editor::redisplay_regions));
        ARDOUR_UI::instance()->secondary_clock->mode_changed.connect (sigc::mem_fun(*this, &EditorRegions::update_all_rows));
-       ARDOUR::Region::RegionPropertyChanged.connect (region_property_connection, MISSING_INVALIDATOR, ui_bind (&EditorRegions::region_changed, this, _1, _2), gui_context());
-       ARDOUR::RegionFactory::CheckNewRegion.connect (check_new_region_connection, MISSING_INVALIDATOR, ui_bind (&EditorRegions::add_region, this, _1), gui_context());
+       ARDOUR::Region::RegionPropertyChanged.connect (region_property_connection, MISSING_INVALIDATOR, boost::bind (&EditorRegions::region_changed, this, _1, _2), gui_context());
+       ARDOUR::RegionFactory::CheckNewRegion.connect (check_new_region_connection, MISSING_INVALIDATOR, boost::bind (&EditorRegions::add_region, this, _1), gui_context());
 
-       e->EditorFreeze.connect (editor_freeze_connection, MISSING_INVALIDATOR, ui_bind (&EditorRegions::freeze_tree_model, this), gui_context());
-       e->EditorThaw.connect (editor_thaw_connection, MISSING_INVALIDATOR, ui_bind (&EditorRegions::thaw_tree_model, this), gui_context());
+       e->EditorFreeze.connect (editor_freeze_connection, MISSING_INVALIDATOR, boost::bind (&EditorRegions::freeze_tree_model, this), gui_context());
+       e->EditorThaw.connect (editor_thaw_connection, MISSING_INVALIDATOR, boost::bind (&EditorRegions::thaw_tree_model, this), gui_context());
 }
 
 bool
@@ -293,7 +299,7 @@ EditorRegions::add_region (boost::shared_ptr<Region> region)
        string str;
        TreeModel::Row row;
        Gdk::Color c;
-       bool missing_source = boost::dynamic_pointer_cast<SilentFileSource>(region->source());
+       bool missing_source = boost::dynamic_pointer_cast<SilentFileSource>(region->source()) != NULL;
 
        if (!_show_automatic_regions && region->automatic()) {
                return;
@@ -303,7 +309,6 @@ EditorRegions::add_region (boost::shared_ptr<Region> region)
 
                TreeModel::iterator iter = _model->get_iter ("0");
                TreeModel::Row parent;
-               TreeModel::Row child;
 
                if (!iter) {
                        parent = *(_model->append());
@@ -340,14 +345,15 @@ EditorRegions::add_region (boost::shared_ptr<Region> region)
                row = *(_model->append());
 
                if (missing_source) {
-                       c.set_rgb(65535,0,0);     // FIXME: error color from style
+                       // c.set_rgb(65535,0,0);     // FIXME: error color from style
+                       set_color_from_rgba (c, UIConfiguration::instance().color ("region list missing source"));
 
                } else if (region->automatic()){
-                       c.set_rgb(0,65535,0);     // FIXME: error color from style
+                       // c.set_rgb(0,65535,0);     // FIXME: error color from style
+                       set_color_from_rgba (c, UIConfiguration::instance().color ("region list automatic"));
 
                } else {
-                       set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
-
+                       set_color_from_rgba (c, UIConfiguration::instance().color ("region list whole file"));
                }
 
                row[_columns.color_] = c;
@@ -386,14 +392,14 @@ EditorRegions::add_region (boost::shared_ptr<Region> region)
                row[_columns.property_toggles_visible] = false;
 
                if (missing_source) {
-                       row[_columns.path] = _("(MISSING) ") + region->source()->name();
+                       row[_columns.path] = _("(MISSING) ") + Gtkmm2ext::markup_escape_text (region->source()->name());
 
                } else {
                        boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource>(region->source());
                        if (fs) {
-                               row[_columns.path] = fs->path();
+                               row[_columns.path] = Gtkmm2ext::markup_escape_text (fs->path());
                        } else {
-                               row[_columns.path] = region->source()->name();
+                               row[_columns.path] = Gtkmm2ext::markup_escape_text (region->source()->name());
                        }
                }
 
@@ -429,7 +435,7 @@ EditorRegions::add_region (boost::shared_ptr<Region> region)
                        */
 
                        row = *(_model->insert (subrows.end()));
-                       
+
                } else {
                        row = *(_model->append());
                }
@@ -550,7 +556,8 @@ EditorRegions::selection_changed ()
 
                for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
 
-                       if (iter = _model->get_iter (*i)) {
+                       if ((iter = _model->get_iter (*i))) {
+
                                boost::shared_ptr<Region> region = (*iter)[_columns.region];
 
                                // they could have clicked on a row that is just a placeholder, like "Hidden"
@@ -559,18 +566,12 @@ EditorRegions::selection_changed ()
 
                                if (region) {
 
-                                       if (region->automatic()) {
-
-                                               _display.get_selection()->unselect(*i);
-
-                                       } else {
-                                               _change_connection.block (true);
-                                               _editor->set_selected_regionview_from_region_list (region, Selection::Add);
-
-                                               _change_connection.block (false);
-                                       }
+                                       _change_connection.block (true);
+                                       _editor->set_selected_regionview_from_region_list (region, Selection::Add);
+                                       _change_connection.block (false);
                                }
                        }
+
                }
        } else {
                _editor->get_selection().clear_regions ();
@@ -693,6 +694,12 @@ EditorRegions::format_position (framepos_t pos, char* buf, size_t bufsize, bool
        Timecode::BBT_Time bbt;
        Timecode::Time timecode;
 
+       if (pos < 0) {
+               error << string_compose (_("EditorRegions::format_position: negative timecode position: %1"), pos) << endmsg;
+               snprintf (buf, bufsize, "invalid");
+               return;
+       }
+
        switch (ARDOUR_UI::instance()->secondary_clock->mode ()) {
        case AudioClock::BBT:
                _session->tempo_map().bbt_time (pos, bbt);
@@ -819,10 +826,12 @@ EditorRegions::populate_row_end (boost::shared_ptr<Region> region, TreeModel::Ro
                row[_columns.end] = "";
        } else if (used > 1) {
                row[_columns.end] = _("Mult.");
-       } else {
+       } else if (region->last_frame() >= region->first_frame()) {
                char buf[16];
                format_position (region->last_frame(), buf, sizeof (buf));
                row[_columns.end] = buf;
+       } else {
+               row[_columns.end] = "empty";
        }
 }
 
@@ -942,9 +951,9 @@ void
 EditorRegions::populate_row_name (boost::shared_ptr<Region> region, TreeModel::Row const &row)
 {
        if (region->n_channels() > 1) {
-               row[_columns.name] = string_compose("%1  [%2]", region->name(), region->n_channels());
+               row[_columns.name] = string_compose("%1  [%2]", Gtkmm2ext::markup_escape_text (region->name()), region->n_channels());
        } else {
-               row[_columns.name] = region->name();
+               row[_columns.name] = Gtkmm2ext::markup_escape_text (region->name());
        }
 }
 
@@ -952,9 +961,9 @@ void
 EditorRegions::populate_row_source (boost::shared_ptr<Region> region, TreeModel::Row const &row)
 {
         if (boost::dynamic_pointer_cast<SilentFileSource>(region->source())) {
-               row[_columns.path] = _("MISSING ") + region->source()->name();
+               row[_columns.path] = _("MISSING ") + Gtkmm2ext::markup_escape_text (region->source()->name());
        } else {
-               row[_columns.path] = region->source()->name();
+               row[_columns.path] = Gtkmm2ext::markup_escape_text (region->source()->name());
        }
 }
 
@@ -1120,7 +1129,7 @@ EditorRegions::sorter (TreeModel::iterator a, TreeModel::iterator b)
 
        switch (_sort_type) {
        case ByName:
-               cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
+               cmp = region1->name().compare(region2->name());
                break;
 
        case ByLength:
@@ -1145,7 +1154,7 @@ EditorRegions::sorter (TreeModel::iterator a, TreeModel::iterator b)
                break;
 
        case BySourceFileName:
-               cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
+               cmp = region1->source()->name().compare(region2->source()->name());
                break;
 
        case BySourceFileLength:
@@ -1158,9 +1167,9 @@ EditorRegions::sorter (TreeModel::iterator a, TreeModel::iterator b)
 
        case BySourceFileFS:
                if (region1->source()->name() == region2->source()->name()) {
-                       cmp = strcasecmp (region1->name().c_str(),  region2->name().c_str());
+                       cmp = region1->name().compare(region2->name());
                } else {
-                       cmp = strcasecmp (region1->source()->name().c_str(),  region2->source()->name().c_str());
+                       cmp = region1->source()->name().compare(region2->source()->name());
                }
                break;
        }
@@ -1238,7 +1247,9 @@ EditorRegions::drag_data_received (const RefPtr<Gdk::DragContext>& context,
 
        if (_editor->convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
                framepos_t pos = 0;
-               if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
+               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);
                } else {
                        _editor->do_embed (paths, Editing::ImportDistinctFiles, ImportAsRegion, pos);
@@ -1300,7 +1311,7 @@ EditorRegions::name_edit (const std::string& path, const std::string& new_text)
 
        if (region) {
                vector<RegionView*> equivalents;
-               _editor->get_regions_corresponding_to (region, equivalents);
+               _editor->get_regions_corresponding_to (region, equivalents, false);
 
                for (vector<RegionView*>::iterator i = equivalents.begin(); i != equivalents.end(); ++i) {
                        if (new_text != (*i)->region()->name()) {
@@ -1562,7 +1573,7 @@ EditorRegions::sort_type_action (Editing::RegionListSortType t) const
                break;
        default:
                fatal << string_compose (_("programming error: %1: %2"), "EditorRegions: impossible sort type", (int) t) << endmsg;
-               /*NOTREACHED*/
+               abort(); /*NOTREACHED*/
        }
 
        RefPtr<Action> act = ActionManager::get_action (X_("RegionList"), action);