cleanup up cleanup at session destruction; clarify the meaning of 3 signals (DropRefe...
[ardour.git] / gtk2_ardour / imageframe_time_axis_group.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 __ardour_imageframe_time_axis_group_h__
21 #define __ardour_imageframe_time_axis_group_h__
22
23 #include <list>
24 #include <cmath>
25
26 #include <gdkmm/color.h>
27
28 #include <libgnomecanvas/libgnomecanvas.h>
29 #include <jack/jack.h>
30 #include "ardour/types.h"
31 #include "imageframe_time_axis_view.h"
32
33 class PublicEditor ;
34 class ImageFrameView ;
35
36 /**
37  * ImageFrameTimeAxisGroup defines a group/scene of ImageFrame view that can appear upon a time axis
38  * At the moment this is a bit bare, we really want to add some kind of time constraints upon
39  * items atht are added to the group, ie bounded by the start and end of the scene, which itself
40  * needs fleshed out.
41  * A viewable object may also be useful...
42  *
43  */
44 class ImageFrameTimeAxisGroup : public sigc::trackable
45 {
46         public:
47                 //---------------------------------------------------------------------------------------//
48                 // Constructor / Desctructor
49
50                 /**
51                  * Constructs a new ImageFrameTimeAxisGroup.
52                  *
53                  * @param iftav the parent ImageFrameTimeAxis of this view helper
54                  * @param group_id the unique name/id of this group
55                  */
56                 ImageFrameTimeAxisGroup(ImageFrameTimeAxisView& iftav, const std::string & group_id) ;
57
58                 /**
59                  * Destructor
60                  * Responsible for destroying any Items that may have been added to this group
61                  *
62                  */
63                 virtual ~ImageFrameTimeAxisGroup() ;
64
65
66                 //---------------------------------------------------------------------------------------//
67                 // Name/Id Accessors/Mutators
68
69                 /**
70                  * Set the name/Id of this group.
71                  *
72                  * @param new_name the new name of this group
73                  * @param src the identity of the object that initiated the change
74                  */
75                 void set_group_name(const std::string & new_name, void* src) ;
76
77                 /**
78                  * Returns the id of this group
79                  * The group id must be unique upon a time axis
80                  *
81                  * @return the id of this group
82                  */
83                 std::string get_group_name() const ;
84
85
86                 //---------------------------------------------------------------------------------------//
87                 // Parent/Child helper object accessors
88
89                 /**
90                  * Returns the TimeAxisView thatt his object is acting as a helper for
91                  *
92                  * @return the TimeAxisView that this object is acting as a view helper for
93                  */
94                 ImageFrameTimeAxisView& get_view() const { return _view_helper ; }
95
96
97
98                 //---------------------------------------------------------------------------------------//
99                 // ui methods & data
100
101                 /**
102                  * Sets the height of the time axis view and the item upon it
103                  *
104                  * @param height the new height
105                  */
106                 int set_item_heights(gdouble) ;
107
108                 /**
109                  * Sets the current samples per unit.
110                  * this method tells each item upon the time axis of the change
111                  *
112                  * @param spu the new samples per canvas unit value
113                  */
114                 int set_item_samples_per_units(gdouble spu) ;
115
116                 /**
117                  * Sets the color of the items contained uopn this view helper
118                  *
119                  * @param color the new base color
120                  */
121                 void apply_item_color(Gdk::Color&) ;
122
123
124                 //---------------------------------------------------------------------------------------//
125                 // child ImageFrameView methods
126
127                 /**
128                  * Adds an ImageFrameView to the list of items upon this time axis view helper
129                  * the new ImageFrameView is returned
130                  *
131                  * @param item_id the unique id of the new item
132                  * @param image_id the id/name of the image data we are usin
133                  * @param start the position the new item should be placed upon the time line
134                  * @param duration the duration the new item should be placed upon the timeline
135                  * @param rgb_data the rgb data of the image
136                  * @param width the original image width of the rgb_data (not the size to display)
137                  * @param height the irigianl height of the rgb_data
138                  * @param num_channels the number of channles within the rgb_data
139                  * @param src the identity of the object that initiated the change
140                  */
141                 ImageFrameView* add_imageframe_item(const std::string & item_id, nframes_t start, nframes_t duration, unsigned char* rgb_data, uint32_t width, uint32_t height, uint32_t num_channels, void* src) ;
142
143                 /**
144                  * Returns the named ImageFrameView or 0 if the named view does not exist on this view helper
145                  *
146                  * @param item_id the unique id of the item to search for
147                  * @return the named ImageFrameView, or 0 if it is not held upon this view
148                  */
149                 ImageFrameView* get_named_imageframe_item(const std::string & item_id) ;
150
151                 /**
152                  * Removes the currently selected ImageFrameView
153                  *
154                  * @param src the identity of the object that initiated the change
155                  * @see add_imageframe_view
156                  */
157                 void remove_selected_imageframe_item(void* src) ;
158
159                 /**
160                  * Removes and returns the named ImageFrameView from the list of ImageFrameViews held by this view helper
161                  *
162                  * @param item_id the ImageFrameView unique id to remove
163                  * @param src the identity of the object that initiated the change
164                  * @see add_imageframe_view
165                  */
166                 ImageFrameView* remove_named_imageframe_item(const std::string & item_id, void* src) ;
167
168                 /**
169                  * Removes ifv from the list of ImageFrameViews upon this TimeAxis.
170                  * if ifv is not upon this TimeAxis, this method takes no action
171                  *
172                  * @param ifv the ImageFrameView to remove
173                  */
174                 void remove_imageframe_item(ImageFrameView*, void* src) ;
175
176
177                 //---------------------------------------------------------------------------------------//
178                 // Selected group methods
179
180
181                 // removed in favour of a track level selectewd item
182                 // this is simply easier to manage a singularly selected item, rather than
183                 // a selected item within each group
184
185                 /**
186                  * Sets the currently selected item upon this time axis
187                  *
188                  * @param ifv the item to set selected
189                  */
190                 //void set_selected_imageframe_item(ImageFrameView* ifv) ;
191
192                 /**
193                  * Sets the currently selected item upon this time axis to the named item
194                  *
195                  * @param item_id the name/id of the item to set selected
196                  */
197                 //void set_selected_imageframe_item(std::string item_id) ;
198
199                 /**
200                  * Returns the currently selected item upon this time axis
201                  *
202                  * @return the currently selected item pon this time axis
203                  */
204                 //ImageFrameView* get_selected_imageframe_item() ;
205
206                 /**
207                  * Returns whether this grou pis currently selected
208                  *
209                  * @returns true if this group is currently selected
210                  */
211                 bool get_selected() const ;
212
213                 /**
214                  * Sets he selected state of this group
215                  *
216                  * @param yn set true if this group is selected, false otherwise
217                  */
218                 void set_selected(bool yn) ;
219
220                 //---------------------------------------------------------------------------------------//
221                 // Handle group removal
222
223                 /**
224                  * Handles the Removal of this VisualTimeAxis
225                  * This _needs_ to be called to alert others of the removal properly, ie where the source
226                  * of the removal came from.
227                  *
228                  * XXX Although im not too happy about this method of doing things, I cant think of a cleaner method
229                  *     just now to capture the source of the removal
230                  *
231                  * @param src the identity of the object that initiated the change
232                  */
233                 virtual void remove_this_group(void* src) ;
234
235                 //---------------------------------------------------------------------------------//
236                 // Emitted Signals
237
238                 static sigc::signal<void,ImageFrameTimeAxisGroup*> CatchDeletion;
239
240                 /**
241                  * Emitted when this Group has been removed
242                  * This is different to the CatchDeletion signal in that this signal
243                  * is emitted during the deletion of this Time Axis, and not during
244                  * the destructor, this allows us to capture the source of the deletion
245                  * event
246                  */
247                 sigc::signal<void,std::string,void*> GroupRemoved ;
248
249                 /** Emitted when we have changed the name of this TimeAxis */
250                 sigc::signal<void,std::string,std::string,void*> NameChanged ;
251
252                 /** Emitted when an ImageFrameView is added to this group */
253                 sigc::signal<void, ImageFrameView*, void*> ImageFrameAdded ;
254
255                 /** Emitted when an ImageFrameView is removed from this group */
256                 sigc::signal<void, const std::string &, const std::string &, const std::string &, void*> ImageFrameRemoved ;
257
258         protected:
259
260
261         private:
262                 /**
263                  * convenience method to re-get the samples per unit and tell items upon this view
264                  *
265                  */
266                 void reset_samples_per_unit() ;
267
268                 /**
269                  * Callback used to remove this group during the gtk idle loop
270                  * This is used to avoid deleting the obejct while inside the remove_this_group
271                  * method
272                  *
273                  * @param group the ImageFrameTimeAxisGroup to remove
274                  * @param src the identity of the object that initiated the change
275                  */
276                 static gint idle_remove_this_group(ImageFrameTimeAxisGroup* group, void* src) ;
277
278                 /** The list of ImageFrameViews held by this view helper */
279                 typedef std::list<ImageFrameView *> ImageFrameViewList ;
280                 ImageFrameViewList imageframe_views ;
281
282                 /** the currently selected time axis item upon this time axis */
283                 ImageFrameView* selected_imageframe_item ;
284
285                 /** the view helper that this object is acting as a container upon on */
286                 ImageFrameTimeAxisView& _view_helper ;
287
288                 /** the is of this group */
289                 std::string _group_id ;
290
291                 /* XXX why are these different? */
292                 Gdk::Color region_color ;
293                 uint32_t stream_base_color ;
294
295                 /** indicates if this group is currently selected */
296                 bool is_selected ;
297
298 } ; /* class ImageFrameTimeAxisGroup */
299
300 #endif /* __ardour_imageframe_time_axis_group_h__ */