1 /*
2  * Copyright (C) 2012 Hermann Meyer, Andreas Degert, Pete Shorthose, Steve Poskitt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  * --------------------------------------------------------------------------
18  */
19 
20 
21 #include <string>
22 #include <iostream>
23 
24 #include <gtkmm.h>
25 #include "gxtuner.h"
26 #include "widget.h"
27 
28 
29 #include <lv2.h>
30 #include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
31 
32 using namespace std;
33 
34 class GxtunerGUI
35 {
36 private:
37 
38   Glib::ustring plugskin;
39   Glib::ustring addKnob;
40   Glib::ustring plug_name;
41   void set_knob(Glib::ustring knob);
42   void set_skin();
43   void set_plug_name(const char * plugin_uri);
44   GtkWidget* make_gui();
45   Widget* widget;
46 
47 public:
48 
49   static LV2UI_Handle instantiate(const LV2UI_Descriptor * descriptor,
50                                   const char * plugin_uri,
51                                   const char * bundle_path,
52                                   LV2UI_Write_Function write_function,
53                                   LV2UI_Controller controller,
54                                   LV2UI_Widget * widget,
55                                   const LV2_Feature * const * features);
56 
57   static void port_event(LV2UI_Handle ui, uint32_t port_index,
58                         uint32_t buffer_size, uint32_t format,
59                         const void *                   buffer);
60 
61   static LV2UI_Descriptor descriptors[];
62   static void cleanup(LV2UI_Handle ui);
63 
GxtunerGUI()64   GxtunerGUI () {};
~GxtunerGUI()65   ~GxtunerGUI () {};
66 } ;
67 
set_knob(Glib::ustring knob)68 void GxtunerGUI::set_knob(Glib::ustring knob)
69 {
70   addKnob =   " style 'gx_";
71   addKnob +=  plug_name;
72   addKnob +=   "_dark_skin_icons'\n"
73                " { \n"
74                "   stock['bigknob'] = {{'";
75   addKnob +=  knob;
76   addKnob +=  ".png'}}\n";
77   addKnob +=  "   stock['smallknobr'] = {{'";
78   addKnob +=  knob;
79   addKnob +=  "-middle.png'}}\n";
80   addKnob +=  "   stock['button_on'] = {{'"
81               "push-switch-on.png'}}\n"
82               "   stock['button_off'] = {{'"
83               "push-switch-off.png'}}\n"
84               " }\n"
85               "widget '*.";
86   addKnob +=  plug_name;
87   addKnob +=  "' style 'gx_";
88   addKnob +=  plug_name;
89   addKnob +=  "_dark_skin_icons' \n"
90               "class '*GxToggleImage' style'gx_";
91   addKnob +=  plug_name;
92   addKnob +=  "_dark_skin_icons' \n";
93 }
94 
set_skin()95 void GxtunerGUI::set_skin()
96 {
97   Glib::ustring toparse = "pixmap_path  ";
98   toparse +=     " '";
99   toparse +=        GX_LV2_STYLE_DIR;
100   toparse +=     "/'\n";
101   toparse +=     "style \"gx_";
102   toparse +=     plug_name;
103   toparse +=     "_dark-paintbox\"\n"
104                  " { \n"
105                  "GxPaintBox::skin-gradient = {\n"
106                  "{ 65536, 0, 0, 13107, 52428 }, \n"
107                  "{ 52428, 0, 0, 0, 52428 },\n"
108                  "{ 13107, 0, 0, 13107, 13107 }}\n"
109                  " GxPaintBox::box-gradient = {\n"
110                  "{ 0, 61, 61, 61, 62428 }, \n"
111                  "{ 22768, 80, 83, 80, 42428 }, \n"
112                  "{ 52428, 8, 8, 80, 32428 }, \n"
113                  "{ 65536, 4, 4, 4, 52428 }} \n"
114 
115                  "   base[NORMAL]     = '#000000'      \n"
116                  "    GxPaintBox::icon-set =11\n"
117                  "    stock['gxhead'] = {{'";
118   toparse +=     plugskin;
119   toparse +=     "'}}\n"
120                  " }\n";
121   toparse +=     "style 'gx_headvalue_box' \n"
122                  " { \n"
123                  "    fg[NORMAL] = '#ff9000' \n"
124                  "    fg[PRELIGHT] ='#00ffff'\n"
125                  "    base[PRELIGHT] ='#222222'\n"
126                  "    base[NORMAL] ='#000000'\n"
127                  "    font_name = 'sans  7.5' \n"
128                  " }\n";
129   toparse +=     " widget '*.valuelabel' style:highest 'gx_headvalue_box'\n";
130   toparse +=     "style 'gx_headtuner_box' \n"
131                  " { \n"
132                  "    fg[NORMAL] = '#888888' \n"
133                  "    bg[PRELIGHT] ='#262640'\n"
134                  "    font_name = 'sans  7.5' \n"
135                  " }\n";
136   toparse +=     addKnob;
137   toparse +=     " widget '*.amplabel' style:highest 'gx_headtuner_box'\n"
138                  "widget '*.";
139   toparse +=     plug_name;
140   toparse +=     "' style 'gx_";
141   toparse +=     plug_name;
142   toparse +=     "_dark-paintbox' ";
143   toparse +=     "style 'gx_switch'\n"
144                  "{\n"
145                  "xthickness = 0\n"
146                  "ythickness = 0\n"
147                  "GtkButton::inner-border = {0, 0, 0, 0}\n"
148                  "GtkButton::default-border = {0, 0, 0, 0}\n"
149                  "GtkButton::focus-line-width = 0\n"
150                  "GtkButton::focus-padding = 0\n"
151                  "GtkButton::interior-focus = 0\n"
152                  "GtkButton::child-displacement-x = 0\n"
153                  "GtkButton::child-displacement-y = 0\n"
154                  " }\n"
155                  "widget '*.";
156   toparse +=     plug_name;
157   toparse +=     "' style:highest 'gx_switch'\n";
158   toparse +=     " style 'gx_selector_";
159   toparse +=     plug_name;
160   toparse +=     "'\n"
161                  " {\n"
162                  " fg[NORMAL] = '#888888'\n"
163                  " GtkRange::trough-border = 2\n"
164                  " GtkRange::stepper-size = 8\n"
165                  " GtkRange::stepper-spacing = 2\n"
166                  " GxRegler::value-border = { 2, 0, 0, 0 }\n"
167                  " font_name = 'sans 7.5'\n"
168                  " xthickness = 10\n"
169                  " ythickness = 1\n"
170                  " }\n"
171                  "widget '*.";
172   toparse +=     plug_name;
173   toparse +=     "' style:highest 'gx_selector_";
174   toparse +=     plug_name;
175   toparse +=     "'\n";
176   toparse +=     "style 'gx_fastmeter'\n"
177                  " {\n"
178                  "   xthickness = 0\n"
179                  "   ythickness = 0\n"
180                  "   base[NORMAL]     = '#000000'      \n"
181                  "   GxFastMeter::clr-bottom = '#003808'\n"
182                  "   GxFastMeter::clr-middle = '#00ff00'\n"
183                  "   GxFastMeter::clr-top    = '#ff0000'\n"
184                  "   GxFastMeter::over       = '#ff0000'\n"
185                  " }\n"
186                  " class '*GxFastMeter' style:highest 'gx_fastmeter'\n";
187   toparse +=     " style \"gx_";
188   toparse +=     plug_name;
189   toparse +=     "_slevel\"\n"
190                  "{\n"
191                  "stock['levelslider'] = {{'simplelevelslider.png'}}\n"
192                  "GxLevelSlider::slider-width = 3\n"
193                  "GxRegler::show-value = 0\n"
194                  "}\n"
195                  "widget '*.";
196   toparse +=     plug_name;
197   toparse +=     "' style 'gx_";
198   toparse +=     plug_name;
199   toparse +=     "_slevel' ";
200   toparse +=     "style 'guitarix_hslider' {\n"
201                  "    GxHSlider::slider-width = 36\n"
202                  "}\n"
203                  "widget_class '*GxHSlider' style:highest 'guitarix_hslider'\n";
204 
205   toparse +=     "style 'guitarix_default' {\n"
206 
207                  "    GxPaintBox::bevel                  = 0.11\n"
208                  "    GxPaintBox::inverse                = 0\n"
209                  "    GxPaintBox::alternate-box          = { 0, 0, 15, 15 }\n"
210 
211                  "    fg[NORMAL]              = '#999999'\n"
212                  "    fg[ACTIVE]              = { 1.0, 1.0, 1.0 }\n"
213                  "    fg[PRELIGHT]            = { 1.0, 1.0, 1.0 }\n"
214                  "    fg[INSENSITIVE]         = { 0.5, 0.5, 0.5 }\n"
215                  "    fg[SELECTED]            = { 0.9, 0.9, 0.9 }\n"
216 
217                  "    bg[NORMAL]              = { 0.13, 0.13, 0.13 }\n"
218                  "    bg[ACTIVE]              = { 0.0, 0.0, 0.0 }\n"
219                  "    bg[PRELIGHT]            = { 0.25, 0.25, 0.25 }\n"
220                  "    bg[INSENSITIVE]         = { 0.2, 0.2, 0.2 }\n"
221                  "    bg[SELECTED]            = { 0.25, 0.25, 0.25 }\n"
222 
223                  "    text[NORMAL]            = { 0.9, 0.9, 0.9 }\n"
224                  "    text[ACTIVE]            = '#999999'\n"
225                  "    text[PRELIGHT]          = { 1.0, 1.0, 1.0 }\n"
226                  "    text[INSENSITIVE]       = { 0.5, 0.5, 0.5 }\n"
227                  "    text[SELECTED]          = { 1.0, 1.0, 1.0 }\n"
228 
229                  "    base[NORMAL]            = { 0.0, 0.0, 0.0 }\n"
230                  "    base[ACTIVE]            = { 0.18, 0.18, 0.18 }\n"
231                  "    base[PRELIGHT]          = { 0.1, 0.1, 0.1 }\n"
232                  "    base[INSENSITIVE]       = { 0.2, 0.2, 0.2 }\n"
233                  "    base[SELECTED]          = { 0.8, 0.18, 0.18 }\n"
234                  "}\n"
235                  "widget '*.";
236   toparse +=     plug_name;
237   toparse +=     "' style:highest 'guitarix_default'\n";
238   toparse +=     " style 'gx_selector'\n"
239                  " {\n"
240                  " fg[NORMAL]     = '#999999'   \n"
241                  " fg[PRELIGHT]   = '#ffffff'    \n"
242                  " bg[NORMAL]     = '#2f2f2f'     \n"
243                  " bg[PRELIGHT]   = '#2f2f2f'      \n"
244                  " base[NORMAL]   = { 0.05, 0.05, 0.05 } \n"
245                  " base[PRELIGHT] = '#000000'      \n"
246                  " text[NORMAL]   = '#999999'     \n"
247                  " text[PRELIGHT] = '#ffffff'    \n"
248                  " GxRegler::value-border      = { 4, 4, 2, 2 } \n"
249                  " GxRegler::border-radius     = 6\n"
250                  " GxRegler::bevel             = 0.12\n"
251                  " GtkRange::trough-border = 2\n"
252                  " GtkRange::stepper-size = 8\n"
253                  " GtkRange::stepper-spacing = 2\n"
254                  " GxRegler::value-border = { 2, 0, 0, 0 }\n"
255                  " font_name = 'sans bold 7.5'\n"
256                  " xthickness = 8\n"
257                  " ythickness = 4\n"
258                  " }\n"
259                  "class '*GxSelector' style:highest 'gx_selector'\n";
260 
261   toparse +=     "style 'gx_notes_style'\n"
262                  "{\n"
263 
264                  "  bg[ACTIVE] = '#000000'\n"
265                  "  bg[NORMAL] = '#49495a'\n"
266                  "  bg[PRELIGHT] ='#262640'\n"
267 
268                  "  fg[NORMAL] = '#f1eded'\n"
269                  "  fg[ACTIVE] = '#c5c5c5'\n"
270                  "  fg[PRELIGHT] = '#ede9e9'\n"
271                  "}\n"
272                  "widget_class '*GtkToggleButton*' style:highest 'gx_notes_style'\n";
273 
274 
275   gtk_rc_parse_string (toparse.c_str());
276 }
277 
set_plug_name(const char * plugin_uri)278 void GxtunerGUI::set_plug_name(const char * plugin_uri)
279 {
280   addKnob = "";
281 
282   if (strcmp("http://guitarix.sourceforge.net/plugins/gxtuner#tuner", plugin_uri) == 0)
283     {
284       plugskin = "metalamp.png";
285       plug_name = "gxtuner";
286       set_knob("sn-knob");
287     }
288   else
289     {
290       plugskin = "preampmono.png";
291       plug_name = "gxtuner";
292     }
293 }
294 
make_gui()295 GtkWidget* GxtunerGUI::make_gui()
296 {
297   // init the gxwmm library
298   Gxw::init();
299   set_skin();
300   GtkWidget* container = gtk_vbox_new(FALSE, 0);
301   widget = new Widget(plug_name);
302   GtkWidget* cWidget = GTK_WIDGET(widget->gobj());
303   gtk_container_add(GTK_CONTAINER(container), cWidget );
304 
305   return container;
306 }
307 
308 
instantiate(const LV2UI_Descriptor * descriptor,const char * plugin_uri,const char * bundle_path,LV2UI_Write_Function write_function,LV2UI_Controller controller,LV2UI_Widget * widget,const LV2_Feature * const * features)309 LV2UI_Handle GxtunerGUI::instantiate(const LV2UI_Descriptor * descriptor,
310                                 const char * plugin_uri,
311                                 const char * bundle_path,
312                                 LV2UI_Write_Function write_function,
313                                 LV2UI_Controller controller,
314                                 LV2UI_Widget * widget,
315                                 const LV2_Feature * const * features)
316 {
317   GxtunerGUI* self = new GxtunerGUI();
318   if (self == NULL) return NULL;
319   self->set_plug_name(plugin_uri);
320   *widget = (LV2UI_Widget)self->make_gui();
321   self->widget->controller = controller;
322   self->widget->write_function = write_function;
323   return (LV2UI_Handle)self;
324 }
325 
cleanup(LV2UI_Handle ui)326 void GxtunerGUI::cleanup(LV2UI_Handle ui)
327 {
328   GxtunerGUI *pluginGui = static_cast<GxtunerGUI*>(ui);
329   delete pluginGui->widget;
330   delete pluginGui;
331 }
332 
port_event(LV2UI_Handle ui,uint32_t port_index,uint32_t buffer_size,uint32_t format,const void * buffer)333 void GxtunerGUI::port_event(LV2UI_Handle ui,
334                        uint32_t port_index,
335                        uint32_t buffer_size,
336                        uint32_t format,
337                        const void * buffer)
338 {
339   GxtunerGUI *self = static_cast<GxtunerGUI*>(ui);
340   self->widget->set_value_static( port_index, buffer_size, format, buffer, self->widget);
341   return;
342 }
343 
344 LV2UI_Descriptor GxtunerGUI::descriptors[] =
345 {
346   {
347     GXPLUGIN_UI_URI,
348     GxtunerGUI::instantiate,
349     GxtunerGUI::cleanup,
350     GxtunerGUI::port_event,
351     NULL
352   }
353 };
354 
lv2ui_descriptor(uint32_t index)355 const LV2UI_Descriptor * lv2ui_descriptor(uint32_t index)
356 {
357   //printf("lv2ui_descriptor(%u) called\n", (uint32_t)index);
358   if (index >= sizeof(GxtunerGUI::descriptors) /
359                sizeof(GxtunerGUI::descriptors[0]))
360     {
361       return NULL;
362     }
363   return GxtunerGUI::descriptors + index;
364 }
365 
366