2 Copyright (C) 2003 Paul Davis
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.
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.
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.
20 #ifndef __gtk_ardour_time_axis_view_item_h__
21 #define __gtk_ardour_time_axis_view_item_h__
23 #include <jack/jack.h>
26 #include <libgnomecanvasmm/pixbuf.h>
28 #include "selectable.h"
29 #include "simplerect.h"
31 #include "shared_ptrs.h"
36 * A base class for 'items' that may appear upon a TimeAxisView
39 class TimeAxisViewItem : public Selectable
42 virtual ~TimeAxisViewItem() ;
45 * Set the position of this item upon the timeline to the specified value
47 * @param pos the new position
48 * @param src the identity of the object that initiated the change
49 * @return true if the position change was a success, false otherwise
51 virtual bool set_position(nframes_t pos, void* src, double* delta = 0) ;
54 * Return the position of this item upon the timeline
56 * @return the position of this item
58 nframes_t get_position() const ;
61 * Sets the duration of this item
63 * @param dur the new duration of this item
64 * @param src the identity of the object that initiated the change
65 * @return true if the duration change was succesful, false otherwise
67 virtual bool set_duration(nframes_t dur, void* src) ;
70 * Returns the duration of this item
73 nframes_t get_duration() const ;
76 * Sets the maximum duration that this item make have.
78 * @param dur the new maximum duration
79 * @param src the identity of the object that initiated the change
81 virtual void set_max_duration(nframes_t dur, void* src) ;
84 * Returns the maxmimum duration that this item may be set to
86 * @return the maximum duration that this item may be set to
88 nframes_t get_max_duration() const ;
91 * Sets the minimu duration that this item may be set to
93 * @param the minimum duration that this item may be set to
94 * @param src the identity of the object that initiated the change
96 virtual void set_min_duration(nframes_t dur, void* src) ;
99 * Returns the minimum duration that this item mey be set to
101 * @return the nimum duration that this item mey be set to
103 nframes_t get_min_duration() const ;
106 * Sets whether the position of this Item is locked to its current position
107 * Locked items cannot be moved until the item is unlocked again.
109 * @param yn set to true to lock this item to its current position
110 * @param src the identity of the object that initiated the change
112 virtual void set_position_locked(bool yn, void* src) ;
115 * Returns whether this item is locked to its current position
117 * @return true if this item is locked to its current posotion
120 bool get_position_locked() const ;
123 * Sets whether the Maximum Duration constraint is active and should be enforced
125 * @param active set true to enforce the max duration constraint
126 * @param src the identity of the object that initiated the change
128 void set_max_duration_active(bool active, void* src) ;
131 * Returns whether the Maximum Duration constraint is active and should be enforced
133 * @return true if the maximum duration constraint is active, false otherwise
135 bool get_max_duration_active() const ;
138 * Sets whether the Minimum Duration constraint is active and should be enforced
140 * @param active set true to enforce the min duration constraint
141 * @param src the identity of the object that initiated the change
143 void set_min_duration_active(bool active, void* src) ;
146 * Returns whether the Maximum Duration constraint is active and should be enforced
148 * @return true if the maximum duration constraint is active, false otherwise
150 bool get_min_duration_active() const ;
153 * Set the name/Id of this item.
155 * @param new_name the new name of this item
156 * @param src the identity of the object that initiated the change
158 void set_item_name(std::string new_name, void* src) ;
161 * Returns the name/id of this item
163 * @return the name/id of this item
165 virtual std::string get_item_name() const ;
168 * Set to true to indicate that this item is currently selected
170 * @param yn true if this item is currently selected
172 virtual void set_selected(bool yn) ;
175 * Set to true to indicate that this item should show its selection status
177 * @param yn true if this item should show its selected status
179 virtual void set_should_show_selection (bool yn) ;
181 void set_sensitive (bool yn) { _sensitive = yn; }
182 bool sensitive () const { return _sensitive; }
184 //---------------------------------------------------------------------------------------//
185 // Parent Component Methods
188 * Returns the TimeAxisView that this item is upon
190 * @return the timeAxisView that this item is placed upon
192 TimeAxisViewPtr get_time_axis_view() ;
194 //---------------------------------------------------------------------------------------//
198 * Sets the displayed item text
199 * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
201 * @param new_name the new name text to display
203 void set_name_text(const Glib::ustring& new_name) ;
206 * Set the height of this item
208 * @param h the new height
210 virtual void set_height(double h) ;
217 void set_color (Gdk::Color const &);
222 ArdourCanvas::Item* get_canvas_frame() ;
227 ArdourCanvas::Group* get_canvas_group();
232 ArdourCanvas::Item* get_name_highlight();
237 ArdourCanvas::Pixbuf* get_name_pixbuf();
241 * Returns the time axis that this item is upon
243 TimeAxisViewPtr get_trackview() const { return trackview; }
246 * Sets the samples per unit of this item.
247 * this item is used to determine the relative visual size and position of this item
248 * based upon its duration and start value.
250 * @param spu the new samples per unit value
252 virtual void set_samples_per_unit(double spu) ;
255 * Returns the current samples per unit of this item
257 * @return the samples per unit of this item
259 double get_samples_per_unit() ;
261 virtual void raise () { return; }
262 virtual void raise_to_top () { return; }
263 virtual void lower () { return; }
264 virtual void lower_to_bottom () { return; }
267 * returns true if the name area should respond to events.
269 bool name_active() const { return name_connected; }
271 // Default sizes, font and spacing
272 static Pango::FontDescription* NAME_FONT ;
273 static bool have_name_font;
274 static const double NAME_X_OFFSET ;
275 static const double GRAB_HANDLE_LENGTH ;
276 /* these are not constant, but vary with the pixel size
277 of the font used to display the item name.
279 static double NAME_Y_OFFSET ;
280 static double NAME_HIGHLIGHT_SIZE ;
281 static double NAME_HIGHLIGHT_THRESH ;
284 * Handles the Removal of this time axis item
285 * This _needs_ to be called to alert others of the removal properly, ie where the source
286 * of the removal came from.
288 * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
289 * just now to capture the source of the removal
291 * @param src the identity of the object that initiated the change
293 virtual void remove_this_item(void* src) ;
296 * Emitted when this Group has been removed
297 * This is different to the GoingAway signal in that this signal
298 * is emitted during the deletion of this Time Axis, and not during
299 * the destructor, this allows us to capture the source of the deletion
303 sigc::signal<void,std::string,void*> ItemRemoved ;
305 /** Emitted when the name/Id of this item is changed */
306 sigc::signal<void,std::string,std::string,void*> NameChanged ;
308 /** Emiited when the position of this item changes */
309 sigc::signal<void,nframes_t,void*> PositionChanged ;
311 /** Emitted when the position lock of this item is changed */
312 sigc::signal<void,bool,void*> PositionLockChanged ;
314 /** Emitted when the duration of this item changes */
315 sigc::signal<void,nframes_t,void*> DurationChanged ;
317 /** Emitted when the maximum item duration is changed */
318 sigc::signal<void,nframes_t,void*> MaxDurationChanged ;
320 /** Emitted when the mionimum item duration is changed */
321 sigc::signal<void,nframes_t,void*> MinDurationChanged ;
325 ShowNameHighlight = 0x2,
328 HideFrameLeft = 0x10,
329 HideFrameRight = 0x20,
331 FullWidthNameHighlight = 0x80
335 * Constructs a new TimeAxisViewItem.
337 * @param it_name the unique name/Id of this item
338 * @param parent the parent canvas group
339 * @param tv the TimeAxisView we are going to be added to
340 * @param spu samples per unit
342 * @param start the start point of this item
343 * @param duration the duration of this item
345 TimeAxisViewItem(const std::string & it_name, ArdourCanvas::Group& parent, TimeAxisViewPtr tv, double spu, Gdk::Color const & base_color,
346 nframes_t start, nframes_t duration, bool recording = false, Visibility v = Visibility (0));
348 TimeAxisViewItem (const TimeAxisViewItem& other);
350 void init (const std::string& it_name, double spu, Gdk::Color const & base_color, nframes_t start, nframes_t duration, Visibility vis);
353 * Calculates some contrasting color for displaying various parts of this item, based upon the base color
355 * @param color the base color of the item
357 virtual void compute_colors (Gdk::Color const & color);
360 * convenience method to set the various canvas item colors
362 virtual void set_colors() ;
365 * Sets the frame color depending on whether this item is selected
367 virtual void set_frame_color() ;
370 * Sets the colors of the start and end trim handle depending on object state
373 void set_trim_handle_colors() ;
375 virtual void reset_width_dependent_items (double pixel_width);
376 void reset_name_width (double pixel_width);
379 * Callback used to remove this item during the gtk idle loop
380 * This is used to avoid deleting the obejct while inside the remove_this_group
383 * @param item the time axis item to remove
384 * @param src the identity of the object that initiated the change
386 static gint idle_remove_this_item(TimeAxisViewItem* item, void* src) ;
388 /** The time axis that this item is upon */
389 TimeAxisViewPtr trackview ;
391 /** indicates whether this item is locked to its current position */
392 bool position_locked ;
394 /** The posotion of this item on the timeline */
395 nframes_t frame_position ;
397 /** the duration of this item upon the timeline */
398 nframes_t item_duration ;
400 /** the maximum duration that we allow this item to take */
401 nframes_t max_item_duration ;
403 /** the minimu duration that we allow this item to take */
404 nframes_t min_item_duration ;
406 /** indicates whether this Max Duration constraint is active */
407 bool max_duration_active ;
409 /** indicates whether this Min Duration constraint is active */
410 bool min_duration_active ;
412 /** the curretn samples per canvas unit */
413 double samples_per_unit ;
415 /** indicates if this item is currently selected */
418 /** should the item show its selected status */
419 bool should_show_selection;
421 /** should the item respond to events */
425 * The unique item name of this Item
426 * Each item upon a time axis must have a unique id
428 std::string item_name ;
431 * true if the name should respond to events
436 * true if a small vestigial rect should be shown when the item gets very narrow
441 uint32_t fill_opacity;
442 uint32_t fill_color ;
443 uint32_t frame_color_r ;
444 uint32_t frame_color_g ;
445 uint32_t frame_color_b ;
446 uint32_t selected_frame_color_r ;
447 uint32_t selected_frame_color_g ;
448 uint32_t selected_frame_color_b ;
449 uint32_t label_color ;
451 uint32_t handle_color_r ;
452 uint32_t handle_color_g ;
453 uint32_t handle_color_b ;
454 uint32_t lock_handle_color_r ;
455 uint32_t lock_handle_color_g ;
456 uint32_t lock_handle_color_b ;
458 ArdourCanvas::Group* group;
459 ArdourCanvas::SimpleRect* vestigial_frame;
460 ArdourCanvas::SimpleRect* frame;
461 ArdourCanvas::Pixbuf* name_pixbuf;
462 ArdourCanvas::SimpleRect* name_highlight;
463 ArdourCanvas::SimpleRect* frame_handle_start;
464 ArdourCanvas::SimpleRect* frame_handle_end;
466 Visibility visibility;
470 }; /* class TimeAxisViewItem */
472 #endif /* __gtk_ardour_time_axis_view_item_h__ */