2 Copyright (C) 2000-2007 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.
22 #include <boost/algorithm/string.hpp>
24 #include <gtkmm/separator.h>
26 #include "pbd/error.h"
27 #include "pbd/memento_command.h"
28 #include "pbd/stacktrace.h"
29 #include "pbd/string_convert.h"
30 #include "pbd/types_convert.h"
31 #include "pbd/unwind.h"
33 #include "ardour/automation_control.h"
34 #include "ardour/beats_frames_converter.h"
35 #include "ardour/event_type_map.h"
36 #include "ardour/parameter_types.h"
37 #include "ardour/profile.h"
38 #include "ardour/route.h"
39 #include "ardour/session.h"
41 #include "gtkmm2ext/utils.h"
43 #include "canvas/debug.h"
45 #include "widgets/tooltips.h"
47 #include "automation_time_axis.h"
48 #include "automation_streamview.h"
49 #include "gui_thread.h"
50 #include "route_time_axis.h"
51 #include "automation_line.h"
52 #include "paste_context.h"
53 #include "public_editor.h"
54 #include "selection.h"
55 #include "rgb_macros.h"
56 #include "point_selection.h"
57 #include "control_point.h"
59 #include "item_counts.h"
60 #include "ui_config.h"
65 using namespace ARDOUR;
66 using namespace ArdourWidgets;
67 using namespace ARDOUR_UI_UTILS;
70 using namespace Gtkmm2ext;
71 using namespace Editing;
73 Pango::FontDescription AutomationTimeAxisView::name_font;
74 bool AutomationTimeAxisView::have_name_font = false;
77 /** \a a the automatable object this time axis is to display data for.
78 * For route/track automation (e.g. gain) pass the route for both \r and \a.
79 * For route child (e.g. plugin) automation, pass the child for \a.
80 * For region automation (e.g. MIDI CC), pass null for \a.
82 AutomationTimeAxisView::AutomationTimeAxisView (
84 boost::shared_ptr<Stripable> strip,
85 boost::shared_ptr<Automatable> a,
86 boost::shared_ptr<AutomationControl> c,
91 ArdourCanvas::Canvas& canvas,
93 const string & nomparent
95 : SessionHandlePtr (s)
96 , TimeAxisView (s, e, &parent, canvas)
101 , _base_rect (new ArdourCanvas::Rectangle (_canvas_display))
102 , _view (show_regions ? new AutomationStreamView (*this) : 0)
104 , _show_regions (show_regions)
106 //concatenate plugin name and param name into the tooltip
107 string tipname = nomparent;
108 if (!tipname.empty()) {
112 set_tooltip(controls_ebox, tipname);
114 //plugin name and param name appear on 2 separate lines in the track header
116 if (!tipname.empty()) {
122 CANVAS_DEBUG_NAME (_canvas_display, string_compose ("main for auto %2/%1", _name, strip->name()));
123 CANVAS_DEBUG_NAME (selection_group, string_compose ("selections for auto %2/%1", _name, strip->name()));
124 CANVAS_DEBUG_NAME (_ghost_group, string_compose ("ghosts for auto %2/%1", _name, strip->name()));
126 if (!have_name_font) {
127 name_font = get_font_for_style (X_("AutomationTrackName"));
128 have_name_font = true;
132 _controller = AutomationController::create (_control->parameter(), _control->desc(), _control);
135 const std::string fill_color_name = (dynamic_cast<MidiTimeAxisView*>(&parent)
136 ? "midi automation track fill"
137 : "audio automation track fill");
143 mode_discrete_item = 0;
148 ignore_state_request = false;
149 ignore_mode_request = false;
150 first_call_to_set_height = true;
152 CANVAS_DEBUG_NAME (_base_rect, string_compose ("base rect for %1", _name));
153 _base_rect->set_x1 (ArdourCanvas::COORD_MAX);
154 _base_rect->set_outline (false);
155 _base_rect->set_fill_color (UIConfiguration::instance().color_mod (fill_color_name, "automation track fill"));
156 _base_rect->set_data ("trackview", this);
157 _base_rect->Event.connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_automation_track_event), _base_rect, this));
159 _base_rect->lower_to_bottom();
162 using namespace Menu_Helpers;
164 auto_dropdown.AddMenuElem (MenuElem (S_("Automation|Manual"), sigc::bind (sigc::mem_fun(*this,
165 &AutomationTimeAxisView::set_automation_state), (AutoState) ARDOUR::Off)));
166 auto_dropdown.AddMenuElem (MenuElem (_("Play"), sigc::bind (sigc::mem_fun(*this,
167 &AutomationTimeAxisView::set_automation_state), (AutoState) Play)));
168 auto_dropdown.AddMenuElem (MenuElem (_("Write"), sigc::bind (sigc::mem_fun(*this,
169 &AutomationTimeAxisView::set_automation_state), (AutoState) Write)));
170 auto_dropdown.AddMenuElem (MenuElem (_("Touch"), sigc::bind (sigc::mem_fun(*this,
171 &AutomationTimeAxisView::set_automation_state), (AutoState) Touch)));
173 /* XXX translators: use a string here that will be at least as long
174 as the longest automation label (see ::automation_state_changed()
175 below). be sure to include a descender.
177 auto_dropdown.set_sizing_text(_("Mgnual"));
179 hide_button.set_icon (ArdourIcon::CloseCross);
180 hide_button.set_tweaks(ArdourButton::TrackHeader);
182 auto_dropdown.set_name ("route button");
183 hide_button.set_name ("route button");
185 auto_dropdown.unset_flags (Gtk::CAN_FOCUS);
186 hide_button.unset_flags (Gtk::CAN_FOCUS);
188 controls_table.set_no_show_all();
190 set_tooltip(auto_dropdown, _("automation state"));
191 set_tooltip(hide_button, _("hide track"));
194 if (get_gui_property ("height", height)) {
197 set_height (preset_height (HeightNormal));
200 //name label isn't editable on an automation track; remove the tooltip
201 set_tooltip (name_label, X_(""));
203 /* repack the name label, which TimeAxisView has already attached to
207 if (name_label.get_parent()) {
208 name_label.get_parent()->remove (name_label);
211 name_label.set_text (_name);
212 name_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
213 name_label.set_name (X_("TrackParameterName"));
214 name_label.set_ellipsize (Pango::ELLIPSIZE_END);
216 /* add the buttons */
217 controls_table.set_border_width (1);
218 controls_table.attach (hide_button, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
219 controls_table.attach (name_label, 2, 3, 1, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 2, 0);
220 controls_table.attach (auto_dropdown, 3, 4, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
222 Gtk::DrawingArea *blank0 = manage (new Gtk::DrawingArea());
223 Gtk::DrawingArea *blank1 = manage (new Gtk::DrawingArea());
225 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&parent);
226 // TODO use rtv->controls_base_unselected_name
227 // subscribe to route_active_changed, ...
228 if (rtv && rtv->is_audio_track()) {
229 blank0->set_name ("AudioTrackControlsBaseUnselected");
230 } else if (rtv && rtv->is_midi_track()) {
231 blank0->set_name ("MidiTrackControlsBaseUnselected");
233 blank0->set_name ("AudioBusControlsBaseUnselected");
235 blank0->set_name ("UnknownControlsBaseUnselected");
237 blank0->set_size_request (-1, -1);
238 blank1->set_size_request (1, 0);
239 VSeparator* separator = manage (new VSeparator());
240 separator->set_name("TrackSeparator");
241 separator->set_size_request (1, -1);
243 controls_button_size_group->add_widget(hide_button);
244 controls_button_size_group->add_widget(*blank0);
246 time_axis_hbox.pack_start (*blank0, false, false);
247 time_axis_hbox.pack_start (*separator, false, false);
248 time_axis_hbox.reorder_child (*blank0, 0);
249 time_axis_hbox.reorder_child (*separator, 1);
250 time_axis_hbox.reorder_child (time_axis_vbox, 2);
252 if (!ARDOUR::Profile->get_mixbus() ) {
253 time_axis_hbox.pack_start (*blank1, false, false);
262 _controller->disable_vertical_scroll ();
263 controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
266 controls_table.show_all ();
268 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked));
270 controls_base_selected_name = X_("AutomationTrackControlsBaseSelected");
271 controls_base_unselected_name = X_("AutomationTrackControlsBase");
273 controls_ebox.set_name (controls_base_unselected_name);
274 time_axis_frame.set_name (controls_base_unselected_name);
276 /* ask for notifications of any new RegionViews */
284 /* no regions, just a single line for the entire track (e.g. bus gain) */
288 boost::shared_ptr<AutomationLine> line (
290 ARDOUR::EventTypeMap::instance().to_symbol(_parameter),
298 line->set_line_color (UIConfiguration::instance().color ("processor automation line"));
299 line->set_fill (true);
300 line->queue_reset ();
304 /* make sure labels etc. are correct */
306 automation_state_changed ();
307 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AutomationTimeAxisView::color_handler));
309 _stripable->DropReferences.connect (
310 _stripable_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::route_going_away, this), gui_context ()
314 AutomationTimeAxisView::~AutomationTimeAxisView ()
316 cleanup_gui_properties ();
321 AutomationTimeAxisView::route_going_away ()
327 AutomationTimeAxisView::set_automation_state (AutoState state)
329 if (ignore_state_request) {
334 _automatable->set_parameter_automation_state (_parameter, state);
337 _control->set_automation_state (state);
338 _session->set_dirty ();
342 _view->set_automation_state (state);
344 /* AutomationStreamViews don't signal when their automation state changes, so handle
345 our updates `manually'.
347 automation_state_changed ();
352 AutomationTimeAxisView::automation_state_changed ()
356 /* update button label */
359 state = _view->automation_state ();
362 state = _control->alist()->automation_state ();
367 switch (state & (ARDOUR::Off|Play|Touch|Write)) {
369 auto_dropdown.set_text (S_("Automation|Manual"));
371 ignore_state_request = true;
372 auto_off_item->set_active (true);
373 auto_play_item->set_active (false);
374 auto_touch_item->set_active (false);
375 auto_write_item->set_active (false);
376 ignore_state_request = false;
380 auto_dropdown.set_text (_("Play"));
381 if (auto_play_item) {
382 ignore_state_request = true;
383 auto_play_item->set_active (true);
384 auto_off_item->set_active (false);
385 auto_touch_item->set_active (false);
386 auto_write_item->set_active (false);
387 ignore_state_request = false;
391 auto_dropdown.set_text (_("Write"));
392 if (auto_write_item) {
393 ignore_state_request = true;
394 auto_write_item->set_active (true);
395 auto_off_item->set_active (false);
396 auto_play_item->set_active (false);
397 auto_touch_item->set_active (false);
398 ignore_state_request = false;
402 auto_dropdown.set_text (_("Touch"));
403 if (auto_touch_item) {
404 ignore_state_request = true;
405 auto_touch_item->set_active (true);
406 auto_off_item->set_active (false);
407 auto_play_item->set_active (false);
408 auto_write_item->set_active (false);
409 ignore_state_request = false;
413 auto_dropdown.set_text (_("???"));
418 /** The interpolation style of our AutomationList has changed, so update */
420 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
422 if (ignore_mode_request) {
425 PBD::Unwinder<bool> uw (ignore_mode_request, true);
427 case AutomationList::Discrete:
428 if (mode_discrete_item) {
429 mode_discrete_item->set_active(true);
432 case AutomationList::Linear:
433 if (mode_line_item) {
434 mode_line_item->set_active(true);
437 case AutomationList::Logarithmic:
439 mode_log_item->set_active(true);
442 case AutomationList::Exponential:
444 mode_exp_item->set_active(true);
452 /** A menu item has been selected to change our interpolation mode */
454 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
456 /* Tell our view's list, if we have one, otherwise tell our own.
457 * Everything else will be signalled back from that.
461 _view->set_interpolation (style);
464 _control->list()->set_interpolation (style);
469 AutomationTimeAxisView::clear_clicked ()
471 assert (_line || _view);
473 _editor.begin_reversible_command (_("clear automation"));
480 set_automation_state ((AutoState) ARDOUR::Off);
481 _editor.commit_reversible_command ();
482 _session->set_dirty ();
486 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
488 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
489 uint32_t const normal = preset_height (HeightNormal);
490 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
492 TimeAxisView::set_height (h, m);
494 _base_rect->set_y1 (h);
497 _line->set_height(h - 2.5);
501 _view->set_height(h);
502 _view->update_contents_height();
505 if (changed_between_small_and_normal || first_call_to_set_height) {
507 first_call_to_set_height = false;
509 if (h >= preset_height (HeightNormal)) {
510 if (!(_parameter.type() >= MidiCCAutomation &&
511 _parameter.type() <= MidiChannelPressureAutomation)) {
512 auto_dropdown.show();
517 } else if (h >= preset_height (HeightSmall)) {
518 controls_table.hide_all ();
519 auto_dropdown.hide();
525 if (_canvas_display->visible() && _stripable) {
526 /* only emit the signal if the height really changed and we were visible */
527 _stripable->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
533 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
535 TimeAxisView::set_samples_per_pixel (fpp);
542 _view->set_samples_per_pixel (fpp);
547 AutomationTimeAxisView::hide_clicked ()
549 hide_button.set_sensitive(false);
550 set_marked_for_display (false);
551 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(parent);
553 rtv->request_redraw ();
555 hide_button.set_sensitive(true);
559 AutomationTimeAxisView::build_display_menu ()
561 using namespace Menu_Helpers;
565 TimeAxisView::build_display_menu ();
567 /* now fill it with our stuff */
569 MenuList& items = display_menu->items();
571 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
572 items.push_back (SeparatorElem());
573 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
574 items.push_back (SeparatorElem());
578 Menu* auto_state_menu = manage (new Menu);
579 auto_state_menu->set_name ("ArdourContextMenu");
580 MenuList& as_items = auto_state_menu->items();
582 as_items.push_back (CheckMenuElem (S_("Automation|Manual"), sigc::bind (
583 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
584 (AutoState) ARDOUR::Off)));
585 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
587 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
588 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
590 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
592 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
593 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
594 (AutoState) Write)));
595 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
597 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
598 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
599 (AutoState) Touch)));
600 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
602 if (!(_parameter.type() >= MidiCCAutomation &&
603 _parameter.type() <= MidiChannelPressureAutomation)) {
604 items.push_back (MenuElem (_("State"), *auto_state_menu));
609 /* current interpolation state */
610 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
612 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
614 Menu* auto_mode_menu = manage (new Menu);
615 auto_mode_menu->set_name ("ArdourContextMenu");
616 MenuList& am_items = auto_mode_menu->items();
618 RadioMenuItem::Group group;
620 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
621 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
622 AutomationList::Discrete)));
623 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
625 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
626 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
627 AutomationList::Linear)));
628 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
630 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
633 #ifdef XXX_NEW_INTERPOLATON__BREAK_SESSION_FORMAT_XXX
634 Menu* auto_mode_menu = manage (new Menu);
635 auto_mode_menu->set_name ("ArdourContextMenu");
636 MenuList& am_items = auto_mode_menu->items();
637 bool have_options = false;
639 RadioMenuItem::Group group;
641 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
642 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
643 AutomationList::Linear)));
644 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
646 if (_control->desc().logarithmic) {
647 am_items.push_back (RadioMenuElem (group, _("Logarithmic"), sigc::bind (
648 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
649 AutomationList::Logarithmic)));
650 mode_log_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
656 if (_line->get_uses_gain_mapping () && !_control->desc().logarithmic) {
657 am_items.push_back (RadioMenuElem (group, _("Exponential"), sigc::bind (
658 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
659 AutomationList::Exponential)));
660 mode_exp_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
667 items.push_back (MenuElem (_("Interpolation"), *auto_mode_menu));
670 delete auto_mode_menu;
676 /* make sure the automation menu state is correct */
678 automation_state_changed ();
679 interpolation_changed (s);
683 AutomationTimeAxisView::add_automation_event (GdkEvent* event, framepos_t frame, double y, bool with_guard_points)
689 boost::shared_ptr<AutomationList> list = _line->the_list ();
691 if (list->in_write_pass()) {
692 /* do not allow the GUI to add automation events during an
693 automation write pass.
698 MusicFrame when (frame, 0);
699 _editor.snap_to_with_modifier (when, event);
701 if (UIConfiguration::instance().get_new_automation_points_on_lane()) {
702 if (_control->list()->size () == 0) {
703 y = _control->get_value ();
705 y = _control->list()->eval (when.frame);
709 _line->grab_item().canvas_to_item (x, y);
710 /* compute vertical fractional position */
711 y = 1.0 - (y / _line->height());
713 _line->view_to_model_coord (x, y);
716 XMLNode& before = list->get_state();
717 std::list<Selectable*> results;
719 if (list->editor_add (when.frame, y, with_guard_points)) {
720 XMLNode& after = list->get_state();
721 _editor.begin_reversible_command (_("add automation event"));
722 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
724 _line->get_selectables (when.frame, when.frame, 0.0, 1.0, results);
725 _editor.get_selection ().set (results);
727 _editor.commit_reversible_command ();
728 _session->set_dirty ();
733 AutomationTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
736 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
738 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
739 if (l == selection.lines.end()) {
740 if (ctx.greedy && selection.lines.size() == 1) {
741 l = selection.lines.begin();
744 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
745 ctx.counts.increase_n_lines(_parameter);
754 AutomationTimeAxisView::paste_one (framepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
756 boost::shared_ptr<AutomationList> alist(_line->the_list());
758 if (_session->transport_rolling() && alist->automation_write()) {
759 /* do not paste if this control is in write mode and we're rolling */
763 /* Get appropriate list from selection. */
764 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
765 if (p == selection.lines.end()) {
766 if (greedy && selection.lines.size() == 1) {
767 p = selection.lines.begin();
772 counts.increase_n_lines(_parameter);
774 /* add multi-paste offset if applicable */
776 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
777 double len = (*p)->length();
779 if (parameter_is_midi (src_type)) {
780 // convert length to samples (incl tempo-ramps)
781 len = DoubleBeatsFramesConverter (_session->tempo_map(), pos).to (len * paste_count);
782 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
784 pos += _editor.get_paste_offset (pos, paste_count, len);
787 /* convert sample-position to model's unit and position */
788 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
790 XMLNode &before = alist->get_state();
791 alist->paste (**p, model_pos, DoubleBeatsFramesConverter (_session->tempo_map(), pos));
792 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
798 AutomationTimeAxisView::get_selectables (framepos_t start, framepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
800 if (!_line && !_view) {
804 if (touched (top, bot)) {
806 /* remember: this is X Window - coordinate space starts in upper left and moves down.
807 _y_position is the "origin" or "top" of the track.
810 /* bottom of our track */
811 double const mybot = _y_position + height;
816 if (_y_position >= top && mybot <= bot) {
818 /* _y_position is below top, mybot is above bot, so we're fully
827 /* top and bot are within _y_position .. mybot */
829 topfrac = 1.0 - ((top - _y_position) / height);
830 botfrac = 1.0 - ((bot - _y_position) / height);
835 _line->get_selectables (start, end, botfrac, topfrac, results);
837 _view->get_selectables (start, end, botfrac, topfrac, results);
843 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
846 _line->get_inverted_selectables (sel, result);
851 AutomationTimeAxisView::set_selected_points (PointSelection& points)
854 _line->set_selected_points (points);
856 _view->set_selected_points (points);
861 AutomationTimeAxisView::clear_lines ()
864 _list_connections.drop_connections ();
868 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
870 if (_control && line) {
871 assert(line->the_list() == _control->list());
873 _control->alist()->automation_state_changed.connect (
874 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
877 _control->alist()->InterpolationChanged.connect (
878 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
884 line->set_height (height - 2.5);
886 /* pick up the current state */
887 automation_state_changed ();
889 line->add_visibility (AutomationLine::Line);
893 AutomationTimeAxisView::propagate_time_selection () const
895 /* MIDI automation is part of the MIDI region. It is always
896 * implicily selected with the parent, regardless of TAV selection
898 if (_parameter.type() >= MidiCCAutomation &&
899 _parameter.type() <= MidiChannelPressureAutomation) {
906 AutomationTimeAxisView::entered()
909 _line->track_entered();
914 AutomationTimeAxisView::exited ()
917 _line->track_exited();
922 AutomationTimeAxisView::color_handler ()
930 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
932 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
935 if (node.get_property (X_("shown"), shown)) {
937 _canvas_display->show (); /* FIXME: necessary? show_at? */
938 set_gui_property ("visible", shown);
941 set_gui_property ("visible", false);
949 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
955 AutomationTimeAxisView::what_has_visible_automation (const boost::shared_ptr<Automatable>& automatable, set<Evoral::Parameter>& visible)
957 /* this keeps "knowledge" of how we store visibility information
958 in XML private to this class.
961 assert (automatable);
963 Automatable::Controls& controls (automatable->controls());
965 for (Automatable::Controls::iterator i = controls.begin(); i != controls.end(); ++i) {
967 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (i->second);
969 if (ac && ac->alist()) {
971 const XMLNode* gui_node = ac->extra_xml ("GUI");
975 if (gui_node->get_property ("shown", shown) && shown) {
976 visible.insert (i->first);
984 /** @return true if this view has any automation data to display */
986 AutomationTimeAxisView::has_automation () const
988 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
991 list<boost::shared_ptr<AutomationLine> >
992 AutomationTimeAxisView::lines () const
994 list<boost::shared_ptr<AutomationLine> > lines;
997 lines.push_back (_line);
999 lines = _view->get_lines ();
1006 AutomationTimeAxisView::state_id() const
1008 if (_parameter && _stripable && _automatable == _stripable) {
1009 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
1010 PBD::to_string (_parameter.id()) + "/" +
1011 PBD::to_string (_parameter.channel ());
1013 return string("automation ") + PBD::to_string(_stripable->id()) + " " + parameter_str;
1014 } else if (_automatable != _stripable && _control) {
1015 return string("automation ") + _control->id().to_s();
1017 error << "Automation time axis has no state ID" << endmsg;
1022 /** Given a state id string, see if it is one generated by
1023 * this class. If so, parse it into its components.
1024 * @param state_id State ID string to parse.
1025 * @param route_id Filled in with the route's ID if the state ID string is parsed.
1026 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
1027 * @param parameter Filled in with the state ID's parameter, if it has one.
1028 * @return true if this is a state ID generated by this class, otherwise false.
1032 AutomationTimeAxisView::parse_state_id (
1033 string const & state_id,
1035 bool & has_parameter,
1036 Evoral::Parameter & parameter)
1044 if (a != X_("automation")) {
1048 route_id = PBD::ID (b);
1051 has_parameter = false;
1055 has_parameter = true;
1058 boost::split (p, c, boost::is_any_of ("/"));
1060 assert (p.size() == 3);
1062 parameter = Evoral::Parameter (
1063 PBD::string_to<uint32_t>(p[0]), // type
1064 PBD::string_to<uint8_t>(p[2]), // channel
1065 PBD::string_to<uint32_t>(p[1]) // id
1072 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1074 list<boost::shared_ptr<AutomationLine> > lines;
1076 lines.push_back (_line);
1078 lines = _view->get_lines ();
1081 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
1082 cut_copy_clear_one (**i, selection, op);
1087 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1089 boost::shared_ptr<Evoral::ControlList> what_we_got;
1090 boost::shared_ptr<AutomationList> alist (line.the_list());
1092 XMLNode &before = alist->get_state();
1094 /* convert time selection to automation list model coordinates */
1095 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& tc = line.time_converter ();
1096 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1097 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1101 if (alist->cut (start, end) != 0) {
1102 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1108 if ((what_we_got = alist->cut (start, end)) != 0) {
1109 _editor.get_cut_buffer().add (what_we_got);
1110 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1114 if ((what_we_got = alist->copy (start, end)) != 0) {
1115 _editor.get_cut_buffer().add (what_we_got);
1120 if ((what_we_got = alist->cut (start, end)) != 0) {
1121 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1127 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1128 double when = (*x)->when;
1129 double val = (*x)->value;
1130 line.model_to_view_coord (when, val);
1137 PresentationInfo const &
1138 AutomationTimeAxisView::presentation_info () const
1140 return _stripable->presentation_info();
1143 boost::shared_ptr<Stripable>
1144 AutomationTimeAxisView::stripable () const
1150 AutomationTimeAxisView::color () const
1152 return gdk_color_from_rgb (_stripable->presentation_info().color());