00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef DSSIUICLIENT_HPP
00024 #define DSSIUICLIENT_HPP
00025
00026 #include <queue>
00027 #include <string>
00028 #include <utility>
00029 #include <vector>
00030
00031 #include <glibmm.h>
00032 #include <gtkmm.h>
00033 #include <lo/lo.h>
00034 #include <sigc++/sigc++.h>
00035
00036
00037 using namespace Glib;
00038 using namespace Gtk;
00039 using namespace sigc;
00040 using namespace std;
00041
00042
00106 class DSSIUIClient {
00107 public:
00108
00118 DSSIUIClient(int argc, char** argv);
00119
00123 ~DSSIUIClient();
00124
00125
00128 bool is_valid() const;
00129
00131 const string& get_identifier() const;
00132
00133
00134
00137
00138
00139
00140
00145 void connect_adjustment(Adjustment* adj, int port);
00146
00147
00148
00149
00150
00151
00154 void send_control(int port, float value);
00155
00157 void send_program(int bank, int program);
00158
00163 void send_update_request();
00164
00166 void send_configure(const string& key, const string& value);
00167
00170 void send_midi(const char event[4]);
00171
00175 void send_exiting();
00176
00177
00178
00179
00182 signal<void, int, float> control_received;
00183
00186 signal<void, int, int> program_received;
00187
00190 signal<void, const string, const string> configure_received;
00191
00194 Dispatcher show_received;
00195
00197 Dispatcher hide_received;
00198
00202 Dispatcher quit_received;
00203
00204
00205
00206
00222 void* allocate_shared_memory(int bytes);
00223
00229 template <class T> T* create_shared_object() {
00230 T* ptr = reinterpret_cast<T*>(allocate_shared_memory(sizeof(T)));
00231 if (ptr)
00232 new (ptr) T();
00233 return ptr;
00234 }
00235
00237 signal<void> plugin_attached;
00238
00240 bool plugin_has_attached();
00241
00242 private:
00243
00244
00245 void update_adjustments(int port, float value);
00246
00247
00248 static int control_handler(const char *path, const char *types,
00249 lo_arg **argv, int argc,
00250 void *data, void *user_data);
00251 static int program_handler(const char *path, const char *types,
00252 lo_arg **argv, int argc,
00253 void *data, void *user_data);
00254 static int configure_handler(const char *path, const char *types,
00255 lo_arg **argv, int argc,
00256 void *data, void *user_data);
00257 static int show_handler(const char *path, const char *types,
00258 lo_arg **argv, int argc,
00259 void *data, void *user_data);
00260 static int hide_handler(const char *path, const char *types,
00261 lo_arg **argv, int argc,
00262 void *data, void *user_data);
00263 static int quit_handler(const char *path, const char *types,
00264 lo_arg **argv, int argc,
00265 void *data, void *user_data);
00266
00267
00268
00269
00270 Dispatcher m_control_dispatcher;
00271 queue<pair<int, float> > m_control_queue;
00272 void control_receiver() {
00273 int port = m_control_queue.front().first;
00274 float value = m_control_queue.front().second;
00275 m_control_queue.pop();
00276 if (unsigned(port) < m_adjustments.size() && m_adjustments[port] != NULL)
00277 m_adjustments[port]->set_value(value);
00278 control_received(port, value);
00279 }
00280 Dispatcher m_program_dispatcher;
00281 queue<pair<int, int> > m_program_queue;
00282 void program_receiver() {
00283
00284
00285
00286
00287 m_blocking = true;
00288 int bank = m_program_queue.front().first;
00289 int program = m_program_queue.front().second;
00290 m_program_queue.pop();
00291 program_received(bank, program);
00292 m_blocking = false;
00293 }
00294 Dispatcher m_configure_dispatcher;
00295 queue<pair<string, string> > m_configure_queue;
00296 void configure_receiver() {
00297 string key = m_configure_queue.front().first;
00298 string value = m_configure_queue.front().second;
00299 m_configure_queue.pop();
00300 configure_received(key, value);
00301 }
00302
00303 bool check_shared_memory();
00304
00305 lo_address m_plugin_address;
00306 string m_plugin_path;
00307 lo_server_thread m_server_thread;
00308 string m_shm_key;
00309 char* m_plugin_flag;
00310
00311 bool m_valid;
00312 string m_identifier;
00313
00314 vector<Adjustment*> m_adjustments;
00315 bool m_blocking;
00316 };
00317
00318
00319 #endif
00320