fix czech translation file
[ardour2.git] / gtk2_ardour / route_time_axis.cc
blobe92960724985b957a31f938fb5b74e7848d68d64
1 /*
2 Copyright (C) 2006 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.
19 #include <cstdlib>
20 #include <cmath>
21 #include <cassert>
23 #include <algorithm>
24 #include <string>
25 #include <vector>
27 #include <sigc++/bind.h>
29 #include <pbd/error.h>
30 #include <pbd/stl_delete.h>
31 #include <pbd/whitespace.h>
32 #include <pbd/memento_command.h>
34 #include <gtkmm/menu.h>
35 #include <gtkmm/menuitem.h>
36 #include <gtkmm2ext/gtk_ui.h>
37 #include <gtkmm2ext/selector.h>
38 #include <gtkmm2ext/stop_signal.h>
39 #include <gtkmm2ext/bindable_button.h>
40 #include <gtkmm2ext/utils.h>
42 #include <ardour/playlist.h>
43 #include <ardour/audioplaylist.h>
44 #include <ardour/diskstream.h>
45 #include <ardour/insert.h>
46 #include <ardour/ladspa_plugin.h>
47 #include <ardour/location.h>
48 #include <ardour/panner.h>
49 #include <ardour/playlist.h>
50 #include <ardour/session.h>
51 #include <ardour/session_playlist.h>
52 #include <ardour/utils.h>
53 #include <ardour/profile.h>
55 #include "ardour_ui.h"
56 #include "route_time_axis.h"
57 #include "automation_time_axis.h"
58 #include "redirect_automation_time_axis.h"
59 #include "redirect_automation_line.h"
60 #include "canvas_impl.h"
61 #include "crossfade_view.h"
62 #include "enums.h"
63 #include "gui_thread.h"
64 #include "keyboard.h"
65 #include "playlist_selector.h"
66 #include "point_selection.h"
67 #include "prompter.h"
68 #include "public_editor.h"
69 #include "region_view.h"
70 #include "rgb_macros.h"
71 #include "selection.h"
72 #include "simplerect.h"
73 #include "streamview.h"
74 #include "utils.h"
76 #include <ardour/track.h>
78 #include "i18n.h"
80 using namespace ARDOUR;
81 using namespace PBD;
82 using namespace Gtkmm2ext;
83 using namespace Gtk;
84 using namespace Editing;
85 using namespace std;
87 Glib::RefPtr<Gdk::Pixbuf> RouteTimeAxisView::slider;
89 void
90 RouteTimeAxisView::setup_slider_pix ()
92 if ((slider = ::get_icon ("fader_belt_h")) == 0) {
93 throw failed_constructor ();
97 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
98 : AxisView(sess),
99 RouteUI(rt, sess, _("m"), _("s"), _("r")), // mute, solo, and record
100 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
101 parent_canvas (canvas),
102 button_table (3, 3),
103 edit_group_button (_("g")), // group
104 playlist_button (_("p")),
105 size_button (_("h")), // height
106 automation_button (_("a")),
107 visual_button (_("v")),
108 gm (sess, slider, true)
110 gm.set_io (rt);
111 gm.get_level_meter().set_no_show_all();
112 gm.get_level_meter().setup_meters(50);
114 _has_state = true;
115 playlist_menu = 0;
116 playlist_action_menu = 0;
117 automation_action_menu = 0;
118 _view = 0;
119 timestretch_rect = 0;
120 no_redraw = false;
121 destructive_track_mode_item = 0;
122 normal_track_mode_item = 0;
124 ignore_toggle = false;
126 edit_group_button.set_name ("TrackGroupButton");
127 playlist_button.set_name ("TrackPlaylistButton");
128 automation_button.set_name ("TrackAutomationButton");
129 size_button.set_name ("TrackSizeButton");
130 visual_button.set_name ("TrackVisualButton");
131 hide_button.set_name ("TrackRemoveButton");
133 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
134 playlist_button.unset_flags (Gtk::CAN_FOCUS);
135 automation_button.unset_flags (Gtk::CAN_FOCUS);
136 size_button.unset_flags (Gtk::CAN_FOCUS);
137 visual_button.unset_flags (Gtk::CAN_FOCUS);
138 hide_button.unset_flags (Gtk::CAN_FOCUS);
140 hide_button.add (*(manage (new Image (::get_icon("hide")))));
141 hide_button.show_all ();
143 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
144 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
145 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
146 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
147 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
148 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
150 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
151 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
152 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
153 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
155 if (is_track()) {
157 /* use icon */
159 rec_enable_button->remove ();
160 switch (track()->mode()) {
161 case ARDOUR::Normal:
162 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
163 break;
164 case ARDOUR::Destructive:
165 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
166 break;
168 rec_enable_button->show_all ();
170 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
171 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
172 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
173 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
177 controls_hbox.pack_start(gm.get_level_meter(), false, false);
178 _route->meter_change.connect (mem_fun(*this, &RouteTimeAxisView::meter_changed));
179 _route->input_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
180 _route->output_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
182 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
183 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
185 controls_table.attach (edit_group_button, 7, 8, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
186 controls_table.attach (gm.get_gain_slider(), 0, 5, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
188 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
189 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
190 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
191 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
192 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
193 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
194 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
195 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
197 label_view ();
199 if (0) {
201 /* old school - when we used to put an extra row of buttons in place */
203 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
204 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
205 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
206 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
208 } else {
210 controls_table.attach (automation_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
213 if (is_track() && track()->mode() == ARDOUR::Normal) {
214 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
217 y_position = -1;
219 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
220 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
222 if (is_track()) {
224 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
225 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
226 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
227 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
229 /* pick up the correct freeze state */
230 map_frozen ();
234 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
235 ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
237 gm.get_gain_slider().signal_scroll_event().connect(mem_fun(*this, &RouteTimeAxisView::controls_ebox_scroll), false);
238 gm.get_gain_slider().set_name ("TrackGainFader");
241 RouteTimeAxisView::~RouteTimeAxisView ()
243 GoingAway (); /* EMIT_SIGNAL */
245 vector_delete (&redirect_automation_curves);
247 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
248 delete *i;
251 if (playlist_menu) {
252 delete playlist_menu;
253 playlist_menu = 0;
256 if (playlist_action_menu) {
257 delete playlist_action_menu;
258 playlist_action_menu = 0;
261 if (_view) {
262 delete _view;
263 _view = 0;
267 void
268 RouteTimeAxisView::post_construct ()
270 /* map current state of the route */
272 update_diskstream_display ();
273 subplugin_menu.items().clear ();
274 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
275 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
276 reset_redirect_automation_curves ();
279 void
280 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
282 boost::shared_ptr<Playlist> pl = playlist();
283 assert(pl);
285 modified_connection.disconnect ();
286 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
289 void
290 RouteTimeAxisView::playlist_modified ()
294 gint
295 RouteTimeAxisView::edit_click (GdkEventButton *ev)
297 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
298 _route->set_edit_group (0, this);
299 return FALSE;
302 using namespace Menu_Helpers;
304 MenuList& items = edit_group_menu.items ();
305 RadioMenuItem::Group group;
307 items.clear ();
308 items.push_back (RadioMenuElem (group, _("No group"),
309 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
311 if (_route->edit_group() == 0) {
312 static_cast<RadioMenuItem*>(&items.back())->set_active ();
315 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
316 edit_group_menu.popup (ev->button, ev->time);
318 return FALSE;
321 void
322 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
324 using namespace Menu_Helpers;
326 MenuList &items = edit_group_menu.items();
328 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
329 if (_route->edit_group() == eg) {
330 static_cast<RadioMenuItem*>(&items.back())->set_active ();
334 void
335 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
337 _route->set_edit_group (eg, this);
340 void
341 RouteTimeAxisView::playlist_changed ()
343 label_view ();
345 if (is_track()) {
346 set_playlist (get_diskstream()->playlist());
350 void
351 RouteTimeAxisView::label_view ()
353 string x = _route->name();
355 if (x != name_entry.get_text()) {
356 name_entry.set_text (x);
359 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
362 void
363 RouteTimeAxisView::route_name_changed (void *src)
365 editor.route_name_changed (this);
366 label_view ();
369 void
370 RouteTimeAxisView::take_name_changed (void *src)
373 if (src != this) {
374 label_view ();
378 void
379 RouteTimeAxisView::playlist_click ()
381 // always build a new action menu
383 if (playlist_action_menu != 0) {
384 delete playlist_action_menu;
387 playlist_action_menu = new Menu;
388 playlist_action_menu->set_name ("ArdourContextMenu");
390 build_playlist_menu (playlist_action_menu);
392 conditionally_add_to_selection ();
393 playlist_action_menu->popup (1, gtk_get_current_event_time());
396 void
397 RouteTimeAxisView::automation_click ()
399 conditionally_add_to_selection ();
400 if (!automation_action_menu)
401 build_automation_action_menu ();
402 automation_action_menu->popup (1, gtk_get_current_event_time());
405 void
406 RouteTimeAxisView::build_automation_action_menu ()
408 using namespace Menu_Helpers;
410 automation_action_menu = manage (new Menu);
411 MenuList& automation_items = automation_action_menu->items();
412 automation_action_menu->set_name ("ArdourContextMenu");
414 automation_items.push_back (MenuElem (_("Show all automation"),
415 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
417 automation_items.push_back (MenuElem (_("Show existing automation"),
418 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
420 automation_items.push_back (MenuElem (_("Hide all automation"),
421 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
423 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
426 void
427 RouteTimeAxisView::build_display_menu ()
429 using namespace Menu_Helpers;
431 /* get the size menu ready */
433 build_size_menu ();
435 /* prepare it */
437 TimeAxisView::build_display_menu ();
439 /* now fill it with our stuff */
441 MenuList& items = display_menu->items();
442 display_menu->set_name ("ArdourContextMenu");
444 items.push_back (MenuElem (_("Height"), *size_menu));
445 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
447 items.push_back (SeparatorElem());
449 if (!Profile->get_sae()) {
450 build_remote_control_menu ();
451 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
452 /* rebuild this every time */
453 build_automation_action_menu ();
454 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
455 items.push_back (SeparatorElem());
458 // Hook for derived classes to add type specific stuff
459 append_extra_display_menu_items ();
460 items.push_back (SeparatorElem());
462 if (is_track()) {
464 Menu* alignment_menu = manage (new Menu);
465 MenuList& alignment_items = alignment_menu->items();
466 alignment_menu->set_name ("ArdourContextMenu");
468 RadioMenuItem::Group align_group;
470 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
471 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
472 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
473 if (get_diskstream()->alignment_style() == ExistingMaterial)
474 align_existing_item->set_active();
476 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
477 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
478 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
479 if (get_diskstream()->alignment_style() == CaptureTime)
480 align_capture_item->set_active();
482 if (!Profile->get_sae()) {
483 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
484 get_diskstream()->AlignmentStyleChanged.connect (mem_fun(*this, &RouteTimeAxisView::align_style_changed));
486 RadioMenuItem::Group mode_group;
487 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
488 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
489 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
490 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
491 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
492 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
494 switch (track()->mode()) {
495 case ARDOUR::Destructive:
496 destructive_track_mode_item->set_active ();
497 break;
498 case ARDOUR::Normal:
499 normal_track_mode_item->set_active ();
500 break;
503 items.push_back (SeparatorElem());
507 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
508 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
509 route_active_menu_item->set_active (_route->active());
511 items.push_back (SeparatorElem());
512 items.push_back (MenuElem (_("Hide"), mem_fun(*this, &RouteTimeAxisView::hide_click)));
513 if (!Profile->get_sae()) {
514 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
515 } else {
516 items.push_front (SeparatorElem());
517 items.push_front (MenuElem (_("Delete"), mem_fun(*this, &RouteUI::remove_this_route)));
521 static bool __reset_item (RadioMenuItem* item)
523 item->set_active ();
524 return false;
527 void
528 RouteTimeAxisView::set_track_mode (TrackMode mode)
530 RadioMenuItem* item;
531 RadioMenuItem* other_item;
533 switch (mode) {
534 case ARDOUR::Normal:
535 item = normal_track_mode_item;
536 other_item = destructive_track_mode_item;
537 break;
538 case ARDOUR::Destructive:
539 item = destructive_track_mode_item;
540 other_item = normal_track_mode_item;
541 break;
542 default:
543 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
544 /*NOTREACHED*/
545 return;
548 if (item && other_item && item->get_active () && track()->mode() != mode) {
549 _set_track_mode (track(), mode, other_item);
553 void
554 RouteTimeAxisView::_set_track_mode (boost::shared_ptr<Track> track, TrackMode mode, RadioMenuItem* reset_item)
556 bool needs_bounce;
558 if (!track->can_use_mode (mode, needs_bounce)) {
560 if (!needs_bounce) {
561 /* cannot be done */
562 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
563 return;
564 } else {
565 cerr << "would bounce this one\n";
566 return;
570 track->set_mode (mode);
572 rec_enable_button->remove ();
573 switch (mode) {
574 case ARDOUR::Normal:
575 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
576 break;
577 case ARDOUR::Destructive:
578 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
579 break;
581 rec_enable_button->show_all ();
585 void
586 RouteTimeAxisView::track_mode_changed ()
588 RadioMenuItem* item;
590 switch (track()->mode()) {
591 case ARDOUR::Normal:
592 item = normal_track_mode_item;
593 break;
594 case ARDOUR::Destructive:
595 item = destructive_track_mode_item;
596 break;
597 default:
598 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
599 /*NOTREACHED*/
600 return;
603 item->set_active ();
606 void
607 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
609 double x1;
610 double x2;
611 double y2;
613 TimeAxisView::show_timestretch (start, end);
615 hide_timestretch ();
617 #if 0
618 if (ts.empty()) {
619 return;
623 /* check that the time selection was made in our route, or our edit group.
624 remember that edit_group() == 0 implies the route is *not* in a edit group.
627 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
628 /* this doesn't apply to us */
629 return;
632 /* ignore it if our edit group is not active */
634 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
635 return;
637 #endif
639 if (timestretch_rect == 0) {
640 timestretch_rect = new SimpleRect (*canvas_display);
641 timestretch_rect->property_x1() = 0.0;
642 timestretch_rect->property_y1() = 0.0;
643 timestretch_rect->property_x2() = 0.0;
644 timestretch_rect->property_y2() = 0.0;
645 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
646 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
649 timestretch_rect->show ();
650 timestretch_rect->raise_to_top ();
652 x1 = start / editor.get_current_zoom();
653 x2 = (end - 1) / editor.get_current_zoom();
654 y2 = current_height() - 2;
656 timestretch_rect->property_x1() = x1;
657 timestretch_rect->property_y1() = 1.0;
658 timestretch_rect->property_x2() = x2;
659 timestretch_rect->property_y2() = y2;
662 void
663 RouteTimeAxisView::hide_timestretch ()
665 TimeAxisView::hide_timestretch ();
667 if (timestretch_rect) {
668 timestretch_rect->hide ();
672 void
673 RouteTimeAxisView::show_selection (TimeSelection& ts)
676 #if 0
677 /* ignore it if our edit group is not active or if the selection was started
678 in some other track or edit group (remember that edit_group() == 0 means
679 that the track is not in an edit group).
682 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
683 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
684 hide_selection ();
685 return;
687 #endif
689 TimeAxisView::show_selection (ts);
692 void
693 RouteTimeAxisView::set_height (uint32_t h)
695 int gmlen = h - 5;
696 bool height_changed = (height == 0) || (h != height);
697 gm.get_level_meter().setup_meters (gmlen);
699 TimeAxisView::set_height (h);
701 ensure_xml_node ();
703 if (_view) {
704 _view->set_height ((double) current_height());
707 char buf[32];
708 snprintf (buf, sizeof (buf), "%u", height);
709 xml_node->add_property ("height", buf);
711 if (height >= hNormal) {
712 reset_meter();
713 show_name_entry ();
714 hide_name_label ();
716 gm.get_gain_slider().show();
717 mute_button->show();
718 solo_button->show();
719 if (rec_enable_button)
720 rec_enable_button->show();
722 edit_group_button.show();
723 hide_button.show();
724 visual_button.show();
725 size_button.show();
726 automation_button.show();
728 if (is_track() && track()->mode() == ARDOUR::Normal) {
729 playlist_button.show();
732 } else if (height >= hSmaller) {
734 reset_meter();
735 show_name_entry ();
736 hide_name_label ();
738 gm.get_gain_slider().hide();
739 mute_button->show();
740 solo_button->show();
741 if (rec_enable_button)
742 rec_enable_button->show();
744 edit_group_button.hide ();
745 hide_button.hide ();
746 visual_button.hide ();
747 size_button.hide ();
748 automation_button.hide ();
750 if (is_track() && track()->mode() == ARDOUR::Normal) {
751 playlist_button.hide ();
754 } else {
756 hide_meter ();
758 /* don't allow name_entry to be hidden while
759 it has focus, otherwise the GUI becomes unusable.
762 if (name_entry.has_focus()) {
763 if (name_entry.get_text() != _route->name()) {
764 name_entry_changed ();
766 controls_ebox.grab_focus ();
769 hide_name_entry ();
770 show_name_label ();
772 gm.get_gain_slider().hide();
773 mute_button->hide();
774 solo_button->hide();
775 if (rec_enable_button)
776 rec_enable_button->hide();
778 edit_group_button.hide ();
779 hide_button.hide ();
780 visual_button.hide ();
781 size_button.hide ();
782 automation_button.hide ();
783 playlist_button.hide ();
784 name_label.set_text (_route->name());
787 if (height_changed) {
788 /* only emit the signal if the height really changed */
789 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
793 void
794 RouteTimeAxisView::select_track_color ()
796 if (RouteUI::choose_color ()) {
798 if (_view) {
799 _view->apply_color (_color, StreamView::RegionColor);
804 void
805 RouteTimeAxisView::reset_samples_per_unit ()
807 set_samples_per_unit (editor.get_current_zoom());
810 void
811 RouteTimeAxisView::set_samples_per_unit (double spu)
813 double speed = 1.0;
815 if (get_diskstream() != 0) {
816 speed = get_diskstream()->speed();
819 if (_view) {
820 _view->set_samples_per_unit (spu * speed);
823 TimeAxisView::set_samples_per_unit (spu * speed);
826 void
827 RouteTimeAxisView::align_style_changed ()
829 switch (get_diskstream()->alignment_style()) {
830 case ExistingMaterial:
831 if (!align_existing_item->get_active()) {
832 align_existing_item->set_active();
834 break;
835 case CaptureTime:
836 if (!align_capture_item->get_active()) {
837 align_capture_item->set_active();
839 break;
843 void
844 RouteTimeAxisView::set_align_style (AlignStyle style)
846 RadioMenuItem* item;
848 switch (style) {
849 case ExistingMaterial:
850 item = align_existing_item;
851 break;
852 case CaptureTime:
853 item = align_capture_item;
854 break;
855 default:
856 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
857 /*NOTREACHED*/
858 return;
861 if (item->get_active()) {
862 get_diskstream()->set_align_style (style);
866 void
867 RouteTimeAxisView::rename_current_playlist ()
869 ArdourPrompter prompter (true);
870 string name;
872 boost::shared_ptr<Diskstream> ds = get_diskstream();
873 if (!ds || ds->destructive())
874 return;
876 boost::shared_ptr<Playlist> pl = ds->playlist();
877 if (!pl)
878 return;
880 prompter.set_prompt (_("Name for playlist"));
881 prompter.set_initial_text (pl->name());
882 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
883 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
885 switch (prompter.run ()) {
886 case Gtk::RESPONSE_ACCEPT:
887 prompter.get_result (name);
888 if (name.length()) {
889 pl->set_name (name);
891 break;
893 default:
894 break;
898 std::string
899 RouteTimeAxisView::resolve_new_group_playlist_name(std::string &basename, vector<boost::shared_ptr<Playlist> > const & playlists)
901 std::string ret(basename);
903 std::string group_string = "."+edit_group()->name()+".";
905 // iterate through all playlists
906 int maxnumber = 0;
907 for (vector<boost::shared_ptr<Playlist> >::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
908 std::string tmp = (*i)->name();
910 std::string::size_type idx = tmp.find(group_string);
911 // find those which belong to this group
912 if (idx != string::npos) {
913 tmp = tmp.substr(idx + group_string.length());
915 // and find the largest current number
916 int x = atoi(tmp.c_str());
917 if (x > maxnumber) {
918 maxnumber = x;
923 maxnumber++;
925 char buf[32];
926 snprintf (buf, sizeof(buf), "%d", maxnumber);
928 ret = this->name()+"."+edit_group()->name()+"."+buf;
930 return ret;
933 void
934 RouteTimeAxisView::use_copy_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op)
936 string name;
938 boost::shared_ptr<Diskstream> ds = get_diskstream();
939 if (!ds || ds->destructive())
940 return;
942 boost::shared_ptr<const Playlist> pl = ds->playlist();
943 if (!pl)
944 return;
946 name = pl->name();
948 if (edit_group() && edit_group()->is_active()) {
949 name = resolve_new_group_playlist_name(name, playlists_before_op);
952 while (_session.playlist_by_name(name)) {
953 name = Playlist::bump_name (name, _session);
956 // TODO: The prompter "new" button should be de-activated if the user
957 // specifies a playlist name which already exists in the session.
959 if (prompt) {
961 ArdourPrompter prompter (true);
963 prompter.set_prompt (_("Name for Playlist"));
964 prompter.set_initial_text (name);
965 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
966 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
967 prompter.show_all ();
969 switch (prompter.run ()) {
970 case Gtk::RESPONSE_ACCEPT:
971 prompter.get_result (name);
972 break;
974 default:
975 return;
979 if (name.length()) {
980 ds->use_copy_playlist ();
981 ds->playlist()->set_name (name);
985 void
986 RouteTimeAxisView::use_new_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op)
988 string name;
990 boost::shared_ptr<Diskstream> ds = get_diskstream();
991 if (!ds || ds->destructive())
992 return;
994 boost::shared_ptr<const Playlist> pl = ds->playlist();
995 if (!pl)
996 return;
998 name = pl->name();
1000 if (edit_group() && edit_group()->is_active()) {
1001 name = resolve_new_group_playlist_name(name,playlists_before_op);
1004 while (_session.playlist_by_name(name)) {
1005 name = Playlist::bump_name (name, _session);
1009 if (prompt) {
1011 ArdourPrompter prompter (true);
1013 prompter.set_prompt (_("Name for Playlist"));
1014 prompter.set_initial_text (name);
1015 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
1016 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
1018 switch (prompter.run ()) {
1019 case Gtk::RESPONSE_ACCEPT:
1020 prompter.get_result (name);
1021 break;
1023 default:
1024 return;
1028 if (name.length()) {
1029 ds->use_new_playlist ();
1030 ds->playlist()->set_name (name);
1034 void
1035 RouteTimeAxisView::clear_playlist ()
1037 boost::shared_ptr<Diskstream> ds = get_diskstream();
1038 if (!ds || ds->destructive())
1039 return;
1041 boost::shared_ptr<Playlist> pl = ds->playlist();
1042 if (!pl)
1043 return;
1045 editor.clear_playlist (pl);
1048 void
1049 RouteTimeAxisView::speed_changed ()
1051 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
1054 void
1055 RouteTimeAxisView::diskstream_changed ()
1057 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
1060 void
1061 RouteTimeAxisView::update_diskstream_display ()
1063 if (!get_diskstream()) // bus
1064 return;
1066 set_playlist (get_diskstream()->playlist());
1067 map_frozen ();
1070 void
1071 RouteTimeAxisView::selection_click (GdkEventButton* ev)
1073 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::TertiaryModifier|Keyboard::PrimaryModifier))) {
1075 /* special case: select/deselect all tracks */
1076 if (editor.get_selection().selected (this)) {
1077 editor.get_selection().clear_tracks ();
1078 } else {
1079 editor.select_all_tracks ();
1082 return;
1085 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1087 switch (Keyboard::selection_type (ev->state)) {
1088 case Selection::Toggle:
1089 editor.get_selection().toggle (*tracks);
1090 break;
1092 case Selection::Set:
1093 editor.get_selection().set (*tracks);
1094 break;
1096 case Selection::Extend:
1097 if (tracks->size() > 1) {
1098 /* add each one, do not "extend" */
1099 editor.get_selection().add (*tracks);
1100 } else {
1101 /* extend to the single track */
1102 editor.extend_selection_to_track (*tracks->front());
1104 break;
1106 case Selection::Add:
1107 editor.get_selection().add (*tracks);
1108 break;
1111 delete tracks;
1114 void
1115 RouteTimeAxisView::set_selected_points (PointSelection& points)
1117 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1118 (*i)->set_selected_points (points);
1122 void
1123 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1125 if (_view) {
1126 _view->set_selected_regionviews (regions);
1130 void
1131 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1133 double speed = 1.0;
1135 if (get_diskstream() != 0) {
1136 speed = get_diskstream()->speed();
1139 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1140 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1142 if ((_view && ((top < 0.0 && bot < 0.0))) || touched (top, bot)) {
1143 _view->get_selectables (start_adjusted, end_adjusted, results);
1146 /* pick up visible automation tracks */
1148 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1149 if (!(*i)->hidden()) {
1150 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1155 void
1156 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1158 if (_view) {
1159 _view->get_inverted_selectables (sel, results);
1162 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1163 if (!(*i)->hidden()) {
1164 (*i)->get_inverted_selectables (sel, results);
1168 return;
1171 RouteGroup*
1172 RouteTimeAxisView::edit_group() const
1174 return _route->edit_group();
1177 string
1178 RouteTimeAxisView::name() const
1180 return _route->name();
1183 boost::shared_ptr<Playlist>
1184 RouteTimeAxisView::playlist () const
1186 boost::shared_ptr<Diskstream> ds;
1188 if ((ds = get_diskstream()) != 0) {
1189 return ds->playlist();
1190 } else {
1191 return boost::shared_ptr<Playlist> ();
1195 void
1196 RouteTimeAxisView::name_entry_changed ()
1198 string x;
1200 x = name_entry.get_text ();
1202 if (x == _route->name()) {
1203 return;
1206 strip_whitespace_edges(x);
1208 if (x.length() == 0) {
1209 name_entry.set_text (_route->name());
1210 return;
1213 if (_session.route_name_unique (x)) {
1214 _route->set_name (x, this);
1215 } else {
1216 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1217 name_entry.set_text (_route->name());
1221 void
1222 RouteTimeAxisView::visual_click ()
1224 popup_display_menu (0);
1227 void
1228 RouteTimeAxisView::hide_click ()
1230 // LAME fix for hide_button refresh fix
1231 hide_button.set_sensitive(false);
1233 editor.hide_track_in_display (*this);
1235 hide_button.set_sensitive(true);
1238 boost::shared_ptr<Region>
1239 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1241 boost::shared_ptr<Diskstream> stream;
1242 boost::shared_ptr<Playlist> playlist;
1244 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1245 return playlist->find_next_region (pos, point, dir);
1248 return boost::shared_ptr<Region> ();
1251 nframes64_t
1252 RouteTimeAxisView::find_next_region_boundary (nframes64_t pos, int32_t dir)
1254 boost::shared_ptr<Diskstream> stream;
1255 boost::shared_ptr<Playlist> playlist;
1257 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1258 return playlist->find_next_region_boundary (pos, dir);
1261 return -1;
1264 bool
1265 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1267 boost::shared_ptr<Playlist> what_we_got;
1268 boost::shared_ptr<Diskstream> ds = get_diskstream();
1269 boost::shared_ptr<Playlist> playlist;
1270 bool ret = false;
1272 if (ds == 0) {
1273 /* route is a bus, not a track */
1274 return false;
1277 playlist = ds->playlist();
1279 TimeSelection time (selection.time);
1280 float speed = ds->speed();
1281 if (speed != 1.0f) {
1282 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1283 (*i).start = session_frame_to_track_frame((*i).start, speed);
1284 (*i).end = session_frame_to_track_frame((*i).end, speed);
1288 XMLNode &before = playlist->get_state();
1289 switch (op) {
1290 case Cut:
1291 if ((what_we_got = playlist->cut (time)) != 0) {
1292 editor.get_cut_buffer().add (what_we_got);
1293 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1294 ret = true;
1296 break;
1297 case Copy:
1298 if ((what_we_got = playlist->copy (time)) != 0) {
1299 editor.get_cut_buffer().add (what_we_got);
1301 break;
1303 case Clear:
1304 if ((what_we_got = playlist->cut (time)) != 0) {
1305 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1306 what_we_got->release ();
1307 ret = true;
1309 break;
1312 return ret;
1315 bool
1316 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1318 if (!is_track()) {
1319 return false;
1322 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1323 PlaylistSelection::iterator p;
1325 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1327 if (p == selection.playlists.end()) {
1328 return false;
1331 if (get_diskstream()->speed() != 1.0f)
1332 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1334 XMLNode &before = playlist->get_state();
1335 playlist->paste (*p, pos, times);
1336 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1338 return true;
1342 list<TimeAxisView*>
1343 RouteTimeAxisView::get_child_list()
1346 list<TimeAxisView*>redirect_children;
1348 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1349 if (!(*i)->hidden()) {
1350 redirect_children.push_back(*i);
1353 return redirect_children;
1357 void
1358 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1360 using namespace Menu_Helpers;
1362 if (!menu || !is_track()) {
1363 return;
1366 MenuList& playlist_items = menu->items();
1367 menu->set_name ("ArdourContextMenu");
1368 playlist_items.clear();
1370 if (playlist_menu) {
1371 delete playlist_menu;
1374 playlist_menu = new Menu;
1375 playlist_menu->set_name ("ArdourContextMenu");
1377 vector<boost::shared_ptr<Playlist> > playlists;
1378 boost::shared_ptr<Diskstream> ds = get_diskstream();
1379 RadioMenuItem::Group playlist_group;
1381 _session.get_playlists (playlists);
1383 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1385 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1386 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1387 boost::weak_ptr<Playlist> (*i))));
1389 if (ds->playlist()->id() == (*i)->id()) {
1390 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1392 } else if (ds->playlist()->id() == (*i)->id()) {
1393 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1394 boost::weak_ptr<Playlist>(*i))));
1395 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1400 playlist_items.push_back (SeparatorElem());
1401 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1402 playlist_items.push_back (SeparatorElem());
1404 if (!edit_group() || !edit_group()->is_active()) {
1405 playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1406 playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1408 } else {
1409 // Use a label which tells the user what is happening
1410 playlist_items.push_back (MenuElem (_("New Take"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1411 playlist_items.push_back (MenuElem (_("Copy Take"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1415 playlist_items.push_back (SeparatorElem());
1416 playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
1417 playlist_items.push_back (SeparatorElem());
1419 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1422 void
1423 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1425 assert (is_track());
1427 boost::shared_ptr<Playlist> pl (wpl.lock());
1429 if (!pl) {
1430 return;
1433 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1435 if (apl) {
1436 if (get_diskstream()->playlist() == apl) {
1437 // radio button cotnrols mean this function is called for both the
1438 // old and new playlist
1439 return;
1441 get_diskstream()->use_playlist (apl);
1444 if (edit_group() && edit_group()->is_active()) {
1445 //PBD::stacktrace(cerr, 20);
1446 std::string group_string = "."+edit_group()->name()+".";
1448 std::string take_name = apl->name();
1449 std::string::size_type idx = take_name.find(group_string);
1451 if (idx == std::string::npos)
1452 return;
1454 take_name = take_name.substr(idx + group_string.length()); // find the bit containing the take number / name
1456 for (list<Route*>::const_iterator i = edit_group()->route_list().begin(); i != edit_group()->route_list().end(); ++i) {
1457 if ( (*i) == this->route().get()) {
1458 continue;
1461 std::string playlist_name = (*i)->name()+group_string+take_name;
1463 Track *track = dynamic_cast<Track *>(*i);
1464 if (!track) {
1465 continue;
1468 boost::shared_ptr<Playlist> ipl = session().playlist_by_name(playlist_name);
1469 if (!ipl) {
1470 // No playlist for this track for this take yet, make it
1471 track->diskstream()->use_new_playlist();
1472 track->diskstream()->playlist()->set_name(playlist_name);
1473 } else {
1474 track->diskstream()->use_playlist(ipl);
1477 //(*i)->get_dis
1483 void
1484 RouteTimeAxisView::show_playlist_selector ()
1486 editor.playlist_selector().show_for (this);
1489 void
1490 RouteTimeAxisView::map_frozen ()
1492 if (!is_track()) {
1493 return;
1496 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1498 switch (track()->freeze_state()) {
1499 case Track::Frozen:
1500 playlist_button.set_sensitive (false);
1501 rec_enable_button->set_sensitive (false);
1502 break;
1503 default:
1504 playlist_button.set_sensitive (true);
1505 rec_enable_button->set_sensitive (true);
1506 break;
1510 void
1511 RouteTimeAxisView::color_handler ()
1513 if (timestretch_rect) {
1514 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
1517 if (timestretch_rect) {
1518 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
1521 reset_meter();
1524 void
1525 RouteTimeAxisView::show_all_automation ()
1527 no_redraw = true;
1529 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1530 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1531 if ((*ii)->view == 0) {
1532 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1535 (*ii)->menu_item->set_active (true);
1539 no_redraw = false;
1541 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1544 void
1545 RouteTimeAxisView::show_existing_automation ()
1547 no_redraw = true;
1549 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1550 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1551 if ((*ii)->view != 0) {
1552 (*ii)->menu_item->set_active (true);
1557 no_redraw = false;
1559 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1562 void
1563 RouteTimeAxisView::hide_all_automation ()
1565 no_redraw = true;
1567 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1568 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1569 (*ii)->menu_item->set_active (false);
1573 no_redraw = false;
1574 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1578 void
1579 RouteTimeAxisView::region_view_added (RegionView* rv)
1581 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1582 AutomationTimeAxisView* atv;
1584 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1585 rv->add_ghost (*atv);
1590 void
1591 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1593 rv->add_ghost (*atv);
1596 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1598 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1599 delete *i;
1604 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1606 parent.remove_ran (this);
1608 if (view) {
1609 delete view;
1613 void
1614 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1616 if (ran->view) {
1617 remove_child (ran->view);
1621 RouteTimeAxisView::RedirectAutomationNode*
1622 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1624 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1626 if ((*i)->redirect == redirect) {
1628 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1629 if ((*ii)->what == what) {
1630 return *ii;
1636 return 0;
1639 // FIXME: duplicated in midi_time_axis.cc
1640 static string
1641 legalize_for_xml_node (string str)
1643 string::size_type pos;
1644 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:";
1645 string legal;
1647 legal = str;
1648 pos = 0;
1650 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1651 legal.replace (pos, 1, "_");
1652 pos += 1;
1655 return legal;
1659 void
1660 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1662 RedirectAutomationLine* ral;
1663 string name;
1664 RedirectAutomationNode* ran;
1666 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1667 fatal << _("programming error: ")
1668 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1669 redirect->name(), what)
1670 << endmsg;
1671 /*NOTREACHED*/
1672 return;
1675 if (ran->view) {
1676 return;
1679 name = redirect->describe_parameter (what);
1681 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1683 char state_name[256];
1684 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1686 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1688 ral = new RedirectAutomationLine (name,
1689 *redirect, what, _session, *ran->view,
1690 *ran->view->canvas_display, redirect->automation_list (what));
1692 ral->set_line_color (ARDOUR_UI::config()->canvasvar_RedirectAutomationLine.get());
1693 ral->queue_reset ();
1695 ran->view->add_line (*ral);
1697 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1699 if (!ran->view->marked_for_display()) {
1700 ran->view->hide ();
1701 } else {
1702 ran->menu_item->set_active (true);
1705 add_child (ran->view);
1707 if (_view) {
1708 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1711 redirect->mark_automation_visible (what, true);
1714 void
1715 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1717 if (!_hidden) {
1718 ran->menu_item->set_active (false);
1721 r->mark_automation_visible (ran->what, false);
1723 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1726 void
1727 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1729 set<uint32_t> s;
1730 RedirectAutomationLine *ral;
1732 redirect->what_has_visible_automation (s);
1734 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1736 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1737 ral->queue_reset ();
1738 } else {
1739 add_redirect_automation_curve (redirect, (*i));
1744 void
1745 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1747 using namespace Menu_Helpers;
1748 RedirectAutomationInfo *rai;
1749 list<RedirectAutomationInfo*>::iterator x;
1751 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1752 std::set<uint32_t> has_visible_automation;
1754 r->what_has_visible_automation(has_visible_automation);
1756 if (automatable.empty()) {
1757 return;
1760 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1761 if ((*x)->redirect == r) {
1762 break;
1766 if (x == redirect_automation.end()) {
1768 rai = new RedirectAutomationInfo (r);
1769 redirect_automation.push_back (rai);
1771 } else {
1773 rai = *x;
1777 /* any older menu was deleted at the top of redirects_changed()
1778 when we cleared the subplugin menu.
1781 rai->menu = manage (new Menu);
1782 MenuList& items = rai->menu->items();
1783 rai->menu->set_name ("ArdourContextMenu");
1785 items.clear ();
1787 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1789 RedirectAutomationNode* ran;
1790 CheckMenuItem* mitem;
1792 string name = r->describe_parameter (*i);
1794 items.push_back (CheckMenuElem (name));
1795 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1797 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1798 mitem->set_active(true);
1801 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1803 /* new item */
1805 ran = new RedirectAutomationNode (*i, mitem, *this);
1807 rai->lines.push_back (ran);
1809 } else {
1811 ran->menu_item = mitem;
1815 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1818 /* add the menu for this redirect, because the subplugin
1819 menu is always cleared at the top of redirects_changed().
1820 this is the result of some poor design in gtkmm and/or
1821 GTK+.
1824 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1825 rai->valid = true;
1828 void
1829 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1830 RouteTimeAxisView::RedirectAutomationNode* ran)
1832 bool showit = ran->menu_item->get_active();
1833 bool redraw = false;
1835 if (ran->view == 0 && showit) {
1836 add_redirect_automation_curve (rai->redirect, ran->what);
1837 redraw = true;
1840 if (showit != ran->view->marked_for_display()) {
1842 if (showit) {
1843 ran->menu_item->set_active(true);
1844 ran->view->set_marked_for_display (true);
1845 ran->view->canvas_display->show();
1846 ran->view->canvas_background->show();
1847 } else {
1848 ran->menu_item->set_active(false);
1849 rai->redirect->mark_automation_visible (ran->what, true);
1850 ran->view->set_marked_for_display (false);
1851 ran->view->hide ();
1854 redraw = true;
1858 if (redraw && !no_redraw) {
1860 /* now trigger a redisplay */
1862 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1867 void
1868 RouteTimeAxisView::redirects_changed (void *src)
1870 using namespace Menu_Helpers;
1872 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1873 (*i)->valid = false;
1876 subplugin_menu.items().clear ();
1878 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1879 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1881 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1883 list<RedirectAutomationInfo*>::iterator tmp;
1885 tmp = i;
1886 ++tmp;
1888 if (!(*i)->valid) {
1890 delete *i;
1891 redirect_automation.erase (i);
1895 i = tmp;
1898 /* change in visibility was possible */
1900 _route->gui_changed ("visible_tracks", this);
1903 RedirectAutomationLine *
1904 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1906 RedirectAutomationNode* ran;
1908 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1909 if (ran->view) {
1910 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1914 return 0;
1917 void
1918 RouteTimeAxisView::reset_redirect_automation_curves ()
1920 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1921 (*i)->reset();
1925 void
1926 RouteTimeAxisView::update_rec_display ()
1928 RouteUI::update_rec_display ();
1929 name_entry.set_sensitive (!_route->record_enabled());
1932 void
1933 RouteTimeAxisView::fast_update ()
1935 gm.get_level_meter().update_meters ();
1938 void
1939 RouteTimeAxisView::hide_meter ()
1941 clear_meter ();
1942 gm.get_level_meter().hide_meters ();
1945 void
1946 RouteTimeAxisView::show_meter ()
1948 reset_meter ();
1951 void
1952 RouteTimeAxisView::reset_meter ()
1954 if (Config->get_show_track_meters()) {
1955 gm.get_level_meter().setup_meters (height-5);
1956 } else {
1957 hide_meter ();
1961 void
1962 RouteTimeAxisView::clear_meter ()
1964 gm.get_level_meter().clear_meters ();
1967 void
1968 RouteTimeAxisView::meter_changed (void *src)
1970 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::meter_changed), src));
1971 reset_meter();
1974 void
1975 RouteTimeAxisView::io_changed (IOChange change, void *src)
1977 reset_meter ();