89b6fb4f2a3a3bb32bac7c47193591aedf89d700
[ardour.git] / gtk2_ardour / redirect_automation_line.cc
1 /*
2     Copyright (C) 2002-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 */
19
20 #include "public_editor.h"
21 #include "redirect_automation_line.h"
22 #include "audio_time_axis.h"
23 #include "utils.h"
24
25 #include <ardour/session.h>
26 #include <ardour/ladspa_plugin.h>
27 #include <ardour/plugin_insert.h>
28 #include <ardour/curve.h>
29
30 #include "i18n.h"
31
32 using namespace std;
33 using namespace ARDOUR;
34 using namespace PBD;
35
36 RedirectAutomationLine::RedirectAutomationLine (const string & name, Insert& i, uint32_t port, Session& s,
37                                                 
38                                                 TimeAxisView& tv, ArdourCanvas::Group& parent,
39                                                 
40                                                 AutomationList& l)
41   
42         : AutomationLine (name, tv, parent, l),
43           session (s),
44           _insert (i),
45           _port (port)
46 {
47         set_verbose_cursor_uses_gain_mapping (false);
48
49         PluginInsert *pi;
50         Plugin::ParameterDescriptor desc;
51
52         if ((pi  = dynamic_cast<PluginInsert*>(&_insert)) == 0) {
53                 fatal << _("insert automation created for non-plugin") << endmsg;
54                 /*NOTREACHED*/
55         }
56
57         pi->plugin()->get_parameter_descriptor (_port, desc);
58
59         upper = desc.upper;
60         lower = desc.lower;
61
62         if (desc.toggled) {
63                 no_draw = true;
64                 return;
65         }
66
67         no_draw = false;
68         range = upper - lower;
69
70         /* XXX set min/max for underlying curve ??? */
71 }
72
73 string
74 RedirectAutomationLine::get_verbose_cursor_string (float fraction)
75 {
76         char buf[32];
77
78         snprintf (buf, sizeof (buf), "%.2f", lower + (fraction * range));
79         return buf;
80 }
81
82 void
83 RedirectAutomationLine::view_to_model_y (double& y)
84 {
85         y = lower + (y * range);
86 }
87
88 void
89 RedirectAutomationLine::model_to_view_y (double& y)
90 {
91         y = (y - lower) / range;
92         y = max (0.0, y);
93         y = min (y, 1.0);
94 }
95