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