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_samples_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");
144 mode_discrete_item = 0;
149 ignore_state_request = false;
150 ignore_mode_request = false;
151 first_call_to_set_height = true;
153 CANVAS_DEBUG_NAME (_base_rect, string_compose ("base rect for %1", _name));
154 _base_rect->set_x1 (ArdourCanvas::COORD_MAX);
155 _base_rect->set_outline (false);
156 _base_rect->set_fill_color (UIConfiguration::instance().color_mod (fill_color_name, "automation track fill"));
157 _base_rect->set_data ("trackview", this);
158 _base_rect->Event.connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_automation_track_event), _base_rect, this));
160 _base_rect->lower_to_bottom();
163 using namespace Menu_Helpers;
165 auto_dropdown.AddMenuElem (MenuElem (automation_state_off_string(), sigc::bind (sigc::mem_fun(*this,
166 &AutomationTimeAxisView::set_automation_state), (AutoState) ARDOUR::Off)));
167 auto_dropdown.AddMenuElem (MenuElem (_("Play"), sigc::bind (sigc::mem_fun(*this,
168 &AutomationTimeAxisView::set_automation_state), (AutoState) Play)));
170 if (!(_parameter.type() >= MidiCCAutomation &&
171 _parameter.type() <= MidiChannelPressureAutomation)) {
172 auto_dropdown.AddMenuElem (MenuElem (_("Write"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Write)));
173 auto_dropdown.AddMenuElem (MenuElem (_("Touch"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Touch)));
174 auto_dropdown.AddMenuElem (MenuElem (_("Latch"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Latch)));
177 /* XXX translators: use a string here that will be at least as long
178 as the longest automation label (see ::automation_state_changed()
179 below). be sure to include a descender.
181 auto_dropdown.set_sizing_text(_("Mgnual"));
183 hide_button.set_icon (ArdourIcon::CloseCross);
184 hide_button.set_tweaks(ArdourButton::TrackHeader);
186 auto_dropdown.set_name ("route button");
187 hide_button.set_name ("route button");
189 auto_dropdown.unset_flags (Gtk::CAN_FOCUS);
190 hide_button.unset_flags (Gtk::CAN_FOCUS);
192 controls_table.set_no_show_all();
194 set_tooltip(auto_dropdown, _("automation state"));
195 set_tooltip(hide_button, _("hide track"));
198 if (get_gui_property ("height", height)) {
201 set_height (preset_height (HeightNormal));
204 //name label isn't editable on an automation track; remove the tooltip
205 set_tooltip (name_label, X_(""));
207 /* repack the name label, which TimeAxisView has already attached to
211 if (name_label.get_parent()) {
212 name_label.get_parent()->remove (name_label);
215 name_label.set_text (_name);
216 name_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
217 name_label.set_name (X_("TrackParameterName"));
218 name_label.set_ellipsize (Pango::ELLIPSIZE_END);
220 /* add the buttons */
221 controls_table.set_border_width (1);
222 controls_table.attach (hide_button, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
223 controls_table.attach (name_label, 2, 3, 1, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 2, 0);
224 controls_table.attach (auto_dropdown, 3, 4, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
226 Gtk::DrawingArea *blank0 = manage (new Gtk::DrawingArea());
227 Gtk::DrawingArea *blank1 = manage (new Gtk::DrawingArea());
229 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&parent);
230 // TODO use rtv->controls_base_unselected_name
231 // subscribe to route_active_changed, ...
232 if (rtv && rtv->is_audio_track()) {
233 blank0->set_name ("AudioTrackControlsBaseUnselected");
234 } else if (rtv && rtv->is_midi_track()) {
235 blank0->set_name ("MidiTrackControlsBaseUnselected");
237 blank0->set_name ("AudioBusControlsBaseUnselected");
239 blank0->set_name ("UnknownControlsBaseUnselected");
241 blank0->set_size_request (-1, -1);
242 blank1->set_size_request (1, 0);
243 VSeparator* separator = manage (new VSeparator());
244 separator->set_name("TrackSeparator");
245 separator->set_size_request (1, -1);
247 controls_button_size_group->add_widget(hide_button);
248 controls_button_size_group->add_widget(*blank0);
250 time_axis_hbox.pack_start (*blank0, false, false);
251 time_axis_hbox.pack_start (*separator, false, false);
252 time_axis_hbox.reorder_child (*blank0, 0);
253 time_axis_hbox.reorder_child (*separator, 1);
254 time_axis_hbox.reorder_child (time_axis_vbox, 2);
256 if (!ARDOUR::Profile->get_mixbus() ) {
257 time_axis_hbox.pack_start (*blank1, false, false);
266 _controller->disable_vertical_scroll ();
267 controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
270 controls_table.show_all ();
272 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked));
274 controls_base_selected_name = X_("AutomationTrackControlsBaseSelected");
275 controls_base_unselected_name = X_("AutomationTrackControlsBase");
277 controls_ebox.set_name (controls_base_unselected_name);
278 time_axis_frame.set_name (controls_base_unselected_name);
280 /* ask for notifications of any new RegionViews */
288 /* no regions, just a single line for the entire track (e.g. bus gain) */
292 boost::shared_ptr<AutomationLine> line (
294 ARDOUR::EventTypeMap::instance().to_symbol(_parameter),
302 line->set_line_color (UIConfiguration::instance().color ("processor automation line"));
303 line->set_fill (true);
304 line->queue_reset ();
308 /* make sure labels etc. are correct */
310 automation_state_changed ();
311 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AutomationTimeAxisView::color_handler));
313 _stripable->DropReferences.connect (
314 _stripable_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::route_going_away, this), gui_context ()
318 AutomationTimeAxisView::~AutomationTimeAxisView ()
321 cleanup_gui_properties ();
327 AutomationTimeAxisView::route_going_away ()
329 cleanup_gui_properties ();
334 AutomationTimeAxisView::set_automation_state (AutoState state)
336 if (ignore_state_request) {
341 _automatable->set_parameter_automation_state (_parameter, state);
344 _control->set_automation_state (state);
345 _session->set_dirty ();
349 _view->set_automation_state (state);
351 /* AutomationStreamViews don't signal when their automation state changes, so handle
352 our updates `manually'.
354 automation_state_changed ();
359 AutomationTimeAxisView::automation_state_changed ()
363 /* update button label */
366 state = _view->automation_state ();
369 state = _control->alist()->automation_state ();
374 switch (state & (ARDOUR::Off|Play|Touch|Write|Latch)) {
376 auto_dropdown.set_text (automation_state_off_string());
377 ignore_state_request = true;
379 auto_off_item->set_active (true);
380 auto_play_item->set_active (false);
382 if (auto_touch_item) {
383 auto_touch_item->set_active (false);
384 auto_latch_item->set_active (false);
385 auto_write_item->set_active (false);
387 ignore_state_request = false;
390 auto_dropdown.set_text (_("Play"));
391 ignore_state_request = true;
393 auto_play_item->set_active (true);
394 auto_off_item->set_active (false);
396 if (auto_touch_item) {
397 auto_touch_item->set_active (false);
398 auto_latch_item->set_active (false);
399 auto_write_item->set_active (false);
401 ignore_state_request = false;
404 auto_dropdown.set_text (_("Write"));
405 ignore_state_request = true;
407 auto_off_item->set_active (false);
408 auto_play_item->set_active (false);
410 if (auto_touch_item) {
411 auto_write_item->set_active (true);
412 auto_touch_item->set_active (false);
413 auto_latch_item->set_active (false);
415 ignore_state_request = false;
418 auto_dropdown.set_text (_("Touch"));
419 ignore_state_request = true;
421 auto_off_item->set_active (false);
422 auto_play_item->set_active (false);
424 if (auto_touch_item) {
425 auto_touch_item->set_active (true);
426 auto_write_item->set_active (false);
427 auto_latch_item->set_active (false);
429 ignore_state_request = false;
432 auto_dropdown.set_text (_("Latch"));
433 ignore_state_request = true;
435 auto_off_item->set_active (false);
436 auto_play_item->set_active (false);
438 if (auto_touch_item) {
439 auto_latch_item->set_active (true);
440 auto_touch_item->set_active (false);
441 auto_write_item->set_active (false);
443 ignore_state_request = false;
446 auto_dropdown.set_text (_("???"));
451 /** The interpolation style of our AutomationList has changed, so update */
453 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
455 if (ignore_mode_request) {
458 PBD::Unwinder<bool> uw (ignore_mode_request, true);
460 case AutomationList::Discrete:
461 if (mode_discrete_item) {
462 mode_discrete_item->set_active(true);
465 case AutomationList::Linear:
466 if (mode_line_item) {
467 mode_line_item->set_active(true);
470 case AutomationList::Logarithmic:
472 mode_log_item->set_active(true);
475 case AutomationList::Exponential:
477 mode_exp_item->set_active(true);
485 /** A menu item has been selected to change our interpolation mode */
487 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
489 /* Tell our view's list, if we have one, otherwise tell our own.
490 * Everything else will be signalled back from that.
494 _view->set_interpolation (style);
497 _control->list()->set_interpolation (style);
502 AutomationTimeAxisView::clear_clicked ()
504 assert (_line || _view);
506 _editor.begin_reversible_command (_("clear automation"));
513 if (!EventTypeMap::instance().type_is_midi (_control->parameter().type())) {
514 set_automation_state ((AutoState) ARDOUR::Off);
516 _editor.commit_reversible_command ();
517 _session->set_dirty ();
521 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
523 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
524 uint32_t const normal = preset_height (HeightNormal);
525 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
527 TimeAxisView::set_height (h, m);
529 _base_rect->set_y1 (h);
532 _line->set_height(h - 2.5);
536 _view->set_height(h);
537 _view->update_contents_height();
540 if (changed_between_small_and_normal || first_call_to_set_height) {
542 first_call_to_set_height = false;
544 if (h >= preset_height (HeightNormal)) {
545 auto_dropdown.show();
549 } else if (h >= preset_height (HeightSmall)) {
550 controls_table.hide_all ();
551 auto_dropdown.hide();
557 if (_canvas_display->visible() && _stripable) {
558 /* only emit the signal if the height really changed and we were visible */
559 _stripable->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
565 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
567 TimeAxisView::set_samples_per_pixel (fpp);
574 _view->set_samples_per_pixel (fpp);
579 AutomationTimeAxisView::hide_clicked ()
581 hide_button.set_sensitive(false);
582 set_marked_for_display (false);
583 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*>(parent);
585 stv->request_redraw ();
587 hide_button.set_sensitive(true);
591 AutomationTimeAxisView::automation_state_off_string () const
593 if (_parameter.type() >= MidiCCAutomation && _parameter.type() <= MidiChannelPressureAutomation) {
594 return S_("Automation|Off");
597 return S_("Automation|Manual");
601 AutomationTimeAxisView::build_display_menu ()
603 using namespace Menu_Helpers;
607 TimeAxisView::build_display_menu ();
609 /* now fill it with our stuff */
611 MenuList& items = display_menu->items();
613 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
614 items.push_back (SeparatorElem());
615 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
616 items.push_back (SeparatorElem());
620 Menu* auto_state_menu = manage (new Menu);
621 auto_state_menu->set_name ("ArdourContextMenu");
622 MenuList& as_items = auto_state_menu->items();
624 as_items.push_back (CheckMenuElem (automation_state_off_string(), sigc::bind (
625 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
626 (AutoState) ARDOUR::Off)));
627 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
629 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
630 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
632 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
634 if (!(_parameter.type() >= MidiCCAutomation &&
635 _parameter.type() <= MidiChannelPressureAutomation)) {
636 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
637 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
638 (AutoState) Write)));
639 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
641 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
642 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
643 (AutoState) Touch)));
644 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
646 as_items.push_back (CheckMenuElem (_("Latch"), sigc::bind (
647 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
648 (AutoState) Latch)));
649 auto_latch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
652 items.push_back (MenuElem (_("State"), *auto_state_menu));
656 /* current interpolation state */
657 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
659 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
661 Menu* auto_mode_menu = manage (new Menu);
662 auto_mode_menu->set_name ("ArdourContextMenu");
663 MenuList& am_items = auto_mode_menu->items();
665 RadioMenuItem::Group group;
667 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
668 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
669 AutomationList::Discrete)));
670 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
672 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
673 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
674 AutomationList::Linear)));
675 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
677 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
681 Menu* auto_mode_menu = manage (new Menu);
682 auto_mode_menu->set_name ("ArdourContextMenu");
683 MenuList& am_items = auto_mode_menu->items();
684 bool have_options = false;
686 RadioMenuItem::Group group;
688 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
689 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
690 AutomationList::Linear)));
691 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
693 if (_control->desc().logarithmic) {
694 am_items.push_back (RadioMenuElem (group, _("Logarithmic"), sigc::bind (
695 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
696 AutomationList::Logarithmic)));
697 mode_log_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
703 if (_line->get_uses_gain_mapping () && !_control->desc().logarithmic) {
704 am_items.push_back (RadioMenuElem (group, _("Exponential"), sigc::bind (
705 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
706 AutomationList::Exponential)));
707 mode_exp_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
714 items.push_back (MenuElem (_("Interpolation"), *auto_mode_menu));
717 delete auto_mode_menu;
722 /* make sure the automation menu state is correct */
724 automation_state_changed ();
725 interpolation_changed (s);
729 AutomationTimeAxisView::add_automation_event (GdkEvent* event, samplepos_t sample, double y, bool with_guard_points)
735 boost::shared_ptr<AutomationList> list = _line->the_list ();
737 if (list->in_write_pass()) {
738 /* do not allow the GUI to add automation events during an
739 automation write pass.
744 MusicSample when (sample, 0);
745 _editor.snap_to_with_modifier (when, event);
747 if (UIConfiguration::instance().get_new_automation_points_on_lane()) {
748 if (_control->list()->size () == 0) {
749 y = _control->get_value ();
751 y = _control->list()->eval (when.sample);
755 _line->grab_item().canvas_to_item (x, y);
756 /* compute vertical fractional position */
757 y = 1.0 - (y / _line->height());
759 _line->view_to_model_coord (x, y);
762 XMLNode& before = list->get_state();
763 std::list<Selectable*> results;
765 if (list->editor_add (when.sample, y, with_guard_points)) {
766 XMLNode& after = list->get_state();
767 _editor.begin_reversible_command (_("add automation event"));
768 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
770 _line->get_selectables (when.sample, when.sample, 0.0, 1.0, results);
771 _editor.get_selection ().set (results);
773 _editor.commit_reversible_command ();
774 _session->set_dirty ();
779 AutomationTimeAxisView::paste (samplepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
782 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
784 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
785 if (l == selection.lines.end()) {
786 if (ctx.greedy && selection.lines.size() == 1) {
787 l = selection.lines.begin();
790 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
791 ctx.counts.increase_n_lines(_parameter);
800 AutomationTimeAxisView::paste_one (samplepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
802 boost::shared_ptr<AutomationList> alist(_line->the_list());
804 if (_session->transport_rolling() && alist->automation_write()) {
805 /* do not paste if this control is in write mode and we're rolling */
809 /* Get appropriate list from selection. */
810 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
811 if (p == selection.lines.end()) {
812 if (greedy && selection.lines.size() == 1) {
813 p = selection.lines.begin();
818 counts.increase_n_lines(_parameter);
820 /* add multi-paste offset if applicable */
822 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
823 double len = (*p)->length();
825 if (parameter_is_midi (src_type)) {
826 // convert length to samples (incl tempo-ramps)
827 len = DoubleBeatsSamplesConverter (_session->tempo_map(), pos).to (len * paste_count);
828 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
830 pos += _editor.get_paste_offset (pos, paste_count, len);
833 /* convert sample-position to model's unit and position */
834 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
836 XMLNode &before = alist->get_state();
837 alist->paste (**p, model_pos, DoubleBeatsSamplesConverter (_session->tempo_map(), pos));
838 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
844 AutomationTimeAxisView::get_selectables (samplepos_t start, samplepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
846 if (!_line && !_view) {
850 if (touched (top, bot)) {
852 /* remember: this is X Window - coordinate space starts in upper left and moves down.
853 _y_position is the "origin" or "top" of the track.
856 /* bottom of our track */
857 double const mybot = _y_position + height;
862 if (_y_position >= top && mybot <= bot) {
864 /* _y_position is below top, mybot is above bot, so we're fully
873 /* top and bot are within _y_position .. mybot */
875 topfrac = 1.0 - ((top - _y_position) / height);
876 botfrac = 1.0 - ((bot - _y_position) / height);
881 _line->get_selectables (start, end, botfrac, topfrac, results);
883 _view->get_selectables (start, end, botfrac, topfrac, results);
889 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
892 _line->get_inverted_selectables (sel, result);
897 AutomationTimeAxisView::set_selected_points (PointSelection& points)
900 _line->set_selected_points (points);
902 _view->set_selected_points (points);
907 AutomationTimeAxisView::clear_lines ()
910 _list_connections.drop_connections ();
914 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
916 if (_control && line) {
917 assert(line->the_list() == _control->list());
919 _control->alist()->automation_state_changed.connect (
920 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
923 _control->alist()->InterpolationChanged.connect (
924 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
930 line->set_height (height - 2.5);
932 /* pick up the current state */
933 automation_state_changed ();
935 line->add_visibility (AutomationLine::Line);
939 AutomationTimeAxisView::propagate_time_selection () const
941 /* MIDI automation is part of the MIDI region. It is always
942 * implicily selected with the parent, regardless of TAV selection
944 if (_parameter.type() >= MidiCCAutomation &&
945 _parameter.type() <= MidiChannelPressureAutomation) {
952 AutomationTimeAxisView::entered()
955 _line->track_entered();
960 AutomationTimeAxisView::exited ()
963 _line->track_exited();
968 AutomationTimeAxisView::color_handler ()
976 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
978 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
981 if (node.get_property (X_("shown"), shown)) {
983 _canvas_display->show (); /* FIXME: necessary? show_at? */
984 set_gui_property ("visible", shown);
987 set_gui_property ("visible", false);
995 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
1001 AutomationTimeAxisView::what_has_visible_automation (const boost::shared_ptr<Automatable>& automatable, set<Evoral::Parameter>& visible)
1003 /* this keeps "knowledge" of how we store visibility information
1004 in XML private to this class.
1007 assert (automatable);
1009 Automatable::Controls& controls (automatable->controls());
1011 for (Automatable::Controls::iterator i = controls.begin(); i != controls.end(); ++i) {
1013 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (i->second);
1015 if (ac && ac->alist()) {
1017 const XMLNode* gui_node = ac->extra_xml ("GUI");
1021 if (gui_node->get_property ("shown", shown) && shown) {
1022 visible.insert (i->first);
1030 /** @return true if this view has any automation data to display */
1032 AutomationTimeAxisView::has_automation () const
1034 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
1037 list<boost::shared_ptr<AutomationLine> >
1038 AutomationTimeAxisView::lines () const
1040 list<boost::shared_ptr<AutomationLine> > lines;
1043 lines.push_back (_line);
1045 lines = _view->get_lines ();
1052 AutomationTimeAxisView::state_id() const
1054 if (_parameter && _stripable && _automatable == _stripable) {
1055 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
1056 PBD::to_string (_parameter.id()) + "/" +
1057 PBD::to_string (_parameter.channel ());
1059 return string("automation ") + PBD::to_string(_stripable->id()) + " " + parameter_str;
1060 } else if (_automatable != _stripable && _control) {
1061 return string("automation ") + _control->id().to_s();
1063 error << "Automation time axis has no state ID" << endmsg;
1068 /** Given a state id string, see if it is one generated by
1069 * this class. If so, parse it into its components.
1070 * @param state_id State ID string to parse.
1071 * @param route_id Filled in with the route's ID if the state ID string is parsed.
1072 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
1073 * @param parameter Filled in with the state ID's parameter, if it has one.
1074 * @return true if this is a state ID generated by this class, otherwise false.
1078 AutomationTimeAxisView::parse_state_id (
1079 string const & state_id,
1081 bool & has_parameter,
1082 Evoral::Parameter & parameter)
1090 if (a != X_("automation")) {
1094 route_id = PBD::ID (b);
1097 has_parameter = false;
1101 has_parameter = true;
1104 boost::split (p, c, boost::is_any_of ("/"));
1106 assert (p.size() == 3);
1108 parameter = Evoral::Parameter (
1109 PBD::string_to<uint32_t>(p[0]), // type
1110 PBD::string_to<uint8_t>(p[2]), // channel
1111 PBD::string_to<uint32_t>(p[1]) // id
1118 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1120 list<boost::shared_ptr<AutomationLine> > lines;
1122 lines.push_back (_line);
1124 lines = _view->get_lines ();
1127 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
1128 cut_copy_clear_one (**i, selection, op);
1133 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1135 boost::shared_ptr<Evoral::ControlList> what_we_got;
1136 boost::shared_ptr<AutomationList> alist (line.the_list());
1138 XMLNode &before = alist->get_state();
1140 /* convert time selection to automation list model coordinates */
1141 const Evoral::TimeConverter<double, ARDOUR::samplepos_t>& tc = line.time_converter ();
1142 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1143 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1147 if (alist->cut (start, end) != 0) {
1148 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1154 if ((what_we_got = alist->cut (start, end)) != 0) {
1155 _editor.get_cut_buffer().add (what_we_got);
1156 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1160 if ((what_we_got = alist->copy (start, end)) != 0) {
1161 _editor.get_cut_buffer().add (what_we_got);
1166 if ((what_we_got = alist->cut (start, end)) != 0) {
1167 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1173 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1174 double when = (*x)->when;
1175 double val = (*x)->value;
1176 line.model_to_view_coord (when, val);
1183 PresentationInfo const &
1184 AutomationTimeAxisView::presentation_info () const
1186 return _stripable->presentation_info();
1189 boost::shared_ptr<Stripable>
1190 AutomationTimeAxisView::stripable () const
1196 AutomationTimeAxisView::color () const
1198 return gdk_color_from_rgb (_stripable->presentation_info().color());