2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
20 #pragma GCC diagnostic ignored "-Wunused-parameter"
23 #define _MODULE_ "nsm-proxy-gui"
25 #define APP_NAME "NSM Proxy"
26 #define APP_TITLE "NSM Proxy"
28 #include "NSM_Proxy_UI.H"
29 #include "FL/Fl_Theme.H"
30 #include "FL/themes.H"
40 static NSM_Proxy_UI *ui;
43 osc_update ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data )
45 printf( "Got update for %s\n", path );
49 if (!strcmp( path, "/nsm/proxy/label" ))
50 ui->label_input->value( &argv[0]->s );
51 else if (!strcmp( path, "/nsm/proxy/arguments" ))
52 ui->arguments_input->value( &argv[0]->s );
53 else if (!strcmp( path, "/nsm/proxy/executable" ))
54 ui->executable_input->value( &argv[0]->s );
55 else if (!strcmp( path, "/nsm/proxy/save_signal" ))
57 if ( argv[0]->i == SIGUSR1 )
58 ui->save_signal_choice->value( 1 );
59 else if ( argv[0]->i == SIGUSR2 )
60 ui->save_signal_choice->value( 2 );
61 else if ( argv[0]->i == SIGINT )
62 ui->save_signal_choice->value( 3 );
64 ui->save_signal_choice->value( 0 );
74 init_osc ( const char *osc_port )
77 lo_server_thread loth = lo_server_thread_new( osc_port, NULL );
78 losrv = lo_server_thread_get_server( loth );
82 char *url = lo_server_get_url(losrv);
83 printf("OSC: %s\n",url);
88 lo_server_thread_add_method( loth, "/nsm/proxy/executable", "s", osc_update, NULL );
89 lo_server_thread_add_method( loth, "/nsm/proxy/arguments", "s", osc_update, NULL );
90 lo_server_thread_add_method( loth, "/nsm/proxy/label", "s", osc_update, NULL );
91 lo_server_thread_add_method( loth, "/nsm/proxy/save_signal", "i", osc_update, NULL );
93 lo_server_thread_start( loth );
101 handle_kill ( Fl_Widget *o, void *v )
103 lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/kill", "" );
107 handle_start ( Fl_Widget *o, void *v )
109 lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/start", "ss",
110 ui->executable_input->value(),
111 ui->arguments_input->value() );
115 handle_label ( Fl_Widget *o, void *v )
117 lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/label", "s",
118 ui->label_input->value() );
122 handle_executable ( Fl_Widget *o, void *v )
124 ui->label_input->value( ui->executable_input->value() );
128 handle_save_signal ( Fl_Widget *o, void *v )
132 const char* picked = ui->save_signal_choice->mvalue()->label();
134 if ( !strcmp( picked, "SIGUSR1" ) )
136 else if ( !strcmp( picked, "SIGUSR2" ) )
138 else if ( !strcmp( picked, "SIGINT" ) )
141 lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE,"/nsm/proxy/save_signal", "i",
148 ui->executable_input->callback( handle_executable, NULL );
149 ui->kill_button->callback( handle_kill, NULL );
150 ui->start_button->callback( handle_start, NULL );
151 ui->save_signal_choice->callback( handle_save_signal, NULL );
152 ui->label_input->callback( handle_label, NULL );
158 main ( int argc, char **argv )
162 fprintf( stderr, "Usage: %s --connect-to url\n", argv[0] );
168 nsmp_addr = lo_address_new_from_url( argv[2] );
170 printf( "Connecting to nsm-proxy at: %s\n", argv[2] );
172 ui = new NSM_Proxy_UI;
174 Fl_Double_Window *w = ui->make_window();
178 lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/update", "" );
182 fl_register_themes();