2 Copyright (C) 2003 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.
20 #include <ardour/processor.h>
21 #include <ardour/session.h>
23 #include <pbd/memento_command.h>
25 #include "processor_automation_time_axis.h"
26 #include "automation_line.h"
27 #include "canvas_impl.h"
31 using namespace ARDOUR;
35 ProcessorAutomationTimeAxisView::ProcessorAutomationTimeAxisView (Session& s, boost::shared_ptr<Route> r,
36 PublicEditor& e, TimeAxisView& parent, Canvas& canvas, std::string n,
37 ParamID param, Processor& proc, string state_name)
40 AutomationTimeAxisView (s, r, e, parent, canvas, n, state_name, proc.name()),
47 _marked_for_display = false;
52 XMLNodeConstIterator iter;
54 kids = _xml_node->children ();
56 snprintf (buf, sizeof(buf), "Port_%" PRIu32, param.id());
58 for (iter = kids.begin(); iter != kids.end(); ++iter) {
59 if ((*iter)->name() == buf) {
61 XMLProperty *shown = (*iter)->property("shown_editor");
63 if (shown && shown->value() == "yes") {
64 _marked_for_display = true;
71 ProcessorAutomationTimeAxisView::~ProcessorAutomationTimeAxisView ()
76 ProcessorAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, GdkEvent* event, nframes_t when, double y)
80 canvas_display->w2i (x, y);
82 /* compute vertical fractional position */
89 y = 1.0 - (y / height);
91 /* map to model space */
94 AutomationList* alist (_processor.automation_list(_param, true));
95 string description = _("add automation event to ");
96 description += _processor.describe_parameter (_param);
98 lines.front()->view_to_model_y (y);
100 _session.begin_reversible_command (description);
101 XMLNode &before = alist->get_state();
102 alist->add (when, y);
103 XMLNode &after = alist->get_state();
104 _session.add_command(new MementoCommand<AutomationList>(*alist, &before, &after));
105 _session.commit_reversible_command ();
106 _session.set_dirty ();
111 ProcessorAutomationTimeAxisView::ensure_xml_node ()
113 if (_xml_node == 0) {
114 if ((_xml_node = _processor.extra_xml ("GUI")) == 0) {
115 _xml_node = new XMLNode ("GUI");
116 _processor.add_extra_xml (*_xml_node);
122 ProcessorAutomationTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
125 update_extra_xml_shown (true);
127 return TimeAxisView::show_at (y, nth, parent);
131 ProcessorAutomationTimeAxisView::hide ()
134 update_extra_xml_shown (false);
136 TimeAxisView::hide ();
141 ProcessorAutomationTimeAxisView::update_extra_xml_shown (bool editor_shown)
145 XMLNodeList nlist = _xml_node->children ();
146 XMLNodeConstIterator i;
147 XMLNode * port_node = 0;
149 snprintf (buf, sizeof(buf), "Port_%" PRIu32, _param.id());
151 for (i = nlist.begin(); i != nlist.end(); ++i) {
152 if ((*i)->name() == buf) {
159 port_node = new XMLNode(buf);
160 _xml_node->add_child_nocopy(*port_node);
163 port_node->add_property ("shown_editor", editor_shown ? "yes": "no");
168 ProcessorAutomationTimeAxisView::set_automation_state (AutoState state)
170 if (!ignore_state_request) {
171 _processor.automation_list (_param, true)->set_automation_state (state);