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.

192 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. #pragma GCC diagnostic ignored "-Wunused-parameter"
  19. #define _MODULE_ "nsm-proxy-gui"
  20. #define APP_NAME "NSM Proxy"
  21. #define APP_TITLE "NSM Proxy"
  22. #include "NSM_Proxy_UI.H"
  23. #include "FL/Fl_Theme.H"
  24. #include "FL/themes.H"
  25. #include <lo/lo.h>
  26. #include <signal.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. lo_server losrv;
  31. lo_address nsmp_addr;
  32. static NSM_Proxy_UI *ui;
  33. int
  34. osc_update ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data )
  35. {
  36. printf( "Got update for %s\n", path );
  37. Fl::lock();
  38. if (!strcmp( path, "/nsm/proxy/label" ))
  39. ui->label_input->value( &argv[0]->s );
  40. else if (!strcmp( path, "/nsm/proxy/arguments" ))
  41. ui->arguments_input->value( &argv[0]->s );
  42. else if (!strcmp( path, "/nsm/proxy/executable" ))
  43. ui->executable_input->value( &argv[0]->s );
  44. else if (!strcmp( path, "/nsm/proxy/save_signal" ))
  45. {
  46. if ( argv[0]->i == SIGUSR1 )
  47. ui->save_signal_choice->value( 1 );
  48. else if ( argv[0]->i == SIGUSR2 )
  49. ui->save_signal_choice->value( 2 );
  50. else if ( argv[0]->i == SIGINT )
  51. ui->save_signal_choice->value( 3 );
  52. else
  53. ui->save_signal_choice->value( 0 );
  54. }
  55. Fl::unlock();
  56. return 0;
  57. }
  58. void
  59. init_osc ( const char *osc_port )
  60. {
  61. lo_server_thread loth = lo_server_thread_new( osc_port, NULL );
  62. losrv = lo_server_thread_get_server( loth );
  63. //error_handler );
  64. char *url = lo_server_get_url(losrv);
  65. printf("OSC: %s\n",url);
  66. free(url);
  67. /* GUI */
  68. lo_server_thread_add_method( loth, "/nsm/proxy/executable", "s", osc_update, NULL );
  69. lo_server_thread_add_method( loth, "/nsm/proxy/arguments", "s", osc_update, NULL );
  70. lo_server_thread_add_method( loth, "/nsm/proxy/label", "s", osc_update, NULL );
  71. lo_server_thread_add_method( loth, "/nsm/proxy/save_signal", "i", osc_update, NULL );
  72. lo_server_thread_start( loth );
  73. }
  74. /*****************/
  75. /* GUI Callbacks */
  76. /*****************/
  77. void
  78. handle_kill ( Fl_Widget *o, void *v )
  79. {
  80. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/kill", "" );
  81. }
  82. void
  83. handle_start ( Fl_Widget *o, void *v )
  84. {
  85. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/start", "ss",
  86. ui->executable_input->value(),
  87. ui->arguments_input->value() );
  88. }
  89. void
  90. handle_label ( Fl_Widget *o, void *v )
  91. {
  92. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/label", "s",
  93. ui->label_input->value() );
  94. }
  95. void
  96. handle_executable ( Fl_Widget *o, void *v )
  97. {
  98. ui->label_input->value( ui->executable_input->value() );
  99. }
  100. void
  101. handle_save_signal ( Fl_Widget *o, void *v )
  102. {
  103. int sig = 0;
  104. const char* picked = ui->save_signal_choice->mvalue()->label();
  105. if ( !strcmp( picked, "SIGUSR1" ) )
  106. sig = SIGUSR1;
  107. else if ( !strcmp( picked, "SIGUSR2" ) )
  108. sig = SIGUSR2;
  109. else if ( !strcmp( picked, "SIGINT" ) )
  110. sig = SIGINT;
  111. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE,"/nsm/proxy/save_signal", "i",
  112. sig );
  113. }
  114. void
  115. connect_ui ( void )
  116. {
  117. ui->executable_input->callback( handle_executable, NULL );
  118. ui->kill_button->callback( handle_kill, NULL );
  119. ui->start_button->callback( handle_start, NULL );
  120. ui->save_signal_choice->callback( handle_save_signal, NULL );
  121. ui->label_input->callback( handle_label, NULL );
  122. }
  123. int
  124. main ( int argc, char **argv )
  125. {
  126. if ( argc != 3 )
  127. {
  128. fprintf( stderr, "Usage: %s --connect-to url\n", argv[0] );
  129. return 1;
  130. }
  131. init_osc( NULL );
  132. nsmp_addr = lo_address_new_from_url( argv[2] );
  133. printf( "Connecting to nsm-proxy at: %s\n", argv[2] );
  134. ui = new NSM_Proxy_UI;
  135. Fl_Double_Window *w = ui->make_window();
  136. connect_ui();
  137. lo_send_from( nsmp_addr, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/update", "" );
  138. w->show();
  139. fl_register_themes();
  140. Fl_Theme::set();
  141. Fl::lock();
  142. Fl::run();
  143. return 0;
  144. }