2 * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
5 * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
6 * Copyright (C) 2006 Hans Fugal <hans@fugal.net>
7 * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
8 * Copyright (C) 2007-2015 David Robillard <d@drobilla.net>
9 * Copyright (C) 2009 Hans Baier <hansfbaier@googlemail.com>
10 * Copyright (C) 2014-2015 Ben Loftis <ben@harrisonconsoles.com>
11 * Copyright (C) 2014-2017 Nick Mainsbridge <mainsbridge@gmail.com>
12 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
13 * Copyright (C) 2015-2017 Tim Mayberry <mojofunk@gmail.com>
14 * Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <boost/algorithm/string.hpp>
35 #include <gtkmm/separator.h>
37 #include "pbd/error.h"
38 #include "pbd/memento_command.h"
39 #include "pbd/stacktrace.h"
40 #include "pbd/string_convert.h"
41 #include "pbd/types_convert.h"
42 #include "pbd/unwind.h"
44 #include "ardour/automation_control.h"
45 #include "ardour/beats_samples_converter.h"
46 #include "ardour/event_type_map.h"
47 #include "ardour/parameter_types.h"
48 #include "ardour/profile.h"
49 #include "ardour/route.h"
50 #include "ardour/session.h"
52 #include "gtkmm2ext/utils.h"
54 #include "canvas/debug.h"
56 #include "widgets/tooltips.h"
58 #include "automation_time_axis.h"
59 #include "automation_streamview.h"
60 #include "gui_thread.h"
61 #include "route_time_axis.h"
62 #include "automation_line.h"
63 #include "paste_context.h"
64 #include "public_editor.h"
65 #include "selection.h"
66 #include "rgb_macros.h"
67 #include "point_selection.h"
68 #include "control_point.h"
70 #include "item_counts.h"
71 #include "ui_config.h"
76 using namespace ARDOUR;
77 using namespace ArdourWidgets;
78 using namespace ARDOUR_UI_UTILS;
81 using namespace Gtkmm2ext;
82 using namespace Editing;
84 Pango::FontDescription AutomationTimeAxisView::name_font;
85 bool AutomationTimeAxisView::have_name_font = false;
88 /** \a a the automatable object this time axis is to display data for.
89 * For route/track automation (e.g. gain) pass the route for both \r and \a.
90 * For route child (e.g. plugin) automation, pass the child for \a.
91 * For region automation (e.g. MIDI CC), pass null for \a.
93 AutomationTimeAxisView::AutomationTimeAxisView (
95 boost::shared_ptr<Stripable> strip,
96 boost::shared_ptr<Automatable> a,
97 boost::shared_ptr<AutomationControl> c,
100 TimeAxisView& parent,
102 ArdourCanvas::Canvas& canvas,
104 const string & nomparent
106 : SessionHandlePtr (s)
107 , TimeAxisView (s, e, &parent, canvas)
112 , _base_rect (new ArdourCanvas::Rectangle (_canvas_display))
113 , _view (show_regions ? new AutomationStreamView (*this) : 0)
115 , _show_regions (show_regions)
117 //concatenate plugin name and param name into the tooltip
118 string tipname = nomparent;
119 if (!tipname.empty()) {
123 set_tooltip(controls_ebox, tipname);
125 //plugin name and param name appear on 2 separate lines in the track header
127 if (!tipname.empty()) {
133 CANVAS_DEBUG_NAME (_canvas_display, string_compose ("main for auto %2/%1", _name, strip->name()));
134 CANVAS_DEBUG_NAME (selection_group, string_compose ("selections for auto %2/%1", _name, strip->name()));
135 CANVAS_DEBUG_NAME (_ghost_group, string_compose ("ghosts for auto %2/%1", _name, strip->name()));
137 if (!have_name_font) {
138 name_font = get_font_for_style (X_("AutomationTrackName"));
139 have_name_font = true;
143 _controller = AutomationController::create (_control->parameter(), _control->desc(), _control);
146 const std::string fill_color_name = (dynamic_cast<MidiTimeAxisView*>(&parent)
147 ? "midi automation track fill"
148 : "audio automation track fill");
155 mode_discrete_item = 0;
160 ignore_state_request = false;
161 ignore_mode_request = false;
162 first_call_to_set_height = true;
164 CANVAS_DEBUG_NAME (_base_rect, string_compose ("base rect for %1", _name));
165 _base_rect->set_x1 (ArdourCanvas::COORD_MAX);
166 _base_rect->set_outline (false);
167 _base_rect->set_fill_color (UIConfiguration::instance().color_mod (fill_color_name, "automation track fill"));
168 _base_rect->set_data ("trackview", this);
169 _base_rect->Event.connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_automation_track_event), _base_rect, this));
171 _base_rect->lower_to_bottom();
174 using namespace Menu_Helpers;
176 auto_dropdown.AddMenuElem (MenuElem (automation_state_off_string(), sigc::bind (sigc::mem_fun(*this,
177 &AutomationTimeAxisView::set_automation_state), (AutoState) ARDOUR::Off)));
178 auto_dropdown.AddMenuElem (MenuElem (_("Play"), sigc::bind (sigc::mem_fun(*this,
179 &AutomationTimeAxisView::set_automation_state), (AutoState) Play)));
181 if (!(_parameter.type() >= MidiCCAutomation &&
182 _parameter.type() <= MidiChannelPressureAutomation)) {
183 auto_dropdown.AddMenuElem (MenuElem (_("Write"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Write)));
184 auto_dropdown.AddMenuElem (MenuElem (_("Touch"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Touch)));
185 auto_dropdown.AddMenuElem (MenuElem (_("Latch"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Latch)));
188 /* XXX translators: use a string here that will be at least as long
189 as the longest automation label (see ::automation_state_changed()
190 below). be sure to include a descender.
192 auto_dropdown.set_sizing_text(_("Mgnual"));
194 hide_button.set_icon (ArdourIcon::CloseCross);
195 hide_button.set_tweaks(ArdourButton::TrackHeader);
197 auto_dropdown.set_name ("route button");
198 hide_button.set_name ("route button");
200 auto_dropdown.unset_flags (Gtk::CAN_FOCUS);
201 hide_button.unset_flags (Gtk::CAN_FOCUS);
203 controls_table.set_no_show_all();
205 set_tooltip(auto_dropdown, _("automation state"));
206 set_tooltip(hide_button, _("hide track"));
209 if (get_gui_property ("height", height)) {
212 set_height (preset_height (HeightNormal));
215 //name label isn't editable on an automation track; remove the tooltip
216 set_tooltip (name_label, X_(""));
218 /* repack the name label, which TimeAxisView has already attached to
222 if (name_label.get_parent()) {
223 name_label.get_parent()->remove (name_label);
226 name_label.set_text (_name);
227 name_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
228 name_label.set_name (X_("TrackParameterName"));
229 name_label.set_ellipsize (Pango::ELLIPSIZE_END);
231 /* add the buttons */
232 controls_table.set_border_width (1);
233 controls_table.attach (hide_button, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
234 controls_table.attach (name_label, 2, 3, 1, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 2, 0);
235 controls_table.attach (auto_dropdown, 3, 4, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
237 Gtk::DrawingArea *blank0 = manage (new Gtk::DrawingArea());
238 Gtk::DrawingArea *blank1 = manage (new Gtk::DrawingArea());
240 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&parent);
241 // TODO use rtv->controls_base_unselected_name
242 // subscribe to route_active_changed, ...
243 if (rtv && rtv->is_audio_track()) {
244 blank0->set_name ("AudioTrackControlsBaseUnselected");
245 } else if (rtv && rtv->is_midi_track()) {
246 blank0->set_name ("MidiTrackControlsBaseUnselected");
248 blank0->set_name ("AudioBusControlsBaseUnselected");
250 blank0->set_name ("UnknownControlsBaseUnselected");
252 blank0->set_size_request (-1, -1);
253 blank1->set_size_request (1, 0);
254 VSeparator* separator = manage (new VSeparator());
255 separator->set_name("TrackSeparator");
256 separator->set_size_request (1, -1);
258 controls_button_size_group->add_widget(hide_button);
259 controls_button_size_group->add_widget(*blank0);
261 time_axis_hbox.pack_start (*blank0, false, false);
262 time_axis_hbox.pack_start (*separator, false, false);
263 time_axis_hbox.reorder_child (*blank0, 0);
264 time_axis_hbox.reorder_child (*separator, 1);
265 time_axis_hbox.reorder_child (time_axis_vbox, 2);
267 if (!ARDOUR::Profile->get_mixbus() ) {
268 time_axis_hbox.pack_start (*blank1, false, false);
277 _controller->disable_vertical_scroll ();
278 controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
281 controls_table.show_all ();
283 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked));
285 controls_base_selected_name = X_("AutomationTrackControlsBaseSelected");
286 controls_base_unselected_name = X_("AutomationTrackControlsBase");
288 controls_ebox.set_name (controls_base_unselected_name);
289 time_axis_frame.set_name (controls_base_unselected_name);
291 /* ask for notifications of any new RegionViews */
299 /* no regions, just a single line for the entire track (e.g. bus gain) */
303 boost::shared_ptr<AutomationLine> line (
305 ARDOUR::EventTypeMap::instance().to_symbol(_parameter),
313 line->set_line_color (UIConfiguration::instance().color ("processor automation line"));
314 line->set_fill (true);
315 line->queue_reset ();
319 /* make sure labels etc. are correct */
321 automation_state_changed ();
322 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AutomationTimeAxisView::color_handler));
324 _stripable->DropReferences.connect (
325 _stripable_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::route_going_away, this), gui_context ()
329 AutomationTimeAxisView::~AutomationTimeAxisView ()
332 cleanup_gui_properties ();
335 CatchDeletion (this);
339 AutomationTimeAxisView::route_going_away ()
341 cleanup_gui_properties ();
346 AutomationTimeAxisView::set_automation_state (AutoState state)
348 if (ignore_state_request) {
353 _automatable->set_parameter_automation_state (_parameter, state);
356 _control->set_automation_state (state);
357 _session->set_dirty ();
361 _view->set_automation_state (state);
363 /* AutomationStreamViews don't signal when their automation state changes, so handle
364 our updates `manually'.
366 automation_state_changed ();
371 AutomationTimeAxisView::automation_state_changed ()
375 /* update button label */
378 state = _view->automation_state ();
381 state = _control->alist()->automation_state ();
386 switch (state & (ARDOUR::Off|Play|Touch|Write|Latch)) {
388 auto_dropdown.set_text (automation_state_off_string());
389 ignore_state_request = true;
391 auto_off_item->set_active (true);
392 auto_play_item->set_active (false);
394 if (auto_touch_item) {
395 auto_touch_item->set_active (false);
396 auto_latch_item->set_active (false);
397 auto_write_item->set_active (false);
399 ignore_state_request = false;
402 auto_dropdown.set_text (_("Play"));
403 ignore_state_request = true;
405 auto_play_item->set_active (true);
406 auto_off_item->set_active (false);
408 if (auto_touch_item) {
409 auto_touch_item->set_active (false);
410 auto_latch_item->set_active (false);
411 auto_write_item->set_active (false);
413 ignore_state_request = false;
416 auto_dropdown.set_text (_("Write"));
417 ignore_state_request = true;
419 auto_off_item->set_active (false);
420 auto_play_item->set_active (false);
422 if (auto_touch_item) {
423 auto_write_item->set_active (true);
424 auto_touch_item->set_active (false);
425 auto_latch_item->set_active (false);
427 ignore_state_request = false;
430 auto_dropdown.set_text (_("Touch"));
431 ignore_state_request = true;
433 auto_off_item->set_active (false);
434 auto_play_item->set_active (false);
436 if (auto_touch_item) {
437 auto_touch_item->set_active (true);
438 auto_write_item->set_active (false);
439 auto_latch_item->set_active (false);
441 ignore_state_request = false;
444 auto_dropdown.set_text (_("Latch"));
445 ignore_state_request = true;
447 auto_off_item->set_active (false);
448 auto_play_item->set_active (false);
450 if (auto_touch_item) {
451 auto_latch_item->set_active (true);
452 auto_touch_item->set_active (false);
453 auto_write_item->set_active (false);
455 ignore_state_request = false;
458 auto_dropdown.set_text (_("???"));
463 /** The interpolation style of our AutomationList has changed, so update */
465 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
467 if (ignore_mode_request) {
470 PBD::Unwinder<bool> uw (ignore_mode_request, true);
472 case AutomationList::Discrete:
473 if (mode_discrete_item) {
474 mode_discrete_item->set_active(true);
477 case AutomationList::Linear:
478 if (mode_line_item) {
479 mode_line_item->set_active(true);
482 case AutomationList::Logarithmic:
484 mode_log_item->set_active(true);
487 case AutomationList::Exponential:
489 mode_exp_item->set_active(true);
497 /** A menu item has been selected to change our interpolation mode */
499 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
501 /* Tell our view's list, if we have one, otherwise tell our own.
502 * Everything else will be signalled back from that.
506 _view->set_interpolation (style);
509 _control->list()->set_interpolation (style);
514 AutomationTimeAxisView::clear_clicked ()
516 assert (_line || _view);
518 _editor.begin_reversible_command (_("clear automation"));
525 if (!EventTypeMap::instance().type_is_midi (_control->parameter().type())) {
526 set_automation_state ((AutoState) ARDOUR::Off);
528 _editor.commit_reversible_command ();
529 _session->set_dirty ();
533 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
535 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
536 uint32_t const normal = preset_height (HeightNormal);
537 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
539 TimeAxisView::set_height (h, m);
541 _base_rect->set_y1 (h);
544 _line->set_height(h - 2.5);
548 _view->set_height(h);
549 _view->update_contents_height();
552 if (changed_between_small_and_normal || first_call_to_set_height) {
554 first_call_to_set_height = false;
556 if (h >= preset_height (HeightNormal)) {
557 auto_dropdown.show();
561 } else if (h >= preset_height (HeightSmall)) {
562 controls_table.hide_all ();
563 auto_dropdown.hide();
569 if (_canvas_display->visible() && _stripable) {
570 /* only emit the signal if the height really changed and we were visible */
571 _stripable->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
577 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
579 TimeAxisView::set_samples_per_pixel (fpp);
586 _view->set_samples_per_pixel (fpp);
591 AutomationTimeAxisView::hide_clicked ()
593 hide_button.set_sensitive(false);
594 set_marked_for_display (false);
595 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*>(parent);
597 stv->request_redraw ();
599 hide_button.set_sensitive(true);
603 AutomationTimeAxisView::automation_state_off_string () const
605 if (_parameter.type() >= MidiCCAutomation && _parameter.type() <= MidiChannelPressureAutomation) {
606 return S_("Automation|Off");
609 return S_("Automation|Manual");
613 AutomationTimeAxisView::build_display_menu ()
615 using namespace Menu_Helpers;
619 TimeAxisView::build_display_menu ();
621 /* now fill it with our stuff */
623 MenuList& items = display_menu->items();
625 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
626 items.push_back (SeparatorElem());
627 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
628 items.push_back (SeparatorElem());
632 Menu* auto_state_menu = manage (new Menu);
633 auto_state_menu->set_name ("ArdourContextMenu");
634 MenuList& as_items = auto_state_menu->items();
636 as_items.push_back (CheckMenuElem (automation_state_off_string(), sigc::bind (
637 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
638 (AutoState) ARDOUR::Off)));
639 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
641 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
642 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
644 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
646 if (!(_parameter.type() >= MidiCCAutomation &&
647 _parameter.type() <= MidiChannelPressureAutomation)) {
648 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
649 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
650 (AutoState) Write)));
651 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
653 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
654 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
655 (AutoState) Touch)));
656 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
658 as_items.push_back (CheckMenuElem (_("Latch"), sigc::bind (
659 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
660 (AutoState) Latch)));
661 auto_latch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
664 items.push_back (MenuElem (_("State"), *auto_state_menu));
668 /* current interpolation state */
669 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
671 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
673 Menu* auto_mode_menu = manage (new Menu);
674 auto_mode_menu->set_name ("ArdourContextMenu");
675 MenuList& am_items = auto_mode_menu->items();
677 RadioMenuItem::Group group;
679 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
680 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
681 AutomationList::Discrete)));
682 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
684 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
685 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
686 AutomationList::Linear)));
687 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
689 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
693 Menu* auto_mode_menu = manage (new Menu);
694 auto_mode_menu->set_name ("ArdourContextMenu");
695 MenuList& am_items = auto_mode_menu->items();
696 bool have_options = false;
698 RadioMenuItem::Group group;
700 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
701 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
702 AutomationList::Linear)));
703 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
705 if (_control->desc().logarithmic) {
706 am_items.push_back (RadioMenuElem (group, _("Logarithmic"), sigc::bind (
707 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
708 AutomationList::Logarithmic)));
709 mode_log_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
715 if (_line->get_uses_gain_mapping () && !_control->desc().logarithmic) {
716 am_items.push_back (RadioMenuElem (group, _("Exponential"), sigc::bind (
717 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
718 AutomationList::Exponential)));
719 mode_exp_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
726 items.push_back (MenuElem (_("Interpolation"), *auto_mode_menu));
729 delete auto_mode_menu;
734 /* make sure the automation menu state is correct */
736 automation_state_changed ();
737 interpolation_changed (s);
741 AutomationTimeAxisView::add_automation_event (GdkEvent* event, samplepos_t sample, double y, bool with_guard_points)
747 boost::shared_ptr<AutomationList> list = _line->the_list ();
749 if (list->in_write_pass()) {
750 /* do not allow the GUI to add automation events during an
751 automation write pass.
756 MusicSample when (sample, 0);
757 _editor.snap_to_with_modifier (when, event);
759 if (UIConfiguration::instance().get_new_automation_points_on_lane()) {
760 if (_control->list()->size () == 0) {
761 y = _control->get_value ();
763 y = _control->list()->eval (when.sample);
767 _line->grab_item().canvas_to_item (x, y);
768 /* compute vertical fractional position */
769 y = 1.0 - (y / _line->height());
771 _line->view_to_model_coord (x, y);
774 XMLNode& before = list->get_state();
775 std::list<Selectable*> results;
777 if (list->editor_add (when.sample, y, with_guard_points)) {
778 XMLNode& after = list->get_state();
779 _editor.begin_reversible_command (_("add automation event"));
780 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
782 _line->get_selectables (when.sample, when.sample, 0.0, 1.0, results);
783 _editor.get_selection ().set (results);
785 _editor.commit_reversible_command ();
786 _session->set_dirty ();
791 AutomationTimeAxisView::paste (samplepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
794 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
796 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
797 if (l == selection.lines.end()) {
798 if (ctx.greedy && selection.lines.size() == 1) {
799 l = selection.lines.begin();
802 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
803 ctx.counts.increase_n_lines(_parameter);
812 AutomationTimeAxisView::paste_one (samplepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
814 boost::shared_ptr<AutomationList> alist(_line->the_list());
816 if (_session->transport_rolling() && alist->automation_write()) {
817 /* do not paste if this control is in write mode and we're rolling */
821 /* Get appropriate list from selection. */
822 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
823 if (p == selection.lines.end()) {
824 if (greedy && selection.lines.size() == 1) {
825 p = selection.lines.begin();
830 counts.increase_n_lines(_parameter);
832 /* add multi-paste offset if applicable */
834 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
835 double len = (*p)->length();
837 if (parameter_is_midi (src_type)) {
838 // convert length to samples (incl tempo-ramps)
839 len = DoubleBeatsSamplesConverter (_session->tempo_map(), pos).to (len * paste_count);
840 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
842 pos += _editor.get_paste_offset (pos, paste_count, len);
845 /* convert sample-position to model's unit and position */
846 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
848 XMLNode &before = alist->get_state();
849 alist->paste (**p, model_pos, DoubleBeatsSamplesConverter (_session->tempo_map(), pos));
850 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
856 AutomationTimeAxisView::get_selectables (samplepos_t start, samplepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
858 if (!_line && !_view) {
862 if (touched (top, bot)) {
864 /* remember: this is X Window - coordinate space starts in upper left and moves down.
865 _y_position is the "origin" or "top" of the track.
868 /* bottom of our track */
869 double const mybot = _y_position + height;
874 if (_y_position >= top && mybot <= bot) {
876 /* _y_position is below top, mybot is above bot, so we're fully
885 /* top and bot are within _y_position .. mybot */
887 topfrac = 1.0 - ((top - _y_position) / height);
888 botfrac = 1.0 - ((bot - _y_position) / height);
893 _line->get_selectables (start, end, botfrac, topfrac, results);
895 _view->get_selectables (start, end, botfrac, topfrac, results);
901 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
904 _line->get_inverted_selectables (sel, result);
909 AutomationTimeAxisView::set_selected_points (PointSelection& points)
912 _line->set_selected_points (points);
914 _view->set_selected_points (points);
919 AutomationTimeAxisView::clear_lines ()
922 _list_connections.drop_connections ();
926 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
928 if (_control && line) {
929 assert(line->the_list() == _control->list());
931 _control->alist()->automation_state_changed.connect (
932 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
935 _control->alist()->InterpolationChanged.connect (
936 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
942 line->set_height (height - 2.5);
944 /* pick up the current state */
945 automation_state_changed ();
947 line->add_visibility (AutomationLine::Line);
951 AutomationTimeAxisView::propagate_time_selection () const
953 /* MIDI automation is part of the MIDI region. It is always
954 * implicily selected with the parent, regardless of TAV selection
956 if (_parameter.type() >= MidiCCAutomation &&
957 _parameter.type() <= MidiChannelPressureAutomation) {
964 AutomationTimeAxisView::entered()
967 _line->track_entered();
972 AutomationTimeAxisView::exited ()
975 _line->track_exited();
980 AutomationTimeAxisView::color_handler ()
988 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
990 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
993 if (node.get_property (X_("shown"), shown)) {
995 _canvas_display->show (); /* FIXME: necessary? show_at? */
996 set_gui_property ("visible", shown);
999 set_gui_property ("visible", false);
1007 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
1013 /** @return true if this view has any automation data to display */
1015 AutomationTimeAxisView::has_automation () const
1017 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
1020 list<boost::shared_ptr<AutomationLine> >
1021 AutomationTimeAxisView::lines () const
1023 list<boost::shared_ptr<AutomationLine> > lines;
1026 lines.push_back (_line);
1028 lines = _view->get_lines ();
1035 AutomationTimeAxisView::state_id() const
1037 if (_parameter && _stripable && _automatable == _stripable) {
1038 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
1039 PBD::to_string (_parameter.id()) + "/" +
1040 PBD::to_string (_parameter.channel ());
1042 return string("automation ") + PBD::to_string(_stripable->id()) + " " + parameter_str;
1043 } else if (_automatable != _stripable && _control) {
1044 return string("automation ") + _control->id().to_s();
1046 error << "Automation time axis has no state ID" << endmsg;
1051 /** Given a state id string, see if it is one generated by
1052 * this class. If so, parse it into its components.
1053 * @param state_id State ID string to parse.
1054 * @param route_id Filled in with the route's ID if the state ID string is parsed.
1055 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
1056 * @param parameter Filled in with the state ID's parameter, if it has one.
1057 * @return true if this is a state ID generated by this class, otherwise false.
1061 AutomationTimeAxisView::parse_state_id (
1062 string const & state_id,
1064 bool & has_parameter,
1065 Evoral::Parameter & parameter)
1073 if (a != X_("automation")) {
1077 route_id = PBD::ID (b);
1080 has_parameter = false;
1084 has_parameter = true;
1087 boost::split (p, c, boost::is_any_of ("/"));
1089 assert (p.size() == 3);
1091 parameter = Evoral::Parameter (
1092 PBD::string_to<uint32_t>(p[0]), // type
1093 PBD::string_to<uint8_t>(p[2]), // channel
1094 PBD::string_to<uint32_t>(p[1]) // id
1101 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1103 list<boost::shared_ptr<AutomationLine> > lines;
1105 lines.push_back (_line);
1107 lines = _view->get_lines ();
1110 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
1111 cut_copy_clear_one (**i, selection, op);
1116 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1118 boost::shared_ptr<Evoral::ControlList> what_we_got;
1119 boost::shared_ptr<AutomationList> alist (line.the_list());
1121 XMLNode &before = alist->get_state();
1123 /* convert time selection to automation list model coordinates */
1124 const Evoral::TimeConverter<double, ARDOUR::samplepos_t>& tc = line.time_converter ();
1125 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1126 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1130 if (alist->cut (start, end) != 0) {
1131 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1137 if ((what_we_got = alist->cut (start, end)) != 0) {
1138 _editor.get_cut_buffer().add (what_we_got);
1139 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1143 if ((what_we_got = alist->copy (start, end)) != 0) {
1144 _editor.get_cut_buffer().add (what_we_got);
1149 if ((what_we_got = alist->cut (start, end)) != 0) {
1150 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1156 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1157 double when = (*x)->when;
1158 double val = (*x)->value;
1159 line.model_to_view_coord (when, val);
1166 PresentationInfo const &
1167 AutomationTimeAxisView::presentation_info () const
1169 return _stripable->presentation_info();
1172 boost::shared_ptr<Stripable>
1173 AutomationTimeAxisView::stripable () const
1179 AutomationTimeAxisView::color () const
1181 return gdk_color_from_rgb (_stripable->presentation_info().color());