Update comments & icon of rubberband example Lua script
[ardour.git] / gtk2_ardour / region_view.h
1 /*
2  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2011 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2007-2019 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2007 Doug McLain <doug@nostar.net>
6  * Copyright (C) 2015-2017 Nick Mainsbridge <mainsbridge@gmail.com>
7  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __gtk_ardour_region_view_h__
25 #define __gtk_ardour_region_view_h__
26
27 #ifdef interface
28 #undef interface
29 #endif
30
31 #include <vector>
32
33 #include <sigc++/signal.h>
34 #include "ardour/region.h"
35 #include "ardour/beats_samples_converter.h"
36
37 #include "canvas/fwd.h"
38
39 #include "time_axis_view_item.h"
40 #include "automation_line.h"
41 #include "enums.h"
42
43 class TimeAxisView;
44 class RegionEditor;
45 class GhostRegion;
46 class AutomationTimeAxisView;
47 class AutomationRegionView;
48
49 namespace ArdourCanvas {
50         class Polygon;
51         class Text;
52 }
53
54 class RegionView : public TimeAxisViewItem
55 {
56 public:
57         RegionView (ArdourCanvas::Container*          parent,
58                     TimeAxisView&                     time_view,
59                     boost::shared_ptr<ARDOUR::Region> region,
60                     double                            samples_per_pixel,
61                     uint32_t                          base_color,
62                     bool                              automation = false);
63
64         RegionView (const RegionView& other);
65         RegionView (const RegionView& other, boost::shared_ptr<ARDOUR::Region> other_region);
66
67         ~RegionView ();
68
69         virtual void set_selected (bool yn) {
70                 _region->set_selected_for_solo(yn);
71                 TimeAxisViewItem::set_selected(yn);
72         }
73
74         virtual void init (bool wait_for_data);
75
76         boost::shared_ptr<ARDOUR::Region> region() const { return _region; }
77
78         bool is_valid() const    { return valid; }
79
80         void set_valid (bool yn) { valid = yn; }
81
82         virtual void set_height (double);
83         virtual void set_samples_per_pixel (double);
84         virtual bool set_duration (samplecnt_t, void*);
85
86         void move (double xdelta, double ydelta);
87
88         void raise_to_top ();
89         void lower_to_bottom ();
90
91         bool set_position(samplepos_t pos, void* src, double* delta = 0);
92
93         virtual void show_region_editor ();
94         void hide_region_editor ();
95
96         virtual void region_changed (const PBD::PropertyChange&);
97
98         uint32_t get_fill_color () const;
99
100         virtual GhostRegion* add_ghost (TimeAxisView&) = 0;
101         void remove_ghost_in (TimeAxisView&);
102         void remove_ghost (GhostRegion*);
103
104         virtual void entered () {}
105         virtual void exited () {}
106
107         virtual void enable_display(bool yn) { _enable_display = yn; }
108         virtual void update_coverage_frame (LayerDisplay);
109
110         static PBD::Signal1<void,RegionView*> RegionViewGoingAway;
111
112         /** Called when a front trim is about to begin */
113         virtual void trim_front_starting () {}
114
115         bool trim_front (samplepos_t, bool, const int32_t sub_num);
116
117         /** Called when a start trim has finished */
118         virtual void trim_front_ending () {}
119
120         bool trim_end (samplepos_t, bool, const int32_t sub_num);
121         void move_contents (ARDOUR::sampleoffset_t);
122         virtual void thaw_after_trim ();
123
124         void set_silent_frames (const ARDOUR::AudioIntervalResult&, double threshold);
125         void drop_silent_frames ();
126         void hide_silent_frames ();
127
128         struct PositionOrder {
129                 bool operator()(const RegionView* a, const RegionView* b) {
130                         return a->region()->position() < b->region()->position();
131                 }
132         };
133
134         ARDOUR::MusicSample snap_sample_to_sample (ARDOUR::sampleoffset_t, bool ensure_snap = false) const;
135
136         void update_visibility ();
137
138 protected:
139
140         /** Allows derived types to specify their visibility requirements
141          * to the TimeAxisViewItem parent class
142          */
143         RegionView (ArdourCanvas::Container *,
144                     TimeAxisView&,
145                     boost::shared_ptr<ARDOUR::Region>,
146                     double samples_per_pixel,
147                     uint32_t basic_color,
148                     bool recording,
149                     TimeAxisViewItem::Visibility);
150
151         bool canvas_group_event (GdkEvent*);
152
153         virtual void region_resized (const PBD::PropertyChange&);
154         virtual void region_muted ();
155         void         region_locked ();
156         void         region_opacity ();
157         virtual void region_renamed ();
158         void         region_sync_changed ();
159
160         std::string make_name () const;
161
162         static gint _lock_toggle (ArdourCanvas::Item*, GdkEvent*, void*);
163         void        lock_toggle ();
164
165         virtual void set_colors ();
166         virtual void set_sync_mark_color ();
167         virtual void reset_width_dependent_items (double pixel_width);
168
169         virtual void color_handler () {}
170
171         boost::shared_ptr<ARDOUR::Region> _region;
172
173         ArdourCanvas::Polygon* sync_mark; ///< polgyon for sync position
174         ArdourCanvas::Line* sync_line; ///< polgyon for sync position
175
176         RegionEditor* editor;
177
178         std::vector<ControlPoint *> control_points;
179         double current_visible_sync_position;
180
181         bool    valid; ///< see StreamView::redisplay_diskstream()
182         bool    _enable_display; ///< see StreamView::redisplay_diskstream()
183         double  _pixel_width;
184         bool    in_destructor;
185
186         bool wait_for_data;
187
188         std::vector<GhostRegion*> ghosts;
189
190         /** a list of rectangles which are used in stacked display mode to colour
191          * different bits of regions according to whether or not they are the one
192          * that will be played at any given time.
193          */
194         std::list<ArdourCanvas::Rectangle*> _coverage_frame;
195
196         /** a list of rectangles used to show silent segments
197         */
198         std::list<ArdourCanvas::Rectangle*> _silent_frames;
199         /** a list of rectangles used to show the current silence threshold
200         */
201         std::list<ArdourCanvas::Rectangle*> _silent_threshold_samples;
202         /** a text item to display strip silence statistics */
203         ArdourCanvas::Text* _silence_text;
204 };
205
206 #endif /* __gtk_ardour_region_view_h__ */