r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[ardour.git] / gtk2_ardour / imageframe_time_axis_view.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_view_h__
22 #define __ardour_imageframe_time_axis_view_h__
23
24 #include <list>
25 #include <cmath>
26
27 #include <gdkmm/color.h>
28
29 #include <jack/jack.h>
30
31 #include <libgnomecanvasmm.h>
32 #include "canvas.h"
33 #include "simplerect.h"
34
35
36 class PublicEditor ;
37 class ImageFrameTimeAxis ;
38 class ImageFrameView ;
39 class ImageFrameTimeAxisGroup ;
40
41 /**
42  * ImageFrameTimeAxisView defines the time axis view helper
43  * This object is responsible for the time axis canvas view, and
44  * maintains the list of items that have been added to it
45  *
46  */
47 class ImageFrameTimeAxisView : public sigc::trackable
48 {
49         public:
50                 //---------------------------------------------------------------------------------------//
51                 // Constructor / Desctructor
52                 
53                 /**
54                  * Constructs a new ImageFrameTimeAxisView.
55                  *
56                  * @param ifta the parent ImageFrameTimeAxis of this view helper
57                  */
58                 ImageFrameTimeAxisView(ImageFrameTimeAxis& ifta) ;
59                 
60                 /**
61                  * Destructor 
62                  * Responsible for destroying all items tat may have been added to this time axis
63                  */
64                 ~ImageFrameTimeAxisView () ;
65                 
66                 //---------------------------------------------------------------------------------------//
67                 // Parent/Child helper object accessors
68
69                 /**
70                  * Returns the TimeAxisView thatt his object is acting as a helper for
71                  *
72                  * @return the TimeAxisView that this object is acting as a view helper for
73                  */
74                 ImageFrameTimeAxis& trackview() { return _trackview; }
75                 
76                 /**
77                  *
78                  */
79                 ArdourCanvas::Group * canvas_item() { return &canvas_group; }
80                 
81                 
82                 //---------------------------------------------------------------------------------------//
83                 // ui methods & data
84                 
85                 /**
86                  * Sets the height of the time axis view and the item upon it
87                  *
88                  * @param height the new height
89                  */
90                 int set_height(gdouble) ;
91                 
92                 /**
93                  * Sets the position of this view helper on the canvas
94                  *
95                  * @param x the x position upon the canvas
96                  * @param y the y position upon the canvas
97                  */
98                 int set_position(gdouble x, gdouble y) ;
99                 
100                 /**
101                  * Sets the current samples per unit.
102                  * this method tells each item upon the time axis of the change
103                  * 
104                  * @param spu the new samples per canvas unit value
105                  */
106                 int set_samples_per_unit(gdouble spu) ;
107                 
108                 /**
109                  * Returns the current samples per unit of this time axis view helper
110                  *
111                  * @return the current samples per unit of this time axis view helper
112                  */
113                 gdouble get_samples_per_unit() { return _samples_per_unit; }
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_color (Gdk::Color&) ;
121                 
122                 //---------------------------------------------------------------------------------------//
123                 // Child ImageFrameTimeAxisGroup Accessors/Mutators
124                 
125                 /**
126                  * Adds an ImageFrameTimeAxisGroup to the list of items upon this time axis view helper
127                  * the new ImageFrameTimeAxisGroup is returned
128                  *
129                  * @param group_id the unique id of the new group
130                  * @param src the identity of the object that initiated the change
131                  */
132                 ImageFrameTimeAxisGroup* add_imageframe_group(std::string group_id, void* src) ;
133                 
134                 /**
135                  * Returns the named ImageFrameTimeAxisGroup or 0 if the named group does not exist on this view helper
136                  *
137                  * @param group_id the unique id of the group to search for
138                  * @return the named ImageFrameTimeAxisGroup, or 0 if it is not held upon this view
139                  */
140                 ImageFrameTimeAxisGroup* get_named_imageframe_group(std::string group_id) ;
141                 
142                 /**
143                  * Removes and returns the named ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroup held by this view helper
144                  *
145                  * @param group_id the ImageFrameTimeAxisGroup unique id to remove
146                  * @param src the identity of the object that initiated the change
147                  * @see add_imageframe_group
148                  */
149                 ImageFrameTimeAxisGroup* remove_named_imageframe_group(std::string group_id, void* src) ;
150                 
151                 /**
152                  * Removes the specified ImageFrameTimeAxisGroup from the list of ImageFrameTimeAxisGroups upon this TimeAxis.
153                  *
154                  * @param iftag the ImageFrameView to remove
155                  */
156                 void remove_imageframe_group(ImageFrameTimeAxisGroup* iftag, void* src) ;
157                 
158                 
159                 //---------------------------------------------------------------------------------------//
160                 // Selected group methods
161                 
162                 /**
163                  * Sets the currently selected group upon this time axis
164                  *
165                  * @param ifv the item to set selected
166                  */
167                 void set_selected_imageframe_group(ImageFrameTimeAxisGroup* iftag) ;
168                 
169                 /**
170                  * Clears the currently selected image frame group unpo this time axis
171                  *
172                  */
173                 void clear_selected_imageframe_group() ;
174                 
175                 /**
176                  * Returns the currently selected group upon this time axis
177                  *
178                  * @return the currently selected group upon this time axis
179                  */             
180                 ImageFrameTimeAxisGroup* get_selected_imageframe_group() const ;
181                 
182
183                 /**
184                  * Sets the duration of the selected ImageFrameView to the specified number of seconds
185                  *
186                  * @param sec the duration to set the ImageFrameView to, in seconds
187                  */
188                 void set_imageframe_duration_sec(double sec) ;
189                 
190                 //---------------------------------------------------------------------------------------//
191                 // Selected item methods
192                 
193                 /**
194                  * Sets the currently selected image frame view item
195                  *
196                  * @param iftag the group the selected item is part
197                  * @param ifv the selected item
198                  */
199                 void set_selected_imageframe_view(ImageFrameTimeAxisGroup* iftag, ImageFrameView* ifv) ;
200                 
201                 /**
202                  * Clears the currently selected image frame view item
203                  *
204                  * @param clear_group set true if the selected parent group of the item should be cleared also
205                  */
206                 void clear_selected_imageframe_item(bool clear_group) ;
207                 
208                 /**
209                  * Returns the currently selected image frame view item upon this time axis
210                  *
211                  * @return the currently selected image frame view item
212                  */
213                 ImageFrameView* get_selected_imageframe_view() const ;
214                 
215
216                 
217                 /**
218                  * Removes the currently selected ImageFrameTimeAxisGroup
219                  *
220                  * @param src the identity of the object that initiated the change
221                  * @see add_imageframe_group
222                  */
223                 void remove_selected_imageframe_item(void* src) ;
224
225                 
226                 //---------------------------------------------------------------------------------//
227                 // Emitted Signals
228                 
229                 /** Emitted when and ImageFrameGroup is added to this time axis */
230                 sigc::signal<void,ImageFrameTimeAxisGroup*,void*> ImageFrameGroupAdded ;
231                 
232                 /** Emitted when an ImageFrameGroup is removed from this time axis */
233                 sigc::signal<void,std::string,void*> ImageFrameGroupRemoved ;
234                 
235         protected:
236
237
238         private:
239                 /**
240                  * convenience method to re-get the samples per unit and tell items upon this view
241                  *
242                  */
243                 void reset_samples_per_unit() ;
244                 
245                 /**
246                  * The list of ImageFrameViews held by this view helper */
247                 typedef std::list<ImageFrameTimeAxisGroup *> ImageFrameGroupList ;
248                 ImageFrameGroupList imageframe_groups ;
249                 
250                 /** the currently selected time axis item upon this time axis */
251                 ImageFrameTimeAxisGroup* selected_imageframe_group ;
252         
253                 /**
254                  * thecurrently selected image frame view
255                  * we keep this here so that we only have one per view, not one per group
256                  */
257                 ImageFrameView* selected_imageframe_view ;
258         
259         
260                 
261                 /* the TimeAxisView that this object is acting as the view helper for */
262                 ImageFrameTimeAxis& _trackview ;
263                 
264                 ArdourCanvas::Group       canvas_group ;
265                 ArdourCanvas::SimpleRect  canvas_rect; /* frame around the whole thing */
266                 
267                 /** the current samples per unit */
268                 double _samples_per_unit ;
269                 
270                 /* XXX why are these different? */
271                 Gdk::Color region_color ;
272                 uint32_t stream_base_color ;
273                 
274 } ; /* class ImageFrameTimeAxisView */
275
276 #endif /* __ardour_imageframe_time_axis_view_h__ */