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.

198 lines
4.8KB

  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 "Region.H"
  25. #include "Sequence.H"
  26. #include "Audio_Sequence.H"
  27. #include "Timeline.H"
  28. #include "Tempo_Sequence.H"
  29. #include "Time_Sequence.H"
  30. #include "Ruler_Sequence.H"
  31. #include "Control_Sequence.H"
  32. #include "Transport.H"
  33. #include "Loggable.H"
  34. #include "Track.H"
  35. #include "Engine.H"
  36. #include "TLE.H"
  37. #include "../FL/Boxtypes.H"
  38. #include <stdlib.h>
  39. #include <sys/stat.h>
  40. Engine *engine;
  41. Timeline *timeline;
  42. Transport *transport;
  43. #define VERSION "0.5.0"
  44. /* TODO: put these in a header */
  45. #define USER_CONFIG_DIR ".non-daw/"
  46. const char APP_NAME[] = "Non-DAW";
  47. const char APP_TITLE[] = "The Non-DAW (Digital Audio Workstation)";
  48. const char COPYRIGHT[] = "Copyright (C) 2008 Jonathan Moore Liles";
  49. #define PACKAGE "non"
  50. #include "debug.h"
  51. char *user_config_dir;
  52. char session_display_name[256];
  53. void
  54. set_display_name ( const char *name )
  55. {
  56. char *s = rindex( name, '/' );
  57. strcpy( session_display_name, s ? s : name );
  58. for ( s = session_display_name; *s; ++s )
  59. if ( *s == '_' || *s == '-' )
  60. *s = ' ';
  61. }
  62. static int
  63. exists ( const char *name )
  64. {
  65. struct stat st;
  66. return 0 == stat( name, &st );
  67. }
  68. #include <errno.h>
  69. static int
  70. ensure_dirs ( void )
  71. {
  72. asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
  73. int r = mkdir( user_config_dir, 0777 );
  74. return r == 0 || errno == EEXIST;
  75. }
  76. bool
  77. create_session ( const char *name )
  78. {
  79. if ( exists( name ) )
  80. {
  81. WARNING( "Session already exists" );
  82. return false;
  83. }
  84. if ( mkdir( name, 0777 ) )
  85. {
  86. WARNING( "Cannot create session directory" );
  87. return false;
  88. }
  89. if ( chdir( name ) )
  90. FATAL( "WTF? Cannot change to new session directory" );
  91. mkdir( "sources", 0777 );
  92. set_display_name( name );
  93. /* TODO: load template */
  94. return true;
  95. }
  96. int
  97. main ( int argc, char **argv )
  98. {
  99. *session_display_name = '\0';
  100. /* welcome to C++ */
  101. LOG_REGISTER_CREATE( Region );
  102. LOG_REGISTER_CREATE( Time_Point );
  103. LOG_REGISTER_CREATE( Tempo_Point );
  104. LOG_REGISTER_CREATE( Ruler_Point );
  105. LOG_REGISTER_CREATE( Control_Point );
  106. LOG_REGISTER_CREATE( Track );
  107. LOG_REGISTER_CREATE( Audio_Sequence );
  108. LOG_REGISTER_CREATE( Control_Sequence );
  109. init_boxtypes();
  110. if ( ! ensure_dirs() )
  111. FATAL( "Cannot create required directories" );
  112. printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
  113. const char *pwd = getenv( "PWD" );
  114. if ( argc > 1 )
  115. {
  116. /* FIXME: what about FLTK arguments? */
  117. /* change to session dir */
  118. if ( chdir( argv[ 1 ] ) )
  119. FATAL( "Cannot change to session dir \"%s\"", argv[ 1 ] );
  120. else
  121. pwd = argv[ 1 ];
  122. }
  123. if ( ! exists( "history" ) ||
  124. ! exists( "sources" ) )
  125. // ! exists( "options" ) )
  126. FATAL( "Not a Non-DAW session: \"%s\"", pwd );
  127. set_display_name( pwd );
  128. TLE tle;
  129. MESSAGE( "Initializing JACK" );
  130. /* we don't really need a pointer for this */
  131. engine = new Engine;
  132. engine->init();
  133. /* always start stopped (please imagine for me a realistic
  134. * scenario requiring otherwise */
  135. transport->stop();
  136. MESSAGE( "Opening session" );
  137. Loggable::open( "history" );
  138. MESSAGE( "Starting GUI" );
  139. // tle.main_window->show( argc, argv );
  140. tle.main_window->show();
  141. Fl::run();
  142. }