Comment and (hopefully) simplify Editor::region_drag_motion_callback, fixing problems...
[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 <ardour/location.h>
26 #include "enums.h"
27 #include "simplerect.h"
28 #include "canvas.h"
29
30 namespace Gdk {
31         class Color;
32 }
33
34 namespace ARDOUR {
35         class Route;
36         class Diskstream;
37         class Crossfade;
38         class PeakData;
39         class Region;
40         class Source;
41 }
42
43 struct RecBoxInfo {
44         ArdourCanvas::SimpleRect* rectangle;
45         nframes_t            start;
46         nframes_t            length;
47 };
48
49 class PublicEditor;
50 class Selectable;
51 class RouteTimeAxisView;
52 class RegionView;
53 class RegionSelection;
54 class CrossfadeView;
55 class Selection;
56
57 class StreamView : public sigc::trackable
58 {
59 public:
60         virtual ~StreamView ();
61
62         RouteTimeAxisView&       trackview()       { return _trackview; }
63         const RouteTimeAxisView& trackview() const { return _trackview; }
64
65         void attach ();
66
67         void set_zoom_all();
68
69         int set_position (gdouble x, gdouble y);
70         virtual int set_height (double);
71
72         virtual int set_samples_per_unit (gdouble spp);
73         gdouble     get_samples_per_unit () { return _samples_per_unit; }
74
75         void set_layer_display (LayerDisplay);
76         LayerDisplay layer_display () const { return _layer_display; }
77
78         ArdourCanvas::Group* background_group() { return _background_group; }
79         ArdourCanvas::Group* canvas_item() { return canvas_group; }
80
81         enum ColorTarget {
82                 RegionColor,
83                 StreamBaseColor
84         };
85
86         Gdk::Color get_region_color () const { return region_color; }
87         void       apply_color (Gdk::Color&, ColorTarget t);
88
89         RegionView*  find_view (boost::shared_ptr<const ARDOUR::Region>);
90         void         foreach_regionview (sigc::slot<void,RegionView*> slot);
91
92         void set_selected_regionviews (RegionSelection&);
93         void get_selectables (nframes_t start, nframes_t end, list<Selectable* >&);
94         void get_inverted_selectables (Selection&, list<Selectable* >& results);
95
96         void add_region_view (boost::shared_ptr<ARDOUR::Region>);
97         void region_layered (RegionView*);
98         virtual void update_contents_height ();
99         
100         virtual void redisplay_diskstream () = 0;
101         double child_height () const;
102         ARDOUR::layer_t layers () const { return _layers; }
103         
104         sigc::signal<void,RegionView*> RegionViewAdded;
105
106 protected:
107         StreamView (RouteTimeAxisView&, ArdourCanvas::Group* group = NULL);
108         
109 //private: (FIXME?)
110
111         void         transport_changed();
112         void         transport_looped();
113         void         rec_enable_changed();
114         void         sess_rec_enable_changed();
115         virtual void setup_rec_box () = 0;
116         void         update_rec_box ();
117         //virtual void update_rec_regions () = 0;
118         
119         virtual RegionView* add_region_view_internal (boost::shared_ptr<ARDOUR::Region>, bool wait_for_waves, bool recording = false) = 0;
120         virtual void remove_region_view (boost::weak_ptr<ARDOUR::Region> );
121         //void         remove_rec_region (boost::shared_ptr<ARDOUR::Region>); (unused)
122
123         void         display_diskstream (boost::shared_ptr<ARDOUR::Diskstream>);
124         virtual void undisplay_diskstream ();
125         void         diskstream_changed ();
126         
127         virtual void playlist_changed (boost::shared_ptr<ARDOUR::Diskstream>);
128         virtual void playlist_modified_weak (boost::weak_ptr<ARDOUR::Diskstream>);
129         virtual void playlist_modified (boost::shared_ptr<ARDOUR::Diskstream>);
130         
131         virtual void color_handler () = 0;
132
133         RouteTimeAxisView&        _trackview;
134         bool                      owns_canvas_group;
135         ArdourCanvas::Group*      _background_group;
136         ArdourCanvas::Group*      canvas_group;
137         ArdourCanvas::SimpleRect* canvas_rect; /* frame around the whole thing */
138
139         typedef list<RegionView* > RegionViewList;
140         RegionViewList  region_views;
141
142         double _samples_per_unit;
143
144         sigc::connection       screen_update_connection;
145         vector<RecBoxInfo>     rec_rects;
146         list< std::pair<boost::shared_ptr<ARDOUR::Region>,RegionView* > > rec_regions;
147         bool                   rec_updating;
148         bool                   rec_active;
149         bool                   use_rec_regions;
150         
151         Gdk::Color region_color;      ///< Contained region color
152         uint32_t   stream_base_color; ///< Background color
153
154         vector<sigc::connection> playlist_connections;
155         sigc::connection         playlist_change_connection;
156
157         ARDOUR::layer_t _layers;
158         double height;
159         LayerDisplay _layer_display;
160
161         list<sigc::connection> rec_data_ready_connections;
162         jack_nframes_t         last_rec_data_frame;
163
164 private:
165
166         void update_coverage_frames ();
167 };
168
169 #endif /* __ardour_streamview_h__ */
170