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 ();
338 AutomationTimeAxisView::route_going_away ()
340 cleanup_gui_properties ();
345 AutomationTimeAxisView::set_automation_state (AutoState state)
347 if (ignore_state_request) {
352 _automatable->set_parameter_automation_state (_parameter, state);
355 _control->set_automation_state (state);
356 _session->set_dirty ();
360 _view->set_automation_state (state);
362 /* AutomationStreamViews don't signal when their automation state changes, so handle
363 our updates `manually'.
365 automation_state_changed ();
370 AutomationTimeAxisView::automation_state_changed ()
374 /* update button label */
377 state = _view->automation_state ();
380 state = _control->alist()->automation_state ();
385 switch (state & (ARDOUR::Off|Play|Touch|Write|Latch)) {
387 auto_dropdown.set_text (automation_state_off_string());
388 ignore_state_request = true;
390 auto_off_item->set_active (true);
391 auto_play_item->set_active (false);
393 if (auto_touch_item) {
394 auto_touch_item->set_active (false);
395 auto_latch_item->set_active (false);
396 auto_write_item->set_active (false);
398 ignore_state_request = false;
401 auto_dropdown.set_text (_("Play"));
402 ignore_state_request = true;
404 auto_play_item->set_active (true);
405 auto_off_item->set_active (false);
407 if (auto_touch_item) {
408 auto_touch_item->set_active (false);
409 auto_latch_item->set_active (false);
410 auto_write_item->set_active (false);
412 ignore_state_request = false;
415 auto_dropdown.set_text (_("Write"));
416 ignore_state_request = true;
418 auto_off_item->set_active (false);
419 auto_play_item->set_active (false);
421 if (auto_touch_item) {
422 auto_write_item->set_active (true);
423 auto_touch_item->set_active (false);
424 auto_latch_item->set_active (false);
426 ignore_state_request = false;
429 auto_dropdown.set_text (_("Touch"));
430 ignore_state_request = true;
432 auto_off_item->set_active (false);
433 auto_play_item->set_active (false);
435 if (auto_touch_item) {
436 auto_touch_item->set_active (true);
437 auto_write_item->set_active (false);
438 auto_latch_item->set_active (false);
440 ignore_state_request = false;
443 auto_dropdown.set_text (_("Latch"));
444 ignore_state_request = true;
446 auto_off_item->set_active (false);
447 auto_play_item->set_active (false);
449 if (auto_touch_item) {
450 auto_latch_item->set_active (true);
451 auto_touch_item->set_active (false);
452 auto_write_item->set_active (false);
454 ignore_state_request = false;
457 auto_dropdown.set_text (_("???"));
462 /** The interpolation style of our AutomationList has changed, so update */
464 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
466 if (ignore_mode_request) {
469 PBD::Unwinder<bool> uw (ignore_mode_request, true);
471 case AutomationList::Discrete:
472 if (mode_discrete_item) {
473 mode_discrete_item->set_active(true);
476 case AutomationList::Linear:
477 if (mode_line_item) {
478 mode_line_item->set_active(true);
481 case AutomationList::Logarithmic:
483 mode_log_item->set_active(true);
486 case AutomationList::Exponential:
488 mode_exp_item->set_active(true);
496 /** A menu item has been selected to change our interpolation mode */
498 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
500 /* Tell our view's list, if we have one, otherwise tell our own.
501 * Everything else will be signalled back from that.
505 _view->set_interpolation (style);
508 _control->list()->set_interpolation (style);
513 AutomationTimeAxisView::clear_clicked ()
515 assert (_line || _view);
517 _editor.begin_reversible_command (_("clear automation"));
524 if (!EventTypeMap::instance().type_is_midi (_control->parameter().type())) {
525 set_automation_state ((AutoState) ARDOUR::Off);
527 _editor.commit_reversible_command ();
528 _session->set_dirty ();
532 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
534 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
535 uint32_t const normal = preset_height (HeightNormal);
536 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
538 TimeAxisView::set_height (h, m);
540 _base_rect->set_y1 (h);
543 _line->set_height(h - 2.5);
547 _view->set_height(h);
548 _view->update_contents_height();
551 if (changed_between_small_and_normal || first_call_to_set_height) {
553 first_call_to_set_height = false;
555 if (h >= preset_height (HeightNormal)) {
556 auto_dropdown.show();
560 } else if (h >= preset_height (HeightSmall)) {
561 controls_table.hide_all ();
562 auto_dropdown.hide();
568 if (_canvas_display->visible() && _stripable) {
569 /* only emit the signal if the height really changed and we were visible */
570 _stripable->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
576 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
578 TimeAxisView::set_samples_per_pixel (fpp);
585 _view->set_samples_per_pixel (fpp);
590 AutomationTimeAxisView::hide_clicked ()
592 hide_button.set_sensitive(false);
593 set_marked_for_display (false);
594 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*>(parent);
596 stv->request_redraw ();
598 hide_button.set_sensitive(true);
602 AutomationTimeAxisView::automation_state_off_string () const
604 if (_parameter.type() >= MidiCCAutomation && _parameter.type() <= MidiChannelPressureAutomation) {
605 return S_("Automation|Off");
608 return S_("Automation|Manual");
612 AutomationTimeAxisView::build_display_menu ()
614 using namespace Menu_Helpers;
618 TimeAxisView::build_display_menu ();
620 /* now fill it with our stuff */
622 MenuList& items = display_menu->items();
624 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
625 items.push_back (SeparatorElem());
626 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
627 items.push_back (SeparatorElem());
631 Menu* auto_state_menu = manage (new Menu);
632 auto_state_menu->set_name ("ArdourContextMenu");
633 MenuList& as_items = auto_state_menu->items();
635 as_items.push_back (CheckMenuElem (automation_state_off_string(), sigc::bind (
636 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
637 (AutoState) ARDOUR::Off)));
638 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
640 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
641 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
643 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
645 if (!(_parameter.type() >= MidiCCAutomation &&
646 _parameter.type() <= MidiChannelPressureAutomation)) {
647 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
648 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
649 (AutoState) Write)));
650 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
652 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
653 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
654 (AutoState) Touch)));
655 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
657 as_items.push_back (CheckMenuElem (_("Latch"), sigc::bind (
658 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
659 (AutoState) Latch)));
660 auto_latch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
663 items.push_back (MenuElem (_("State"), *auto_state_menu));
667 /* current interpolation state */
668 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
670 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
672 Menu* auto_mode_menu = manage (new Menu);
673 auto_mode_menu->set_name ("ArdourContextMenu");
674 MenuList& am_items = auto_mode_menu->items();
676 RadioMenuItem::Group group;
678 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
679 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
680 AutomationList::Discrete)));
681 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
683 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
684 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
685 AutomationList::Linear)));
686 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
688 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
692 Menu* auto_mode_menu = manage (new Menu);
693 auto_mode_menu->set_name ("ArdourContextMenu");
694 MenuList& am_items = auto_mode_menu->items();
695 bool have_options = false;
697 RadioMenuItem::Group group;
699 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
700 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
701 AutomationList::Linear)));
702 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
704 if (_control->desc().logarithmic) {
705 am_items.push_back (RadioMenuElem (group, _("Logarithmic"), sigc::bind (
706 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
707 AutomationList::Logarithmic)));
708 mode_log_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
714 if (_line->get_uses_gain_mapping () && !_control->desc().logarithmic) {
715 am_items.push_back (RadioMenuElem (group, _("Exponential"), sigc::bind (
716 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
717 AutomationList::Exponential)));
718 mode_exp_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
725 items.push_back (MenuElem (_("Interpolation"), *auto_mode_menu));
728 delete auto_mode_menu;
733 /* make sure the automation menu state is correct */
735 automation_state_changed ();
736 interpolation_changed (s);
740 AutomationTimeAxisView::add_automation_event (GdkEvent* event, samplepos_t sample, double y, bool with_guard_points)
746 boost::shared_ptr<AutomationList> list = _line->the_list ();
748 if (list->in_write_pass()) {
749 /* do not allow the GUI to add automation events during an
750 automation write pass.
755 MusicSample when (sample, 0);
756 _editor.snap_to_with_modifier (when, event);
758 if (UIConfiguration::instance().get_new_automation_points_on_lane()) {
759 if (_control->list()->size () == 0) {
760 y = _control->get_value ();
762 y = _control->list()->eval (when.sample);
766 _line->grab_item().canvas_to_item (x, y);
767 /* compute vertical fractional position */
768 y = 1.0 - (y / _line->height());
770 _line->view_to_model_coord (x, y);
773 XMLNode& before = list->get_state();
774 std::list<Selectable*> results;
776 if (list->editor_add (when.sample, y, with_guard_points)) {
777 XMLNode& after = list->get_state();
778 _editor.begin_reversible_command (_("add automation event"));
779 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
781 _line->get_selectables (when.sample, when.sample, 0.0, 1.0, results);
782 _editor.get_selection ().set (results);
784 _editor.commit_reversible_command ();
785 _session->set_dirty ();
790 AutomationTimeAxisView::paste (samplepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
793 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
795 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
796 if (l == selection.lines.end()) {
797 if (ctx.greedy && selection.lines.size() == 1) {
798 l = selection.lines.begin();
801 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
802 ctx.counts.increase_n_lines(_parameter);
811 AutomationTimeAxisView::paste_one (samplepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
813 boost::shared_ptr<AutomationList> alist(_line->the_list());
815 if (_session->transport_rolling() && alist->automation_write()) {
816 /* do not paste if this control is in write mode and we're rolling */
820 /* Get appropriate list from selection. */
821 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
822 if (p == selection.lines.end()) {
823 if (greedy && selection.lines.size() == 1) {
824 p = selection.lines.begin();
829 counts.increase_n_lines(_parameter);
831 /* add multi-paste offset if applicable */
833 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
834 double len = (*p)->length();
836 if (parameter_is_midi (src_type)) {
837 // convert length to samples (incl tempo-ramps)
838 len = DoubleBeatsSamplesConverter (_session->tempo_map(), pos).to (len * paste_count);
839 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
841 pos += _editor.get_paste_offset (pos, paste_count, len);
844 /* convert sample-position to model's unit and position */
845 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
847 XMLNode &before = alist->get_state();
848 alist->paste (**p, model_pos, DoubleBeatsSamplesConverter (_session->tempo_map(), pos));
849 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
855 AutomationTimeAxisView::get_selectables (samplepos_t start, samplepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
857 if (!_line && !_view) {
861 if (touched (top, bot)) {
863 /* remember: this is X Window - coordinate space starts in upper left and moves down.
864 _y_position is the "origin" or "top" of the track.
867 /* bottom of our track */
868 double const mybot = _y_position + height;
873 if (_y_position >= top && mybot <= bot) {
875 /* _y_position is below top, mybot is above bot, so we're fully
884 /* top and bot are within _y_position .. mybot */
886 topfrac = 1.0 - ((top - _y_position) / height);
887 botfrac = 1.0 - ((bot - _y_position) / height);
892 _line->get_selectables (start, end, botfrac, topfrac, results);
894 _view->get_selectables (start, end, botfrac, topfrac, results);
900 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
903 _line->get_inverted_selectables (sel, result);
908 AutomationTimeAxisView::set_selected_points (PointSelection& points)
911 _line->set_selected_points (points);
913 _view->set_selected_points (points);
918 AutomationTimeAxisView::clear_lines ()
921 _list_connections.drop_connections ();
925 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
927 if (_control && line) {
928 assert(line->the_list() == _control->list());
930 _control->alist()->automation_state_changed.connect (
931 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
934 _control->alist()->InterpolationChanged.connect (
935 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
941 line->set_height (height - 2.5);
943 /* pick up the current state */
944 automation_state_changed ();
946 line->add_visibility (AutomationLine::Line);
950 AutomationTimeAxisView::propagate_time_selection () const
952 /* MIDI automation is part of the MIDI region. It is always
953 * implicily selected with the parent, regardless of TAV selection
955 if (_parameter.type() >= MidiCCAutomation &&
956 _parameter.type() <= MidiChannelPressureAutomation) {
963 AutomationTimeAxisView::entered()
966 _line->track_entered();
971 AutomationTimeAxisView::exited ()
974 _line->track_exited();
979 AutomationTimeAxisView::color_handler ()
987 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
989 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
992 if (node.get_property (X_("shown"), shown)) {
994 _canvas_display->show (); /* FIXME: necessary? show_at? */
995 set_gui_property ("visible", shown);
998 set_gui_property ("visible", false);
1006 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
1012 AutomationTimeAxisView::what_has_visible_automation (const boost::shared_ptr<Automatable>& automatable, set<Evoral::Parameter>& visible)
1014 /* this keeps "knowledge" of how we store visibility information
1015 in XML private to this class.
1018 assert (automatable);
1020 Automatable::Controls& controls (automatable->controls());
1022 for (Automatable::Controls::iterator i = controls.begin(); i != controls.end(); ++i) {
1024 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (i->second);
1026 if (ac && ac->alist()) {
1028 const XMLNode* gui_node = ac->extra_xml ("GUI");
1032 if (gui_node->get_property ("shown", shown) && shown) {
1033 visible.insert (i->first);
1041 /** @return true if this view has any automation data to display */
1043 AutomationTimeAxisView::has_automation () const
1045 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
1048 list<boost::shared_ptr<AutomationLine> >
1049 AutomationTimeAxisView::lines () const
1051 list<boost::shared_ptr<AutomationLine> > lines;
1054 lines.push_back (_line);
1056 lines = _view->get_lines ();
1063 AutomationTimeAxisView::state_id() const
1065 if (_parameter && _stripable && _automatable == _stripable) {
1066 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
1067 PBD::to_string (_parameter.id()) + "/" +
1068 PBD::to_string (_parameter.channel ());
1070 return string("automation ") + PBD::to_string(_stripable->id()) + " " + parameter_str;
1071 } else if (_automatable != _stripable && _control) {
1072 return string("automation ") + _control->id().to_s();
1074 error << "Automation time axis has no state ID" << endmsg;
1079 /** Given a state id string, see if it is one generated by
1080 * this class. If so, parse it into its components.
1081 * @param state_id State ID string to parse.
1082 * @param route_id Filled in with the route's ID if the state ID string is parsed.
1083 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
1084 * @param parameter Filled in with the state ID's parameter, if it has one.
1085 * @return true if this is a state ID generated by this class, otherwise false.
1089 AutomationTimeAxisView::parse_state_id (
1090 string const & state_id,
1092 bool & has_parameter,
1093 Evoral::Parameter & parameter)
1101 if (a != X_("automation")) {
1105 route_id = PBD::ID (b);
1108 has_parameter = false;
1112 has_parameter = true;
1115 boost::split (p, c, boost::is_any_of ("/"));
1117 assert (p.size() == 3);
1119 parameter = Evoral::Parameter (
1120 PBD::string_to<uint32_t>(p[0]), // type
1121 PBD::string_to<uint8_t>(p[2]), // channel
1122 PBD::string_to<uint32_t>(p[1]) // id
1129 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1131 list<boost::shared_ptr<AutomationLine> > lines;
1133 lines.push_back (_line);
1135 lines = _view->get_lines ();
1138 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
1139 cut_copy_clear_one (**i, selection, op);
1144 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1146 boost::shared_ptr<Evoral::ControlList> what_we_got;
1147 boost::shared_ptr<AutomationList> alist (line.the_list());
1149 XMLNode &before = alist->get_state();
1151 /* convert time selection to automation list model coordinates */
1152 const Evoral::TimeConverter<double, ARDOUR::samplepos_t>& tc = line.time_converter ();
1153 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1154 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1158 if (alist->cut (start, end) != 0) {
1159 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1165 if ((what_we_got = alist->cut (start, end)) != 0) {
1166 _editor.get_cut_buffer().add (what_we_got);
1167 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1171 if ((what_we_got = alist->copy (start, end)) != 0) {
1172 _editor.get_cut_buffer().add (what_we_got);
1177 if ((what_we_got = alist->cut (start, end)) != 0) {
1178 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1184 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1185 double when = (*x)->when;
1186 double val = (*x)->value;
1187 line.model_to_view_coord (when, val);
1194 PresentationInfo const &
1195 AutomationTimeAxisView::presentation_info () const
1197 return _stripable->presentation_info();
1200 boost::shared_ptr<Stripable>
1201 AutomationTimeAxisView::stripable () const
1207 AutomationTimeAxisView::color () const
1209 return gdk_color_from_rgb (_stripable->presentation_info().color());