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