Fix thinkos in cubasish theme
[ardour.git] / gtk2_ardour / automation_streamview.cc
index e504d13931d551981194cb9748e67c946c81a1d9..1628612badf853c5358d569f5aa9f1839444d7d0 100644 (file)
@@ -1,22 +1,25 @@
 /*
-    Copyright (C) 2001-2007 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Copyright (C) 2007-2014 David Robillard <d@drobilla.net>
+ * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
-#include <cassert>
 #include <cmath>
 #include <list>
 #include <utility>
 #include "ardour/midi_region.h"
 #include "ardour/midi_source.h"
 
-#include "ardour_ui.h"
 #include "automation_region_view.h"
 #include "automation_streamview.h"
 #include "automation_time_axis.h"
-#include "global_signals.h"
 #include "gui_thread.h"
 #include "public_editor.h"
 #include "region_selection.h"
 #include "region_view.h"
 #include "rgb_macros.h"
 #include "selection.h"
+#include "ui_config.h"
+
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -51,7 +55,7 @@ using namespace Editing;
 
 AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv)
        : StreamView (*dynamic_cast<RouteTimeAxisView*>(tv.get_parent()),
-                     tv.canvas_display())
+                     tv.canvas_display())
        , _automation_view(tv)
        , _pending_automation_state (Off)
 {
@@ -60,7 +64,7 @@ AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv)
 
        color_handler ();
 
-       ColorsChanged.connect(sigc::mem_fun(*this, &AutomationStreamView::color_handler));
+       UIConfiguration::instance().ColorsChanged.connect(sigc::mem_fun(*this, &AutomationStreamView::color_handler));
 }
 
 AutomationStreamView::~AutomationStreamView ()
@@ -71,7 +75,9 @@ AutomationStreamView::~AutomationStreamView ()
 RegionView*
 AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region, bool wait_for_data, bool /*recording*/)
 {
-       assert (region);
+       if (!region) {
+               return 0;
+       }
 
        if (wait_for_data) {
                boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(region);
@@ -88,7 +94,10 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
        boost::shared_ptr<AutomationList> list;
        if (control) {
                list = boost::dynamic_pointer_cast<AutomationList>(control->list());
-               assert(!control->list() || list);
+               if (control->list() && !list) {
+                       error << _("unable to display automation region for control without list") << endmsg;
+                       return 0;
+               }
        }
 
        AutomationRegionView *region_view;
@@ -197,9 +206,9 @@ void
 AutomationStreamView::color_handler ()
 {
        if (_trackview.is_midi_track()) {
-               canvas_rect->set_fill_color (ARDOUR_UI::config()->color_mod ("midi track base", "midi track base"));
+               canvas_rect->set_fill_color (UIConfiguration::instance().color_mod ("midi track base", "midi track base"));
        } else {
-               canvas_rect->set_fill_color (ARDOUR_UI::config()->color ("midi bus base"));
+               canvas_rect->set_fill_color (UIConfiguration::instance().color ("midi bus base"));
        }
 }
 
@@ -270,23 +279,21 @@ AutomationStreamView::clear ()
        }
 }
 
-/** @param start Start position in session frames.
- *  @param end End position in session frames.
+/** @param start Start position in session samples.
+ *  @param end End position in session samples.
  *  @param bot Bottom position expressed as a fraction of track height where 0 is the bottom of the track.
  *  @param top Top position expressed as a fraction of track height where 0 is the bottom of the track.
  *  NOTE: this y system is different to that for the StreamView method that this overrides, which is a little
  *  confusing.
  */
 void
-AutomationStreamView::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
+AutomationStreamView::get_selectables (samplepos_t start, samplepos_t end, double botfrac, double topfrac, list<Selectable*>& results, bool /*within*/)
 {
-       if (!_trackview.editor().internal_editing()) {
-               return;  // TODO: selection of automation regions
-       }
        for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
                AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
-               assert (arv);
-               arv->line()->get_selectables (start, end, botfrac, topfrac, results);
+               if (arv) {
+                       arv->line()->get_selectables (start, end, botfrac, topfrac, results);
+               }
        }
 }
 
@@ -307,22 +314,16 @@ AutomationStreamView::get_lines () const
 
        for (list<RegionView*>::const_iterator i = region_views.begin(); i != region_views.end(); ++i) {
                AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
-               assert (arv);
-               lines.push_back (arv->line());
+               if (arv) {
+                       lines.push_back (arv->line());
+               }
        }
 
        return lines;
 }
 
-struct RegionPositionSorter {
-       bool operator() (RegionView* a, RegionView* b) {
-               return a->region()->position() < b->region()->position();
-       }
-};
-
-
 bool
-AutomationStreamView::paste (framepos_t                                pos,
+AutomationStreamView::paste (samplepos_t                               pos,
                              unsigned                                  paste_count,
                              float                                     times,
                              boost::shared_ptr<ARDOUR::AutomationList> alist)
@@ -333,7 +334,7 @@ AutomationStreamView::paste (framepos_t                                pos,
                return false;
        }
 
-       region_views.sort (RegionPositionSorter ());
+       region_views.sort (RegionView::PositionOrder());
 
        list<RegionView*>::const_iterator prev = region_views.begin ();