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