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.

258 lines
6.0KB

  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 <FL/Fl.H>
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <sys/stat.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. /* for registrations */
  26. #include "Audio_Region.H"
  27. #include "Sequence.H"
  28. #include "Audio_Sequence.H"
  29. #include "Timeline.H"
  30. #include "Tempo_Sequence.H"
  31. #include "Time_Sequence.H"
  32. #include "Annotation_Sequence.H"
  33. #include "Control_Sequence.H"
  34. #include "Track.H"
  35. #include "TLE.H"
  36. #include "Timeline.H"
  37. #include "../FL/Boxtypes.H"
  38. #include "Project.H"
  39. #include "Transport.H"
  40. #include "Engine/Engine.H"
  41. #include "Thread.H"
  42. #include "NSM.H"
  43. Engine *engine;
  44. Timeline *timeline;
  45. Transport *transport;
  46. TLE *tle;
  47. NSM_Client *nsm;
  48. char *instance_name = NULL;
  49. /* TODO: put these in a header */
  50. #define USER_CONFIG_DIR ".non-daw/"
  51. const char APP_NAME[] = "Non-DAW";
  52. const char APP_TITLE[] = "The Non-DAW";
  53. const char COPYRIGHT[] = "Copyright (C) 2008-2010 Jonathan Moore Liles";
  54. const double NSM_CHECK_INTERVAL = 0.25f;
  55. #define PACKAGE "non"
  56. #include "const.h"
  57. #include "debug.h"
  58. char *user_config_dir;
  59. #include <errno.h>
  60. static int
  61. ensure_dirs ( void )
  62. {
  63. asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
  64. int r = mkdir( user_config_dir, 0777 );
  65. return r == 0 || errno == EEXIST;
  66. }
  67. #include <FL/Fl_Shared_Image.H>
  68. #include <signal.h>
  69. void
  70. shift ( char **argv, int *argc, int n )
  71. {
  72. int i;
  73. for ( i = 0; i < *argc; ++i )
  74. argv[ i ] = argv[ i + n ];
  75. argv[ i ] = 0;
  76. argc -= n;
  77. }
  78. extern Timeline *timeline;
  79. void
  80. check_nsm ( void * v )
  81. {
  82. nsm->check();
  83. Fl::repeat_timeout( NSM_CHECK_INTERVAL, check_nsm, v );
  84. }
  85. static int got_sigterm = 0;
  86. void
  87. sigterm_handler ( int )
  88. {
  89. got_sigterm = 1;
  90. Fl::awake();
  91. }
  92. void
  93. check_sigterm ( void * )
  94. {
  95. if ( got_sigterm )
  96. {
  97. MESSAGE( "Got SIGTERM, quitting..." );
  98. timeline->command_quit();
  99. }
  100. }
  101. int
  102. main ( int argc, char **argv )
  103. {
  104. Thread::init();
  105. Thread thread( "UI" );
  106. thread.set();
  107. signal( SIGTERM, sigterm_handler );
  108. fl_register_images();
  109. /* welcome to C++ */
  110. LOG_REGISTER_CREATE( Annotation_Point );
  111. LOG_REGISTER_CREATE( Annotation_Region );
  112. LOG_REGISTER_CREATE( Annotation_Sequence );
  113. LOG_REGISTER_CREATE( Audio_Region );
  114. LOG_REGISTER_CREATE( Audio_Sequence );
  115. LOG_REGISTER_CREATE( Control_Point );
  116. LOG_REGISTER_CREATE( Control_Sequence );
  117. LOG_REGISTER_CREATE( Tempo_Point );
  118. LOG_REGISTER_CREATE( Time_Point );
  119. LOG_REGISTER_CREATE( Track );
  120. init_boxtypes();
  121. signal( SIGPIPE, SIG_IGN );
  122. if ( ! ensure_dirs() )
  123. FATAL( "Cannot create required directories" );
  124. printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
  125. tle = new TLE;
  126. instance_name = strdup( APP_NAME );
  127. /* we don't really need a pointer for this */
  128. // will be created on project new/open
  129. engine = NULL;
  130. nsm = new NSM_Client;
  131. const char *osc_port = NULL;
  132. {
  133. int r = argc - 1;
  134. int i = 1;
  135. for ( ; i < argc; ++i, --r )
  136. if ( !strcmp( argv[i], "--osc-port" ) )
  137. {
  138. if ( r > 1 )
  139. {
  140. MESSAGE( "Using OSC port \"%s\"", argv[i+1] );
  141. osc_port = argv[i+1];
  142. --r;
  143. ++i;
  144. }
  145. else
  146. {
  147. FATAL( "Missing OSC port" );
  148. }
  149. }
  150. MESSAGE( "Starting GUI" );
  151. tle->run();
  152. timeline->init_osc( NULL );
  153. char *nsm_url = getenv( "NSM_URL" );
  154. if ( nsm_url )
  155. {
  156. if ( ! nsm->init( nsm_url ) );
  157. {
  158. nsm->announce( APP_NAME, ":progress:switch:", argv[0] );
  159. /* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
  160. Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL );
  161. }
  162. }
  163. else
  164. {
  165. if ( r >= 1 )
  166. {
  167. MESSAGE( "Loading \"%s\"", argv[i] );
  168. tle->open( argv[i] );
  169. /* ) */
  170. /* { */
  171. /* fl_alert( "Error opening project specified on commandline" ); */
  172. /* } */
  173. }
  174. }
  175. }
  176. Fl::add_check( check_sigterm );
  177. Fl::run();
  178. /* cleanup for valgrind's sake */
  179. if ( engine )
  180. {
  181. delete engine;
  182. engine = NULL;
  183. }
  184. delete timeline;
  185. timeline = NULL;
  186. delete tle;
  187. tle = NULL;
  188. delete nsm;
  189. nsm = NULL;
  190. MESSAGE( "Your fun is over" );
  191. }