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.
21 #include <gtkmm2ext/barcontroller.h>
22 #include <gtkmm2ext/utils.h>
23 #include <boost/algorithm/string.hpp>
25 #include "pbd/error.h"
26 #include "pbd/memento_command.h"
27 #include "pbd/stacktrace.h"
28 #include "pbd/string_convert.h"
29 #include "pbd/types_convert.h"
31 #include "ardour/automation_control.h"
32 #include "ardour/beats_frames_converter.h"
33 #include "ardour/event_type_map.h"
34 #include "ardour/parameter_types.h"
35 #include "ardour/profile.h"
36 #include "ardour/route.h"
37 #include "ardour/session.h"
39 #include "canvas/debug.h"
41 #include "automation_time_axis.h"
42 #include "automation_streamview.h"
43 #include "gui_thread.h"
44 #include "route_time_axis.h"
45 #include "automation_line.h"
46 #include "paste_context.h"
47 #include "public_editor.h"
48 #include "selection.h"
50 #include "rgb_macros.h"
51 #include "point_selection.h"
52 #include "control_point.h"
54 #include "item_counts.h"
55 #include "ui_config.h"
60 using namespace ARDOUR;
61 using namespace ARDOUR_UI_UTILS;
64 using namespace Gtkmm2ext;
65 using namespace Editing;
67 Pango::FontDescription AutomationTimeAxisView::name_font;
68 bool AutomationTimeAxisView::have_name_font = false;
71 /** \a a the automatable object this time axis is to display data for.
72 * For route/track automation (e.g. gain) pass the route for both \r and \a.
73 * For route child (e.g. plugin) automation, pass the child for \a.
74 * For region automation (e.g. MIDI CC), pass null for \a.
76 AutomationTimeAxisView::AutomationTimeAxisView (
78 boost::shared_ptr<Route> r,
79 boost::shared_ptr<Automatable> a,
80 boost::shared_ptr<AutomationControl> c,
85 ArdourCanvas::Canvas& canvas,
87 const string & nomparent
89 : SessionHandlePtr (s)
90 , TimeAxisView (s, e, &parent, canvas)
95 , _base_rect (new ArdourCanvas::Rectangle (_canvas_display))
96 , _view (show_regions ? new AutomationStreamView (*this) : 0)
98 , _show_regions (show_regions)
100 //concatenate plugin name and param name into the tooltip
101 string tipname = nomparent;
102 if (!tipname.empty()) {
106 set_tooltip(controls_ebox, tipname);
108 //plugin name and param name appear on 2 separate lines in the track header
110 if (!tipname.empty()) {
116 CANVAS_DEBUG_NAME (_canvas_display, string_compose ("main for auto %2/%1", _name, r->name()));
117 CANVAS_DEBUG_NAME (selection_group, string_compose ("selections for auto %2/%1", _name, r->name()));
118 CANVAS_DEBUG_NAME (_ghost_group, string_compose ("ghosts for auto %2/%1", _name, r->name()));
120 if (!have_name_font) {
121 name_font = get_font_for_style (X_("AutomationTrackName"));
122 have_name_font = true;
125 if (_automatable && _control) {
126 _controller = AutomationController::create (_automatable, _control->parameter(), _control->desc(), _control);
129 const std::string fill_color_name = (dynamic_cast<MidiTimeAxisView*>(&parent)
130 ? "midi automation track fill"
131 : "audio automation track fill");
137 mode_discrete_item = 0;
140 ignore_state_request = false;
141 first_call_to_set_height = true;
143 CANVAS_DEBUG_NAME (_base_rect, string_compose ("base rect for %1", _name));
144 _base_rect->set_x1 (ArdourCanvas::COORD_MAX);
145 _base_rect->set_outline (false);
146 _base_rect->set_fill_color (UIConfiguration::instance().color_mod (fill_color_name, "automation track fill"));
147 _base_rect->set_data ("trackview", this);
148 _base_rect->Event.connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_automation_track_event), _base_rect, this));
150 _base_rect->lower_to_bottom();
153 using namespace Menu_Helpers;
155 auto_dropdown.AddMenuElem (MenuElem (S_("Automation|Manual"), sigc::bind (sigc::mem_fun(*this,
156 &AutomationTimeAxisView::set_automation_state), (AutoState) ARDOUR::Off)));
157 auto_dropdown.AddMenuElem (MenuElem (_("Play"), sigc::bind (sigc::mem_fun(*this,
158 &AutomationTimeAxisView::set_automation_state), (AutoState) Play)));
159 auto_dropdown.AddMenuElem (MenuElem (_("Write"), sigc::bind (sigc::mem_fun(*this,
160 &AutomationTimeAxisView::set_automation_state), (AutoState) Write)));
161 auto_dropdown.AddMenuElem (MenuElem (_("Touch"), sigc::bind (sigc::mem_fun(*this,
162 &AutomationTimeAxisView::set_automation_state), (AutoState) Touch)));
164 /* XXX translators: use a string here that will be at least as long
165 as the longest automation label (see ::automation_state_changed()
166 below). be sure to include a descender.
168 auto_dropdown.set_sizing_text(_("Mgnual"));
170 hide_button.set_icon (ArdourIcon::CloseCross);
171 hide_button.set_tweaks(ArdourButton::TrackHeader);
173 auto_dropdown.set_name ("route button");
174 hide_button.set_name ("route button");
176 auto_dropdown.unset_flags (Gtk::CAN_FOCUS);
177 hide_button.unset_flags (Gtk::CAN_FOCUS);
179 controls_table.set_no_show_all();
181 set_tooltip(auto_dropdown, _("automation state"));
182 set_tooltip(hide_button, _("hide track"));
185 if (get_gui_property ("height", height)) {
188 set_height (preset_height (HeightNormal));
191 //name label isn't editable on an automation track; remove the tooltip
192 set_tooltip (name_label, X_(""));
194 /* repack the name label, which TimeAxisView has already attached to
198 if (name_label.get_parent()) {
199 name_label.get_parent()->remove (name_label);
202 name_label.set_text (_name);
203 name_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
204 name_label.set_name (X_("TrackParameterName"));
205 name_label.set_ellipsize (Pango::ELLIPSIZE_END);
207 /* add the buttons */
208 controls_table.set_border_width (1);
209 controls_table.attach (hide_button, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
210 controls_table.attach (name_label, 2, 3, 1, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 2, 0);
211 controls_table.attach (auto_dropdown, 3, 4, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
213 Gtk::DrawingArea *blank0 = manage (new Gtk::DrawingArea());
214 Gtk::DrawingArea *blank1 = manage (new Gtk::DrawingArea());
216 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&parent);
217 // TODO use rtv->controls_base_unselected_name
218 // subscribe to route_active_changed, ...
219 if (rtv && rtv->is_audio_track()) {
220 blank0->set_name ("AudioTrackControlsBaseUnselected");
221 } else if (rtv && rtv->is_midi_track()) {
222 blank0->set_name ("MidiTrackControlsBaseUnselected");
224 blank0->set_name ("AudioBusControlsBaseUnselected");
226 blank0->set_name ("UnknownControlsBaseUnselected");
228 blank0->set_size_request (-1, -1);
229 blank1->set_size_request (1, 0);
230 VSeparator* separator = manage (new VSeparator());
231 separator->set_name("TrackSeparator");
232 separator->set_size_request (1, -1);
234 controls_button_size_group->add_widget(hide_button);
235 controls_button_size_group->add_widget(*blank0);
237 time_axis_hbox.pack_start (*blank0, false, false);
238 time_axis_hbox.pack_start (*separator, false, false);
239 time_axis_hbox.reorder_child (*blank0, 0);
240 time_axis_hbox.reorder_child (*separator, 1);
241 time_axis_hbox.reorder_child (time_axis_vbox, 2);
243 if (!ARDOUR::Profile->get_mixbus() ) {
244 time_axis_hbox.pack_start (*blank1, false, false);
253 _controller->disable_vertical_scroll ();
254 controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
257 controls_table.show_all ();
259 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked));
261 controls_base_selected_name = X_("AutomationTrackControlsBaseSelected");
262 controls_base_unselected_name = X_("AutomationTrackControlsBase");
264 controls_ebox.set_name (controls_base_unselected_name);
265 time_axis_frame.set_name (controls_base_unselected_name);
267 /* ask for notifications of any new RegionViews */
275 /* no regions, just a single line for the entire track (e.g. bus gain) */
279 boost::shared_ptr<AutomationLine> line (
281 ARDOUR::EventTypeMap::instance().to_symbol(_parameter),
289 line->set_line_color (UIConfiguration::instance().color ("processor automation line"));
290 line->set_fill (true);
291 line->queue_reset ();
295 /* make sure labels etc. are correct */
297 automation_state_changed ();
298 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AutomationTimeAxisView::color_handler));
300 _route->DropReferences.connect (
301 _route_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::route_going_away, this), gui_context ()
305 AutomationTimeAxisView::~AutomationTimeAxisView ()
307 cleanup_gui_properties ();
312 AutomationTimeAxisView::route_going_away ()
318 AutomationTimeAxisView::set_automation_state (AutoState state)
320 if (ignore_state_request) {
325 _automatable->set_parameter_automation_state (_parameter, state);
329 _view->set_automation_state (state);
331 /* AutomationStreamViews don't signal when their automation state changes, so handle
332 our updates `manually'.
334 automation_state_changed ();
339 AutomationTimeAxisView::automation_state_changed ()
343 /* update button label */
346 state = _view->automation_state ();
349 state = _control->alist()->automation_state ();
354 switch (state & (ARDOUR::Off|Play|Touch|Write)) {
356 auto_dropdown.set_text (S_("Automation|Manual"));
358 ignore_state_request = true;
359 auto_off_item->set_active (true);
360 auto_play_item->set_active (false);
361 auto_touch_item->set_active (false);
362 auto_write_item->set_active (false);
363 ignore_state_request = false;
367 auto_dropdown.set_text (_("Play"));
368 if (auto_play_item) {
369 ignore_state_request = true;
370 auto_play_item->set_active (true);
371 auto_off_item->set_active (false);
372 auto_touch_item->set_active (false);
373 auto_write_item->set_active (false);
374 ignore_state_request = false;
378 auto_dropdown.set_text (_("Write"));
379 if (auto_write_item) {
380 ignore_state_request = true;
381 auto_write_item->set_active (true);
382 auto_off_item->set_active (false);
383 auto_play_item->set_active (false);
384 auto_touch_item->set_active (false);
385 ignore_state_request = false;
389 auto_dropdown.set_text (_("Touch"));
390 if (auto_touch_item) {
391 ignore_state_request = true;
392 auto_touch_item->set_active (true);
393 auto_off_item->set_active (false);
394 auto_play_item->set_active (false);
395 auto_write_item->set_active (false);
396 ignore_state_request = false;
400 auto_dropdown.set_text (_("???"));
405 /** The interpolation style of our AutomationList has changed, so update */
407 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
409 if (mode_line_item && mode_discrete_item) {
410 if (s == AutomationList::Discrete) {
411 mode_discrete_item->set_active(true);
412 mode_line_item->set_active(false);
414 mode_line_item->set_active(true);
415 mode_discrete_item->set_active(false);
420 /** A menu item has been selected to change our interpolation mode */
422 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
424 /* Tell our view's list, if we have one, otherwise tell our own.
425 * Everything else will be signalled back from that.
429 _view->set_interpolation (style);
432 _control->list()->set_interpolation (style);
437 AutomationTimeAxisView::clear_clicked ()
439 assert (_line || _view);
441 _editor.begin_reversible_command (_("clear automation"));
448 set_automation_state ((AutoState) ARDOUR::Off);
449 _editor.commit_reversible_command ();
450 _session->set_dirty ();
454 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
456 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
457 uint32_t const normal = preset_height (HeightNormal);
458 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
460 TimeAxisView::set_height (h, m);
462 _base_rect->set_y1 (h);
465 _line->set_height(h - 2.5);
469 _view->set_height(h);
470 _view->update_contents_height();
473 if (changed_between_small_and_normal || first_call_to_set_height) {
475 first_call_to_set_height = false;
477 if (h >= preset_height (HeightNormal)) {
478 if (!(_parameter.type() >= MidiCCAutomation &&
479 _parameter.type() <= MidiChannelPressureAutomation)) {
480 auto_dropdown.show();
485 } else if (h >= preset_height (HeightSmall)) {
486 controls_table.hide_all ();
487 auto_dropdown.hide();
493 if (_canvas_display->visible() && _route) {
494 /* only emit the signal if the height really changed and we were visible */
495 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
501 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
503 TimeAxisView::set_samples_per_pixel (fpp);
510 _view->set_samples_per_pixel (fpp);
515 AutomationTimeAxisView::hide_clicked ()
517 hide_button.set_sensitive(false);
518 set_marked_for_display (false);
519 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(parent);
521 rtv->request_redraw ();
523 hide_button.set_sensitive(true);
527 AutomationTimeAxisView::build_display_menu ()
529 using namespace Menu_Helpers;
533 TimeAxisView::build_display_menu ();
535 /* now fill it with our stuff */
537 MenuList& items = display_menu->items();
539 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
540 items.push_back (SeparatorElem());
541 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
542 items.push_back (SeparatorElem());
546 Menu* auto_state_menu = manage (new Menu);
547 auto_state_menu->set_name ("ArdourContextMenu");
548 MenuList& as_items = auto_state_menu->items();
550 as_items.push_back (CheckMenuElem (S_("Automation|Manual"), sigc::bind (
551 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
552 (AutoState) ARDOUR::Off)));
553 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
555 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
556 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
558 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
560 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
561 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
562 (AutoState) Write)));
563 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
565 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
566 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
567 (AutoState) Touch)));
568 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
570 if (!(_parameter.type() >= MidiCCAutomation &&
571 _parameter.type() <= MidiChannelPressureAutomation)) {
572 items.push_back (MenuElem (_("State"), *auto_state_menu));
577 /* current interpolation state */
578 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
580 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
582 Menu* auto_mode_menu = manage (new Menu);
583 auto_mode_menu->set_name ("ArdourContextMenu");
584 MenuList& am_items = auto_mode_menu->items();
586 RadioMenuItem::Group group;
588 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
589 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
590 AutomationList::Discrete)));
591 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
592 mode_discrete_item->set_active (s == AutomationList::Discrete);
594 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
595 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
596 AutomationList::Linear)));
597 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
598 mode_line_item->set_active (s == AutomationList::Linear);
600 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
603 /* make sure the automation menu state is correct */
605 automation_state_changed ();
606 interpolation_changed (s);
610 AutomationTimeAxisView::add_automation_event (GdkEvent* event, framepos_t frame, double y, bool with_guard_points)
616 boost::shared_ptr<AutomationList> list = _line->the_list ();
618 if (list->in_write_pass()) {
619 /* do not allow the GUI to add automation events during an
620 automation write pass.
627 _line->grab_item().canvas_to_item (x, y);
629 /* compute vertical fractional position */
631 y = 1.0 - (y / _line->height());
635 _line->view_to_model_coord (x, y);
637 MusicFrame when (frame, 0);
638 _editor.snap_to_with_modifier (when, event);
640 XMLNode& before = list->get_state();
641 std::list<Selectable*> results;
643 if (list->editor_add (when.frame, y, with_guard_points)) {
644 XMLNode& after = list->get_state();
645 _editor.begin_reversible_command (_("add automation event"));
646 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
648 _line->get_selectables (when.frame, when.frame, 0.0, 1.0, results);
649 _editor.get_selection ().set (results);
651 _editor.commit_reversible_command ();
652 _session->set_dirty ();
657 AutomationTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
660 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
662 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
663 if (l == selection.lines.end()) {
664 if (ctx.greedy && selection.lines.size() == 1) {
665 l = selection.lines.begin();
668 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
669 ctx.counts.increase_n_lines(_parameter);
678 AutomationTimeAxisView::paste_one (framepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
680 boost::shared_ptr<AutomationList> alist(_line->the_list());
682 if (_session->transport_rolling() && alist->automation_write()) {
683 /* do not paste if this control is in write mode and we're rolling */
687 /* Get appropriate list from selection. */
688 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
689 if (p == selection.lines.end()) {
690 if (greedy && selection.lines.size() == 1) {
691 p = selection.lines.begin();
696 counts.increase_n_lines(_parameter);
698 /* add multi-paste offset if applicable */
700 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
701 double len = (*p)->length();
703 if (parameter_is_midi (src_type)) {
704 // convert length to samples (incl tempo-ramps)
705 len = DoubleBeatsFramesConverter (_session->tempo_map(), pos).to (len * paste_count);
706 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
708 pos += _editor.get_paste_offset (pos, paste_count, len);
711 /* convert sample-position to model's unit and position */
712 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
714 XMLNode &before = alist->get_state();
715 alist->paste (**p, model_pos, DoubleBeatsFramesConverter (_session->tempo_map(), pos));
716 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
722 AutomationTimeAxisView::get_selectables (framepos_t start, framepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
724 if (!_line && !_view) {
728 if (touched (top, bot)) {
730 /* remember: this is X Window - coordinate space starts in upper left and moves down.
731 _y_position is the "origin" or "top" of the track.
734 /* bottom of our track */
735 double const mybot = _y_position + height;
740 if (_y_position >= top && mybot <= bot) {
742 /* _y_position is below top, mybot is above bot, so we're fully
751 /* top and bot are within _y_position .. mybot */
753 topfrac = 1.0 - ((top - _y_position) / height);
754 botfrac = 1.0 - ((bot - _y_position) / height);
759 _line->get_selectables (start, end, botfrac, topfrac, results);
761 _view->get_selectables (start, end, botfrac, topfrac, results);
767 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
770 _line->get_inverted_selectables (sel, result);
775 AutomationTimeAxisView::set_selected_points (PointSelection& points)
778 _line->set_selected_points (points);
780 _view->set_selected_points (points);
785 AutomationTimeAxisView::clear_lines ()
788 _list_connections.drop_connections ();
792 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
794 if (_control && line) {
795 assert(line->the_list() == _control->list());
797 _control->alist()->automation_state_changed.connect (
798 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
801 _control->alist()->InterpolationChanged.connect (
802 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
808 line->set_height (height - 2.5);
810 /* pick up the current state */
811 automation_state_changed ();
813 line->add_visibility (AutomationLine::Line);
817 AutomationTimeAxisView::entered()
820 _line->track_entered();
825 AutomationTimeAxisView::exited ()
828 _line->track_exited();
833 AutomationTimeAxisView::color_handler ()
841 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
843 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
846 if (node.get_property (X_("shown"), shown)) {
848 _canvas_display->show (); /* FIXME: necessary? show_at? */
849 set_gui_property ("visible", shown);
852 set_gui_property ("visible", false);
860 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
866 AutomationTimeAxisView::what_has_visible_automation (const boost::shared_ptr<Automatable>& automatable, set<Evoral::Parameter>& visible)
868 /* this keeps "knowledge" of how we store visibility information
869 in XML private to this class.
872 assert (automatable);
874 Automatable::Controls& controls (automatable->controls());
876 for (Automatable::Controls::iterator i = controls.begin(); i != controls.end(); ++i) {
878 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (i->second);
880 if (ac && ac->alist()) {
882 const XMLNode* gui_node = ac->extra_xml ("GUI");
886 if (gui_node->get_property ("shown", shown) && shown) {
887 visible.insert (i->first);
895 /** @return true if this view has any automation data to display */
897 AutomationTimeAxisView::has_automation () const
899 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
902 list<boost::shared_ptr<AutomationLine> >
903 AutomationTimeAxisView::lines () const
905 list<boost::shared_ptr<AutomationLine> > lines;
908 lines.push_back (_line);
910 lines = _view->get_lines ();
917 AutomationTimeAxisView::state_id() const
919 if (_automatable != _route && _control) {
920 return string("automation ") + _control->id().to_s();
921 } else if (_parameter) {
922 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
923 PBD::to_string (_parameter.id()) + "/" +
924 PBD::to_string (_parameter.channel ());
926 return string("automation ") + PBD::to_string(_route->id()) + " " + parameter_str;
928 error << "Automation time axis has no state ID" << endmsg;
933 /** Given a state id string, see if it is one generated by
934 * this class. If so, parse it into its components.
935 * @param state_id State ID string to parse.
936 * @param route_id Filled in with the route's ID if the state ID string is parsed.
937 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
938 * @param parameter Filled in with the state ID's parameter, if it has one.
939 * @return true if this is a state ID generated by this class, otherwise false.
943 AutomationTimeAxisView::parse_state_id (
944 string const & state_id,
946 bool & has_parameter,
947 Evoral::Parameter & parameter)
955 if (a != X_("automation")) {
959 route_id = PBD::ID (b);
962 has_parameter = false;
966 has_parameter = true;
969 boost::split (p, c, boost::is_any_of ("/"));
971 assert (p.size() == 3);
973 parameter = Evoral::Parameter (
974 PBD::string_to<uint32_t>(p[0]), // type
975 PBD::string_to<uint8_t>(p[2]), // channel
976 PBD::string_to<uint32_t>(p[1]) // id
983 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
985 list<boost::shared_ptr<AutomationLine> > lines;
987 lines.push_back (_line);
989 lines = _view->get_lines ();
992 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
993 cut_copy_clear_one (**i, selection, op);
998 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1000 boost::shared_ptr<Evoral::ControlList> what_we_got;
1001 boost::shared_ptr<AutomationList> alist (line.the_list());
1003 XMLNode &before = alist->get_state();
1005 /* convert time selection to automation list model coordinates */
1006 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& tc = line.time_converter ();
1007 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1008 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1012 if (alist->cut (start, end) != 0) {
1013 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1019 if ((what_we_got = alist->cut (start, end)) != 0) {
1020 _editor.get_cut_buffer().add (what_we_got);
1021 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1025 if ((what_we_got = alist->copy (start, end)) != 0) {
1026 _editor.get_cut_buffer().add (what_we_got);
1031 if ((what_we_got = alist->cut (start, end)) != 0) {
1032 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1038 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1039 double when = (*x)->when;
1040 double val = (*x)->value;
1041 line.model_to_view_coord (when, val);
1048 PresentationInfo const &
1049 AutomationTimeAxisView::presentation_info () const
1051 return _route->presentation_info();
1054 boost::shared_ptr<Stripable>
1055 AutomationTimeAxisView::stripable () const
1061 AutomationTimeAxisView::color () const
1063 return gdk_color_from_rgb (_route->presentation_info().color());