summaryrefslogtreecommitdiff
path: root/gtk2_ardour/time_axis_view_item.h
blob: 167f1932c06a31a8886728790b534412edcd5b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/*
    Copyright (C) 2003 Paul Davis 

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __gtk_ardour_time_axis_view_item_h__
#define __gtk_ardour_time_axis_view_item_h__

#include <jack/jack.h>
#include <string>

#include <libgnomecanvasmm/pixbuf.h>

#include "selectable.h"
#include "simplerect.h"
#include "canvas.h"

class TimeAxisView;

/**
 * A base class for 'items' that may appear upon a TimeAxisView
 *
 */
class TimeAxisViewItem : public Selectable
{
   public:
	virtual ~TimeAxisViewItem() ;
    
    /**
     * Set the position of this item upon the timeline to the specified value
     *
     * @param pos the new position
     * @param src the identity of the object that initiated the change
     * @return true if the position change was a success, false otherwise
     */
    virtual bool set_position(nframes_t pos, void* src, double* delta = 0) ;
    
    /**
     * Return the position of this item upon the timeline
     *
     * @return the position of this item
     */
    nframes_t get_position() const ; 
    
    /**
     * Sets the duration of this item
     *
     * @param dur the new duration of this item
     * @param src the identity of the object that initiated the change
     * @return true if the duration change was succesful, false otherwise
     */
    virtual bool set_duration(nframes_t dur, void* src) ;
    
    /**
     * Returns the duration of this item
     *
     */
    nframes_t get_duration() const ;
    
    /**
     * Sets the maximum duration that this item make have.
     *
     * @param dur the new maximum duration
     * @param src the identity of the object that initiated the change
     */
    virtual void set_max_duration(nframes_t dur, void* src) ;
    
    /**
     * Returns the maxmimum duration that this item may be set to
     *
     * @return the maximum duration that this item may be set to
     */
    nframes_t get_max_duration() const ;
    
    /**
     * Sets the minimu duration that this item may be set to
     *
     * @param the minimum duration that this item may be set to
     * @param src the identity of the object that initiated the change
     */
    virtual void set_min_duration(nframes_t dur, void* src) ;
    
    /**
     * Returns the minimum duration that this item mey be set to
     *
     * @return the nimum duration that this item mey be set to
     */
    nframes_t get_min_duration() const ;
    
    /**
     * Sets whether the position of this Item is locked to its current position
     * Locked items cannot be moved until the item is unlocked again.
     *
     * @param yn set to true to lock this item to its current position
     * @param src the identity of the object that initiated the change
     */
    virtual void set_position_locked(bool yn, void* src) ;
    
    /**
     * Returns whether this item is locked to its current position
     *
     * @return true if this item is locked to its current posotion
     *         false otherwise
     */
    bool get_position_locked() const ;
    
    /**
     * Sets whether the Maximum Duration constraint is active and should be enforced
     *
     * @param active set true to enforce the max duration constraint
     * @param src the identity of the object that initiated the change
     */
    void set_max_duration_active(bool active, void* src) ;
    
    /**
     * Returns whether the Maximum Duration constraint is active and should be enforced
     *
     * @return true if the maximum duration constraint is active, false otherwise
     */
    bool get_max_duration_active() const ;
    
    /**
     * Sets whether the Minimum Duration constraint is active and should be enforced
     *
     * @param active set true to enforce the min duration constraint
     * @param src the identity of the object that initiated the change
     */
    void set_min_duration_active(bool active, void* src) ;
    
    /**
     * Returns whether the Maximum Duration constraint is active and should be enforced
     *
     * @return true if the maximum duration constraint is active, false otherwise
     */
    bool get_min_duration_active() const ;
    
    /**
     * Set the name/Id of this item.
     *
     * @param new_name the new name of this item
     * @param src the identity of the object that initiated the change
     */
    void set_item_name(std::string new_name, void* src) ;
    
    /**
     * Returns the name/id of this item
     *
     * @return the name/id of this item
     */
    virtual std::string get_item_name() const ;
    
    /**
     * Set to true to indicate that this item is currently selected
     *
     * @param yn true if this item is currently selected
     */
    virtual void set_selected(bool yn) ;

    /**
     * Set to true to indicate that this item should show its selection status
     *
     * @param yn true if this item should show its selected status
     */
    virtual void set_should_show_selection (bool yn) ;

    void set_sensitive (bool yn) { _sensitive = yn; }
    bool sensitive () const { return _sensitive; }
    
    //---------------------------------------------------------------------------------------//
    // Parent Component Methods
    
    /**
     * Returns the TimeAxisView that this item is upon
     *
     * @return the timeAxisView that this item is placed upon
     */
    TimeAxisView& get_time_axis_view() ;
    
    //---------------------------------------------------------------------------------------//
    // ui methods & data
    
    /**
     * Sets the displayed item text
     * This item is the visual text name displayed on the canvas item, this can be different to the name of the item
     *
     * @param new_name the new name text to display
     */
    void set_name_text(const Glib::ustring& new_name) ;

    /**
     * Set the height of this item
     *
     * @param h the new height
     */
    virtual void set_height(double h) ;
    
    /**
     * 
     */
    void set_color(Gdk::Color& color) ;
    
    /**
     * 
     */
    ArdourCanvas::Item* get_canvas_frame() ;

    /**
     * 
     */
    ArdourCanvas::Group* get_canvas_group();

    /**
     * 
     */
    ArdourCanvas::Item* get_name_highlight();

    /**
     * 
     */
    ArdourCanvas::Pixbuf* get_name_pixbuf();


    /**
     * Returns the time axis that this item is upon
     */
    TimeAxisView& get_trackview() const { return trackview; }

    /**
     * Sets the samples per unit of this item.
     * this item is used to determine the relative visual size and position of this item
     * based upon its duration and start value.
     *
     * @param spu the new samples per unit value
     */
    virtual void set_samples_per_unit(double spu) ;
    
    /**
     * Returns the current samples per unit of this item
     *
     * @return the samples per unit of this item
     */
    double get_samples_per_unit() ;

    virtual void raise () { return; }
    virtual void raise_to_top () { return; }
    virtual void lower () { return; }
    virtual void lower_to_bottom () { return; }
    
    /**
     * returns true if the name area should respond to events.
     */
    bool name_active() const { return name_connected; }

    // Default sizes, font and spacing
    static Pango::FontDescription* NAME_FONT ;
    static bool have_name_font;
    static const double NAME_X_OFFSET ;
    static const double GRAB_HANDLE_LENGTH ;
    /* these are not constant, but vary with the pixel size
       of the font used to display the item name.
    */
    static int NAME_HEIGHT ;
    static double NAME_Y_OFFSET ;
    static double NAME_HIGHLIGHT_SIZE ;
    static double NAME_HIGHLIGHT_THRESH ;

    /**
     * Handles the Removal of this time axis item
     * This _needs_ to be called to alert others of the removal properly, ie where the source
     * of the removal came from.
     *
     * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
     *     just now to capture the source of the removal
     *
     * @param src the identity of the object that initiated the change
     */
    virtual void remove_this_item(void* src) ;
    
    /**
     * Emitted when this Group has been removed
     * This is different to the GoingAway signal in that this signal
     * is emitted during the deletion of this Time Axis, and not during
     * the destructor, this allows us to capture the source of the deletion
     * event
     */

    sigc::signal<void,std::string,void*> ItemRemoved ;
    
    /** Emitted when the name/Id of this item is changed */
    sigc::signal<void,std::string,std::string,void*> NameChanged ;
    
    /** Emiited when the position of this item changes */
    sigc::signal<void,nframes_t,void*> PositionChanged ;
    
    /** Emitted when the position lock of this item is changed */
    sigc::signal<void,bool,void*> PositionLockChanged ;
    
    /** Emitted when the duration of this item changes */
    sigc::signal<void,nframes_t,void*> DurationChanged ;
    
    /** Emitted when the maximum item duration is changed */
    sigc::signal<void,nframes_t,void*> MaxDurationChanged ;
    
    /** Emitted when the mionimum item duration is changed */
    sigc::signal<void,nframes_t,void*> MinDurationChanged ;
    
    enum Visibility {
	    ShowFrame = 0x1,
	    ShowNameHighlight = 0x2,
	    ShowNameText = 0x4,
	    ShowHandles = 0x8,
	    HideFrameLeft = 0x10,
	    HideFrameRight = 0x20,
	    HideFrameTB = 0x40,
	    FullWidthNameHighlight = 0x80
    };
  protected:
    /**
     * Constructs a new TimeAxisViewItem.
     *
     * @param it_name the unique name/Id of this item
     * @param parent the parent canvas group
     * @param tv the TimeAxisView we are going to be added to
     * @param spu samples per unit
     * @param base_color
     * @param start the start point of this item
     * @param duration the duration of this item
     */
    TimeAxisViewItem(const std::string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color& base_color, 
		     nframes_t start, nframes_t duration, bool recording = false, Visibility v = Visibility (0));

    TimeAxisViewItem (const TimeAxisViewItem& other);

    void init (const std::string& it_name, double spu, Gdk::Color& base_color, nframes_t start, nframes_t duration, Visibility vis);
    
    /**
     * Calculates some contrasting color for displaying various parts of this item, based upon the base color
     *
     * @param color the base color of the item
     */
    virtual void compute_colors(Gdk::Color& color) ;
    
    /**
     * convenience method to set the various canvas item colors
     */
    virtual void set_colors() ;
    
    /**
     * Sets the frame color depending on whether this item is selected
     */
    virtual void set_frame_color() ;
    
    /**
     * Sets the colors of the start and end trim handle depending on object state
     *
     */
    void set_trim_handle_colors() ;

    virtual void reset_width_dependent_items (double pixel_width);
    void reset_name_width (double pixel_width);

    void color_handler ();

    /**
     * Callback used to remove this item during the gtk idle loop
     * This is used to avoid deleting the obejct while inside the remove_this_group
     * method
     *
     * @param item the time axis item to remove
     * @param src the identity of the object that initiated the change
     */
    static gint idle_remove_this_item(TimeAxisViewItem* item, void* src) ;
    
    /** The time axis that this item is upon */
    TimeAxisView& trackview ;
    
    /** indicates whether this item is locked to its current position */
    bool position_locked ;
    
    /** The posotion of this item on the timeline */
    nframes_t frame_position ;
    
    /** the duration of this item upon the timeline */
    nframes_t item_duration ;
    
    /** the maximum duration that we allow this item to take */
    nframes_t max_item_duration ;
    
    /** the minimu duration that we allow this item to take */
    nframes_t min_item_duration ;
    
    /** indicates whether this Max Duration constraint is active */
    bool max_duration_active ;
    
    /** indicates whether this Min Duration constraint is active */
    bool min_duration_active ;
    
    /** the curretn samples per canvas unit */
    double samples_per_unit ;
    
    /** indicates if this item is currently selected */
    bool selected ;

    /** should the item show its selected status */
    bool should_show_selection;

    /** should the item respond to events */
    bool _sensitive;
    
    /**
     * The unique item name of this Item
     * Each item upon a time axis must have a unique id
     */
    std::string item_name ;
    
    /**
     * true if the name should respond to events
     */
    bool name_connected;

    /**
     * true if a small vestigial rect should be shown when the item gets very narrow
     */

    bool show_vestigial;
    uint32_t fill_opacity;
    uint32_t fill_color ;
    uint32_t frame_color_r ;
    uint32_t frame_color_g ;
    uint32_t frame_color_b ;
    uint32_t selected_frame_color_r ;
    uint32_t selected_frame_color_g ;
    uint32_t selected_frame_color_b ;
    uint32_t label_color ;
    
    uint32_t handle_color_r ;
    uint32_t handle_color_g ;
    uint32_t handle_color_b ;
    uint32_t lock_handle_color_r ;
    uint32_t lock_handle_color_g ;
    uint32_t lock_handle_color_b ;
    uint32_t last_item_width;
    int name_pixbuf_width;

    ArdourCanvas::Group*      group;
    ArdourCanvas::SimpleRect* vestigial_frame;
    ArdourCanvas::SimpleRect* frame;
    ArdourCanvas::Pixbuf*     name_pixbuf;
    ArdourCanvas::SimpleRect* name_highlight;
    ArdourCanvas::SimpleRect* frame_handle_start;
    ArdourCanvas::SimpleRect* frame_handle_end;

    double  _height;
    Visibility visibility;
    bool _recregion;
    std::string _name;

}; /* class TimeAxisViewItem */

#endif /* __gtk_ardour_time_axis_view_item_h__ */