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