Merge branch 'master' into cairocanvas
[ardour.git] / gtk2_ardour / streamview.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 __ardour_streamview_h__
20 #define __ardour_streamview_h__
21
22 #include <list>
23 #include <cmath>
24
25 #include "pbd/signals.h"
26
27 #include "ardour/location.h"
28 #include "enums.h"
29
30 namespace Gdk {
31         class Color;
32 }
33
34 namespace ARDOUR {
35         class Crossfade;
36         class Region;
37         class Route;
38         class Source;
39         class Track;
40         struct PeakData;
41 }
42
43 namespace ArdourCanvas {
44         class Rectangle;
45         class Group;
46 }
47
48 struct RecBoxInfo {
49         ArdourCanvas::Rectangle*   rectangle;
50         framepos_t                 start;
51         ARDOUR::framecnt_t         length;
52 };
53
54 class Selectable;
55 class RouteTimeAxisView;
56 class RegionView;
57 class RegionSelection;
58 class CrossfadeView;
59 class Selection;
60
61 class StreamView : public sigc::trackable, public PBD::ScopedConnectionList
62 {
63 public:
64         virtual ~StreamView ();
65
66         RouteTimeAxisView&       trackview()       { return _trackview; }
67         const RouteTimeAxisView& trackview() const { return _trackview; }
68
69         void attach ();
70
71         void set_zoom_all();
72
73         int set_position (gdouble x, gdouble y);
74         virtual int set_height (double);
75
76         virtual int set_frames_per_pixel (double);
77         gdouble     get_frames_per_pixel () const { return _frames_per_pixel; }
78         virtual void horizontal_position_changed () {}
79
80         virtual void enter_internal_edit_mode ();
81         virtual void leave_internal_edit_mode ();
82
83         void set_layer_display (LayerDisplay);
84         LayerDisplay layer_display () const { return _layer_display; }
85
86         ArdourCanvas::Group* background_group() { return _background_group; }
87         ArdourCanvas::Group* canvas_item() { return _canvas_group; }
88
89         enum ColorTarget {
90                 RegionColor,
91                 StreamBaseColor
92         };
93
94         Gdk::Color get_region_color () const { return region_color; }
95         void       apply_color (Gdk::Color, ColorTarget t);
96
97         uint32_t     num_selected_regionviews () const;
98
99         RegionView*  find_view (boost::shared_ptr<const ARDOUR::Region>);
100         void         foreach_regionview (sigc::slot<void,RegionView*> slot);
101         void         foreach_selected_regionview (sigc::slot<void,RegionView*> slot);
102
103         void set_selected_regionviews (RegionSelection&);
104         void get_selectables (ARDOUR::framepos_t, ARDOUR::framepos_t, double, double, std::list<Selectable* >&);
105         void get_inverted_selectables (Selection&, std::list<Selectable* >& results);
106
107         virtual void update_contents_metrics(boost::shared_ptr<ARDOUR::Region>) {}
108
109         void add_region_view (boost::weak_ptr<ARDOUR::Region>);
110
111         void region_layered (RegionView*);
112         virtual void update_contents_height ();
113
114         virtual void redisplay_track () = 0;
115         double child_height () const;
116         ARDOUR::layer_t layers () const { return _layers; }
117
118         virtual RegionView* create_region_view (boost::shared_ptr<ARDOUR::Region>, bool, bool) {
119                 return 0;
120         }
121
122         void check_record_layers (boost::shared_ptr<ARDOUR::Region>, ARDOUR::framepos_t);
123
124         virtual void playlist_layered (boost::weak_ptr<ARDOUR::Track>);
125         
126         sigc::signal<void, RegionView*> RegionViewAdded;
127         sigc::signal<void> RegionViewRemoved;
128         /** Emitted when the height of regions has changed */
129         sigc::signal<void> ContentsHeightChanged;
130
131 protected:
132         StreamView (RouteTimeAxisView&, ArdourCanvas::Group* background_group = 0, ArdourCanvas::Group* canvas_group = 0);
133
134         void         transport_changed();
135         void         transport_looped();
136         void         rec_enable_changed();
137         void         sess_rec_enable_changed();
138         virtual void setup_rec_box () = 0;
139         virtual void update_rec_box ();
140
141         virtual RegionView* add_region_view_internal (boost::shared_ptr<ARDOUR::Region>,
142                       bool wait_for_waves, bool recording = false) = 0;
143         virtual void remove_region_view (boost::weak_ptr<ARDOUR::Region> );
144
145         void         display_track (boost::shared_ptr<ARDOUR::Track>);
146         virtual void undisplay_track ();
147         void         diskstream_changed ();
148         void         layer_regions ();
149
150         void playlist_switched (boost::weak_ptr<ARDOUR::Track>);
151
152         virtual void color_handler () = 0;
153
154         RouteTimeAxisView&        _trackview;
155         bool                      owns_background_group;
156         bool                      owns_canvas_group;
157         ArdourCanvas::Group*      _background_group;
158         ArdourCanvas::Group*      _canvas_group;
159         ArdourCanvas::Rectangle*  canvas_rect; /* frame around the whole thing */
160
161         typedef std::list<RegionView* > RegionViewList;
162         RegionViewList  region_views;
163
164         double _frames_per_pixel;
165
166         sigc::connection       screen_update_connection;
167         std::vector<RecBoxInfo>     rec_rects;
168         std::list< std::pair<boost::shared_ptr<ARDOUR::Region>,RegionView* > > rec_regions;
169         bool                   rec_updating;
170         bool                   rec_active;
171
172         Gdk::Color region_color;      ///< Contained region color
173         uint32_t   stream_base_color; ///< Background color
174
175         PBD::ScopedConnectionList playlist_connections;
176         PBD::ScopedConnection playlist_switched_connection;
177
178         ARDOUR::layer_t _layers;
179         LayerDisplay    _layer_display;
180
181         double height;
182
183         PBD::ScopedConnectionList rec_data_ready_connections;
184         framepos_t                last_rec_data_frame;
185
186         /* When recording, the session time at which a new layer must be created for the region
187            being recorded, or max_framepos if not applicable.
188         */
189         framepos_t _new_rec_layer_time;
190         void setup_new_rec_layer_time (boost::shared_ptr<ARDOUR::Region>);
191
192 private:
193         void update_coverage_frames ();
194 };
195
196 #endif /* __ardour_streamview_h__ */
197