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