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.

299 lines
7.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 <getopt.h>
  24. #include <FL/Fl.H>
  25. #include <FL/Fl_Double_Window.H>
  26. #include <FL/Fl_Scroll.H>
  27. #include <FL/Fl_Tooltip.H>
  28. #include <FL/fl_ask.H>
  29. #include <FL/Fl_Shared_Image.H>
  30. #include <FL/Fl_Pack.H>
  31. #include <FL/Crystal_Boxtypes.H>
  32. #include <FL/Gleam_Boxtypes.H>
  33. #include "Thread.H"
  34. #include "debug.h"
  35. #include "Mixer.H"
  36. #include "Project.H"
  37. #include "Loggable.H"
  38. /* for registration */
  39. #include "Module.H"
  40. #include "Gain_Module.H"
  41. #include "Plugin_Module.H"
  42. #include "JACK_Module.H"
  43. #include "Meter_Module.H"
  44. #include "Meter_Indicator_Module.H"
  45. #include "Controller_Module.H"
  46. #include "Mono_Pan_Module.H"
  47. #include "Chain.H"
  48. #include "Mixer_Strip.H"
  49. #include "NSM.H"
  50. #include <signal.h>
  51. #ifdef HAVE_XPM
  52. #include "FL/Fl.H"
  53. #include "FL/x.H"
  54. #include <X11/xpm.h>
  55. #include "../icons/icon-16x16.xpm"
  56. #endif
  57. /* TODO: put these in a header */
  58. #define USER_CONFIG_DIR ".non-mixer/"
  59. const double NSM_CHECK_INTERVAL = 0.25f;
  60. const char COPYRIGHT[] = "Copyright (c) 2008-2012 Jonathan Moore Liles";
  61. char *user_config_dir;
  62. Mixer *mixer;
  63. NSM_Client *nsm;
  64. char *instance_name;
  65. #include <errno.h>
  66. static int
  67. ensure_dirs ( void )
  68. {
  69. asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
  70. int r = mkdir( user_config_dir, 0777 );
  71. return r == 0 || errno == EEXIST;
  72. }
  73. #include <signal.h>
  74. static void cb_main ( Fl_Double_Window *, void *)
  75. {
  76. if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape )
  77. return;
  78. mixer->command_quit();
  79. }
  80. void
  81. check_nsm ( void * v )
  82. {
  83. nsm->check();
  84. Fl::repeat_timeout( NSM_CHECK_INTERVAL, check_nsm, v );
  85. }
  86. static int got_sigterm = 0;
  87. void
  88. sigterm_handler ( int )
  89. {
  90. got_sigterm = 1;
  91. Fl::awake();
  92. }
  93. void
  94. check_sigterm ( void * )
  95. {
  96. if ( got_sigterm )
  97. {
  98. MESSAGE( "Got SIGTERM, quitting..." );
  99. mixer->quit();
  100. }
  101. }
  102. int
  103. main ( int argc, char **argv )
  104. {
  105. printf( "%s %s %s -- %s\n", APP_TITLE, VERSION, "", COPYRIGHT );
  106. if ( ! Fl::visual( FL_DOUBLE | FL_RGB ) )
  107. {
  108. WARNING( "Xdbe not supported, FLTK will fake double buffering." );
  109. }
  110. #ifdef HAVE_XPM
  111. fl_open_display();
  112. Pixmap p, mask;
  113. XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display),
  114. (char**)icon_16x16, &p, &mask, NULL);
  115. #endif
  116. Thread::init();
  117. Thread thread( "UI" );
  118. thread.set();
  119. ensure_dirs();
  120. signal( SIGTERM, sigterm_handler );
  121. signal( SIGHUP, sigterm_handler );
  122. signal( SIGINT, sigterm_handler );
  123. Fl_Tooltip::color( FL_BLACK );
  124. Fl_Tooltip::textcolor( FL_YELLOW );
  125. Fl_Tooltip::size( 14 );
  126. Fl_Tooltip::hoverdelay( 0.1f );
  127. Fl::visible_focus( 0 );
  128. fl_register_images();
  129. LOG_REGISTER_CREATE( Mixer_Strip );
  130. LOG_REGISTER_CREATE( Chain );
  131. LOG_REGISTER_CREATE( Plugin_Module );
  132. LOG_REGISTER_CREATE( Gain_Module );
  133. LOG_REGISTER_CREATE( Meter_Module );
  134. LOG_REGISTER_CREATE( JACK_Module );
  135. LOG_REGISTER_CREATE( Mono_Pan_Module );
  136. LOG_REGISTER_CREATE( Meter_Indicator_Module );
  137. LOG_REGISTER_CREATE( Controller_Module );
  138. init_crystal_boxtypes();
  139. init_gleam_boxtypes();
  140. signal( SIGPIPE, SIG_IGN );
  141. Fl::get_system_colors();
  142. Fl::scheme( "gtk+" );
  143. Fl::lock();
  144. Fl_Double_Window *main_window;
  145. {
  146. Fl_Double_Window *o = main_window = new Fl_Double_Window( 800, 600, "Non-DAW : Mixer" );
  147. {
  148. main_window->xclass( APP_NAME );
  149. {
  150. Fl_Widget *o = mixer = new Mixer( 0, 0, main_window->w(), main_window->h(), NULL );
  151. Fl_Group::current()->resizable(o);
  152. }
  153. }
  154. o->end();
  155. o->size_range( main_window->w(), mixer->min_h(), 0, 0 );
  156. o->callback( (Fl_Callback*)cb_main, main_window );
  157. #ifdef HAVE_XPM
  158. o->icon((char *)p);
  159. #endif
  160. o->show( 0, 0 );
  161. }
  162. const char *osc_port = NULL;
  163. nsm = new NSM_Client;
  164. instance_name = strdup( APP_NAME );
  165. bool instance_override = false;
  166. static struct option long_options[] =
  167. {
  168. { "help", no_argument, 0, '?' },
  169. { "instance", required_argument, 0, 'i' },
  170. { "osc-port", required_argument, 0, 'p' },
  171. { 0, 0, 0, 0 }
  172. };
  173. int option_index = 0;
  174. int c = 0;
  175. while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 )
  176. {
  177. switch ( c )
  178. {
  179. case 'p':
  180. DMESSAGE( "Using OSC port %s", optarg );
  181. osc_port = optarg;
  182. break;
  183. case 'i':
  184. DMESSAGE( "Using OSC port %s", optarg );
  185. free( instance_name );
  186. instance_name = strdup( optarg );
  187. instance_override = true;
  188. break;
  189. case '?':
  190. printf( "\nUsage: %s [--instance instance_name] [--osc-port portnum] [path_to_project]\n\n", argv[0] );
  191. exit(0);
  192. break;
  193. }
  194. }
  195. Plugin_Module::spawn_discover_thread();
  196. mixer->init_osc( osc_port );
  197. char *nsm_url = getenv( "NSM_URL" );
  198. if ( nsm_url )
  199. {
  200. if ( ! nsm->init( nsm_url ) )
  201. {
  202. if ( instance_override )
  203. WARNING( "--instance option is not available when running under session management, ignoring." );
  204. if ( optind < argc )
  205. WARNING( "Loading files from the command-line is incompatible with session management, ignoring." );
  206. nsm->announce( APP_NAME, ":switch:dirty:", argv[0] );
  207. // poll so we can keep OSC handlers running in the GUI thread and avoid extra sync
  208. Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL );
  209. }
  210. }
  211. else
  212. {
  213. if ( optind < argc )
  214. {
  215. MESSAGE( "Waiting for plugins..." );
  216. Plugin_Module::join_discover_thread();
  217. MESSAGE( "Loading \"%s\"", argv[optind] );
  218. if ( ! mixer->command_load( argv[optind] ) )
  219. {
  220. fl_alert( "Error opening project specified on commandline" );
  221. }
  222. }
  223. }
  224. Fl::add_check( check_sigterm );
  225. Fl::run();
  226. delete main_window;
  227. main_window = NULL;
  228. MESSAGE( "Your fun is over" );
  229. }