Update GPL boilerplate and (C)
[ardour.git] / gtk2_ardour / region_view.cc
index d94c1fae64591a2fa30ad6c60f1491e63ade07bf..8f22d716c60b8b2d80c39be5e15ee2318dd48dd8 100644 (file)
@@ -1,21 +1,27 @@
 /*
-    Copyright (C) 2001-2006 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) 2006-2014 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2007-2019 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2007 Doug McLain <doug@nostar.net>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2015-2017 Nick Mainsbridge <mainsbridge@gmail.com>
+ * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.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 <cmath>
 #include <algorithm>
@@ -71,7 +77,7 @@ RegionView::RegionView (ArdourCanvas::Container*          parent,
                         bool                              automation)
        : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), false, automation,
                            (automation ? TimeAxisViewItem::ShowFrame :
-                            TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
+                            TimeAxisViewItem::Visibility ((UIConfiguration::instance().get_show_region_name() ? TimeAxisViewItem::ShowNameText : 0) |
                                                           TimeAxisViewItem::ShowNameHighlight| TimeAxisViewItem::ShowFrame)))
        , _region (r)
        , sync_mark(0)
@@ -199,7 +205,7 @@ RegionView::~RegionView ()
                delete *g;
        }
 
-       for (list<ArdourCanvas::Rectangle*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
+       for (list<ArdourCanvas::Rectangle*>::iterator i = _coverage_frame.begin (); i != _coverage_frame.end (); ++i) {
                delete *i;
        }
 
@@ -220,7 +226,7 @@ RegionView::canvas_group_event (GdkEvent* event)
 void
 RegionView::set_silent_frames (const AudioIntervalResult& silences, double /*threshold*/)
 {
-       framecnt_t shortest = max_framecnt;
+       samplecnt_t shortest = max_samplecnt;
 
        /* remove old silent frames */
        drop_silent_frames ();
@@ -250,11 +256,11 @@ RegionView::set_silent_frames (const AudioIntervalResult& silences, double /*thr
        }
 
        /* Find shortest audible segment */
-       framecnt_t shortest_audible = max_framecnt;
+       samplecnt_t shortest_audible = max_samplecnt;
 
-       framecnt_t s = _region->start();
+       samplecnt_t s = _region->start();
        for (AudioIntervalResult::const_iterator i = silences.begin(); i != silences.end(); ++i) {
-               framecnt_t const dur = i->first - s;
+               samplecnt_t const dur = i->first - s;
                if (dur > 0) {
                        shortest_audible = min (shortest_audible, dur);
                }
@@ -262,7 +268,7 @@ RegionView::set_silent_frames (const AudioIntervalResult& silences, double /*thr
                s = i->second;
        }
 
-       framecnt_t const dur = _region->start() + _region->length() - 1 - s;
+       samplecnt_t const dur = _region->start() + _region->length() - 1 - s;
        if (dur > 0) {
                shortest_audible = min (shortest_audible, dur);
        }
@@ -277,7 +283,7 @@ RegionView::set_silent_frames (const AudioIntervalResult& silences, double /*thr
        _silence_text->set_x_position (trackview.editor().sample_to_pixel (silences.front().first - _region->start()) + 10.0);
        _silence_text->set_y_position (20.0);
 
-       double ms = (float) shortest/_region->session().frame_rate();
+       double ms = (float) shortest/_region->session().sample_rate();
 
        /* ms are now in seconds */
 
@@ -297,9 +303,9 @@ RegionView::set_silent_frames (const AudioIntervalResult& silences, double /*thr
                + ", "
                + string_compose (_("shortest = %1 %2"), ms, sunits);
 
-       if (shortest_audible != max_framepos) {
+       if (shortest_audible != max_samplepos) {
                /* ms are now in seconds */
-               double ma = (float) shortest_audible / _region->session().frame_rate();
+               double ma = (float) shortest_audible / _region->session().sample_rate();
                char const * aunits;
 
                if (ma >= 60.0) {
@@ -414,11 +420,11 @@ RegionView::region_resized (const PropertyChange& what_changed)
 
                unit_length = _region->length() / samples_per_pixel;
 
-               for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
+               for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
 
-                       (*i)->set_duration (unit_length);
+                       (*i)->set_duration (unit_length);
 
-               }
+               }
        }
 }
 
@@ -455,7 +461,7 @@ RegionView::lower_to_bottom ()
 }
 
 bool
-RegionView::set_position (framepos_t pos, void* /*src*/, double* ignored)
+RegionView::set_position (samplepos_t pos, void* /*src*/, double* ignored)
 {
        double delta;
        bool ret;
@@ -491,9 +497,9 @@ RegionView::set_samples_per_pixel (double fpp)
 }
 
 bool
-RegionView::set_duration (framecnt_t frames, void *src)
+RegionView::set_duration (samplecnt_t samples, void *src)
 {
-       if (!TimeAxisViewItem::set_duration (frames, src)) {
+       if (!TimeAxisViewItem::set_duration (samples, src)) {
                return false;
        }
 
@@ -600,7 +606,7 @@ void
 RegionView::region_sync_changed ()
 {
        int sync_dir;
-       framecnt_t sync_offset;
+       samplecnt_t sync_offset;
 
        sync_offset = _region->sync_offset (sync_dir);
 
@@ -728,7 +734,7 @@ RegionView::set_height (double h)
        if (sync_line) {
                Points points;
                int sync_dir;
-               framecnt_t sync_offset;
+               samplecnt_t sync_offset;
                sync_offset = _region->sync_offset (sync_dir);
                double offset = sync_offset / samples_per_pixel;
 
@@ -738,7 +744,7 @@ RegionView::set_height (double h)
                        );
        }
 
-       for (list<ArdourCanvas::Rectangle*>::iterator i = _coverage_frames.begin(); i != _coverage_frames.end(); ++i) {
+       for (list<ArdourCanvas::Rectangle*>::iterator i = _coverage_frame.begin(); i != _coverage_frame.end(); ++i) {
                (*i)->set_y1 (h + 1);
        }
 
@@ -748,20 +754,20 @@ RegionView::set_height (double h)
 
 }
 
-/** Remove old coverage frames and make new ones, if we're in a LayerDisplay mode
+/** Remove old coverage frame and make new ones, if we're in a LayerDisplay mode
  *  which uses them. */
 void
-RegionView::update_coverage_frames (LayerDisplay d)
+RegionView::update_coverage_frame (LayerDisplay d)
 {
-       /* remove old coverage frames */
-       for (list<ArdourCanvas::Rectangle*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
+       /* remove old coverage frame */
+       for (list<ArdourCanvas::Rectangle*>::iterator i = _coverage_frame.begin (); i != _coverage_frame.end (); ++i) {
                delete *i;
        }
 
-       _coverage_frames.clear ();
+       _coverage_frame.clear ();
 
        if (d != Stacked) {
-               /* don't do coverage frames unless we're in stacked mode */
+               /* don't do coverage frame unless we're in stacked mode */
                return;
        }
 
@@ -770,9 +776,9 @@ RegionView::update_coverage_frames (LayerDisplay d)
                return;
        }
 
-       framepos_t const position = _region->first_frame ();
-       framepos_t t = position;
-       framepos_t const end = _region->last_frame ();
+       samplepos_t const position = _region->first_sample ();
+       samplepos_t t = position;
+       samplepos_t const end = _region->last_sample ();
 
        ArdourCanvas::Rectangle* cr = 0;
        bool me = false;
@@ -795,7 +801,7 @@ RegionView::update_coverage_frames (LayerDisplay d)
                /* start off any new rect, if required */
                if (cr == 0 || me != new_me) {
                        cr = new ArdourCanvas::Rectangle (group);
-                       _coverage_frames.push_back (cr);
+                       _coverage_frame.push_back (cr);
                        cr->set_x0 (trackview.editor().sample_to_pixel (t - position));
                        cr->set_y0 (1);
                        cr->set_y1 (_height + 1);
@@ -839,13 +845,13 @@ RegionView::update_coverage_frames (LayerDisplay d)
 }
 
 bool
-RegionView::trim_front (framepos_t new_bound, bool no_overlap, const int32_t sub_num)
+RegionView::trim_front (samplepos_t new_bound, bool no_overlap, const int32_t sub_num)
 {
        if (_region->locked()) {
                return false;
        }
 
-       framepos_t const pre_trim_first_frame = _region->first_frame();
+       samplepos_t const pre_trim_first_sample = _region->first_sample();
 
        if (_region->position() == new_bound) {
                return false;
@@ -854,52 +860,52 @@ RegionView::trim_front (framepos_t new_bound, bool no_overlap, const int32_t sub
        _region->trim_front (new_bound, sub_num);
 
        if (no_overlap) {
-               // Get the next region on the left of this region and shrink/expand it.
+               /* Get the next region on the left of this region and shrink/expand it. */
                boost::shared_ptr<Playlist> playlist (_region->playlist());
-               boost::shared_ptr<Region> region_left = playlist->find_next_region (pre_trim_first_frame, End, 0);
+               boost::shared_ptr<Region> region_left = playlist->find_next_region (pre_trim_first_sample, End, 0);
 
                bool regions_touching = false;
 
-               if (region_left != 0 && (pre_trim_first_frame == region_left->last_frame() + 1)) {
+               if (region_left != 0 && (pre_trim_first_sample == region_left->last_sample() + 1)) {
                        regions_touching = true;
                }
 
-               // Only trim region on the left if the first frame has gone beyond the left region's last frame.
-               if (region_left != 0 && (region_left->last_frame() > _region->first_frame() || regions_touching)) {
-                       region_left->trim_end (_region->first_frame() - 1);
+               /* Only trim region on the left if the first sample has gone beyond the left region's last sample. */
+               if (region_left != 0 && (region_left->last_sample() > _region->first_sample() || regions_touching)) {
+                       region_left->trim_end (_region->first_sample() - 1);
                }
        }
 
        region_changed (ARDOUR::bounds_change);
 
-       return (pre_trim_first_frame != _region->first_frame());  //return true if we actually changed something
+       return (pre_trim_first_sample != _region->first_sample()); // return true if we actually changed something
 }
 
 bool
-RegionView::trim_end (framepos_t new_bound, bool no_overlap, const int32_t sub_num)
+RegionView::trim_end (samplepos_t new_bound, bool no_overlap, const int32_t sub_num)
 {
        if (_region->locked()) {
                return false;
        }
 
-       framepos_t const pre_trim_last_frame = _region->last_frame();
+       samplepos_t const pre_trim_last_sample = _region->last_sample();
 
        _region->trim_end (new_bound, sub_num);
 
        if (no_overlap) {
-               // Get the next region on the right of this region and shrink/expand it.
+               /* Get the next region on the right of this region and shrink/expand it. */
                boost::shared_ptr<Playlist> playlist (_region->playlist());
-               boost::shared_ptr<Region> region_right = playlist->find_next_region (pre_trim_last_frame, Start, 1);
+               boost::shared_ptr<Region> region_right = playlist->find_next_region (pre_trim_last_sample, Start, 1);
 
                bool regions_touching = false;
 
-               if (region_right != 0 && (pre_trim_last_frame == region_right->first_frame() - 1)) {
+               if (region_right != 0 && (pre_trim_last_sample == region_right->first_sample() - 1)) {
                        regions_touching = true;
                }
 
-               // Only trim region on the right if the last frame has gone beyond the right region's first frame.
-               if (region_right != 0 && (region_right->first_frame() < _region->last_frame() || regions_touching)) {
-                       region_right->trim_front (_region->last_frame() + 1, sub_num);
+               /* Only trim region on the right if the last sample has gone beyond the right region's first sample. */
+               if (region_right != 0 && (region_right->first_sample() < _region->last_sample() || regions_touching)) {
+                       region_right->trim_front (_region->last_sample() + 1, sub_num);
                }
 
                region_changed (ARDOUR::bounds_change);
@@ -908,7 +914,7 @@ RegionView::trim_end (framepos_t new_bound, bool no_overlap, const int32_t sub_n
                region_changed (PropertyChange (ARDOUR::Properties::length));
        }
 
-       return (pre_trim_last_frame != _region->last_frame());  //return true if we actually changed something
+       return (pre_trim_last_sample != _region->last_sample()); // return true if we actually changed something
 }
 
 
@@ -924,7 +930,7 @@ RegionView::thaw_after_trim ()
 
 
 void
-RegionView::move_contents (frameoffset_t distance)
+RegionView::move_contents (sampleoffset_t distance)
 {
        if (_region->locked()) {
                return;
@@ -933,29 +939,43 @@ RegionView::move_contents (frameoffset_t distance)
        region_changed (PropertyChange (ARDOUR::Properties::start));
 }
 
-/** Snap a frame offset within our region using the current snap settings.
+/** Snap a sample offset within our region using the current snap settings.
  *  @param x Frame offset from this region's position.
  *  @param ensure_snap whether to ignore snap_mode (in the case of SnapOff) and magnetic snap.
  *  Used when inverting snap mode logic with key modifiers, or snap distance calculation.
- *  @return Snapped frame offset from this region's position.
+ *  @return Snapped sample offset from this region's position.
  */
-MusicFrame
-RegionView::snap_frame_to_frame (frameoffset_t x, bool ensure_snap) const
+MusicSample
+RegionView::snap_sample_to_sample (sampleoffset_t x, bool ensure_snap) const
 {
        PublicEditor& editor = trackview.editor();
-       /* x is region relative, convert it to global absolute frames */
-       framepos_t const session_frame = x + _region->position();
+       /* x is region relative, convert it to global absolute samples */
+       samplepos_t const session_sample = x + _region->position();
 
        /* try a snap in either direction */
-       MusicFrame frame (session_frame, 0);
-       editor.snap_to (frame, RoundNearest, false, ensure_snap);
+       MusicSample sample (session_sample, 0);
+       editor.snap_to (sample, RoundNearest, SnapToAny_Visual, ensure_snap);
 
        /* if we went off the beginning of the region, snap forwards */
-       if (frame.frame < _region->position ()) {
-               frame.frame = session_frame;
-               editor.snap_to (frame, RoundUpAlways, false, ensure_snap);
+       if (sample.sample < _region->position ()) {
+               sample.sample = session_sample;
+               editor.snap_to (sample, RoundUpAlways, SnapToAny_Visual, ensure_snap);
        }
 
        /* back to region relative, keeping the relevant divisor */
-       return MusicFrame (frame.frame - _region->position(), frame.division);
+       return MusicSample (sample.sample - _region->position(), sample.division);
+}
+
+void
+RegionView::update_visibility ()
+{
+       /* currently only the name visibility can be changed dynamically */
+
+       if (UIConfiguration::instance().get_show_region_name()) {
+               visibility = Visibility (visibility | ShowNameText);
+       } else {
+               visibility = Visibility (visibility & ~ShowNameText);
+       }
+
+       manage_name_text ();
 }