incomplete changes based on karsten's megapatch
[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 <sigc++/signal.h>
25 #include <jack/jack.h>
26 #include <string>
27
28 #include <libgnomecanvasmm/text.h>
29
30 #include "selectable.h"
31 #include "simplerect.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 sigc::trackable, 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      * @param src the identity of the object that initiated the change
172      */
173     virtual void set_selected(bool yn, void* src) ;
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     /**
183      * Returns whether this item is currently selected.
184      *
185      * @return true if this item is currently selected, false otherwise
186      */
187     bool get_selected() const ; 
188     
189     //---------------------------------------------------------------------------------------//
190     // Parent Component Methods
191     
192     /**
193      * Returns the TimeAxisView that this item is upon
194      *
195      * @return the timeAxisView that this item is placed upon
196      */
197     TimeAxisView& get_time_axis_view() ;
198     
199     //---------------------------------------------------------------------------------------//
200     // ui methods & data
201     
202     /**
203      * Sets the displayed item text
204      * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
205      *
206      * @param new_name the new name text to display
207      */
208     void set_name_text(std::string new_name) ;
209     
210     /**
211      * Set the height of this item
212      *
213      * @param h the new height
214      */
215     virtual void set_height(double h) ;
216     
217     /**
218      * 
219      */
220     void set_color(Gdk::Color& color) ;
221     
222     /**
223      * 
224      */
225     Gnome::Canvas::Item* get_canvas_frame() ;
226
227     /**
228      * 
229      */
230     Gnome::Canvas::Item* get_canvas_group();
231
232     /**
233      * 
234      */
235     Gnome::Canvas::Item* get_name_highlight();
236
237     /**
238      * 
239      */
240     Gnome::Canvas::Item* get_name_text();
241
242     /**
243      * Sets the samples per unit of this item.
244      * this item is used to determine the relative visual size and position of this item
245      * based upon its duration and start value.
246      *
247      * @param spu the new samples per unit value
248      */
249     virtual void set_samples_per_unit(double spu) ;
250     
251     /**
252      * Returns the current samples per unit of this item
253      *
254      * @return the samples per unit of this item
255      */
256     double get_samples_per_unit() ;
257
258     virtual void raise () { return; }
259     virtual void raise_to_top () { return; }
260     virtual void lower () { return; }
261     virtual void lower_to_bottom () { return; }
262     
263     /**
264      * returns true if the name area should respond to events.
265      */
266     bool name_active() const { return name_connected; }
267
268     // Default sizes, font and spacing
269     static Pango::FontDescription NAME_FONT ;
270     static bool have_name_font;
271     static const double NAME_X_OFFSET ;
272     static const double NAME_Y_OFFSET ;
273     static const double NAME_HIGHLIGHT_SIZE ;
274     static const double NAME_HIGHLIGHT_THRESH ;
275     static const double GRAB_HANDLE_LENGTH ;
276
277     /**
278      * Handles the Removal of this time axis item
279      * This _needs_ to be called to alert others of the removal properly, ie where the source
280      * of the removal came from.
281      *
282      * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
283      *     just now to capture the source of the removal
284      *
285      * @param src the identity of the object that initiated the change
286      */
287     virtual void remove_this_item(void* src) ;
288     
289     /**
290      * Emitted when this Group has been removed
291      * This is different to the GoingAway signal in that this signal
292      * is emitted during the deletion of this Time Axis, and not during
293      * the destructor, this allows us to capture the source of the deletion
294      * event
295      */
296     sigc::signal<void,std::string,void*> ItemRemoved ;
297     
298     /** Emitted when the name/Id of this item is changed */
299     sigc::signal<void,std::string,std::string,void*> NameChanged ;
300     
301     /** Emiited when the position of this item changes */
302     sigc::signal<void,jack_nframes_t,void*> PositionChanged ;
303     
304     /** Emitted when the position lock of this item is changed */
305     sigc::signal<void,bool,void*> PositionLockChanged ;
306     
307     /** Emitted when the duration of this item changes */
308     sigc::signal<void,jack_nframes_t,void*> DurationChanged ;
309     
310     /** Emitted when the maximum item duration is changed */
311     sigc::signal<void,jack_nframes_t,void*> MaxDurationChanged ;
312     
313     /** Emitted when the mionimum item duration is changed */
314     sigc::signal<void,jack_nframes_t,void*> MinDurationChanged ;
315     
316     /** Emitted when the selected status of this item changes */
317     sigc::signal<void, bool> Selected ;
318     
319
320   protected:
321     
322     enum Visibility {
323             ShowFrame = 0x1,
324             ShowNameHighlight = 0x2,
325             ShowNameText = 0x4,
326             ShowHandles = 0x8
327     };
328
329     /**
330      * Constructs a new TimeAxisViewItem.
331      *
332      * @param it_name the unique name/Id of this item
333      * @param parent the parent canvas group
334      * @param tv the TimeAxisView we are going to be added to
335      * @param spu samples per unit
336      * @param base_color
337      * @param start the start point of this item
338      * @param duration the duration of this item
339      */
340     TimeAxisViewItem(std::string it_name, Gnome::Canvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color& base_color, 
341                      jack_nframes_t start, jack_nframes_t duration, Visibility v = Visibility (0));
342     
343     /**
344      * Calculates some contrasting color for displaying various parts of this item, based upon the base color
345      *
346      * @param color the base color of the item
347      */
348     virtual void compute_colors(Gdk::Color& color) ;
349     
350     /**
351      * convenience method to set the various canvas item colors
352      */
353     virtual void set_colors() ;
354     
355     /**
356      * Sets the frame color depending on whether this item is selected
357      */
358     void set_frame_color() ;
359     
360     /**
361      * Sets the colors of the start and end trim handle depending on object state
362      *
363      */
364     void set_trim_handle_colors() ;
365
366     virtual void reset_width_dependent_items (double pixel_width);
367     void reset_name_width (double pixel_width);
368
369     /**
370      * Callback used to remove this item during the gtk idle loop
371      * This is used to avoid deleting the obejct while inside the remove_this_group
372      * method
373      *
374      * @param item the time axis item to remove
375      * @param src the identity of the object that initiated the change
376      */
377     static gint idle_remove_this_item(TimeAxisViewItem* item, void* src) ;
378     
379     /** The time axis that this item is upon */
380     TimeAxisView& trackview ;
381     
382     /** indicates whether this item is locked to its current position */
383     bool position_locked ;
384     
385     /** The posotion of this item on the timeline */
386     jack_nframes_t frame_position ;
387     
388     /** the duration of this item upon the timeline */
389     jack_nframes_t item_duration ;
390     
391     /** the maximum duration that we allow this item to take */
392     jack_nframes_t max_item_duration ;
393     
394     /** the minimu duration that we allow this item to take */
395     jack_nframes_t min_item_duration ;
396     
397     /** indicates whether this Max Duration constraint is active */
398     bool max_duration_active ;
399     
400     /** indicates whether this Min Duration constraint is active */
401     bool min_duration_active ;
402     
403     /** the curretn samples per canvas unit */
404     double samples_per_unit ;
405     
406     /** indicates if this item is currently selected */
407     bool selected ;
408
409     /** should the item show its selected status */
410     bool should_show_selection;
411     
412     /**
413      * The unique item name of this Item
414      * Each item upon a time axis must have a unique id
415      */
416     std::string item_name ;
417     
418     /**
419      * true if the name should respond to events
420      */
421     bool name_connected;
422
423     /**
424      * true if a small vestigial rect should be shown when the item gets very narrow
425      */
426
427     bool show_vestigial;
428
429     uint32_t fill_opacity;
430     uint32_t fill_color ;
431     uint32_t frame_color_r ;
432     uint32_t frame_color_g ;
433     uint32_t frame_color_b ;
434     uint32_t selected_frame_color_r ;
435     uint32_t selected_frame_color_g ;
436     uint32_t selected_frame_color_b ;
437     uint32_t label_color ;
438     
439     uint32_t handle_color_r ;
440     uint32_t handle_color_g ;
441     uint32_t handle_color_b ;
442     uint32_t lock_handle_color_r ;
443     uint32_t lock_handle_color_g ;
444     uint32_t lock_handle_color_b ;
445     
446     Gnome::Canvas::Group*      group;
447     Gnome::Canvas::SimpleRect* vestigial_frame;
448     Gnome::Canvas::SimpleRect* frame;
449     Gnome::Canvas::Text*       name_text;
450     Gnome::Canvas::SimpleRect* name_highlight;
451     Gnome::Canvas::SimpleRect* frame_handle_start;
452     Gnome::Canvas::SimpleRect* frame_handle_end;
453
454 }; /* class TimeAxisViewItem */
455
456 #endif /* __gtk_ardour_time_axis_view_item_h__ */