5f97ddcf4f2e55883e91ef37f6e17502a52e1179
[ardour.git] / gtk2_ardour / time_axis_view_item.h
1 /*
2     Copyright (C) 2003 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
20 #ifndef __gtk_ardour_time_axis_view_item_h__
21 #define __gtk_ardour_time_axis_view_item_h__
22
23 #include <jack/jack.h>
24 #include <string>
25
26 #include <libgnomecanvasmm/pixbuf.h>
27
28 #include "pbd/signals.h"
29
30 #include "selectable.h"
31 #include "simplerect.h"
32 #include "canvas.h"
33
34 class TimeAxisView;
35
36 /**
37  * A base class for 'items' that may appear upon a TimeAxisView
38  *
39  */
40 class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList
41 {
42    public:
43         virtual ~TimeAxisViewItem() ;
44
45     /**
46      * Set the position of this item upon the timeline to the specified value
47      *
48      * @param pos the new position
49      * @param src the identity of the object that initiated the change
50      * @return true if the position change was a success, false otherwise
51      */
52     virtual bool set_position(nframes64_t pos, void* src, double* delta = 0) ;
53
54     /**
55      * Return the position of this item upon the timeline
56      *
57      * @return the position of this item
58      */
59     nframes64_t get_position() const ;
60
61     /**
62      * Sets the duration of this item
63      *
64      * @param dur the new duration of this item
65      * @param src the identity of the object that initiated the change
66      * @return true if the duration change was succesful, false otherwise
67      */
68     virtual bool set_duration(nframes64_t dur, void* src) ;
69
70     /**
71      * Returns the duration of this item
72      *
73      */
74     nframes64_t get_duration() const ;
75
76     /**
77      * Sets the maximum duration that this item make have.
78      *
79      * @param dur the new maximum duration
80      * @param src the identity of the object that initiated the change
81      */
82     virtual void set_max_duration(nframes64_t dur, void* src) ;
83
84     /**
85      * Returns the maxmimum duration that this item may be set to
86      *
87      * @return the maximum duration that this item may be set to
88      */
89     nframes64_t get_max_duration() const ;
90
91     /**
92      * Sets the minimu duration that this item may be set to
93      *
94      * @param the minimum duration that this item may be set to
95      * @param src the identity of the object that initiated the change
96      */
97     virtual void set_min_duration(nframes64_t dur, void* src) ;
98
99     /**
100      * Returns the minimum duration that this item mey be set to
101      *
102      * @return the nimum duration that this item mey be set to
103      */
104     nframes64_t get_min_duration() const ;
105
106     /**
107      * Sets whether the position of this Item is locked to its current position
108      * Locked items cannot be moved until the item is unlocked again.
109      *
110      * @param yn set to true to lock this item to its current position
111      * @param src the identity of the object that initiated the change
112      */
113     virtual void set_position_locked(bool yn, void* src) ;
114
115     /**
116      * Returns whether this item is locked to its current position
117      *
118      * @return true if this item is locked to its current posotion
119      *         false otherwise
120      */
121     bool get_position_locked() const ;
122
123     /**
124      * Sets whether the Maximum Duration constraint is active and should be enforced
125      *
126      * @param active set true to enforce the max duration constraint
127      * @param src the identity of the object that initiated the change
128      */
129     void set_max_duration_active(bool active, void* src) ;
130
131     /**
132      * Returns whether the Maximum Duration constraint is active and should be enforced
133      *
134      * @return true if the maximum duration constraint is active, false otherwise
135      */
136     bool get_max_duration_active() const ;
137
138     /**
139      * Sets whether the Minimum Duration constraint is active and should be enforced
140      *
141      * @param active set true to enforce the min duration constraint
142      * @param src the identity of the object that initiated the change
143      */
144     void set_min_duration_active(bool active, void* src) ;
145
146     /**
147      * Returns whether the Maximum Duration constraint is active and should be enforced
148      *
149      * @return true if the maximum duration constraint is active, false otherwise
150      */
151     bool get_min_duration_active() const ;
152
153     /**
154      * Set the name/Id of this item.
155      *
156      * @param new_name the new name of this item
157      * @param src the identity of the object that initiated the change
158      */
159     void set_item_name(std::string new_name, void* src) ;
160
161     /**
162      * Returns the name/id of this item
163      *
164      * @return the name/id of this item
165      */
166     virtual std::string get_item_name() const ;
167
168     /**
169      * Set to true to indicate that this item is currently selected
170      *
171      * @param yn true if this item is currently selected
172      */
173     virtual void set_selected(bool yn) ;
174
175     /**
176      * Set to true to indicate that this item should show its selection status
177      *
178      * @param yn true if this item should show its selected status
179      */
180     virtual void set_should_show_selection (bool yn) ;
181
182     void set_sensitive (bool yn) { _sensitive = yn; }
183     bool sensitive () const { return _sensitive; }
184
185     //---------------------------------------------------------------------------------------//
186     // Parent Component Methods
187
188     /**
189      * Returns the TimeAxisView that this item is upon
190      *
191      * @return the timeAxisView that this item is placed upon
192      */
193     TimeAxisView& get_time_axis_view() ;
194
195     //---------------------------------------------------------------------------------------//
196     // ui methods & data
197
198     /**
199      * Sets the displayed item text
200      * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
201      *
202      * @param new_name the new name text to display
203      */
204     void set_name_text(const Glib::ustring& new_name) ;
205
206     /**
207      * Set the height of this item
208      *
209      * @param h the new height
210      */
211     virtual void set_height(double h) ;
212
213     void set_y (double);
214
215     /**
216      *
217      */
218     void set_color (Gdk::Color const &);
219
220     /**
221      *
222      */
223     ArdourCanvas::Item* get_canvas_frame() ;
224
225     /**
226      *
227      */
228     ArdourCanvas::Group* get_canvas_group();
229
230     /**
231      *
232      */
233     ArdourCanvas::Item* get_name_highlight();
234
235     /**
236      *
237      */
238     ArdourCanvas::Pixbuf* get_name_pixbuf();
239
240
241     /**
242      * Returns the time axis that this item is upon
243      */
244     TimeAxisView& get_trackview() const { return trackview; }
245
246     /**
247      * Sets the samples per unit of this item.
248      * this item is used to determine the relative visual size and position of this item
249      * based upon its duration and start value.
250      *
251      * @param spu the new samples per unit value
252      */
253     virtual void set_samples_per_unit(double spu) ;
254
255     /**
256      * Returns the current samples per unit of this item
257      *
258      * @return the samples per unit of this item
259      */
260     double get_samples_per_unit() ;
261
262     virtual void raise () { return; }
263     virtual void raise_to_top () { return; }
264     virtual void lower () { return; }
265     virtual void lower_to_bottom () { return; }
266
267     /**
268      * returns true if the name area should respond to events.
269      */
270     bool name_active() const { return name_connected; }
271
272     // Default sizes, font and spacing
273     static Pango::FontDescription* NAME_FONT ;
274     static bool have_name_font;
275     static const double NAME_X_OFFSET ;
276     static const double GRAB_HANDLE_LENGTH ;
277     /* these are not constant, but vary with the pixel size
278        of the font used to display the item name.
279     */
280     static int    NAME_HEIGHT;
281     static double NAME_Y_OFFSET ;
282     static double NAME_HIGHLIGHT_SIZE ;
283     static double NAME_HIGHLIGHT_THRESH ;
284
285     /**
286      * Handles the Removal of this time axis item
287      * This _needs_ to be called to alert others of the removal properly, ie where the source
288      * of the removal came from.
289      *
290      * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
291      *     just now to capture the source of the removal
292      *
293      * @param src the identity of the object that initiated the change
294      */
295     virtual void remove_this_item(void* src) ;
296
297     /**
298      * Emitted when this Group has been removed
299      * This is different to the CatchDeletion signal in that this signal
300      * is emitted during the deletion of this Time Axis, and not during
301      * the destructor, this allows us to capture the source of the deletion
302      * event
303      */
304
305     sigc::signal<void,std::string,void*> ItemRemoved ;
306
307     /** Emitted when the name/Id of this item is changed */
308     sigc::signal<void,std::string,std::string,void*> NameChanged ;
309
310     /** Emiited when the position of this item changes */
311     sigc::signal<void,nframes64_t,void*> PositionChanged ;
312
313     /** Emitted when the position lock of this item is changed */
314     sigc::signal<void,bool,void*> PositionLockChanged ;
315
316     /** Emitted when the duration of this item changes */
317     sigc::signal<void,nframes64_t,void*> DurationChanged ;
318
319     /** Emitted when the maximum item duration is changed */
320     sigc::signal<void,nframes64_t,void*> MaxDurationChanged ;
321
322     /** Emitted when the mionimum item duration is changed */
323     sigc::signal<void,nframes64_t,void*> MinDurationChanged ;
324
325     enum Visibility {
326             ShowFrame = 0x1,
327             ShowNameHighlight = 0x2,
328             ShowNameText = 0x4,
329             ShowHandles = 0x8,
330             HideFrameLeft = 0x10,
331             HideFrameRight = 0x20,
332             HideFrameTB = 0x40,
333             FullWidthNameHighlight = 0x80
334     };
335   protected:
336     /**
337      * Constructs a new TimeAxisViewItem.
338      *
339      * @param it_name the unique name/Id of this item
340      * @param parent the parent canvas group
341      * @param tv the TimeAxisView we are going to be added to
342      * @param spu samples per unit
343      * @param base_color
344      * @param start the start point of this item
345      * @param duration the duration of this item
346      */
347     TimeAxisViewItem(const std::string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color const & base_color,
348                      nframes64_t start, nframes64_t duration, bool recording = false, Visibility v = Visibility (0));
349
350     TimeAxisViewItem (const TimeAxisViewItem& other);
351
352     void init (const std::string& it_name, double spu, Gdk::Color const & base_color, nframes64_t start, nframes64_t duration, Visibility vis, bool, bool);
353
354     /**
355      * Calculates some contrasting color for displaying various parts of this item, based upon the base color
356      *
357      * @param color the base color of the item
358      */
359     virtual void compute_colors (Gdk::Color const & color);
360
361     /**
362      * convenience method to set the various canvas item colors
363      */
364     virtual void set_colors() ;
365
366     /**
367      * Sets the frame color depending on whether this item is selected
368      */
369     virtual void set_frame_color() ;
370
371     /**
372      * Sets the colors of the start and end trim handle depending on object state
373      *
374      */
375     void set_trim_handle_colors() ;
376
377     virtual void reset_width_dependent_items (double pixel_width);
378     void reset_name_width (double pixel_width);
379     void update_name_pixbuf_visibility ();
380
381     /**
382      * Callback used to remove this item during the gtk idle loop
383      * This is used to avoid deleting the obejct while inside the remove_this_group
384      * method
385      *
386      * @param item the time axis item to remove
387      * @param src the identity of the object that initiated the change
388      */
389     static gint idle_remove_this_item(TimeAxisViewItem* item, void* src) ;
390
391     /** The time axis that this item is upon */
392     TimeAxisView& trackview ;
393
394     /** indicates whether this item is locked to its current position */
395     bool position_locked ;
396
397     /** The posotion of this item on the timeline */
398     nframes64_t frame_position ;
399
400     /** the duration of this item upon the timeline */
401     nframes64_t item_duration ;
402
403     /** the maximum duration that we allow this item to take */
404     nframes64_t max_item_duration ;
405
406     /** the minimu duration that we allow this item to take */
407     nframes64_t min_item_duration ;
408
409     /** indicates whether this Max Duration constraint is active */
410     bool max_duration_active ;
411
412     /** indicates whether this Min Duration constraint is active */
413     bool min_duration_active ;
414
415     /** the curretn samples per canvas unit */
416     double samples_per_unit ;
417
418     /** should the item show its selected status */
419     bool should_show_selection;
420
421     /** should the item respond to events */
422     bool _sensitive;
423
424     /**
425      * The unique item name of this Item
426      * Each item upon a time axis must have a unique id
427      */
428     std::string item_name ;
429
430     /**
431      * true if the name should respond to events
432      */
433     bool name_connected;
434
435     /**
436      * true if a small vestigial rect should be shown when the item gets very narrow
437      */
438
439     bool show_vestigial;
440
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 ;
450
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 ;
457     uint32_t last_item_width;
458     int name_pixbuf_width;
459     bool wide_enough_for_name;
460     bool high_enough_for_name;
461
462     ArdourCanvas::Group*      group;
463     ArdourCanvas::SimpleRect* vestigial_frame;
464     ArdourCanvas::SimpleRect* frame;
465     ArdourCanvas::Pixbuf*     name_pixbuf;
466     ArdourCanvas::SimpleRect* name_highlight;
467     ArdourCanvas::SimpleRect* frame_handle_start;
468     ArdourCanvas::SimpleRect* frame_handle_end;
469
470     Visibility visibility;
471     bool _recregion;
472
473 }; /* class TimeAxisViewItem */
474
475 #endif /* __gtk_ardour_time_axis_view_item_h__ */