1dd742a4591060f8e63a43b755b57014afab5924
[ardour.git] / gtk2_ardour / marker_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_marker_time_axis_view_h__
22 #define __ardour_marker_time_axis_view_h__
23
24 #include <list>
25 #include <gdkmm/color.h>
26 #include <libgnomecanvasmm/group.h>
27
28 #include <ardour/location.h>
29 #include "simplerect.h"
30 #include "canvas.h"
31
32 class PublicEditor;
33 class MarkerTimeAxis;
34 class ImageFrameView ;
35 class MarkerView ;
36 class TimeAxisView ;
37 class TimeAxisViewItem ;
38
39 /**
40  * A view helper for handling MarkerView objects.
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 class MarkerTimeAxisView : public sigc::trackable
45 {
46         public:
47                 //---------------------------------------------------------------------------------------//
48                 // Constructor / Desctructor
49                 
50                 /**
51                  * Construct a new MarkerTimeAxisView helper time axis helper
52                  *
53                  * @param mta the TimeAxsiView that this objbect is the helper for
54                  */
55                 MarkerTimeAxisView(MarkerTimeAxis& mta) ;
56                 
57                 /**
58                  * Destructor
59                  * Reposinsibly for destroying all marker items that may have been added to this time axis view
60                  *
61                  */
62                 ~MarkerTimeAxisView () ;
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                 MarkerTimeAxis& trackview() { return _trackview; }
73                 
74                 /**
75                  *
76                  */
77                 ArdourCanvas::Item *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 height) ;
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 upon this view helper
115                  *
116                  * @param color the new base color
117                  */
118                 void apply_color(Gdk::Color& color) ;
119
120                 //---------------------------------------------------------------------------------------//
121                 // Child MarkerView Accessors/Mutators
122                 
123                 /**
124                  * Adds a marker view to the list of items upon this time axis view helper
125                  * the new MarkerView is returned
126                  *
127                  * @param ifv the ImageFrameView that the new item is marking up
128                  * @param mark_text the text to be displayed uopn the new marker item
129                  * @param mark_id the unique id of the new item
130                  * @param start the position the new item should be placed upon the time line
131                  * @param duration the duration the new item should be placed upon the timeline
132                  * @param src the identity of the object that initiated the change
133                  */
134                 MarkerView* add_marker_view(ImageFrameView* ifv, std::string mark_type, std::string mark_id, jack_nframes_t start, jack_nframes_t dur, void* src) ;
135                 
136                 /**
137                  * Returns the named MarkerView or 0 if the named marker does not exist
138                  *
139                  * @param item_id the unique id of the item to search for
140                  * @return the named MarkerView, or 0 if it is not held upon this view
141                  */
142                 MarkerView* get_named_marker_view(std::string item_id) ;
143                 
144                 /**
145                  * Removes the currently selected MarverView
146                  * Note that this method actually destroys the MarkerView too.
147                  * We assume that since we own the object, we are allowed to do this
148                  *
149                  * @param src the identity of the object that initiated the change
150                  * @see add_marker_view
151                  */
152                 void remove_selected_marker_view(void* src) ;
153                 
154                 /**
155                  * Removes and returns the named MarkerView from the list of MarkerView held by this view helper
156                  *
157                  * @param item_id the MarkerView unique id to remove
158                  * @param src the identity of the object that initiated the change
159                  * @see add_marker_view
160                  */
161                 MarkerView* remove_named_marker_view(std::string item_id, void* src) ;
162                 
163                 /**
164                  * Removes mv from the list of MarkerView upon this TimeAxis
165                  *
166                  * @param mv the MarkerView to remove
167                  * @param src the identity of the object that initiated the change
168                  */
169                 void remove_marker_view(MarkerView* item, void* src) ;
170                 
171                 //---------------------------------------------------------------------------------------//
172                 // Selected item methods
173
174                 /**
175                  * Sets the currently selected item upon this time axis
176                  *
177                  * @param mv the item to set selected
178                  */
179                 void set_selected_time_axis_item(MarkerView* mv) ;
180                 
181                 /**
182                  * Clears any selected item upon this time axis
183                  *
184                  */
185                 void clear_selected_time_axis_item() ;
186                 
187                 /**
188                  * Returnsthe currently selected item upon this time axis
189                  *
190                  * @return the currently selected item pon this time axis
191                  */
192                 MarkerView* get_selected_time_axis_item() ;
193                 
194                 
195                 /**
196                  * Sets the duration of the selected MarkerView to the specified number of seconds
197                  *
198                  * @param sec the duration to set the MArkerView to, in seconds
199                  */
200                 void set_marker_duration_sec(double sec) ;
201
202                 //---------------------------------------------------------------------------------//
203                 // Emitted Signals
204                 
205                 /** Emitted when a MarkerView is Added */
206                 sigc::signal<void,MarkerView*,void*> MarkerViewAdded ;
207                 
208                 /** Emitted when a MarkerView Item is removed */
209                 sigc::signal<void,std::string,void*> MarkerViewRemoved ;
210                 
211         private:
212                 /**
213                  * convenience method to re-get the samples per unit and tell items upon this view
214                  *
215                  */
216                 void reset_samples_per_unit() ;
217                         
218                 /** The list of items held by this time axis view helper */
219                 typedef std::list<MarkerView *> MarkerViewList ;
220                 MarkerViewList marker_view_list;
221                 
222                 /** the currently selected time axis item upon this time axis */
223                 MarkerView* selected_time_axis_item ;
224                 
225                 /* the TimeAxisView that this object is acting as the view helper for */
226                 MarkerTimeAxis& _trackview ;
227                 
228                 ArdourCanvas::Group *canvas_group ;
229                 ArdourCanvas::SimpleRect *canvas_rect ; /* frame around the whole thing */
230
231                 /** the current samples per unit */
232                 double _samples_per_unit;
233
234                 /* XXX why are these different? */
235                 Gdk::Color region_color;
236                 uint32_t stream_base_color;
237                 
238 }; /* class MarkerTimeAxisView */
239
240 #endif /* __ardour_marker_time_axis_view_h__ */