Added dialog to allow adding any Midi CC track.
[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, ParamID param, 
36                                                 TimeAxisView& tv, ArdourCanvas::Group& parent, AutomationList& l)
37   
38         : AutomationLine (name, tv, parent, l),
39         _processor(proc),
40         _param(param)
41 {
42         set_verbose_cursor_uses_gain_mapping (false);
43
44         PluginInsert *pi;
45         Plugin::ParameterDescriptor desc;
46
47         if ((pi  = dynamic_cast<PluginInsert*>(&_processor)) == 0) {
48                 fatal << _("insert automation created for non-plugin") << endmsg;
49                 /*NOTREACHED*/
50         }
51
52         pi->plugin()->get_parameter_descriptor (_param, desc);
53
54         _upper = desc.upper;
55         _lower = desc.lower;
56
57         if (desc.toggled) {
58                 no_draw = true;
59                 return;
60         }
61
62         no_draw = false;
63         _range = _upper - _lower;
64
65         /* XXX set min/max for underlying curve ??? */
66 }
67
68 string
69 ProcessorAutomationLine::get_verbose_cursor_string (float fraction)
70 {
71         char buf[32];
72
73         snprintf (buf, sizeof (buf), "%.2f", _lower + (fraction * _range));
74         return buf;
75 }
76
77 void
78 ProcessorAutomationLine::view_to_model_y (double& y)
79 {
80         y = _lower + (y * _range);
81 }
82
83 void
84 ProcessorAutomationLine::model_to_view_y (double& y)
85 {
86         y = (y - _lower) / _range;
87         y = max (0.0, y);
88         y = min (y, 1.0);
89 }
90