1 /*
2  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Nick Mainsbridge <mainsbridge@gmail.com>
4  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
5  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
6  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2007 Doug McLain <doug@nostar.net>
8  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef __ardour_streamview_h__
26 #define __ardour_streamview_h__
27 
28 #include <list>
29 #include <cmath>
30 
31 #include "pbd/signals.h"
32 
33 #include "ardour/location.h"
34 #include "enums.h"
35 
36 namespace Gdk {
37 	class Color;
38 }
39 
40 namespace ARDOUR {
41 	class Crossfade;
42 	class Region;
43 	class Route;
44 	class Source;
45 	class Track;
46 	struct PeakData;
47 }
48 
49 namespace ArdourCanvas {
50 	class Rectangle;
51 	class Container;
52 }
53 
54 struct RecBoxInfo {
55 	ArdourCanvas::Rectangle* rectangle;
56 	samplepos_t              start;
57 	ARDOUR::samplecnt_t      length;
58 };
59 
60 class Selectable;
61 class RouteTimeAxisView;
62 class RegionView;
63 class RegionSelection;
64 class CrossfadeView;
65 class Selection;
66 
67 class StreamView : public sigc::trackable, public PBD::ScopedConnectionList
68 {
69 public:
70 	virtual ~StreamView ();
71 
trackview()72 	RouteTimeAxisView&       trackview()       { return _trackview; }
trackview()73 	const RouteTimeAxisView& trackview() const { return _trackview; }
74 
75 	void attach ();
76 
77 	void set_zoom_all();
78 
79 	int set_position (gdouble x, gdouble y);
80 	virtual int set_height (double);
81 
82 	virtual int set_samples_per_pixel (double);
get_samples_per_pixel()83 	gdouble     get_samples_per_pixel () const { return _samples_per_pixel; }
84 
85 	virtual void set_layer_display (LayerDisplay);
can_change_layer_display()86 	virtual bool can_change_layer_display() const { return true; }
layer_display()87 	LayerDisplay layer_display () const { return _layer_display; }
88 
canvas_item()89 	ArdourCanvas::Container* canvas_item() { return _canvas_group; }
90 
91 	enum ColorTarget {
92 		RegionColor,
93 		StreamBaseColor
94 	};
95 
get_region_color()96 	uint32_t get_region_color () const { return region_color; }
97 	void     apply_color (uint32_t, ColorTarget t);
98 	void     apply_color (Gdk::Color const &, ColorTarget t);
99 
100 	uint32_t     num_selected_regionviews () const;
101 
102 	RegionView*  find_view (boost::shared_ptr<const ARDOUR::Region>);
103 	void         foreach_regionview (sigc::slot<void,RegionView*> slot);
104 	void         foreach_selected_regionview (sigc::slot<void,RegionView*> slot);
105 
106 	void set_selected_regionviews (RegionSelection&);
107 	void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list<Selectable* >&, bool within = false);
108 	void get_inverted_selectables (Selection&, std::list<Selectable* >& results);
109 
update_contents_metrics(boost::shared_ptr<ARDOUR::Region>)110 	virtual void update_contents_metrics(boost::shared_ptr<ARDOUR::Region>) {}
111 
112 	void add_region_view (boost::weak_ptr<ARDOUR::Region>);
113 
114 	void region_layered (RegionView*);
115 	virtual void update_contents_height ();
116 
117 	virtual void redisplay_track () = 0;
118 	double child_height () const;
layers()119 	ARDOUR::layer_t layers () const { return _layers; }
120 
create_region_view(boost::shared_ptr<ARDOUR::Region>,bool,bool)121 	virtual RegionView* create_region_view (boost::shared_ptr<ARDOUR::Region>, bool, bool) {
122 		return 0;
123 	}
124 
125 	void check_record_layers (boost::shared_ptr<ARDOUR::Region>, ARDOUR::samplepos_t);
126 
127 	virtual void playlist_layered (boost::weak_ptr<ARDOUR::Track>);
128 
129 	sigc::signal<void, RegionView*> RegionViewAdded;
130 	sigc::signal<void> RegionViewRemoved;
131 	/** Emitted when the height of regions has changed */
132 	sigc::signal<void> ContentsHeightChanged;
133 
134 	virtual void parameter_changed (std::string const &);
135 
136 protected:
137 	StreamView (RouteTimeAxisView&, ArdourCanvas::Container* canvas_group = 0);
138 
139 	void         transport_changed();
140 	void         transport_looped();
141 	void         rec_enable_changed();
142 	void         sess_rec_enable_changed();
143 	void         create_rec_box(samplepos_t sample_pos, double width);
144 	virtual void setup_rec_box () = 0;
145 	virtual void update_rec_box ();
146 
147 	virtual RegionView* add_region_view_internal (boost::shared_ptr<ARDOUR::Region>,
148 		      bool wait_for_waves, bool recording = false) = 0;
149 	virtual void remove_region_view (boost::weak_ptr<ARDOUR::Region> );
150 
151 	void         display_track (boost::shared_ptr<ARDOUR::Track>);
152 	virtual void undisplay_track ();
153 	void         layer_regions ();
154 
155 	void playlist_switched (boost::weak_ptr<ARDOUR::Track>);
156 
157 	virtual void color_handler () = 0;
158 
159 	RouteTimeAxisView&       _trackview;
160 	ArdourCanvas::Container* _canvas_group;
161 	ArdourCanvas::Rectangle*  canvas_rect; /* frame around the whole thing */
162 
163 	typedef std::list<RegionView* > RegionViewList;
164 	RegionViewList region_views;
165 
166 	double _samples_per_pixel;
167 
168 	sigc::connection        screen_update_connection;
169 	std::vector<RecBoxInfo> rec_rects;
170 	std::list< std::pair<boost::shared_ptr<ARDOUR::Region>,RegionView* > > rec_regions;
171 	bool                    rec_updating;
172 	bool                    rec_active;
173 
174 	uint32_t region_color;      ///< Contained region color
175 	uint32_t stream_base_color; ///< Background color
176 
177 	PBD::ScopedConnectionList playlist_connections;
178 	PBD::ScopedConnection playlist_switched_connection;
179 
180 	ARDOUR::layer_t _layers;
181 	LayerDisplay    _layer_display;
182 
183 	double height;
184 
185 	PBD::ScopedConnectionList rec_data_ready_connections;
186 	samplepos_t               last_rec_data_sample;
187 
188 	/* When recording, the session time at which a new layer must be created for the region
189 	   being recorded, or max_samplepos if not applicable.
190 	*/
191 	samplepos_t _new_rec_layer_time;
192 	void setup_new_rec_layer_time (boost::shared_ptr<ARDOUR::Region>);
193 
194 private:
195 	void update_coverage_frame ();
196 };
197 
198 #endif /* __ardour_streamview_h__ */
199 
200