Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.3KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2012 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #define _GNU_SOURCE
  19. #pragma GCC diagnostic ignored "-Wunused-parameter"
  20. #define _MODULE_ "nsm-proxy-gui"
  21. #define APP_NAME "NSM Proxy"
  22. #define APP_TITLE "NSM Proxy"
  23. #include "NSM_Proxy_UI.H"
  24. #include "FL/Fl_Theme.H"
  25. #include "FL/themes.H"
  26. #include <lo/lo.h>
  27. #include <signal.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. lo_server losrv;
  32. lo_address nsmp_addr;
  33. static NSM_Proxy_UI *ui;
  34. int
  35. osc_update ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data )
  36. {
  37. printf( "Got update for %s\n", path );
  38. Fl::lock();
  39. if (!strcmp( path, "/nsm/proxy/label" ))
  40. ui->label_input->value( &argv[0]->s );
  41. else if (!strcmp( path, "/nsm/proxy/arguments" ))
  42. ui->arguments_input->value( &argv[0]->s );
  43. else if (!strcmp( path, "/nsm/proxy/executable" ))
  44. ui->executable_input->value( &argv[0]->s );
  45. else if (!strcmp( path, "/nsm/proxy/save_signal" ))
  46. {
  47. if ( argv[0]->i == SIGUSR1 )
  48. ui->save_signal_choice->value( 1 );
  49. else if ( argv[0]->i == SIGUSR2 )
  50. ui->save_signal_choice->value( 2 );
  51. else if ( argv[0]->i == SIGINT )
  52. ui->save_signal_choice->value( 3 );
  53. else
  54. ui->save_signal_choice->value( 0 );
  55. }
  56. Fl::unlock();
  57. return 0;
  58. }
  59. void
  60. init_osc ( const char *osc_port )
  61. {
  62. lo_server_thread loth = lo_server_thread_new( osc_port, NULL );
  63. losrv = lo_server_thread_get_server( loth );
  64. //error_handler );
  65. char *url = lo_server_get_url(losrv);
  66. printf("OSC: %s\n",url);
  67. free(url);
  68. /* GUI */
  69. lo_server_thread_add_method( loth, "/nsm/proxy/executable", "s", osc_update, NULL );
  70. lo_server_thread_add_method( loth, "/nsm/proxy/arguments", "s", osc_update, NULL );
  71. lo_server_thread_add_method( loth, "/nsm/proxy/label", "s", osc_update, NULL );
  72. lo_server_thread_add_method( loth, "/nsm/proxy/save_signal", "i", osc_update, NULL );
  73. lo_server_thread_start( loth );
  74. }
  75. /*****************/
  76. /* GUI Callbacks */
  77. /*****************/
  78. void
  79. handle_kill ( Fl_Widget *o, void *v )
  80. {
  81. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/kill", "" );
  82. }
  83. void
  84. handle_start ( Fl_Widget *o, void *v )
  85. {
  86. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/start", "ss",
  87. ui->executable_input->value(),
  88. ui->arguments_input->value() );
  89. }
  90. void
  91. handle_label ( Fl_Widget *o, void *v )
  92. {
  93. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/label", "s",
  94. ui->label_input->value() );
  95. }
  96. void
  97. handle_executable ( Fl_Widget *o, void *v )
  98. {
  99. ui->label_input->value( ui->executable_input->value() );
  100. }
  101. void
  102. handle_save_signal ( Fl_Widget *o, void *v )
  103. {
  104. int sig = 0;
  105. const char* picked = ui->save_signal_choice->mvalue()->label();
  106. if ( !strcmp( picked, "SIGUSR1" ) )
  107. sig = SIGUSR1;
  108. else if ( !strcmp( picked, "SIGUSR2" ) )
  109. sig = SIGUSR2;
  110. else if ( !strcmp( picked, "SIGINT" ) )
  111. sig = SIGINT;
  112. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE,"/nsm/proxy/save_signal", "i",
  113. sig );
  114. }
  115. void
  116. connect_ui ( void )
  117. {
  118. ui->executable_input->callback( handle_executable, NULL );
  119. ui->kill_button->callback( handle_kill, NULL );
  120. ui->start_button->callback( handle_start, NULL );
  121. ui->save_signal_choice->callback( handle_save_signal, NULL );
  122. ui->label_input->callback( handle_label, NULL );
  123. }
  124. int
  125. main ( int argc, char **argv )
  126. {
  127. if ( argc != 3 )
  128. {
  129. fprintf( stderr, "Usage: %s --connect-to url\n", argv[0] );
  130. return 1;
  131. }
  132. init_osc( NULL );
  133. nsmp_addr = lo_address_new_from_url( argv[2] );
  134. printf( "Connecting to nsm-proxy at: %s\n", argv[2] );
  135. ui = new NSM_Proxy_UI;
  136. Fl_Double_Window *w = ui->make_window();
  137. connect_ui();
  138. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/update", "" );
  139. w->show();
  140. fl_register_themes();
  141. Fl_Theme::set();
  142. Fl::lock();
  143. Fl::run();
  144. return 0;
  145. }