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 (automation_state_off_string(), 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)));
169 if (!(_parameter.type() >= MidiCCAutomation &&
170 _parameter.type() <= MidiChannelPressureAutomation)) {
171 auto_dropdown.AddMenuElem (MenuElem (_("Write"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Write)));
172 auto_dropdown.AddMenuElem (MenuElem (_("Touch"), sigc::bind (sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state), (AutoState) Touch)));
175 /* XXX translators: use a string here that will be at least as long
176 as the longest automation label (see ::automation_state_changed()
177 below). be sure to include a descender.
179 auto_dropdown.set_sizing_text(_("Mgnual"));
181 hide_button.set_icon (ArdourIcon::CloseCross);
182 hide_button.set_tweaks(ArdourButton::TrackHeader);
184 auto_dropdown.set_name ("route button");
185 hide_button.set_name ("route button");
187 auto_dropdown.unset_flags (Gtk::CAN_FOCUS);
188 hide_button.unset_flags (Gtk::CAN_FOCUS);
190 controls_table.set_no_show_all();
192 set_tooltip(auto_dropdown, _("automation state"));
193 set_tooltip(hide_button, _("hide track"));
196 if (get_gui_property ("height", height)) {
199 set_height (preset_height (HeightNormal));
202 //name label isn't editable on an automation track; remove the tooltip
203 set_tooltip (name_label, X_(""));
205 /* repack the name label, which TimeAxisView has already attached to
209 if (name_label.get_parent()) {
210 name_label.get_parent()->remove (name_label);
213 name_label.set_text (_name);
214 name_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
215 name_label.set_name (X_("TrackParameterName"));
216 name_label.set_ellipsize (Pango::ELLIPSIZE_END);
218 /* add the buttons */
219 controls_table.set_border_width (1);
220 controls_table.attach (hide_button, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
221 controls_table.attach (name_label, 2, 3, 1, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 2, 0);
222 controls_table.attach (auto_dropdown, 3, 4, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
224 Gtk::DrawingArea *blank0 = manage (new Gtk::DrawingArea());
225 Gtk::DrawingArea *blank1 = manage (new Gtk::DrawingArea());
227 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&parent);
228 // TODO use rtv->controls_base_unselected_name
229 // subscribe to route_active_changed, ...
230 if (rtv && rtv->is_audio_track()) {
231 blank0->set_name ("AudioTrackControlsBaseUnselected");
232 } else if (rtv && rtv->is_midi_track()) {
233 blank0->set_name ("MidiTrackControlsBaseUnselected");
235 blank0->set_name ("AudioBusControlsBaseUnselected");
237 blank0->set_name ("UnknownControlsBaseUnselected");
239 blank0->set_size_request (-1, -1);
240 blank1->set_size_request (1, 0);
241 VSeparator* separator = manage (new VSeparator());
242 separator->set_name("TrackSeparator");
243 separator->set_size_request (1, -1);
245 controls_button_size_group->add_widget(hide_button);
246 controls_button_size_group->add_widget(*blank0);
248 time_axis_hbox.pack_start (*blank0, false, false);
249 time_axis_hbox.pack_start (*separator, false, false);
250 time_axis_hbox.reorder_child (*blank0, 0);
251 time_axis_hbox.reorder_child (*separator, 1);
252 time_axis_hbox.reorder_child (time_axis_vbox, 2);
254 if (!ARDOUR::Profile->get_mixbus() ) {
255 time_axis_hbox.pack_start (*blank1, false, false);
264 _controller->disable_vertical_scroll ();
265 controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
268 controls_table.show_all ();
270 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked));
272 controls_base_selected_name = X_("AutomationTrackControlsBaseSelected");
273 controls_base_unselected_name = X_("AutomationTrackControlsBase");
275 controls_ebox.set_name (controls_base_unselected_name);
276 time_axis_frame.set_name (controls_base_unselected_name);
278 /* ask for notifications of any new RegionViews */
286 /* no regions, just a single line for the entire track (e.g. bus gain) */
290 boost::shared_ptr<AutomationLine> line (
292 ARDOUR::EventTypeMap::instance().to_symbol(_parameter),
300 line->set_line_color (UIConfiguration::instance().color ("processor automation line"));
301 line->set_fill (true);
302 line->queue_reset ();
306 /* make sure labels etc. are correct */
308 automation_state_changed ();
309 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AutomationTimeAxisView::color_handler));
311 _stripable->DropReferences.connect (
312 _stripable_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::route_going_away, this), gui_context ()
316 AutomationTimeAxisView::~AutomationTimeAxisView ()
319 cleanup_gui_properties ();
325 AutomationTimeAxisView::route_going_away ()
327 cleanup_gui_properties ();
332 AutomationTimeAxisView::set_automation_state (AutoState state)
334 if (ignore_state_request) {
339 _automatable->set_parameter_automation_state (_parameter, state);
342 _control->set_automation_state (state);
343 _session->set_dirty ();
347 _view->set_automation_state (state);
349 /* AutomationStreamViews don't signal when their automation state changes, so handle
350 our updates `manually'.
352 automation_state_changed ();
357 AutomationTimeAxisView::automation_state_changed ()
361 /* update button label */
364 state = _view->automation_state ();
367 state = _control->alist()->automation_state ();
372 switch (state & (ARDOUR::Off|Play|Touch|Write)) {
374 auto_dropdown.set_text (automation_state_off_string());
375 ignore_state_request = true;
377 auto_off_item->set_active (true);
378 auto_play_item->set_active (false);
380 if (auto_touch_item) {
381 auto_touch_item->set_active (false);
382 auto_write_item->set_active (false);
384 ignore_state_request = false;
387 auto_dropdown.set_text (_("Play"));
388 ignore_state_request = true;
390 auto_play_item->set_active (true);
391 auto_off_item->set_active (false);
393 if (auto_touch_item) {
394 auto_touch_item->set_active (false);
395 auto_write_item->set_active (false);
397 ignore_state_request = false;
400 auto_dropdown.set_text (_("Write"));
401 ignore_state_request = true;
403 auto_off_item->set_active (false);
404 auto_play_item->set_active (false);
406 if (auto_touch_item) {
407 auto_write_item->set_active (true);
408 auto_touch_item->set_active (false);
410 ignore_state_request = false;
413 auto_dropdown.set_text (_("Touch"));
414 ignore_state_request = true;
416 auto_off_item->set_active (false);
417 auto_play_item->set_active (false);
419 if (auto_touch_item) {
420 auto_touch_item->set_active (true);
421 auto_write_item->set_active (false);
423 ignore_state_request = false;
426 auto_dropdown.set_text (_("???"));
431 /** The interpolation style of our AutomationList has changed, so update */
433 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
435 if (ignore_mode_request) {
438 PBD::Unwinder<bool> uw (ignore_mode_request, true);
440 case AutomationList::Discrete:
441 if (mode_discrete_item) {
442 mode_discrete_item->set_active(true);
445 case AutomationList::Linear:
446 if (mode_line_item) {
447 mode_line_item->set_active(true);
450 case AutomationList::Logarithmic:
452 mode_log_item->set_active(true);
455 case AutomationList::Exponential:
457 mode_exp_item->set_active(true);
465 /** A menu item has been selected to change our interpolation mode */
467 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
469 /* Tell our view's list, if we have one, otherwise tell our own.
470 * Everything else will be signalled back from that.
474 _view->set_interpolation (style);
477 _control->list()->set_interpolation (style);
482 AutomationTimeAxisView::clear_clicked ()
484 assert (_line || _view);
486 _editor.begin_reversible_command (_("clear automation"));
493 if (!EventTypeMap::instance().type_is_midi (_control->parameter().type())) {
494 set_automation_state ((AutoState) ARDOUR::Off);
496 _editor.commit_reversible_command ();
497 _session->set_dirty ();
501 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
503 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
504 uint32_t const normal = preset_height (HeightNormal);
505 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
507 TimeAxisView::set_height (h, m);
509 _base_rect->set_y1 (h);
512 _line->set_height(h - 2.5);
516 _view->set_height(h);
517 _view->update_contents_height();
520 if (changed_between_small_and_normal || first_call_to_set_height) {
522 first_call_to_set_height = false;
524 if (h >= preset_height (HeightNormal)) {
525 auto_dropdown.show();
529 } else if (h >= preset_height (HeightSmall)) {
530 controls_table.hide_all ();
531 auto_dropdown.hide();
537 if (_canvas_display->visible() && _stripable) {
538 /* only emit the signal if the height really changed and we were visible */
539 _stripable->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
545 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
547 TimeAxisView::set_samples_per_pixel (fpp);
554 _view->set_samples_per_pixel (fpp);
559 AutomationTimeAxisView::hide_clicked ()
561 hide_button.set_sensitive(false);
562 set_marked_for_display (false);
563 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*>(parent);
565 stv->request_redraw ();
567 hide_button.set_sensitive(true);
571 AutomationTimeAxisView::automation_state_off_string () const
573 if (_parameter.type() >= MidiCCAutomation && _parameter.type() <= MidiChannelPressureAutomation) {
574 return S_("Automation|Off");
577 return S_("Automation|Manual");
581 AutomationTimeAxisView::build_display_menu ()
583 using namespace Menu_Helpers;
587 TimeAxisView::build_display_menu ();
589 /* now fill it with our stuff */
591 MenuList& items = display_menu->items();
593 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
594 items.push_back (SeparatorElem());
595 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
596 items.push_back (SeparatorElem());
600 Menu* auto_state_menu = manage (new Menu);
601 auto_state_menu->set_name ("ArdourContextMenu");
602 MenuList& as_items = auto_state_menu->items();
604 as_items.push_back (CheckMenuElem (automation_state_off_string(), sigc::bind (
605 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
606 (AutoState) ARDOUR::Off)));
607 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
609 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
610 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
612 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
614 if (!(_parameter.type() >= MidiCCAutomation &&
615 _parameter.type() <= MidiChannelPressureAutomation)) {
616 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
617 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
618 (AutoState) Write)));
619 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
621 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
622 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
623 (AutoState) Touch)));
624 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
627 items.push_back (MenuElem (_("State"), *auto_state_menu));
631 /* current interpolation state */
632 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
634 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
636 Menu* auto_mode_menu = manage (new Menu);
637 auto_mode_menu->set_name ("ArdourContextMenu");
638 MenuList& am_items = auto_mode_menu->items();
640 RadioMenuItem::Group group;
642 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
643 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
644 AutomationList::Discrete)));
645 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
647 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
648 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
649 AutomationList::Linear)));
650 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
652 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
655 #ifdef XXX_NEW_INTERPOLATON__BREAK_SESSION_FORMAT_XXX
656 Menu* auto_mode_menu = manage (new Menu);
657 auto_mode_menu->set_name ("ArdourContextMenu");
658 MenuList& am_items = auto_mode_menu->items();
659 bool have_options = false;
661 RadioMenuItem::Group group;
663 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
664 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
665 AutomationList::Linear)));
666 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
668 if (_control->desc().logarithmic) {
669 am_items.push_back (RadioMenuElem (group, _("Logarithmic"), sigc::bind (
670 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
671 AutomationList::Logarithmic)));
672 mode_log_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
678 if (_line->get_uses_gain_mapping () && !_control->desc().logarithmic) {
679 am_items.push_back (RadioMenuElem (group, _("Exponential"), sigc::bind (
680 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
681 AutomationList::Exponential)));
682 mode_exp_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
689 items.push_back (MenuElem (_("Interpolation"), *auto_mode_menu));
692 delete auto_mode_menu;
698 /* make sure the automation menu state is correct */
700 automation_state_changed ();
701 interpolation_changed (s);
705 AutomationTimeAxisView::add_automation_event (GdkEvent* event, framepos_t frame, double y, bool with_guard_points)
711 boost::shared_ptr<AutomationList> list = _line->the_list ();
713 if (list->in_write_pass()) {
714 /* do not allow the GUI to add automation events during an
715 automation write pass.
720 MusicFrame when (frame, 0);
721 _editor.snap_to_with_modifier (when, event);
723 if (UIConfiguration::instance().get_new_automation_points_on_lane()) {
724 if (_control->list()->size () == 0) {
725 y = _control->get_value ();
727 y = _control->list()->eval (when.frame);
731 _line->grab_item().canvas_to_item (x, y);
732 /* compute vertical fractional position */
733 y = 1.0 - (y / _line->height());
735 _line->view_to_model_coord (x, y);
738 XMLNode& before = list->get_state();
739 std::list<Selectable*> results;
741 if (list->editor_add (when.frame, y, with_guard_points)) {
742 XMLNode& after = list->get_state();
743 _editor.begin_reversible_command (_("add automation event"));
744 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
746 _line->get_selectables (when.frame, when.frame, 0.0, 1.0, results);
747 _editor.get_selection ().set (results);
749 _editor.commit_reversible_command ();
750 _session->set_dirty ();
755 AutomationTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
758 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
760 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
761 if (l == selection.lines.end()) {
762 if (ctx.greedy && selection.lines.size() == 1) {
763 l = selection.lines.begin();
766 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
767 ctx.counts.increase_n_lines(_parameter);
776 AutomationTimeAxisView::paste_one (framepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
778 boost::shared_ptr<AutomationList> alist(_line->the_list());
780 if (_session->transport_rolling() && alist->automation_write()) {
781 /* do not paste if this control is in write mode and we're rolling */
785 /* Get appropriate list from selection. */
786 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
787 if (p == selection.lines.end()) {
788 if (greedy && selection.lines.size() == 1) {
789 p = selection.lines.begin();
794 counts.increase_n_lines(_parameter);
796 /* add multi-paste offset if applicable */
798 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
799 double len = (*p)->length();
801 if (parameter_is_midi (src_type)) {
802 // convert length to samples (incl tempo-ramps)
803 len = DoubleBeatsFramesConverter (_session->tempo_map(), pos).to (len * paste_count);
804 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
806 pos += _editor.get_paste_offset (pos, paste_count, len);
809 /* convert sample-position to model's unit and position */
810 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
812 XMLNode &before = alist->get_state();
813 alist->paste (**p, model_pos, DoubleBeatsFramesConverter (_session->tempo_map(), pos));
814 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
820 AutomationTimeAxisView::get_selectables (framepos_t start, framepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
822 if (!_line && !_view) {
826 if (touched (top, bot)) {
828 /* remember: this is X Window - coordinate space starts in upper left and moves down.
829 _y_position is the "origin" or "top" of the track.
832 /* bottom of our track */
833 double const mybot = _y_position + height;
838 if (_y_position >= top && mybot <= bot) {
840 /* _y_position is below top, mybot is above bot, so we're fully
849 /* top and bot are within _y_position .. mybot */
851 topfrac = 1.0 - ((top - _y_position) / height);
852 botfrac = 1.0 - ((bot - _y_position) / height);
857 _line->get_selectables (start, end, botfrac, topfrac, results);
859 _view->get_selectables (start, end, botfrac, topfrac, results);
865 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
868 _line->get_inverted_selectables (sel, result);
873 AutomationTimeAxisView::set_selected_points (PointSelection& points)
876 _line->set_selected_points (points);
878 _view->set_selected_points (points);
883 AutomationTimeAxisView::clear_lines ()
886 _list_connections.drop_connections ();
890 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
892 if (_control && line) {
893 assert(line->the_list() == _control->list());
895 _control->alist()->automation_state_changed.connect (
896 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
899 _control->alist()->InterpolationChanged.connect (
900 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
906 line->set_height (height - 2.5);
908 /* pick up the current state */
909 automation_state_changed ();
911 line->add_visibility (AutomationLine::Line);
915 AutomationTimeAxisView::propagate_time_selection () const
917 /* MIDI automation is part of the MIDI region. It is always
918 * implicily selected with the parent, regardless of TAV selection
920 if (_parameter.type() >= MidiCCAutomation &&
921 _parameter.type() <= MidiChannelPressureAutomation) {
928 AutomationTimeAxisView::entered()
931 _line->track_entered();
936 AutomationTimeAxisView::exited ()
939 _line->track_exited();
944 AutomationTimeAxisView::color_handler ()
952 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
954 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
957 if (node.get_property (X_("shown"), shown)) {
959 _canvas_display->show (); /* FIXME: necessary? show_at? */
960 set_gui_property ("visible", shown);
963 set_gui_property ("visible", false);
971 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
977 AutomationTimeAxisView::what_has_visible_automation (const boost::shared_ptr<Automatable>& automatable, set<Evoral::Parameter>& visible)
979 /* this keeps "knowledge" of how we store visibility information
980 in XML private to this class.
983 assert (automatable);
985 Automatable::Controls& controls (automatable->controls());
987 for (Automatable::Controls::iterator i = controls.begin(); i != controls.end(); ++i) {
989 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (i->second);
991 if (ac && ac->alist()) {
993 const XMLNode* gui_node = ac->extra_xml ("GUI");
997 if (gui_node->get_property ("shown", shown) && shown) {
998 visible.insert (i->first);
1006 /** @return true if this view has any automation data to display */
1008 AutomationTimeAxisView::has_automation () const
1010 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
1013 list<boost::shared_ptr<AutomationLine> >
1014 AutomationTimeAxisView::lines () const
1016 list<boost::shared_ptr<AutomationLine> > lines;
1019 lines.push_back (_line);
1021 lines = _view->get_lines ();
1028 AutomationTimeAxisView::state_id() const
1030 if (_parameter && _stripable && _automatable == _stripable) {
1031 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
1032 PBD::to_string (_parameter.id()) + "/" +
1033 PBD::to_string (_parameter.channel ());
1035 return string("automation ") + PBD::to_string(_stripable->id()) + " " + parameter_str;
1036 } else if (_automatable != _stripable && _control) {
1037 return string("automation ") + _control->id().to_s();
1039 error << "Automation time axis has no state ID" << endmsg;
1044 /** Given a state id string, see if it is one generated by
1045 * this class. If so, parse it into its components.
1046 * @param state_id State ID string to parse.
1047 * @param route_id Filled in with the route's ID if the state ID string is parsed.
1048 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
1049 * @param parameter Filled in with the state ID's parameter, if it has one.
1050 * @return true if this is a state ID generated by this class, otherwise false.
1054 AutomationTimeAxisView::parse_state_id (
1055 string const & state_id,
1057 bool & has_parameter,
1058 Evoral::Parameter & parameter)
1066 if (a != X_("automation")) {
1070 route_id = PBD::ID (b);
1073 has_parameter = false;
1077 has_parameter = true;
1080 boost::split (p, c, boost::is_any_of ("/"));
1082 assert (p.size() == 3);
1084 parameter = Evoral::Parameter (
1085 PBD::string_to<uint32_t>(p[0]), // type
1086 PBD::string_to<uint8_t>(p[2]), // channel
1087 PBD::string_to<uint32_t>(p[1]) // id
1094 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1096 list<boost::shared_ptr<AutomationLine> > lines;
1098 lines.push_back (_line);
1100 lines = _view->get_lines ();
1103 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
1104 cut_copy_clear_one (**i, selection, op);
1109 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1111 boost::shared_ptr<Evoral::ControlList> what_we_got;
1112 boost::shared_ptr<AutomationList> alist (line.the_list());
1114 XMLNode &before = alist->get_state();
1116 /* convert time selection to automation list model coordinates */
1117 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& tc = line.time_converter ();
1118 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1119 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1123 if (alist->cut (start, end) != 0) {
1124 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1130 if ((what_we_got = alist->cut (start, end)) != 0) {
1131 _editor.get_cut_buffer().add (what_we_got);
1132 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1136 if ((what_we_got = alist->copy (start, end)) != 0) {
1137 _editor.get_cut_buffer().add (what_we_got);
1142 if ((what_we_got = alist->cut (start, end)) != 0) {
1143 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1149 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1150 double when = (*x)->when;
1151 double val = (*x)->value;
1152 line.model_to_view_coord (when, val);
1159 PresentationInfo const &
1160 AutomationTimeAxisView::presentation_info () const
1162 return _stripable->presentation_info();
1165 boost::shared_ptr<Stripable>
1166 AutomationTimeAxisView::stripable () const
1172 AutomationTimeAxisView::color () const
1174 return gdk_color_from_rgb (_stripable->presentation_info().color());