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