various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / gtk2_ardour / marker_time_axis.cc
blobdd827b4c3cb980790d49e05fdd514288cf946b7d
1 /*
2 Copyright (C) 2003 Paul Davis
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.
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.
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.
20 #include <string>
22 #include "pbd/error.h"
24 #include <gtkmm/menu.h>
26 #include <gtkmm2ext/utils.h>
28 #include "ardour/session.h"
29 #include "ardour/utils.h"
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"
41 #include "i18n.h"
43 using namespace ARDOUR;
44 using namespace PBD;
45 using namespace Gtk;
47 //---------------------------------------------------------------------------------------//
48 // Constructor / Desctructor
50 /**
51 * Constructs a new MarkerTimeAxis
53 * @param ed the PublicEditor
54 * @param sess the current session
55 * @param canvas the parent canvas item
56 * @param name the name/id of this time axis
57 * @param tav the associated track view that this MarkerTimeAxis is marking up
59 MarkerTimeAxis::MarkerTimeAxis (PublicEditor& ed, ARDOUR::Session* sess, Canvas& canvas, const string & name, TimeAxisView* tav)
60 : AxisView(sess),
61 VisualTimeAxis(name, ed, sess, canvas)
63 /* the TimeAxisView these markers are associated with */
64 marked_time_axis = tav ;
66 _color = unique_random_color() ;
67 time_axis_name = name ;
69 selection_group = new Group (*canvas_display);
70 selection_group->hide();
72 // intialize our data items
73 marker_menu = 0 ;
75 y_position = -1 ;
77 /* create our new marker time axis strip view */
78 view = new MarkerTimeAxisView(*this) ;
80 // set the initial time axis text label
81 label_view() ;
83 // set the initial height of this time axis
84 set_height(hSmall) ;
87 /**
88 * Destructor
89 * Responsible for destroying any marker items upon this time axis
91 MarkerTimeAxis::~MarkerTimeAxis()
93 CatchDeletion (this); /* EMIT_SIGNAL */
95 // destroy the view helper
96 // this handles removing and destroying individual marker items
98 if(view) {
99 delete view ;
100 view = 0 ;
105 //---------------------------------------------------------------------------------------//
106 // ui methods & data
108 void
109 MarkerTimeAxis::set_height (uint32_t h)
111 VisualTimeAxis::set_height(h) ;
113 // tell out view helper of the change too
114 if (view != 0)
116 view->set_height((double) height) ;
119 // tell those interested that we have had our height changed
120 gui_changed("track_height",(void*)0) ; /* EMIT_SIGNAL */
124 * Sets the number of samples per unit that are used.
125 * This is used to determine the sizes of items upon this time axis
127 * @param spu the number of samples per unit
129 void
130 MarkerTimeAxis::set_samples_per_unit(double spu)
132 TimeAxisView::set_samples_per_unit (editor.get_current_zoom());
134 if (view) {
135 view->set_samples_per_unit(spu) ;
140 * Show the popup edit menu
142 * @param button the mouse button pressed
143 * @param time when to show the popup
144 * @param clicked_mv the MarkerView that the event ocured upon, or 0 if none
145 * @param with_item true if an item has been selected upon the time axis, used to set context menu
147 void
148 MarkerTimeAxis::popup_marker_time_axis_edit_menu(int button, int32_t time, MarkerView* clicked_mv, bool with_item)
150 if (!marker_menu)
152 build_marker_menu() ;
155 if (with_item)
157 marker_item_menu->set_sensitive(true) ;
159 else
161 marker_item_menu->set_sensitive(false) ;
164 marker_menu->popup(button,time) ;
169 * convenience method to select a new track color and apply it to the view and view items
172 void
173 MarkerTimeAxis::select_track_color()
175 if(VisualTimeAxis::choose_time_axis_color())
177 if(view)
179 view->apply_color(_color) ;
185 * Handles the building of the popup menu
187 void
188 MarkerTimeAxis::build_display_menu()
190 using namespace Menu_Helpers;
192 /* get the size menu ready */
193 build_size_menu() ;
195 /* prepare it */
196 TimeAxisView::build_display_menu();
198 /* now fill it with our stuff */
199 MenuList& items = display_menu->items();
201 items.push_back(MenuElem (_("Rename"), sigc::mem_fun(*this, &VisualTimeAxis::start_time_axis_rename)));
203 items.push_back(SeparatorElem()) ;
204 items.push_back(MenuElem (_("Height"), *size_menu));
205 items.push_back(MenuElem (_("Color"), sigc::mem_fun(*this, &MarkerTimeAxis::select_track_color)));
206 items.push_back(SeparatorElem()) ;
208 items.push_back(MenuElem (_("Remove"), sigc::bind(sigc::mem_fun(*this, &MarkerTimeAxis::remove_this_time_axis), (void*)this)));
212 * handles the building of the MarkerView sub menu
214 void
215 MarkerTimeAxis::build_marker_menu()
217 using namespace Menu_Helpers;
218 using Gtk::Menu;
220 marker_menu = manage(new Menu) ;
221 marker_menu->set_name ("ArdourContextMenu");
222 MenuList& items = marker_menu->items();
224 marker_item_menu = manage(new Menu) ;
225 marker_item_menu->set_name ("ArdourContextMenu");
226 MenuList& marker_sub_items = marker_item_menu->items() ;
228 /* duration menu */
229 Menu* duration_menu = manage(new Menu) ;
230 duration_menu->set_name ("ArdourContextMenu");
231 MenuList& duration_items = duration_menu->items() ;
233 if(view)
235 duration_items.push_back(MenuElem (_("1 seconds"), sigc::bind (sigc::mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 1.0))) ;
236 duration_items.push_back(MenuElem (_("1.5 seconds"), sigc::bind (sigc::mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 1.5))) ;
237 duration_items.push_back(MenuElem (_("2 seconds"), sigc::bind (sigc::mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 2.0))) ;
238 duration_items.push_back(MenuElem (_("2.5 seconds"), sigc::bind (sigc::mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 2.5))) ;
239 duration_items.push_back(MenuElem (_("3 seconds"), sigc::bind (sigc::mem_fun (view, &MarkerTimeAxisView::set_marker_duration_sec), 3.0))) ;
241 //duration_items.push_back(SeparatorElem()) ;
242 //duration_items.push_back(MenuElem (_("custom"), sigc::mem_fun(*this, &ImageFrameTimeAxis::set_marker_duration_custom))) ;
244 marker_sub_items.push_back(MenuElem(_("Duration (sec)"), *duration_menu)) ;
246 marker_sub_items.push_back(SeparatorElem()) ;
247 marker_sub_items.push_back(MenuElem (_("Remove Marker"), sigc::bind(sigc::mem_fun(view, &MarkerTimeAxisView::remove_selected_marker_view),(void*)this))) ;
249 items.push_back(MenuElem(_("Marker"), *marker_item_menu)) ;
250 items.push_back(MenuElem (_("Rename Track"), sigc::mem_fun(*this,&MarkerTimeAxis::start_time_axis_rename))) ;
252 marker_menu->show_all() ;
258 * Returns the view helper of this TimeAxis
260 * @return the view helper of this TimeAxis
262 MarkerTimeAxisView*
263 MarkerTimeAxis::get_view()
265 return(view) ;
269 * Returns the TimeAxisView that this markerTimeAxis is marking up
271 * @return the TimeAXisView that this MarkerTimeAxis is marking
273 TimeAxisView*
274 MarkerTimeAxis::get_marked_time_axis()
276 return(marked_time_axis) ;