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.

263 lines
6.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 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. #include "const.h"
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <FL/Fl.H>
  24. #include <FL/Fl_Double_Window.H>
  25. #include <FL/Fl_Scroll.H>
  26. #include <FL/Fl_Tooltip.H>
  27. #include <FL/fl_ask.H>
  28. #include <FL/Fl_Shared_Image.H>
  29. #include <FL/Fl_Pack.H>
  30. #include <FL/Boxtypes.H>
  31. #include "Thread.H"
  32. #include "debug.h"
  33. #include "Mixer.H"
  34. #include "Project.H"
  35. #include "Loggable.H"
  36. /* for registration */
  37. #include "Module.H"
  38. #include "Gain_Module.H"
  39. #include "Plugin_Module.H"
  40. #include "JACK_Module.H"
  41. #include "Meter_Module.H"
  42. #include "Meter_Indicator_Module.H"
  43. #include "Controller_Module.H"
  44. #include "Mono_Pan_Module.H"
  45. #include "Chain.H"
  46. #include "Mixer_Strip.H"
  47. #include "NSM.H"
  48. #include <signal.h>
  49. /* TODO: put these in a header */
  50. #define USER_CONFIG_DIR ".non-mixer/"
  51. const double NSM_CHECK_INTERVAL = 0.25f;
  52. char *user_config_dir;
  53. Mixer *mixer;
  54. NSM_Client *nsm;
  55. char *instance_name;
  56. #include <errno.h>
  57. static int
  58. ensure_dirs ( void )
  59. {
  60. asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
  61. int r = mkdir( user_config_dir, 0777 );
  62. return r == 0 || errno == EEXIST;
  63. }
  64. #include <signal.h>
  65. static void cb_main ( Fl_Double_Window *o, void *)
  66. {
  67. if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape )
  68. return;
  69. mixer->command_quit();
  70. }
  71. void
  72. check_nsm ( void * v )
  73. {
  74. nsm->check();
  75. Fl::repeat_timeout( NSM_CHECK_INTERVAL, check_nsm, v );
  76. }
  77. static int got_sigterm = 0;
  78. void
  79. sigterm_handler ( int )
  80. {
  81. got_sigterm = 1;
  82. Fl::awake();
  83. }
  84. void
  85. check_sigterm ( void * )
  86. {
  87. if ( got_sigterm )
  88. {
  89. MESSAGE( "Got SIGTERM, quitting..." );
  90. mixer->command_quit();
  91. }
  92. }
  93. int
  94. main ( int argc, char **argv )
  95. {
  96. Thread::init();
  97. Thread thread( "UI" );
  98. thread.set();
  99. ensure_dirs();
  100. signal( SIGTERM, sigterm_handler );
  101. Fl_Tooltip::color( FL_BLACK );
  102. Fl_Tooltip::textcolor( FL_YELLOW );
  103. Fl_Tooltip::size( 14 );
  104. Fl_Tooltip::hoverdelay( 0.1f );
  105. Fl::visible_focus( 0 );
  106. fl_register_images();
  107. LOG_REGISTER_CREATE( Mixer_Strip );
  108. LOG_REGISTER_CREATE( Chain );
  109. LOG_REGISTER_CREATE( Plugin_Module );
  110. LOG_REGISTER_CREATE( Gain_Module );
  111. LOG_REGISTER_CREATE( Meter_Module );
  112. LOG_REGISTER_CREATE( JACK_Module );
  113. LOG_REGISTER_CREATE( Mono_Pan_Module );
  114. LOG_REGISTER_CREATE( Meter_Indicator_Module );
  115. LOG_REGISTER_CREATE( Controller_Module );
  116. init_boxtypes();
  117. signal( SIGPIPE, SIG_IGN );
  118. Fl::get_system_colors();
  119. Fl::scheme( "plastic" );
  120. Fl::lock();
  121. Plugin_Module::spawn_discover_thread();
  122. Fl_Double_Window *main_window;
  123. {
  124. Fl_Double_Window *o = main_window = new Fl_Double_Window( 800, 600, "Non-DAW : Mixer" );
  125. {
  126. main_window->xclass( APP_NAME );
  127. Fl_Widget *o = mixer = new Mixer( 0, 0, main_window->w(), main_window->h(), NULL );
  128. Fl_Group::current()->resizable(o);
  129. }
  130. o->end();
  131. o->size_range( main_window->w(), mixer->min_h(), 0, 0 );
  132. o->callback( (Fl_Callback*)cb_main, main_window );
  133. o->show( argc, argv );
  134. // o->show();
  135. }
  136. const char *osc_port = NULL;
  137. nsm = new NSM_Client;
  138. instance_name = strdup( APP_NAME );
  139. {
  140. int r = argc - 1;
  141. int i = 1;
  142. for ( ; i < argc; ++i, --r )
  143. {
  144. if ( !strcmp( argv[i], "--instance" ) )
  145. {
  146. if ( r > 1 )
  147. {
  148. MESSAGE( "Using instance name \"%s\"", argv[i+1] );
  149. instance_name = strdup( argv[i+1] );
  150. --r;
  151. ++i;
  152. }
  153. else
  154. {
  155. FATAL( "Missing instance name" );
  156. }
  157. }
  158. else if ( !strcmp( argv[i], "--osc-port" ) )
  159. {
  160. if ( r > 1 )
  161. {
  162. MESSAGE( "Using OSC port \"%s\"", argv[i+1] );
  163. osc_port = argv[i+1];
  164. --r;
  165. ++i;
  166. }
  167. else
  168. {
  169. FATAL( "Missing OSC port" );
  170. }
  171. }
  172. else if ( !strncmp( argv[i], "--", 2 ) )
  173. {
  174. WARNING( "Unrecognized option: %s", argv[i] );
  175. }
  176. else
  177. break;
  178. }
  179. mixer->init_osc( osc_port );
  180. char *nsm_url = getenv( "NSM_URL" );
  181. if ( nsm_url )
  182. {
  183. if ( ! nsm->init() )
  184. {
  185. nsm->announce( nsm_url, APP_NAME, ":switch:dirty:", argv[0] );
  186. // poll so we can keep OSC handlers running in the GUI thread and avoid extra sync
  187. Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL );
  188. }
  189. }
  190. else
  191. {
  192. if ( r >= 1 )
  193. {
  194. MESSAGE( "Loading \"%s\"", argv[i] );
  195. if ( ! mixer->command_load( argv[i] ) )
  196. {
  197. fl_alert( "Error opening project specified on commandline" );
  198. }
  199. }
  200. }
  201. }
  202. Fl::add_check( check_sigterm );
  203. Fl::run();
  204. delete main_window;
  205. main_window = NULL;
  206. MESSAGE( "Your fun is over" );
  207. }