fixes for destructive track offsets of various kinds; move from jack_nframes_t -...
[ardour.git] / gtk2_ardour / pan_automation_time_axis.cc
1 /*
2     Copyright (C) 2003 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <ardour/curve.h>
22 #include <ardour/route.h>
23 #include <ardour/panner.h>
24
25 #include <gtkmm2ext/popup.h>
26 #include <pbd/memento_command.h>
27
28 #include "pan_automation_time_axis.h"
29 #include "automation_line.h"
30 #include "canvas_impl.h"
31 #include "route_ui.h"
32
33 #include "i18n.h"
34
35 using namespace ARDOUR;
36 using namespace PBD;
37 using namespace Gtk;
38
39 PanAutomationTimeAxisView::PanAutomationTimeAxisView (Session& s, boost::shared_ptr<Route> r, PublicEditor& e, 
40                                                       TimeAxisView& parent, Canvas& canvas, std::string n)
41
42         : AxisView (s),
43           AutomationTimeAxisView (s, r, e, parent, canvas, n, X_("pan"), "")
44 {
45         multiline_selector.set_name ("PanAutomationLineSelector");
46         
47         controls_table.attach (multiline_selector, 1, 5, 1, 2, Gtk::EXPAND, Gtk::EXPAND);
48 }
49
50 PanAutomationTimeAxisView::~PanAutomationTimeAxisView ()
51 {
52 }
53
54 void
55 PanAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, GdkEvent* event, nframes_t when, double y)
56 {
57         if (lines.empty()) {
58                 /* no data, possibly caused by no outputs/inputs */
59                 return;
60         }
61
62         int line_index = 0;
63
64         if (lines.size() > 1) {
65                 line_index = multiline_selector.get_active_row_number();
66
67                 if (line_index < 0 || line_index >= (int)lines.size()) {
68                         Gtkmm2ext::PopUp* msg = new Gtkmm2ext::PopUp (Gtk::WIN_POS_MOUSE, 5000, true);
69                 
70                         msg->set_text (_("You need to select which line to edit"));
71                         msg->touch ();
72
73                         return;
74                 }
75         }
76
77         double x = 0;
78
79         canvas_display->w2i (x, y);
80
81         /* compute vertical fractional position */
82
83         y = 1.0 - (y / height);
84
85         /* map using line */
86
87         lines.front()->view_to_model_y (y);
88
89         AutomationList& alist (lines[line_index]->the_list());
90
91         _session.begin_reversible_command (_("add pan automation event"));
92         XMLNode &before = alist.get_state();
93         alist.add (when, y);
94         XMLNode &after = alist.get_state();
95         _session.add_command(new MementoCommand<AutomationList>(alist, &before, &after));
96         _session.commit_reversible_command ();
97         _session.set_dirty ();
98 }
99
100 void
101 PanAutomationTimeAxisView::clear_lines ()
102 {
103         AutomationTimeAxisView::clear_lines();
104         multiline_selector.clear();
105 }
106
107 void
108 PanAutomationTimeAxisView::add_line (AutomationLine& line)
109 {
110         char buf[32];
111         snprintf(buf,32,"Line %zu",lines.size()+1);
112         multiline_selector.append_text(buf);
113
114         if (lines.empty()) {
115                 multiline_selector.set_active(0);
116         }
117
118         if (lines.size() + 1 > 1 && (height_style != Small && height_style != Smaller)) {
119                 multiline_selector.show();
120         } else {
121                 multiline_selector.hide();
122
123         }
124
125         AutomationTimeAxisView::add_line(line);
126 }
127
128 void
129 PanAutomationTimeAxisView::set_height (TimeAxisView::TrackHeight th)
130 {
131         AutomationTimeAxisView::set_height(th);
132
133         switch (th) {
134                 case Largest:
135                 case Large:
136                 case Larger:
137                 case Normal:
138                         if (lines.size() > 1) {
139                                 multiline_selector.show();
140                                 break;
141                         } 
142                 default:
143                         multiline_selector.hide();
144         }
145 }
146
147 void
148 PanAutomationTimeAxisView::set_automation_state (AutoState state)
149 {
150         if (!ignore_state_request) {
151                 route->panner().set_automation_state (state);
152         }
153 }