1 /***************************************************************************
2  *   Copyright (C) 2015 by Pere Ràfols Soler                               *
3  *   sapista2@gmail.com                                                    *
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                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 
21 /***************************************************************************
22 This file contains some definitions of the BassUp plugin UI
23 This plugin is inside the Sapista Plugins Bundle
24 ****************************************************************************/
25 
26 //LV2 UI headers
27 #include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
28 #include <gtkmm/main.h>
29 #include "widgets/midsidewindow.h"
30 #include <string>
31 #include "../plugins_uris.h"
32 
33 //Testing Headers TODO: comment define TESTING_EQ10Q for the final relase
34 //#define TESTING_EQ10Q
35 #ifdef TESTING_EQ10Q
36 #include <iostream>
37 using namespace std;
38 #endif
39 
instantiateMidSide_gui(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)40 static LV2UI_Handle instantiateMidSide_gui(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)
41 {
42   #ifdef TESTING_EQ10Q
43   cout<<"instantiateEq10q_gui Entring... ";
44   #endif
45 
46   bool bIsLR2MS;
47   bool bAllOk = false;
48 
49   std::string str_plugin_uri(plugin_uri);
50   if( str_plugin_uri == LR2MS_URI )
51   {
52     bIsLR2MS = true;
53     bAllOk = true;
54   }
55   if( str_plugin_uri == MS2LR_URI )
56   {
57     bIsLR2MS = false;
58     bAllOk = true;
59   }
60   if(! bAllOk)
61   {
62     return NULL;
63   }
64 
65   Gtk::Main::init_gtkmm_internals();
66   MidSideMainWindow* gui_data = new MidSideMainWindow(plugin_uri, std::string(bundle_path), bIsLR2MS);
67   gui_data->controller = controller;
68   gui_data->write_function = write_function;
69   *widget = gui_data->gobj();
70 
71   #ifdef TESTING_EQ10Q
72   cout<<" Done"<<endl;
73   #endif
74 
75   return (LV2UI_Handle)gui_data;
76 }
77 
78 
cleanupMidSide_gui(LV2UI_Handle instance)79 static void cleanupMidSide_gui(LV2UI_Handle instance)
80 {
81   #ifdef TESTING_EQ10Q
82   cout<<"cleanupEq10q_gui Entring... ";
83   #endif
84 
85   ///delete static_cast<MidSideMainWindow*>(instance);
86   MidSideMainWindow *gui = (MidSideMainWindow *)instance;
87   delete gui;
88 
89   #ifdef TESTING_EQ10Q
90   cout<<" Done"<<endl;
91   #endif
92 }
93 
portEventMidSide_gui(LV2UI_Handle ui,uint32_t port_index,uint32_t buffer_size,uint32_t format,const void * buffer)94 static void portEventMidSide_gui(LV2UI_Handle ui, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void *buffer)
95 {
96   #ifdef TESTING_EQ10Q
97   cout<<"portEventEq10q_gui Entring... "<<"Port Index = "<<port_index;
98   #endif
99 
100   MidSideMainWindow *gui = (MidSideMainWindow *)ui;
101   gui->gui_port_event(ui, port_index, buffer_size, format, buffer);
102 
103   #ifdef TESTING_EQ10Q
104   cout<<" Done"<<endl;
105   #endif
106 }
107 
108 static const LV2UI_Descriptor MidSide_guiDescriptor = {
109   MIDSIDEMAT_GUI_URI,
110   instantiateMidSide_gui,
111   cleanupMidSide_gui,
112   portEventMidSide_gui,
113   NULL
114 };
115 
116 LV2_SYMBOL_EXPORT
lv2ui_descriptor(uint32_t index)117 const LV2UI_Descriptor *lv2ui_descriptor(uint32_t index)
118 {
119   #ifdef TESTING_EQ10Q
120   cout<<"lv2ui_descriptor Entring... ";
121   #endif
122 
123     switch (index) {
124             case 0:
125                     #ifdef TESTING_EQ10Q
126                     cout<<" Done with OK result (return LV2UI_Descriptor)"<<endl;
127                     #endif
128                     return &MidSide_guiDescriptor;
129             default:
130                     #ifdef TESTING_EQ10Q
131                     cout<<" Done with NOK result (return NULL)"<<endl;
132                     #endif
133                     return NULL;
134     }
135 
136 
137 }
138