2 * Copyright (C) 2005-2009 Nick Mainsbridge <mainsbridge@gmail.com>
3 * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
5 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
6 * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2008-2014 David Robillard <d@drobilla.net>
8 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
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.
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.
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.
25 #ifndef __gtk_ardour_time_axis_view_item_h__
26 #define __gtk_ardour_time_axis_view_item_h__
30 #include <gdkmm/color.h>
31 #include <pangomm/fontdescription.h>
32 #include "pbd/signals.h"
33 #include "selectable.h"
37 namespace ArdourCanvas {
45 using ARDOUR::samplepos_t;
46 using ARDOUR::samplecnt_t;
49 * Base class for items that may appear upon a TimeAxisView.
52 class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList
55 virtual ~TimeAxisViewItem();
57 virtual bool set_position(samplepos_t, void*, double* delta = 0);
58 samplepos_t get_position() const;
59 virtual bool set_duration(samplecnt_t, void*);
60 samplecnt_t get_duration() const;
61 virtual void set_max_duration(samplecnt_t, void*);
62 samplecnt_t get_max_duration() const;
63 virtual void set_min_duration(samplecnt_t, void*);
64 samplecnt_t get_min_duration() const;
65 virtual void set_position_locked(bool, void*);
66 bool get_position_locked() const;
67 void set_max_duration_active(bool, void*);
68 bool get_max_duration_active() const;
69 void set_min_duration_active(bool, void*);
70 bool get_min_duration_active() const;
71 void set_item_name(std::string, void*);
72 virtual std::string get_item_name() const;
73 virtual void set_selected(bool yn);
74 void set_sensitive (bool yn) { _sensitive = yn; }
75 bool sensitive () const { return _sensitive; }
76 TimeAxisView& get_time_axis_view () const;
77 void set_name_text(const std::string&);
78 virtual void set_height(double h);
79 virtual double height() const { return _height; }
81 void set_color (uint32_t);
82 void set_name_text_color ();
84 virtual uint32_t get_fill_color () const;
86 ArdourCanvas::Item* get_canvas_frame();
87 ArdourCanvas::Item* get_canvas_group();
88 ArdourCanvas::Item* get_name_highlight();
90 virtual void set_samples_per_pixel (double);
92 double get_samples_per_pixel () const;
94 virtual void drag_start();
95 virtual void drag_end();
96 bool dragging() const { return _dragging; }
98 virtual void raise () { return; }
99 virtual void raise_to_top () { return; }
100 virtual void lower () { return; }
101 virtual void lower_to_bottom () { return; }
103 /** @return true if the name area should respond to events */
104 bool name_active() const { return name_connected; }
106 // Default sizes, font and spacing
107 static Pango::FontDescription NAME_FONT;
108 static void set_constant_heights ();
109 static const double NAME_X_OFFSET;
110 static const double GRAB_HANDLE_TOP;
111 static const double GRAB_HANDLE_WIDTH;
113 /* these are not constant, but vary with the pixel size
114 * of the font used to display the item name.
116 static int NAME_HEIGHT;
117 static double NAME_Y_OFFSET;
118 static double NAME_HIGHLIGHT_SIZE;
119 static double NAME_HIGHLIGHT_THRESH;
122 * Emitted when this Group has been removed.
123 * This is different to the CatchDeletion signal in that this signal
124 * is emitted during the deletion of this Time Axis, and not during
125 * the destructor, this allows us to capture the source of the deletion
129 sigc::signal<void,std::string,void*> ItemRemoved;
131 /** Emitted when the name of this item is changed */
132 sigc::signal<void,std::string,std::string,void*> NameChanged;
134 /** Emiited when the position of this item changes */
135 sigc::signal<void,samplepos_t,void*> PositionChanged;
137 /** Emitted when the position lock of this item is changed */
138 sigc::signal<void,bool,void*> PositionLockChanged;
140 /** Emitted when the duration of this item changes */
141 sigc::signal<void,samplecnt_t,void*> DurationChanged;
143 /** Emitted when the maximum item duration is changed */
144 sigc::signal<void,samplecnt_t,void*> MaxDurationChanged;
146 /** Emitted when the mionimum item duration is changed */
147 sigc::signal<void,samplecnt_t,void*> MinDurationChanged;
151 ShowNameHighlight = 0x2,
154 HideFrameLeft = 0x10,
155 HideFrameRight = 0x20,
157 FullWidthNameHighlight = 0x80
160 virtual void update_visibility () {}
163 TimeAxisViewItem (const std::string &, ArdourCanvas::Item&, TimeAxisView&, double, uint32_t fill_color,
164 samplepos_t, samplecnt_t, bool recording = false, bool automation = false, Visibility v = Visibility (0));
166 TimeAxisViewItem (const TimeAxisViewItem&);
168 void init (ArdourCanvas::Item*, double, uint32_t, samplepos_t, samplepos_t, Visibility, bool, bool);
170 virtual bool canvas_group_event (GdkEvent*);
172 virtual void set_colors();
173 virtual void set_frame_color();
174 virtual void set_frame_gradient ();
175 void set_trim_handle_colors();
177 virtual void reset_width_dependent_items (double);
179 static gint idle_remove_this_item(TimeAxisViewItem*, void*);
181 /** time axis that this item is on */
182 TimeAxisView& trackview;
184 /** indicates whether this item is locked to its current position */
185 bool position_locked;
187 /** position of this item on the timeline */
188 samplepos_t sample_position;
190 /** duration of this item upon the timeline */
191 samplecnt_t item_duration;
193 /** maximum duration that this item can have */
194 samplecnt_t max_item_duration;
196 /** minimum duration that this item can have */
197 samplecnt_t min_item_duration;
199 /** indicates whether the max duration constraint is active */
200 bool max_duration_active;
202 /** indicates whether the min duration constraint is active */
203 bool min_duration_active;
205 /** samples per canvas pixel */
206 double samples_per_pixel;
208 /** should the item respond to events */
212 * The unique item name of this Item.
213 * Each item upon a time axis must have a unique id.
215 std::string item_name;
217 /** true if the name should respond to events */
222 uint32_t last_item_width;
224 bool wide_enough_for_name;
225 bool high_enough_for_name;
227 ArdourCanvas::Container* group;
228 ArdourCanvas::Rectangle* frame;
229 ArdourCanvas::Rectangle* selection_frame;
230 ArdourCanvas::Text* name_text;
231 ArdourCanvas::Rectangle* name_highlight;
233 /* with these two values, if frame_handle_start == 0 then frame_handle_end will also be 0 */
234 ArdourCanvas::Rectangle* frame_handle_start; ///< `frame' (fade) handle for the start of the item, or 0
235 ArdourCanvas::Rectangle* frame_handle_end; ///< `frame' (fade) handle for the end of the item, or 0
237 bool frame_handle_crossing (GdkEvent*, ArdourCanvas::Rectangle*);
240 Visibility visibility;
241 std::string fill_color_name;
243 bool _automation; ///< true if this is an automation region view
247 void manage_name_text ();
250 void parameter_changed (std::string);
251 void manage_name_highlight ();
253 }; /* class TimeAxisViewItem */
255 #endif /* __gtk_ardour_time_axis_view_item_h__ */