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