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"
30 #include "pbd/unwind.h"
32 #include "ardour/automation_control.h"
33 #include "ardour/beats_frames_converter.h"
34 #include "ardour/event_type_map.h"
35 #include "ardour/parameter_types.h"
36 #include "ardour/profile.h"
37 #include "ardour/route.h"
38 #include "ardour/session.h"
40 #include "canvas/debug.h"
42 #include "automation_time_axis.h"
43 #include "automation_streamview.h"
44 #include "gui_thread.h"
45 #include "route_time_axis.h"
46 #include "automation_line.h"
47 #include "paste_context.h"
48 #include "public_editor.h"
49 #include "selection.h"
51 #include "rgb_macros.h"
52 #include "point_selection.h"
53 #include "control_point.h"
55 #include "item_counts.h"
56 #include "ui_config.h"
61 using namespace ARDOUR;
62 using namespace ARDOUR_UI_UTILS;
65 using namespace Gtkmm2ext;
66 using namespace Editing;
68 Pango::FontDescription AutomationTimeAxisView::name_font;
69 bool AutomationTimeAxisView::have_name_font = false;
72 /** \a a the automatable object this time axis is to display data for.
73 * For route/track automation (e.g. gain) pass the route for both \r and \a.
74 * For route child (e.g. plugin) automation, pass the child for \a.
75 * For region automation (e.g. MIDI CC), pass null for \a.
77 AutomationTimeAxisView::AutomationTimeAxisView (
79 boost::shared_ptr<Stripable> strip,
80 boost::shared_ptr<Automatable> a,
81 boost::shared_ptr<AutomationControl> c,
86 ArdourCanvas::Canvas& canvas,
88 const string & nomparent
90 : SessionHandlePtr (s)
91 , TimeAxisView (s, e, &parent, canvas)
96 , _base_rect (new ArdourCanvas::Rectangle (_canvas_display))
97 , _view (show_regions ? new AutomationStreamView (*this) : 0)
99 , _show_regions (show_regions)
101 //concatenate plugin name and param name into the tooltip
102 string tipname = nomparent;
103 if (!tipname.empty()) {
107 set_tooltip(controls_ebox, tipname);
109 //plugin name and param name appear on 2 separate lines in the track header
111 if (!tipname.empty()) {
117 CANVAS_DEBUG_NAME (_canvas_display, string_compose ("main for auto %2/%1", _name, strip->name()));
118 CANVAS_DEBUG_NAME (selection_group, string_compose ("selections for auto %2/%1", _name, strip->name()));
119 CANVAS_DEBUG_NAME (_ghost_group, string_compose ("ghosts for auto %2/%1", _name, strip->name()));
121 if (!have_name_font) {
122 name_font = get_font_for_style (X_("AutomationTrackName"));
123 have_name_font = true;
127 _controller = AutomationController::create (_control->parameter(), _control->desc(), _control);
130 const std::string fill_color_name = (dynamic_cast<MidiTimeAxisView*>(&parent)
131 ? "midi automation track fill"
132 : "audio automation track fill");
138 mode_discrete_item = 0;
143 ignore_state_request = false;
144 ignore_mode_request = false;
145 first_call_to_set_height = true;
147 CANVAS_DEBUG_NAME (_base_rect, string_compose ("base rect for %1", _name));
148 _base_rect->set_x1 (ArdourCanvas::COORD_MAX);
149 _base_rect->set_outline (false);
150 _base_rect->set_fill_color (UIConfiguration::instance().color_mod (fill_color_name, "automation track fill"));
151 _base_rect->set_data ("trackview", this);
152 _base_rect->Event.connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_automation_track_event), _base_rect, this));
154 _base_rect->lower_to_bottom();
157 using namespace Menu_Helpers;
159 auto_dropdown.AddMenuElem (MenuElem (S_("Automation|Manual"), sigc::bind (sigc::mem_fun(*this,
160 &AutomationTimeAxisView::set_automation_state), (AutoState) ARDOUR::Off)));
161 auto_dropdown.AddMenuElem (MenuElem (_("Play"), sigc::bind (sigc::mem_fun(*this,
162 &AutomationTimeAxisView::set_automation_state), (AutoState) Play)));
163 auto_dropdown.AddMenuElem (MenuElem (_("Write"), sigc::bind (sigc::mem_fun(*this,
164 &AutomationTimeAxisView::set_automation_state), (AutoState) Write)));
165 auto_dropdown.AddMenuElem (MenuElem (_("Touch"), sigc::bind (sigc::mem_fun(*this,
166 &AutomationTimeAxisView::set_automation_state), (AutoState) Touch)));
168 /* XXX translators: use a string here that will be at least as long
169 as the longest automation label (see ::automation_state_changed()
170 below). be sure to include a descender.
172 auto_dropdown.set_sizing_text(_("Mgnual"));
174 hide_button.set_icon (ArdourIcon::CloseCross);
175 hide_button.set_tweaks(ArdourButton::TrackHeader);
177 auto_dropdown.set_name ("route button");
178 hide_button.set_name ("route button");
180 auto_dropdown.unset_flags (Gtk::CAN_FOCUS);
181 hide_button.unset_flags (Gtk::CAN_FOCUS);
183 controls_table.set_no_show_all();
185 set_tooltip(auto_dropdown, _("automation state"));
186 set_tooltip(hide_button, _("hide track"));
189 if (get_gui_property ("height", height)) {
192 set_height (preset_height (HeightNormal));
195 //name label isn't editable on an automation track; remove the tooltip
196 set_tooltip (name_label, X_(""));
198 /* repack the name label, which TimeAxisView has already attached to
202 if (name_label.get_parent()) {
203 name_label.get_parent()->remove (name_label);
206 name_label.set_text (_name);
207 name_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
208 name_label.set_name (X_("TrackParameterName"));
209 name_label.set_ellipsize (Pango::ELLIPSIZE_END);
211 /* add the buttons */
212 controls_table.set_border_width (1);
213 controls_table.attach (hide_button, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
214 controls_table.attach (name_label, 2, 3, 1, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 2, 0);
215 controls_table.attach (auto_dropdown, 3, 4, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
217 Gtk::DrawingArea *blank0 = manage (new Gtk::DrawingArea());
218 Gtk::DrawingArea *blank1 = manage (new Gtk::DrawingArea());
220 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&parent);
221 // TODO use rtv->controls_base_unselected_name
222 // subscribe to route_active_changed, ...
223 if (rtv && rtv->is_audio_track()) {
224 blank0->set_name ("AudioTrackControlsBaseUnselected");
225 } else if (rtv && rtv->is_midi_track()) {
226 blank0->set_name ("MidiTrackControlsBaseUnselected");
228 blank0->set_name ("AudioBusControlsBaseUnselected");
230 blank0->set_name ("UnknownControlsBaseUnselected");
232 blank0->set_size_request (-1, -1);
233 blank1->set_size_request (1, 0);
234 VSeparator* separator = manage (new VSeparator());
235 separator->set_name("TrackSeparator");
236 separator->set_size_request (1, -1);
238 controls_button_size_group->add_widget(hide_button);
239 controls_button_size_group->add_widget(*blank0);
241 time_axis_hbox.pack_start (*blank0, false, false);
242 time_axis_hbox.pack_start (*separator, false, false);
243 time_axis_hbox.reorder_child (*blank0, 0);
244 time_axis_hbox.reorder_child (*separator, 1);
245 time_axis_hbox.reorder_child (time_axis_vbox, 2);
247 if (!ARDOUR::Profile->get_mixbus() ) {
248 time_axis_hbox.pack_start (*blank1, false, false);
257 _controller->disable_vertical_scroll ();
258 controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
261 controls_table.show_all ();
263 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked));
265 controls_base_selected_name = X_("AutomationTrackControlsBaseSelected");
266 controls_base_unselected_name = X_("AutomationTrackControlsBase");
268 controls_ebox.set_name (controls_base_unselected_name);
269 time_axis_frame.set_name (controls_base_unselected_name);
271 /* ask for notifications of any new RegionViews */
279 /* no regions, just a single line for the entire track (e.g. bus gain) */
283 boost::shared_ptr<AutomationLine> line (
285 ARDOUR::EventTypeMap::instance().to_symbol(_parameter),
293 line->set_line_color (UIConfiguration::instance().color ("processor automation line"));
294 line->set_fill (true);
295 line->queue_reset ();
299 /* make sure labels etc. are correct */
301 automation_state_changed ();
302 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &AutomationTimeAxisView::color_handler));
304 _stripable->DropReferences.connect (
305 _stripable_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::route_going_away, this), gui_context ()
309 AutomationTimeAxisView::~AutomationTimeAxisView ()
311 cleanup_gui_properties ();
316 AutomationTimeAxisView::route_going_away ()
322 AutomationTimeAxisView::set_automation_state (AutoState state)
324 if (ignore_state_request) {
329 _automatable->set_parameter_automation_state (_parameter, state);
332 _control->set_automation_state (state);
336 _view->set_automation_state (state);
338 /* AutomationStreamViews don't signal when their automation state changes, so handle
339 our updates `manually'.
341 automation_state_changed ();
346 AutomationTimeAxisView::automation_state_changed ()
350 /* update button label */
353 state = _view->automation_state ();
356 state = _control->alist()->automation_state ();
361 switch (state & (ARDOUR::Off|Play|Touch|Write)) {
363 auto_dropdown.set_text (S_("Automation|Manual"));
365 ignore_state_request = true;
366 auto_off_item->set_active (true);
367 auto_play_item->set_active (false);
368 auto_touch_item->set_active (false);
369 auto_write_item->set_active (false);
370 ignore_state_request = false;
374 auto_dropdown.set_text (_("Play"));
375 if (auto_play_item) {
376 ignore_state_request = true;
377 auto_play_item->set_active (true);
378 auto_off_item->set_active (false);
379 auto_touch_item->set_active (false);
380 auto_write_item->set_active (false);
381 ignore_state_request = false;
385 auto_dropdown.set_text (_("Write"));
386 if (auto_write_item) {
387 ignore_state_request = true;
388 auto_write_item->set_active (true);
389 auto_off_item->set_active (false);
390 auto_play_item->set_active (false);
391 auto_touch_item->set_active (false);
392 ignore_state_request = false;
396 auto_dropdown.set_text (_("Touch"));
397 if (auto_touch_item) {
398 ignore_state_request = true;
399 auto_touch_item->set_active (true);
400 auto_off_item->set_active (false);
401 auto_play_item->set_active (false);
402 auto_write_item->set_active (false);
403 ignore_state_request = false;
407 auto_dropdown.set_text (_("???"));
412 /** The interpolation style of our AutomationList has changed, so update */
414 AutomationTimeAxisView::interpolation_changed (AutomationList::InterpolationStyle s)
416 if (ignore_mode_request) {
419 PBD::Unwinder<bool> uw (ignore_mode_request, true);
421 case AutomationList::Discrete:
422 if (mode_discrete_item) {
423 mode_discrete_item->set_active(true);
426 case AutomationList::Linear:
427 if (mode_line_item) {
428 mode_line_item->set_active(true);
431 case AutomationList::Logarithmic:
433 mode_log_item->set_active(true);
436 case AutomationList::Exponential:
438 mode_exp_item->set_active(true);
446 /** A menu item has been selected to change our interpolation mode */
448 AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
450 /* Tell our view's list, if we have one, otherwise tell our own.
451 * Everything else will be signalled back from that.
455 _view->set_interpolation (style);
458 _control->list()->set_interpolation (style);
463 AutomationTimeAxisView::clear_clicked ()
465 assert (_line || _view);
467 _editor.begin_reversible_command (_("clear automation"));
474 set_automation_state ((AutoState) ARDOUR::Off);
475 _editor.commit_reversible_command ();
476 _session->set_dirty ();
480 AutomationTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
482 bool const changed = (height != (uint32_t) h) || first_call_to_set_height;
483 uint32_t const normal = preset_height (HeightNormal);
484 bool const changed_between_small_and_normal = ( (height < normal && h >= normal) || (height >= normal || h < normal) );
486 TimeAxisView::set_height (h, m);
488 _base_rect->set_y1 (h);
491 _line->set_height(h - 2.5);
495 _view->set_height(h);
496 _view->update_contents_height();
499 if (changed_between_small_and_normal || first_call_to_set_height) {
501 first_call_to_set_height = false;
503 if (h >= preset_height (HeightNormal)) {
504 if (!(_parameter.type() >= MidiCCAutomation &&
505 _parameter.type() <= MidiChannelPressureAutomation)) {
506 auto_dropdown.show();
511 } else if (h >= preset_height (HeightSmall)) {
512 controls_table.hide_all ();
513 auto_dropdown.hide();
519 if (_canvas_display->visible() && _stripable) {
520 /* only emit the signal if the height really changed and we were visible */
521 _stripable->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
527 AutomationTimeAxisView::set_samples_per_pixel (double fpp)
529 TimeAxisView::set_samples_per_pixel (fpp);
536 _view->set_samples_per_pixel (fpp);
541 AutomationTimeAxisView::hide_clicked ()
543 hide_button.set_sensitive(false);
544 set_marked_for_display (false);
545 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(parent);
547 rtv->request_redraw ();
549 hide_button.set_sensitive(true);
553 AutomationTimeAxisView::build_display_menu ()
555 using namespace Menu_Helpers;
559 TimeAxisView::build_display_menu ();
561 /* now fill it with our stuff */
563 MenuList& items = display_menu->items();
565 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &AutomationTimeAxisView::hide_clicked)));
566 items.push_back (SeparatorElem());
567 items.push_back (MenuElem (_("Clear"), sigc::mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
568 items.push_back (SeparatorElem());
572 Menu* auto_state_menu = manage (new Menu);
573 auto_state_menu->set_name ("ArdourContextMenu");
574 MenuList& as_items = auto_state_menu->items();
576 as_items.push_back (CheckMenuElem (S_("Automation|Manual"), sigc::bind (
577 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
578 (AutoState) ARDOUR::Off)));
579 auto_off_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
581 as_items.push_back (CheckMenuElem (_("Play"), sigc::bind (
582 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
584 auto_play_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
586 as_items.push_back (CheckMenuElem (_("Write"), sigc::bind (
587 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
588 (AutoState) Write)));
589 auto_write_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
591 as_items.push_back (CheckMenuElem (_("Touch"), sigc::bind (
592 sigc::mem_fun(*this, &AutomationTimeAxisView::set_automation_state),
593 (AutoState) Touch)));
594 auto_touch_item = dynamic_cast<Gtk::CheckMenuItem*>(&as_items.back());
596 if (!(_parameter.type() >= MidiCCAutomation &&
597 _parameter.type() <= MidiChannelPressureAutomation)) {
598 items.push_back (MenuElem (_("State"), *auto_state_menu));
603 /* current interpolation state */
604 AutomationList::InterpolationStyle const s = _view ? _view->interpolation() : _control->list()->interpolation ();
606 if (ARDOUR::parameter_is_midi((AutomationType)_parameter.type())) {
608 Menu* auto_mode_menu = manage (new Menu);
609 auto_mode_menu->set_name ("ArdourContextMenu");
610 MenuList& am_items = auto_mode_menu->items();
612 RadioMenuItem::Group group;
614 am_items.push_back (RadioMenuElem (group, _("Discrete"), sigc::bind (
615 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
616 AutomationList::Discrete)));
617 mode_discrete_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
619 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
620 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
621 AutomationList::Linear)));
622 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
624 items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
628 Menu* auto_mode_menu = manage (new Menu);
629 auto_mode_menu->set_name ("ArdourContextMenu");
630 MenuList& am_items = auto_mode_menu->items();
631 bool have_options = false;
633 RadioMenuItem::Group group;
635 am_items.push_back (RadioMenuElem (group, _("Linear"), sigc::bind (
636 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
637 AutomationList::Linear)));
638 mode_line_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
640 if (_control->desc().logarithmic) {
641 am_items.push_back (RadioMenuElem (group, _("Logarithmic"), sigc::bind (
642 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
643 AutomationList::Logarithmic)));
644 mode_log_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
650 if (_line->get_uses_gain_mapping () && !_control->desc().logarithmic) {
651 am_items.push_back (RadioMenuElem (group, _("Exponential"), sigc::bind (
652 sigc::mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
653 AutomationList::Exponential)));
654 mode_exp_item = dynamic_cast<Gtk::CheckMenuItem*>(&am_items.back());
661 items.push_back (MenuElem (_("Interpolation"), *auto_mode_menu));
664 delete auto_mode_menu;
669 /* make sure the automation menu state is correct */
671 automation_state_changed ();
672 interpolation_changed (s);
676 AutomationTimeAxisView::add_automation_event (GdkEvent* event, framepos_t frame, double y, bool with_guard_points)
682 boost::shared_ptr<AutomationList> list = _line->the_list ();
684 if (list->in_write_pass()) {
685 /* do not allow the GUI to add automation events during an
686 automation write pass.
691 MusicFrame when (frame, 0);
692 _editor.snap_to_with_modifier (when, event);
694 if (UIConfiguration::instance().get_new_automation_points_on_lane()) {
695 if (_control->list()->size () == 0) {
696 y = _control->get_value ();
698 y = _control->list()->eval (when.frame);
702 _line->grab_item().canvas_to_item (x, y);
703 /* compute vertical fractional position */
704 y = 1.0 - (y / _line->height());
706 _line->view_to_model_coord (x, y);
709 XMLNode& before = list->get_state();
710 std::list<Selectable*> results;
712 if (list->editor_add (when.frame, y, with_guard_points)) {
713 XMLNode& after = list->get_state();
714 _editor.begin_reversible_command (_("add automation event"));
715 _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
717 _line->get_selectables (when.frame, when.frame, 0.0, 1.0, results);
718 _editor.get_selection ().set (results);
720 _editor.commit_reversible_command ();
721 _session->set_dirty ();
726 AutomationTimeAxisView::paste (framepos_t pos, const Selection& selection, PasteContext& ctx, const int32_t divisions)
729 return paste_one (pos, ctx.count, ctx.times, selection, ctx.counts, ctx.greedy);
731 AutomationSelection::const_iterator l = selection.lines.get_nth(_parameter, ctx.counts.n_lines(_parameter));
732 if (l == selection.lines.end()) {
733 if (ctx.greedy && selection.lines.size() == 1) {
734 l = selection.lines.begin();
737 if (l != selection.lines.end() && _view->paste (pos, ctx.count, ctx.times, *l)) {
738 ctx.counts.increase_n_lines(_parameter);
747 AutomationTimeAxisView::paste_one (framepos_t pos, unsigned paste_count, float times, const Selection& selection, ItemCounts& counts, bool greedy)
749 boost::shared_ptr<AutomationList> alist(_line->the_list());
751 if (_session->transport_rolling() && alist->automation_write()) {
752 /* do not paste if this control is in write mode and we're rolling */
756 /* Get appropriate list from selection. */
757 AutomationSelection::const_iterator p = selection.lines.get_nth(_parameter, counts.n_lines(_parameter));
758 if (p == selection.lines.end()) {
759 if (greedy && selection.lines.size() == 1) {
760 p = selection.lines.begin();
765 counts.increase_n_lines(_parameter);
767 /* add multi-paste offset if applicable */
769 AutomationType src_type = (AutomationType)(*p)->parameter().type ();
770 double len = (*p)->length();
772 if (parameter_is_midi (src_type)) {
773 // convert length to samples (incl tempo-ramps)
774 len = DoubleBeatsFramesConverter (_session->tempo_map(), pos).to (len * paste_count);
775 pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
777 pos += _editor.get_paste_offset (pos, paste_count, len);
780 /* convert sample-position to model's unit and position */
781 double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
783 XMLNode &before = alist->get_state();
784 alist->paste (**p, model_pos, DoubleBeatsFramesConverter (_session->tempo_map(), pos));
785 _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
791 AutomationTimeAxisView::get_selectables (framepos_t start, framepos_t end, double top, double bot, list<Selectable*>& results, bool /*within*/)
793 if (!_line && !_view) {
797 if (touched (top, bot)) {
799 /* remember: this is X Window - coordinate space starts in upper left and moves down.
800 _y_position is the "origin" or "top" of the track.
803 /* bottom of our track */
804 double const mybot = _y_position + height;
809 if (_y_position >= top && mybot <= bot) {
811 /* _y_position is below top, mybot is above bot, so we're fully
820 /* top and bot are within _y_position .. mybot */
822 topfrac = 1.0 - ((top - _y_position) / height);
823 botfrac = 1.0 - ((bot - _y_position) / height);
828 _line->get_selectables (start, end, botfrac, topfrac, results);
830 _view->get_selectables (start, end, botfrac, topfrac, results);
836 AutomationTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
839 _line->get_inverted_selectables (sel, result);
844 AutomationTimeAxisView::set_selected_points (PointSelection& points)
847 _line->set_selected_points (points);
849 _view->set_selected_points (points);
854 AutomationTimeAxisView::clear_lines ()
857 _list_connections.drop_connections ();
861 AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
863 if (_control && line) {
864 assert(line->the_list() == _control->list());
866 _control->alist()->automation_state_changed.connect (
867 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::automation_state_changed, this), gui_context()
870 _control->alist()->InterpolationChanged.connect (
871 _list_connections, invalidator (*this), boost::bind (&AutomationTimeAxisView::interpolation_changed, this, _1), gui_context()
877 line->set_height (height - 2.5);
879 /* pick up the current state */
880 automation_state_changed ();
882 line->add_visibility (AutomationLine::Line);
886 AutomationTimeAxisView::entered()
889 _line->track_entered();
894 AutomationTimeAxisView::exited ()
897 _line->track_exited();
902 AutomationTimeAxisView::color_handler ()
910 AutomationTimeAxisView::set_state_2X (const XMLNode& node, int /*version*/)
912 if (node.name() == X_("gain") && _parameter == Evoral::Parameter (GainAutomation)) {
915 if (node.get_property (X_("shown"), shown)) {
917 _canvas_display->show (); /* FIXME: necessary? show_at? */
918 set_gui_property ("visible", shown);
921 set_gui_property ("visible", false);
929 AutomationTimeAxisView::set_state (const XMLNode&, int /*version*/)
935 AutomationTimeAxisView::what_has_visible_automation (const boost::shared_ptr<Automatable>& automatable, set<Evoral::Parameter>& visible)
937 /* this keeps "knowledge" of how we store visibility information
938 in XML private to this class.
941 assert (automatable);
943 Automatable::Controls& controls (automatable->controls());
945 for (Automatable::Controls::iterator i = controls.begin(); i != controls.end(); ++i) {
947 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (i->second);
949 if (ac && ac->alist()) {
951 const XMLNode* gui_node = ac->extra_xml ("GUI");
955 if (gui_node->get_property ("shown", shown) && shown) {
956 visible.insert (i->first);
964 /** @return true if this view has any automation data to display */
966 AutomationTimeAxisView::has_automation () const
968 return ( (_line && _line->npoints() > 0) || (_view && _view->has_automation()) );
971 list<boost::shared_ptr<AutomationLine> >
972 AutomationTimeAxisView::lines () const
974 list<boost::shared_ptr<AutomationLine> > lines;
977 lines.push_back (_line);
979 lines = _view->get_lines ();
986 AutomationTimeAxisView::state_id() const
988 if (_parameter && _stripable && _automatable == _stripable) {
989 const string parameter_str = PBD::to_string (_parameter.type()) + "/" +
990 PBD::to_string (_parameter.id()) + "/" +
991 PBD::to_string (_parameter.channel ());
993 return string("automation ") + PBD::to_string(_stripable->id()) + " " + parameter_str;
994 } else if (_automatable != _stripable && _control) {
995 return string("automation ") + _control->id().to_s();
997 error << "Automation time axis has no state ID" << endmsg;
1002 /** Given a state id string, see if it is one generated by
1003 * this class. If so, parse it into its components.
1004 * @param state_id State ID string to parse.
1005 * @param route_id Filled in with the route's ID if the state ID string is parsed.
1006 * @param has_parameter Filled in with true if the state ID has a parameter, otherwise false.
1007 * @param parameter Filled in with the state ID's parameter, if it has one.
1008 * @return true if this is a state ID generated by this class, otherwise false.
1012 AutomationTimeAxisView::parse_state_id (
1013 string const & state_id,
1015 bool & has_parameter,
1016 Evoral::Parameter & parameter)
1024 if (a != X_("automation")) {
1028 route_id = PBD::ID (b);
1031 has_parameter = false;
1035 has_parameter = true;
1038 boost::split (p, c, boost::is_any_of ("/"));
1040 assert (p.size() == 3);
1042 parameter = Evoral::Parameter (
1043 PBD::string_to<uint32_t>(p[0]), // type
1044 PBD::string_to<uint8_t>(p[2]), // channel
1045 PBD::string_to<uint32_t>(p[1]) // id
1052 AutomationTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1054 list<boost::shared_ptr<AutomationLine> > lines;
1056 lines.push_back (_line);
1058 lines = _view->get_lines ();
1061 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
1062 cut_copy_clear_one (**i, selection, op);
1067 AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& selection, CutCopyOp op)
1069 boost::shared_ptr<Evoral::ControlList> what_we_got;
1070 boost::shared_ptr<AutomationList> alist (line.the_list());
1072 XMLNode &before = alist->get_state();
1074 /* convert time selection to automation list model coordinates */
1075 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& tc = line.time_converter ();
1076 double const start = tc.from (selection.time.front().start - tc.origin_b ());
1077 double const end = tc.from (selection.time.front().end - tc.origin_b ());
1081 if (alist->cut (start, end) != 0) {
1082 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1088 if ((what_we_got = alist->cut (start, end)) != 0) {
1089 _editor.get_cut_buffer().add (what_we_got);
1090 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1094 if ((what_we_got = alist->copy (start, end)) != 0) {
1095 _editor.get_cut_buffer().add (what_we_got);
1100 if ((what_we_got = alist->cut (start, end)) != 0) {
1101 _session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
1107 for (AutomationList::iterator x = what_we_got->begin(); x != what_we_got->end(); ++x) {
1108 double when = (*x)->when;
1109 double val = (*x)->value;
1110 line.model_to_view_coord (when, val);
1117 PresentationInfo const &
1118 AutomationTimeAxisView::presentation_info () const
1120 return _stripable->presentation_info();
1123 boost::shared_ptr<Stripable>
1124 AutomationTimeAxisView::stripable () const
1130 AutomationTimeAxisView::color () const
1132 return gdk_color_from_rgb (_stripable->presentation_info().color());