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/choice.h>
35 #include "ardour/session.h"
36 #include "ardour/utils.h"
37 #include "ardour/processor.h"
38 #include "ardour/location.h"
40 #include "ardour_ui.h"
41 #include "public_editor.h"
42 #include "imageframe_time_axis.h"
43 #include "imageframe_time_axis_view.h"
44 #include "marker_time_axis_view.h"
45 #include "imageframe_view.h"
46 #include "marker_time_axis.h"
47 #include "marker_view.h"
50 #include "rgb_macros.h"
51 #include "canvas_impl.h"
55 using namespace ARDOUR;
60 * Abstract Constructor for base visual time axis classes
62 * @param name the name/Id of thie TimeAxis
63 * @param ed the Ardour PublicEditor
64 * @param sess the current session
65 * @param canvas the parent canvas object
67 VisualTimeAxis::VisualTimeAxis(const string & name, PublicEditor& ed, ARDOUR::Session* sess, Canvas& canvas)
69 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
70 visual_button (_("v")),
73 time_axis_name = name ;
74 _color = unique_random_color() ;
76 name_entry.signal_activate().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_changed)) ;
77 name_entry.signal_button_press_event().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_button_press_handler)) ;
78 name_entry.signal_button_release_event().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_button_release_handler)) ;
79 name_entry.signal_key_release_event().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_key_release_handler)) ;
81 size_button.set_name("TrackSizeButton") ;
82 visual_button.set_name("TrackVisualButton") ;
83 hide_button.set_name("TrackRemoveButton") ;
84 hide_button.add(*(Gtk::manage(new Gtk::Image(get_xpm("small_x.xpm")))));
85 size_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VisualTimeAxis::size_click)) ;
86 visual_button.signal_clicked().connect (sigc::mem_fun (*this, &VisualTimeAxis::visual_click)) ;
87 hide_button.signal_clicked().connect (sigc::mem_fun (*this, &VisualTimeAxis::hide_click)) ;
88 ARDOUR_UI::instance()->set_tip(size_button,_("Display Height")) ;
89 ARDOUR_UI::instance()->set_tip(visual_button, _("Visual options")) ;
90 ARDOUR_UI::instance()->set_tip(hide_button, _("Hide this track")) ;
92 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
93 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
94 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
96 /* remove focus from the buttons */
97 size_button.unset_flags(Gtk::CAN_FOCUS) ;
98 hide_button.unset_flags(Gtk::CAN_FOCUS) ;
99 visual_button.unset_flags(Gtk::CAN_FOCUS) ;
101 set_height (hNormal) ;
105 * VisualTimeAxis Destructor
108 VisualTimeAxis::~VisualTimeAxis()
113 //---------------------------------------------------------------------------------------//
114 // Name/Id Accessors/Mutators
117 VisualTimeAxis::set_time_axis_name(const string & name, void* src)
119 std::string old_name = time_axis_name ;
121 if(name != time_axis_name)
123 time_axis_name = name ;
125 editor.route_name_changed(this) ;
127 NameChanged(time_axis_name, old_name, src) ; /* EMIT_SIGNAL */
132 VisualTimeAxis::name() const
134 return(time_axis_name) ;
138 //---------------------------------------------------------------------------------------//
142 * Sets the height of this TrackView to one of the defined TrackHeghts
147 VisualTimeAxis::set_height(uint32_t h)
149 TimeAxisView::set_height(h);
152 other_button_hbox.show_all() ;
153 } else if (h >= hSmaller) {
154 other_button_hbox.hide_all() ;
155 } else if (h >= hSmall) {
156 other_button_hbox.hide_all() ;
161 * Handle the visuals button click
165 VisualTimeAxis::visual_click()
167 popup_display_menu(0);
172 * Handle the hide buttons click
176 VisualTimeAxis::hide_click()
178 // LAME fix for hide_button display refresh
179 hide_button.set_sensitive(false);
181 editor.hide_track_in_display (*this);
183 hide_button.set_sensitive(true);
188 * Allows the selection of a new color for this TimeAxis
192 VisualTimeAxis::select_track_color ()
194 if(choose_time_axis_color())
196 //Does nothing at this abstract point
201 * Provides a color chooser for the selection of a new time axis color.
205 VisualTimeAxis::choose_time_axis_color()
210 Gdk::Color current_color ;
212 current[0] = _color.get_red() / 65535.0 ;
213 current[1] = _color.get_green() / 65535.0 ;
214 current[2] = _color.get_blue() / 65535.0 ;
217 current_color.set_rgb_p (current[0],current[1],current[2]);
218 color = Gtkmm2ext::UI::instance()->get_color(_("Color Selection"),picked, ¤t_color) ;
222 set_time_axis_color(color) ;
228 * Sets the color of this TimeAxis to the specified color c
230 * @param c the new TimeAxis color
233 VisualTimeAxis::set_time_axis_color(Gdk::Color c)
239 VisualTimeAxis::set_selected_regionviews (RegionSelection& regions)
241 // Not handled by purely visual TimeAxis
244 //---------------------------------------------------------------------------------------//
245 // Handle time axis removal
248 * Handles the Removal of this VisualTimeAxis
250 * @param src the identity of the object that initiated the change
253 VisualTimeAxis::remove_this_time_axis(void* src)
255 vector<string> choices;
257 std::string prompt = string_compose (_("Do you really want to remove track \"%1\" ?\n\nYou may also lose the playlist used by this track.\n\n(This action cannot be undone, and the session file will be overwritten)"), time_axis_name);
259 choices.push_back (_("No, do nothing."));
260 choices.push_back (_("Yes, remove it."));
262 Gtkmm2ext::Choice prompter (prompt, choices);
264 if (prompter.run () == 1) {
266 defer to idle loop, otherwise we'll delete this object
267 while we're still inside this function ...
269 Glib::signal_idle().connect(sigc::bind(sigc::ptr_fun(&VisualTimeAxis::idle_remove_this_time_axis), this, src));
274 * Callback used to remove this time axis during the gtk idle loop
275 * This is used to avoid deleting the obejct while inside the remove_this_time_axis
278 * @param ta the VisualTimeAxis to remove
279 * @param src the identity of the object that initiated the change
282 VisualTimeAxis::idle_remove_this_time_axis(VisualTimeAxis* ta, void* src)
284 ta->VisualTimeAxisRemoved(ta->name(), src) ; /* EMIT_SIGNAL */
293 //---------------------------------------------------------------------------------------//
294 // Handle TimeAxis rename
297 * Construct a new prompt to receive a new name for this TimeAxis
299 * @see finish_time_axis_rename()
302 VisualTimeAxis::start_time_axis_rename()
304 ArdourPrompter name_prompter;
306 name_prompter.set_prompt (_("new name: ")) ;
307 name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
308 name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
309 name_prompter.show_all() ;
311 switch (name_prompter.run ()) {
312 case Gtk::RESPONSE_ACCEPT:
314 name_prompter.get_result (result);
315 if (result.length()) {
316 if (editor.get_named_time_axis(result) != 0) {
317 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
321 set_time_axis_name(result, this) ;
328 * Handles the new name for this TimeAxis from the name prompt
330 * @see start_time_axis_rename()
334 VisualTimeAxis::label_view()
336 name_label.set_text (time_axis_name);
337 name_entry.set_text (time_axis_name);
338 ARDOUR_UI::instance()->set_tip (name_entry, Glib::Markup::escape_text (time_axis_name));
342 //---------------------------------------------------------------------------------------//
343 // Handle name entry signals
346 VisualTimeAxis::name_entry_changed()
348 TimeAxisView::name_entry_changed ();
350 string x = name_entry.get_text ();
352 if (x == time_axis_name) {
356 strip_whitespace_edges(x);
358 if (x.length() == 0) {
359 name_entry.set_text (time_axis_name);
363 if (!editor.get_named_time_axis(x)) {
364 set_time_axis_name (x, this);
366 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
367 name_entry.set_text(time_axis_name);
372 VisualTimeAxis::name_entry_button_press_handler(GdkEventButton *ev)
374 if (ev->button == 3) {
381 VisualTimeAxis::name_entry_button_release_handler(GdkEventButton *ev)
387 VisualTimeAxis::name_entry_key_release_handler(GdkEventKey* ev)
389 switch (ev->keyval) {
393 name_entry_changed ();
404 //---------------------------------------------------------------------------------------//
405 // Super class methods not handled by VisualTimeAxis
408 VisualTimeAxis::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
410 // Not handled by purely visual TimeAxis
414 VisualTimeAxis::hide_timestretch()
416 // Not handled by purely visual TimeAxis