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.

118 lines
3.1KB

  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. /* Routings for opening/closing/creation of sessions. All the actual
  19. session state belongs to Timeline and other classes. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <sys/stat.h>
  24. #include <sys/types.h>
  25. #include <fcntl.h>
  26. #include "Loggable.H"
  27. #include "Session.H"
  28. #include "debug.h"
  29. char Session::_name[256];
  30. void
  31. Session::set_name ( const char *name )
  32. {
  33. char *s = rindex( name, '/' );
  34. strcpy( Session::_name, s ? s + 1 : name );
  35. for ( s = Session::_name; *s; ++s )
  36. if ( *s == '_' || *s == '-' )
  37. *s = ' ';
  38. }
  39. static int
  40. exists ( const char *name )
  41. {
  42. struct stat st;
  43. return 0 == stat( name, &st );
  44. }
  45. #include <errno.h>
  46. bool
  47. Session::close ( void )
  48. {
  49. Loggable::close();
  50. }
  51. bool
  52. Session::open ( const char *name )
  53. {
  54. if ( chdir( name ) )
  55. {
  56. WARNING( "Cannot change to session dir \"%s\"", name );
  57. return false;
  58. }
  59. if ( ! exists( "history" ) ||
  60. ! exists( "sources" ) )
  61. // ! exists( "options" ) )
  62. {
  63. WARNING( "Not a Non-DAW session: \"%s\"", name );
  64. return false;
  65. }
  66. if ( ! Loggable::open( "history" ) )
  67. FATAL( "error opening journal" );
  68. set_name( name );
  69. return true;
  70. }
  71. bool
  72. Session::create ( const char *name, const char *template_name )
  73. {
  74. if ( exists( name ) )
  75. {
  76. WARNING( "Session already exists" );
  77. return false;
  78. }
  79. if ( mkdir( name, 0777 ) )
  80. {
  81. WARNING( "Cannot create session directory" );
  82. return false;
  83. }
  84. if ( chdir( name ) )
  85. FATAL( "WTF? Cannot change to new session directory" );
  86. mkdir( "sources", 0777 );
  87. creat( "history", 0666 );
  88. /* TODO: copy template */
  89. close();
  90. return open( name );
  91. }