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