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.
26 #include "pbd/error.h"
27 #include "pbd/stl_delete.h"
28 #include "pbd/whitespace.h"
30 #include <gtkmm2ext/utils.h>
31 #include <gtkmm2ext/selector.h>
32 #include <gtkmm2ext/gtk_ui.h>
33 #include <gtkmm2ext/stop_signal.h>
34 #include <gtkmm2ext/choice.h>
36 #include "ardour/session.h"
37 #include "ardour/utils.h"
38 #include "ardour/processor.h"
39 #include "ardour/location.h"
41 #include "ardour_ui.h"
42 #include "public_editor.h"
43 #include "imageframe_time_axis.h"
44 #include "imageframe_time_axis_view.h"
45 #include "marker_time_axis_view.h"
46 #include "imageframe_view.h"
47 #include "marker_time_axis.h"
48 #include "marker_view.h"
51 #include "rgb_macros.h"
52 #include "canvas_impl.h"
56 using namespace ARDOUR;
62 * Abstract Constructor for base visual time axis classes
64 * @param name the name/Id of thie TimeAxis
65 * @param ed the Ardour PublicEditor
66 * @param sess the current session
67 * @param canvas the parent canvas object
69 VisualTimeAxis::VisualTimeAxis(const string & name, PublicEditor& ed, ARDOUR::Session& sess, Canvas& canvas)
71 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
72 visual_button (_("v")),
75 time_axis_name = name ;
76 _color = unique_random_color() ;
78 name_entry.signal_activate().connect(mem_fun(*this, &VisualTimeAxis::name_entry_changed)) ;
79 name_entry.signal_button_press_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_button_press_handler)) ;
80 name_entry.signal_button_release_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_button_release_handler)) ;
81 name_entry.signal_key_release_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_key_release_handler)) ;
83 size_button.set_name("TrackSizeButton") ;
84 visual_button.set_name("TrackVisualButton") ;
85 hide_button.set_name("TrackRemoveButton") ;
86 hide_button.add(*(Gtk::manage(new Gtk::Image(get_xpm("small_x.xpm")))));
87 size_button.signal_button_release_event().connect (mem_fun (*this, &VisualTimeAxis::size_click)) ;
88 visual_button.signal_clicked().connect (mem_fun (*this, &VisualTimeAxis::visual_click)) ;
89 hide_button.signal_clicked().connect (mem_fun (*this, &VisualTimeAxis::hide_click)) ;
90 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height")) ;
91 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options")) ;
92 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track")) ;
94 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
95 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
96 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
98 /* remove focus from the buttons */
99 size_button.unset_flags(Gtk::CAN_FOCUS) ;
100 hide_button.unset_flags(Gtk::CAN_FOCUS) ;
101 visual_button.unset_flags(Gtk::CAN_FOCUS) ;
103 set_height (hNormal) ;
107 * VisualTimeAxis Destructor
110 VisualTimeAxis::~VisualTimeAxis()
115 //---------------------------------------------------------------------------------------//
116 // Name/Id Accessors/Mutators
119 VisualTimeAxis::set_time_axis_name(const string & name, void* src)
121 std::string old_name = time_axis_name ;
123 if(name != time_axis_name)
125 time_axis_name = name ;
127 editor.route_name_changed(this) ;
129 NameChanged(time_axis_name, old_name, src) ; /* EMIT_SIGNAL */
134 VisualTimeAxis::name() const
136 return(time_axis_name) ;
140 //---------------------------------------------------------------------------------------//
144 * Sets the height of this TrackView to one of the defined TrackHeghts
149 VisualTimeAxis::set_height(uint32_t h)
151 TimeAxisView::set_height(h);
156 other_button_hbox.show_all() ;
157 } else if (h >= hSmaller) {
160 other_button_hbox.hide_all() ;
161 } else if (h >= hSmall) {
164 other_button_hbox.hide_all() ;
169 * Handle the visuals button click
173 VisualTimeAxis::visual_click()
175 popup_display_menu(0);
180 * Handle the hide buttons click
184 VisualTimeAxis::hide_click()
186 // LAME fix for hide_button display refresh
187 hide_button.set_sensitive(false);
189 editor.hide_track_in_display (*this);
191 hide_button.set_sensitive(true);
196 * Allows the selection of a new color for this TimeAxis
200 VisualTimeAxis::select_track_color ()
202 if(choose_time_axis_color())
204 //Does nothing at this abstract point
209 * Provides a color chooser for the selection of a new time axis color.
213 VisualTimeAxis::choose_time_axis_color()
218 Gdk::Color current_color ;
220 current[0] = _color.get_red() / 65535.0 ;
221 current[1] = _color.get_green() / 65535.0 ;
222 current[2] = _color.get_blue() / 65535.0 ;
225 current_color.set_rgb_p (current[0],current[1],current[2]);
226 color = Gtkmm2ext::UI::instance()->get_color(_("ardour: color selection"),picked, ¤t_color) ;
230 set_time_axis_color(color) ;
236 * Sets the color of this TimeAxis to the specified color c
238 * @param c the new TimeAxis color
241 VisualTimeAxis::set_time_axis_color(Gdk::Color c)
247 VisualTimeAxis::set_selected_regionviews (RegionSelection& regions)
249 // Not handled by purely visual TimeAxis
252 //---------------------------------------------------------------------------------------//
253 // Handle time axis removal
256 * Handles the Removal of this VisualTimeAxis
258 * @param src the identity of the object that initiated the change
261 VisualTimeAxis::remove_this_time_axis(void* src)
263 vector<string> choices;
265 std::string prompt = string_compose (_("Do you really want to remove track \"%1\" ?\n(cannot be undone)"), time_axis_name);
267 choices.push_back (_("No, do nothing."));
268 choices.push_back (_("Yes, remove it."));
270 Gtkmm2ext::Choice prompter (prompt, choices);
272 if (prompter.run () == 1) {
274 defer to idle loop, otherwise we'll delete this object
275 while we're still inside this function ...
277 Glib::signal_idle().connect(bind(sigc::ptr_fun(&VisualTimeAxis::idle_remove_this_time_axis), this, src));
282 * Callback used to remove this time axis during the gtk idle loop
283 * This is used to avoid deleting the obejct while inside the remove_this_time_axis
286 * @param ta the VisualTimeAxis to remove
287 * @param src the identity of the object that initiated the change
290 VisualTimeAxis::idle_remove_this_time_axis(VisualTimeAxis* ta, void* src)
292 ta->VisualTimeAxisRemoved(ta->name(), src) ; /* EMIT_SIGNAL */
301 //---------------------------------------------------------------------------------------//
302 // Handle TimeAxis rename
305 * Construct a new prompt to receive a new name for this TimeAxis
307 * @see finish_time_axis_rename()
310 VisualTimeAxis::start_time_axis_rename()
312 ArdourPrompter name_prompter;
314 name_prompter.set_prompt (_("new name: ")) ;
315 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
316 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
317 name_prompter.show_all() ;
319 switch (name_prompter.run ()) {
320 case Gtk::RESPONSE_ACCEPT:
322 name_prompter.get_result (result);
323 if (result.length()) {
324 if (editor.get_named_time_axis(result) != 0) {
325 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
329 set_time_axis_name(result, this) ;
336 * Handles the new name for this TimeAxis from the name prompt
338 * @see start_time_axis_rename()
342 VisualTimeAxis::label_view()
344 name_label.set_text(time_axis_name) ;
345 name_entry.set_text(time_axis_name) ;
346 ARDOUR_UI::instance()->tooltips().set_tip(name_entry, time_axis_name) ;
350 //---------------------------------------------------------------------------------------//
351 // Handle name entry signals
354 VisualTimeAxis::name_entry_changed()
356 string x = name_entry.get_text ();
358 if (x == time_axis_name) {
362 strip_whitespace_edges(x);
364 if (x.length() == 0) {
365 name_entry.set_text (time_axis_name);
369 if (!editor.get_named_time_axis(x)) {
370 set_time_axis_name(x, this);
372 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
373 name_entry.set_text(time_axis_name);
378 VisualTimeAxis::name_entry_button_press_handler(GdkEventButton *ev)
380 if (ev->button == 3) {
381 return stop_signal (name_entry, "button_press_event");
387 VisualTimeAxis::name_entry_button_release_handler(GdkEventButton *ev)
393 VisualTimeAxis::name_entry_key_release_handler(GdkEventKey* ev)
395 switch (ev->keyval) {
399 name_entry_changed ();
408 //---------------------------------------------------------------------------------------//
409 // Super class methods not handled by VisualTimeAxis
412 VisualTimeAxis::show_timestretch (nframes_t start, nframes_t end)
414 // Not handled by purely visual TimeAxis
418 VisualTimeAxis::hide_timestretch()
420 // Not handled by purely visual TimeAxis