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 ;
95 _color = unique_random_color() ;
96 _marked_for_display = true;
98 name_entry.signal_activate().connect(mem_fun(*this, &VisualTimeAxis::name_entry_changed)) ;
99 name_entry.signal_button_press_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_button_press_handler)) ;
100 name_entry.signal_button_release_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_button_release_handler)) ;
101 name_entry.signal_key_release_event().connect(mem_fun(*this, &VisualTimeAxis::name_entry_key_release_handler)) ;
103 size_button.set_name("TrackSizeButton") ;
104 visual_button.set_name("TrackVisualButton") ;
105 hide_button.set_name("TrackRemoveButton") ;
106 Glib::RefPtr<Gdk::Pixbuf> small_x_pixbuf = Gdk::Pixbuf::create_from_xpm_data(small_x_xpm);
107 hide_button.add(*(Gtk::manage(new Gtk::Image(small_x_pixbuf)))) ;
108 size_button.signal_button_release_event().connect (mem_fun (*this, &VisualTimeAxis::size_click)) ;
109 visual_button.signal_clicked().connect (mem_fun (*this, &VisualTimeAxis::visual_click)) ;
110 hide_button.signal_clicked().connect (mem_fun (*this, &VisualTimeAxis::hide_click)) ;
111 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height")) ;
112 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options")) ;
113 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track")) ;
115 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
116 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
117 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
119 /* remove focus from the buttons */
120 size_button.unset_flags(Gtk::CAN_FOCUS) ;
121 hide_button.unset_flags(Gtk::CAN_FOCUS) ;
122 visual_button.unset_flags(Gtk::CAN_FOCUS) ;
128 * VisualTimeAxis Destructor
131 VisualTimeAxis::~VisualTimeAxis()
135 delete name_prompter ;
141 //---------------------------------------------------------------------------------------//
142 // Name/Id Accessors/Mutators
145 VisualTimeAxis::set_time_axis_name(const string & name, void* src)
147 std::string old_name = time_axis_name ;
149 if(name != time_axis_name)
151 time_axis_name = name ;
153 editor.route_name_changed(this) ;
155 NameChanged(time_axis_name, old_name, src) ; /* EMIT_SIGNAL */
160 VisualTimeAxis::name() const
162 return(time_axis_name) ;
166 //---------------------------------------------------------------------------------------//
170 * Sets the height of this TrackView to one of the defined TrackHeghts
172 * @param h the TrackHeight value to set
175 VisualTimeAxis::set_height(TrackHeight h)
177 TimeAxisView::set_height(h) ;
188 other_button_hbox.show_all() ;
195 other_button_hbox.hide_all() ;
202 other_button_hbox.hide_all() ;
209 * Handle the visuals button click
213 VisualTimeAxis::visual_click()
215 popup_display_menu(0);
220 * Handle the hide buttons click
224 VisualTimeAxis::hide_click()
226 editor.hide_track_in_display (*this);
231 * Allows the selection of a new color for this TimeAxis
235 VisualTimeAxis::select_track_color ()
237 if(choose_time_axis_color())
239 //Does nothing at this abstract point
244 * Provides a color chooser for the selection of a new time axis color.
248 VisualTimeAxis::choose_time_axis_color()
253 Gdk::Color current_color ;
255 current[0] = _color.get_red() / 65535.0 ;
256 current[1] = _color.get_green() / 65535.0 ;
257 current[2] = _color.get_blue() / 65535.0 ;
260 current_color.set_rgb_p (current[0],current[1],current[2]);
261 color = Gtkmm2ext::UI::instance()->get_color(_("ardour: color selection"),picked, ¤t_color) ;
265 set_time_axis_color(color) ;
271 * Sets the color of this TimeAxis to the specified color c
273 * @param c the new TimeAxis color
276 VisualTimeAxis::set_time_axis_color(Gdk::Color c)
282 VisualTimeAxis::set_selected_regionviews (AudioRegionSelection& regions)
284 // Not handled by purely visual TimeAxis
287 //---------------------------------------------------------------------------------------//
288 // Handle time axis removal
291 * Handles the Removal of this VisualTimeAxis
293 * @param src the identity of the object that initiated the change
296 VisualTimeAxis::remove_this_time_axis(void* src)
298 vector<string> choices;
300 std::string prompt = string_compose (_("Do you really want to remove track \"%1\" ?\n(cannot be undone)"), time_axis_name);
302 choices.push_back (_("Yes, remove it."));
303 choices.push_back (_("No, do nothing."));
305 Gtkmm2ext::Choice prompter (prompt, choices);
307 prompter.chosen.connect(sigc::ptr_fun(Gtk::Main::quit));
308 prompter.show_all ();
312 if (prompter.get_choice() == 0)
315 defer to idle loop, otherwise we'll delete this object
316 while we're still inside this function ...
318 Glib::signal_idle().connect(bind(sigc::ptr_fun(&VisualTimeAxis::idle_remove_this_time_axis), this, src));
323 * Callback used to remove this time axis during the gtk idle loop
324 * This is used to avoid deleting the obejct while inside the remove_this_time_axis
327 * @param ta the VisualTimeAxis to remove
328 * @param src the identity of the object that initiated the change
331 VisualTimeAxis::idle_remove_this_time_axis(VisualTimeAxis* ta, void* src)
333 ta->VisualTimeAxisRemoved(ta->name(), src) ; /* EMIT_SIGNAL */
342 //---------------------------------------------------------------------------------------//
343 // Handle TimeAxis rename
346 * Construct a new prompt to receive a new name for this TimeAxis
348 * @see finish_time_axis_rename()
351 VisualTimeAxis::start_time_axis_rename()
355 delete name_prompter ;
359 name_prompter = new ArdourPrompter() ;
361 name_prompter->set_prompt (_("new name: ")) ;
362 name_prompter->show_all() ;
364 switch (name_prompter->run ()) {
365 case Gtk::RESPONSE_ACCEPT:
367 name_prompter->get_result (result);
368 if (editor.get_named_time_axis(result) != 0) {
369 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
373 set_time_axis_name(result, this) ;
375 delete name_prompter ;
383 * Handles the new name for this TimeAxis from the name prompt
385 * @see start_time_axis_rename()
389 VisualTimeAxis::label_view()
391 name_label.set_text(time_axis_name) ;
392 name_entry.set_text(time_axis_name) ;
393 ARDOUR_UI::instance()->tooltips().set_tip(name_entry, time_axis_name) ;
397 //---------------------------------------------------------------------------------------//
398 // Handle name entry signals
401 VisualTimeAxis::name_entry_changed()
403 string x = name_entry.get_text ();
405 if (x == time_axis_name) {
409 if (x.length() == 0) {
410 name_entry.set_text (time_axis_name);
414 strip_whitespace_edges(x);
416 if (!editor.get_named_time_axis(x)) {
417 set_time_axis_name(x, this);
419 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
420 name_entry.set_text(time_axis_name);
425 VisualTimeAxis::name_entry_button_press_handler(GdkEventButton *ev)
427 if (ev->button == 3) {
428 return stop_signal (name_entry, "button_press_event");
434 VisualTimeAxis::name_entry_button_release_handler(GdkEventButton *ev)
440 VisualTimeAxis::name_entry_key_release_handler(GdkEventKey* ev)
442 switch (ev->keyval) {
446 name_entry_changed ();
455 //---------------------------------------------------------------------------------------//
456 // Super class methods not handled by VisualTimeAxis
459 VisualTimeAxis::show_timestretch (jack_nframes_t start, jack_nframes_t end)
461 // Not handled by purely visual TimeAxis
465 VisualTimeAxis::hide_timestretch()
467 // Not handled by purely visual TimeAxis