Fix CC interpolation (i.e. output a maximum reslution stream of CC for a line segment).
[ardour.git] / gtk2_ardour / lv2_plugin_ui.cc
1 /*
2     Copyright (C) 2008 Paul Davis 
3     Author: Dave Robillard
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include <ardour/processor.h>
22 #include <ardour/lv2_plugin.h>
23
24 #include "lv2_plugin_ui.h"
25
26 using namespace Gtk;
27 using namespace ARDOUR;
28 using namespace PBD;
29
30 void
31 LV2PluginUI::lv2_ui_write(LV2UI_Controller controller,
32              uint32_t         port_index,
33              uint32_t         buffer_size,
34              uint32_t         format,
35              const void*      buffer)
36 {
37         LV2PluginUI* me = (LV2PluginUI*)controller;
38         if (*(float*)buffer != me->_values[port_index])
39                 me->_lv2->set_parameter(port_index, *(float*)buffer);
40 }
41
42 void
43 LV2PluginUI::parameter_changed (uint32_t port_index, float val)
44 {
45         if (val != _values[port_index]) {
46                 const LV2UI_Descriptor* ui_desc = slv2_ui_instance_get_descriptor(_inst);
47                 LV2UI_Handle ui_handle = slv2_ui_instance_get_handle(_inst);
48                 if (ui_desc->port_event)
49                         ui_desc->port_event(ui_handle, port_index, 4, 0, &val);
50                 _values[port_index] = val;
51         }
52 }
53
54 LV2PluginUI::LV2PluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<LV2Plugin> lv2p)
55         : PlugUIBase (pi)
56         , _lv2(lv2p)
57 {
58         _inst = slv2_ui_instantiate(
59                         _lv2->slv2_plugin(), _lv2->slv2_ui(), LV2PluginUI::lv2_ui_write, this,
60                         _lv2->features());
61                         
62         GtkWidget* c_widget = (GtkWidget*)slv2_ui_instance_get_widget(_inst);
63         _gui_widget = Glib::wrap(c_widget);
64         _gui_widget->show_all();
65         pack_start(*_gui_widget, true, true);
66         
67         uint32_t num_ports = slv2_plugin_get_num_ports(lv2p->slv2_plugin());
68         _values = new float[num_ports];
69         for (uint32_t i = 0; i < num_ports; ++i) {
70                 bool ok;
71                 _values[i] = lv2p->nth_parameter(i, ok);
72                 if (ok)
73                         lv2_ui_write(this, i, 4, /* FIXME: format */0, &_values[i]);
74         }
75                 
76         _lv2->ParameterChanged.connect(mem_fun(*this, &LV2PluginUI::parameter_changed));
77 }
78
79 LV2PluginUI::~LV2PluginUI ()
80 {
81         delete[] _values;
82         // plugin destructor destroys the GUI
83 }
84
85 int
86 LV2PluginUI::get_preferred_height ()
87 {
88         Gtk::Requisition r = size_request();
89         return r.height;
90 }
91
92 int
93 LV2PluginUI::get_preferred_width ()
94 {
95         Gtk::Requisition r = size_request();
96         return r.width;
97 }
98
99 int
100 LV2PluginUI::package (Gtk::Window& win)
101 {
102         /* forward configure events to plugin window */
103         win.signal_configure_event().connect (mem_fun (*this, &LV2PluginUI::configure_handler));
104         return 0;
105 }
106
107 bool
108 LV2PluginUI::configure_handler (GdkEventConfigure* ev)
109 {
110         cout << "CONFIGURE" << endl;
111         return false;
112 }
113