df041f8f765373e4af48f9057c486f160859a503
[ardour.git] / gtk2_ardour / marker_time_axis.cc
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 */
19
20 #include <string>
21
22 #include <pbd/error.h>
23
24 #include <gtkmm/menu.h>
25
26 #include <gtkmm2ext/utils.h>
27
28 #include <ardour/session.h>
29 #include <ardour/utils.h>
30
31 #include "ardour_ui.h"
32 #include "public_editor.h"
33 #include "imageframe_time_axis.h"
34 #include "selection.h"
35 #include "imageframe_time_axis_view.h"
36 #include "marker_time_axis_view.h"
37 #include "imageframe_view.h"
38 #include "marker_time_axis.h"
39 #include "canvas_impl.h"
40
41 #include "i18n.h"
42
43 using namespace ARDOUR;
44 using namespace PBD;
45 using namespace sigc;
46 using namespace Gtk;
47
48 //---------------------------------------------------------------------------------------//
49 // Constructor / Desctructor
50
51 /**
52  * Constructs a new MarkerTimeAxis
53  *
54  * @param ed the PublicEditor
55  * @param sess the current session
56  * @param canvas the parent canvas item
57  * @param name the name/id of this time axis
58  * @param tav the associated track view that this MarkerTimeAxis is marking up
59  */
60 MarkerTimeAxis::MarkerTimeAxis (PublicEditor& ed, ARDOUR::Session& sess, Canvas& canvas, const string & name, TimeAxisView* tav)
61         : AxisView(sess),
62           VisualTimeAxis(name, ed, sess, canvas)
63 {
64         /* the TimeAxisView these markers are associated with */
65         marked_time_axis = tav ;
66         
67         _color = unique_random_color() ;
68         time_axis_name = name ;
69
70         selection_group = new Group (*canvas_display);
71         selection_group->hide();
72
73         // intialize our data items
74         marker_menu = 0 ;
75
76         y_position = -1 ;
77
78         /* create our new marker time axis strip view */
79         view = new MarkerTimeAxisView(*this) ;
80
81         // set the initial time axis text label
82         label_view() ;
83                 
84         // set the initial height of this time axis
85         set_height(hSmall) ;
86 }
87
88 /**
89  * Destructor
90  * Responsible for destroying any marker items upon this time axis
91  */
92 MarkerTimeAxis::~MarkerTimeAxis()
93 {
94         GoingAway() ; /* EMIT_SIGNAL */
95
96         // destroy the view helper
97         // this handles removing and destroying individual marker items
98
99         if(view) {
100                 delete view ;
101                 view = 0 ;
102         }
103 }
104
105
106 //---------------------------------------------------------------------------------------//
107 // ui methods & data
108         
109 void
110 MarkerTimeAxis::set_height (uint32_t h)
111 {
112         VisualTimeAxis::set_height(h) ;
113         
114         // tell out view helper of the change too
115         if (view != 0)
116         {
117                 view->set_height((double) height) ;
118         }
119         
120         // tell those interested that we have had our height changed
121          gui_changed("track_height",(void*)0) ; /* EMIT_SIGNAL */
122 }
123
124 /**
125  * Sets the number of samples per unit that are used.
126  * This is used to determine the sizes of items upon this time axis
127  *
128  * @param spu the number of samples per unit
129  */
130 void
131 MarkerTimeAxis::set_samples_per_unit(double spu)
132 {
133         TimeAxisView::set_samples_per_unit (editor.get_current_zoom());
134
135         if (view) {
136                 view->set_samples_per_unit(spu) ;
137         }
138 }
139
140 /**
141  * Show the popup edit menu
142  *
143  * @param button the mouse button pressed
144  * @param time when to show the popup
145  * @param clicked_mv the MarkerView that the event ocured upon, or 0 if none
146  * @param with_item true if an item has been selected upon the time axis, used to set context menu
147  */
148 void
149 MarkerTimeAxis::popup_marker_time_axis_edit_menu(int button, int32_t time, MarkerView* clicked_mv, bool with_item)
150 {
151         if (!marker_menu)
152         {
153                 build_marker_menu() ;
154         }
155
156         if (with_item)
157         {
158                 marker_item_menu->set_sensitive(true) ;
159         }
160         else
161         {
162                 marker_item_menu->set_sensitive(false) ;
163         }
164         
165         marker_menu->popup(button,time) ;
166 }
167
168
169 /**
170  * convenience method to select a new track color and apply it to the view and view items
171  *
172  */
173 void
174 MarkerTimeAxis::select_track_color()
175 {
176         if(VisualTimeAxis::choose_time_axis_color())
177         {
178                 if(view)
179                 {
180                         view->apply_color(_color) ;
181                 }
182         }
183 }
184
185 /**
186  * Handles the building of the popup menu
187  */
188 void
189 MarkerTimeAxis::build_display_menu()
190 {
191         using namespace Menu_Helpers;
192
193         /* get the size menu ready */
194         build_size_menu() ;
195
196         /* prepare it */
197         TimeAxisView::build_display_menu();
198
199         /* now fill it with our stuff */
200         MenuList& items = display_menu->items();
201
202         items.push_back(MenuElem (_("Rename"), mem_fun(*this, &VisualTimeAxis::start_time_axis_rename)));
203
204         items.push_back(SeparatorElem()) ;
205         items.push_back(MenuElem (_("Height"), *size_menu));
206         items.push_back(MenuElem (_("Color"), mem_fun(*this, &MarkerTimeAxis::select_track_color)));
207         items.push_back(SeparatorElem()) ;
208         
209         items.push_back(MenuElem (_("Remove"), bind(mem_fun(*this, &MarkerTimeAxis::remove_this_time_axis), (void*)this)));
210 }
211
212 /**
213  * handles the building of the MarkerView sub menu
214  */
215 void
216 MarkerTimeAxis::build_marker_menu()
217 {
218         using namespace Menu_Helpers;
219         using Gtk::Menu;
220
221         marker_menu = manage(new Menu) ;
222         marker_menu->set_name ("ArdourContextMenu");
223         MenuList& items = marker_menu->items();
224         
225         marker_item_menu = manage(new Menu) ;
226         marker_item_menu->set_name ("ArdourContextMenu");
227         MenuList& marker_sub_items = marker_item_menu->items() ;
228
229         /* duration menu */
230         Menu* duration_menu = manage(new Menu) ;
231         duration_menu->set_name ("ArdourContextMenu");
232         MenuList& duration_items = duration_menu->items() ;
233         
234         if(view)
235         {
236                 duration_items.push_back(MenuElem (_("1 seconds"), bind (mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 1.0))) ;
237                 duration_items.push_back(MenuElem (_("1.5 seconds"), bind (mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 1.5))) ;
238                 duration_items.push_back(MenuElem (_("2 seconds"), bind (mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 2.0))) ;
239                 duration_items.push_back(MenuElem (_("2.5 seconds"), bind (mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 2.5))) ;
240                 duration_items.push_back(MenuElem (_("3 seconds"), bind (mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 3.0))) ;
241         }
242         //duration_items.push_back(SeparatorElem()) ;
243         //duration_items.push_back(MenuElem (_("custom"), mem_fun(*this, &ImageFrameTimeAxis::set_marker_duration_custom))) ;
244
245         marker_sub_items.push_back(MenuElem(_("Duration (sec)"), *duration_menu)) ;
246
247         marker_sub_items.push_back(SeparatorElem()) ;
248         marker_sub_items.push_back(MenuElem (_("Remove Marker"), bind(mem_fun(view, &MarkerTimeAxisView::remove_selected_marker_view),(void*)this))) ;
249         
250         items.push_back(MenuElem(_("Marker"), *marker_item_menu)) ;
251         items.push_back(MenuElem (_("Rename Track"), mem_fun(*this,&MarkerTimeAxis::start_time_axis_rename))) ;
252
253         marker_menu->show_all() ;
254 }
255
256
257
258 /**
259  * Returns the view helper of this TimeAxis
260  *
261  * @return the view helper of this TimeAxis
262  */
263 MarkerTimeAxisView*
264 MarkerTimeAxis::get_view()
265 {
266         return(view) ;
267 }
268
269 /**
270  * Returns the TimeAxisView that this markerTimeAxis is marking up
271  *
272  * @return the TimeAXisView that this MarkerTimeAxis is marking
273  */
274 TimeAxisView*
275 MarkerTimeAxis::get_marked_time_axis()
276 {
277         return(marked_time_axis) ;
278 }
279
280
281
282