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.
27 #include <pbd/error.h>
28 #include <pbd/stl_delete.h>
29 #include <pbd/whitespace.h>
31 #include <gtkmm2ext/utils.h>
32 #include <gtkmm2ext/selector.h>
33 #include <gtkmm2ext/gtk_ui.h>
34 #include <gtkmm2ext/stop_signal.h>
35 #include <gtkmm2ext/choice.h>
37 #include <ardour/session.h>
38 #include <ardour/utils.h>
39 #include <ardour/insert.h>
40 #include <ardour/location.h>
42 #include "ardour_ui.h"
43 #include "public_editor.h"
44 #include "imageframe_time_axis.h"
45 #include "imageframe_time_axis_view.h"
46 #include "marker_time_axis_view.h"
47 #include "imageframe_view.h"
48 #include "marker_time_axis.h"
49 #include "marker_view.h"
52 #include "rgb_macros.h"
53 #include "canvas_impl.h"
57 using namespace ARDOUR;
61 //XXX should really have a common home...
62 static const gchar* small_x_xpm[] = {
80 * Abstract Constructor for base visual time axis classes
82 * @param name the name/Id of thie TimeAxis
83 * @param ed the Ardour PublicEditor
84 * @param sess the current session
85 * @param canvas the parent canvas object
87 VisualTimeAxis::VisualTimeAxis(const string & name, PublicEditor& ed, ARDOUR::Session& sess, Canvas& canvas)
89 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
90 visual_button (_("v")),
93 time_axis_name = name ;
94 _color = unique_random_color() ;
95 _marked_for_display = true;
97 name_entry.signal_activate().connect(mem_fun(*this, &VisualTimeAxis::name_entry_changed)) ;
98 name_entry.signal_button_press_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_button_press_handler)) ;
99 name_entry.signal_button_release_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_button_release_handler)) ;
100 name_entry.signal_key_release_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_key_release_handler)) ;
102 size_button.set_name("TrackSizeButton") ;
103 visual_button.set_name("TrackVisualButton") ;
104 hide_button.set_name("TrackRemoveButton") ;
105 Glib::RefPtr<Gdk::Pixbuf> small_x_pixbuf = Gdk::Pixbuf::create_from_xpm_data(small_x_xpm);
106 hide_button.add(*(Gtk::manage(new Gtk::Image(small_x_pixbuf)))) ;
107 size_button.signal_button_release_event().connect (mem_fun (*this, &VisualTimeAxis::size_click)) ;
108 visual_button.signal_clicked().connect (mem_fun (*this, &VisualTimeAxis::visual_click)) ;
109 hide_button.signal_clicked().connect (mem_fun (*this, &VisualTimeAxis::hide_click)) ;
110 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height")) ;
111 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options")) ;
112 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track")) ;
114 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
115 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
116 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
118 /* remove focus from the buttons */
119 size_button.unset_flags(Gtk::CAN_FOCUS) ;
120 hide_button.unset_flags(Gtk::CAN_FOCUS) ;
121 visual_button.unset_flags(Gtk::CAN_FOCUS) ;
127 * VisualTimeAxis Destructor
130 VisualTimeAxis::~VisualTimeAxis()
135 //---------------------------------------------------------------------------------------//
136 // Name/Id Accessors/Mutators
139 VisualTimeAxis::set_time_axis_name(const string & name, void* src)
141 std::string old_name = time_axis_name ;
143 if(name != time_axis_name)
145 time_axis_name = name ;
147 editor.route_name_changed(this) ;
149 NameChanged(time_axis_name, old_name, src) ; /* EMIT_SIGNAL */
154 VisualTimeAxis::name() const
156 return(time_axis_name) ;
160 //---------------------------------------------------------------------------------------//
164 * Sets the height of this TrackView to one of the defined TrackHeghts
166 * @param h the TrackHeight value to set
169 VisualTimeAxis::set_height(TrackHeight h)
171 TimeAxisView::set_height(h) ;
182 other_button_hbox.show_all() ;
189 other_button_hbox.hide_all() ;
196 other_button_hbox.hide_all() ;
203 * Handle the visuals button click
207 VisualTimeAxis::visual_click()
209 popup_display_menu(0);
214 * Handle the hide buttons click
218 VisualTimeAxis::hide_click()
220 editor.hide_track_in_display (*this);
225 * Allows the selection of a new color for this TimeAxis
229 VisualTimeAxis::select_track_color ()
231 if(choose_time_axis_color())
233 //Does nothing at this abstract point
238 * Provides a color chooser for the selection of a new time axis color.
242 VisualTimeAxis::choose_time_axis_color()
247 Gdk::Color current_color ;
249 current[0] = _color.get_red() / 65535.0 ;
250 current[1] = _color.get_green() / 65535.0 ;
251 current[2] = _color.get_blue() / 65535.0 ;
254 current_color.set_rgb_p (current[0],current[1],current[2]);
255 color = Gtkmm2ext::UI::instance()->get_color(_("ardour: color selection"),picked, ¤t_color) ;
259 set_time_axis_color(color) ;
265 * Sets the color of this TimeAxis to the specified color c
267 * @param c the new TimeAxis color
270 VisualTimeAxis::set_time_axis_color(Gdk::Color c)
276 VisualTimeAxis::set_selected_regionviews (AudioRegionSelection& regions)
278 // Not handled by purely visual TimeAxis
281 //---------------------------------------------------------------------------------------//
282 // Handle time axis removal
285 * Handles the Removal of this VisualTimeAxis
287 * @param src the identity of the object that initiated the change
290 VisualTimeAxis::remove_this_time_axis(void* src)
292 vector<string> choices;
294 std::string prompt = string_compose (_("Do you really want to remove track \"%1\" ?\n(cannot be undone)"), time_axis_name);
296 choices.push_back (_("Yes, remove it."));
297 choices.push_back (_("No, do nothing."));
299 Gtkmm2ext::Choice prompter (prompt, choices);
301 prompter.chosen.connect(sigc::ptr_fun(Gtk::Main::quit));
302 prompter.show_all ();
306 if (prompter.get_choice() == 0)
309 defer to idle loop, otherwise we'll delete this object
310 while we're still inside this function ...
312 Glib::signal_idle().connect(bind(sigc::ptr_fun(&VisualTimeAxis::idle_remove_this_time_axis), this, src));
317 * Callback used to remove this time axis during the gtk idle loop
318 * This is used to avoid deleting the obejct while inside the remove_this_time_axis
321 * @param ta the VisualTimeAxis to remove
322 * @param src the identity of the object that initiated the change
325 VisualTimeAxis::idle_remove_this_time_axis(VisualTimeAxis* ta, void* src)
327 ta->VisualTimeAxisRemoved(ta->name(), src) ; /* EMIT_SIGNAL */
336 //---------------------------------------------------------------------------------------//
337 // Handle TimeAxis rename
340 * Construct a new prompt to receive a new name for this TimeAxis
342 * @see finish_time_axis_rename()
345 VisualTimeAxis::start_time_axis_rename()
347 ArdourPrompter name_prompter;
349 name_prompter.set_prompt (_("new name: ")) ;
350 name_prompter.show_all() ;
352 switch (name_prompter.run ()) {
353 case Gtk::RESPONSE_ACCEPT:
355 name_prompter.get_result (result);
356 if (result.length()) {
357 if (editor.get_named_time_axis(result) != 0) {
358 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
362 set_time_axis_name(result, this) ;
369 * Handles the new name for this TimeAxis from the name prompt
371 * @see start_time_axis_rename()
375 VisualTimeAxis::label_view()
377 name_label.set_text(time_axis_name) ;
378 name_entry.set_text(time_axis_name) ;
379 ARDOUR_UI::instance()->tooltips().set_tip(name_entry, time_axis_name) ;
383 //---------------------------------------------------------------------------------------//
384 // Handle name entry signals
387 VisualTimeAxis::name_entry_changed()
389 string x = name_entry.get_text ();
391 if (x == time_axis_name) {
395 if (x.length() == 0) {
396 name_entry.set_text (time_axis_name);
400 strip_whitespace_edges(x);
402 if (!editor.get_named_time_axis(x)) {
403 set_time_axis_name(x, this);
405 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
406 name_entry.set_text(time_axis_name);
411 VisualTimeAxis::name_entry_button_press_handler(GdkEventButton *ev)
413 if (ev->button == 3) {
414 return stop_signal (name_entry, "button_press_event");
420 VisualTimeAxis::name_entry_button_release_handler(GdkEventButton *ev)
426 VisualTimeAxis::name_entry_key_release_handler(GdkEventKey* ev)
428 switch (ev->keyval) {
432 name_entry_changed ();
441 //---------------------------------------------------------------------------------------//
442 // Super class methods not handled by VisualTimeAxis
445 VisualTimeAxis::show_timestretch (jack_nframes_t start, jack_nframes_t end)
447 // Not handled by purely visual TimeAxis
451 VisualTimeAxis::hide_timestretch()
453 // Not handled by purely visual TimeAxis