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.

123 lines
3.2KB

  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. bool Session::_is_open = false;
  31. void
  32. Session::set_name ( const char *name )
  33. {
  34. char *s = rindex( name, '/' );
  35. strcpy( Session::_name, s ? s + 1 : name );
  36. for ( s = Session::_name; *s; ++s )
  37. if ( *s == '_' || *s == '-' )
  38. *s = ' ';
  39. }
  40. static int
  41. exists ( const char *name )
  42. {
  43. struct stat st;
  44. return 0 == stat( name, &st );
  45. }
  46. #include <errno.h>
  47. bool
  48. Session::close ( void )
  49. {
  50. Loggable::close();
  51. _is_open = false;
  52. }
  53. bool
  54. Session::open ( const char *name )
  55. {
  56. if ( chdir( name ) )
  57. {
  58. WARNING( "Cannot change to session dir \"%s\"", name );
  59. return false;
  60. }
  61. if ( ! exists( "history" ) ||
  62. ! exists( "sources" ) )
  63. // ! exists( "options" ) )
  64. {
  65. WARNING( "Not a Non-DAW session: \"%s\"", name );
  66. return false;
  67. }
  68. if ( ! Loggable::open( "history" ) )
  69. FATAL( "error opening journal" );
  70. set_name( name );
  71. _is_open = true;
  72. return true;
  73. }
  74. bool
  75. Session::create ( const char *name, const char *template_name )
  76. {
  77. if ( exists( name ) )
  78. {
  79. WARNING( "Session already exists" );
  80. return false;
  81. }
  82. if ( mkdir( name, 0777 ) )
  83. {
  84. WARNING( "Cannot create session directory" );
  85. return false;
  86. }
  87. if ( chdir( name ) )
  88. FATAL( "WTF? Cannot change to new session directory" );
  89. mkdir( "sources", 0777 );
  90. creat( "history", 0666 );
  91. /* TODO: copy template */
  92. close();
  93. return open( name );
  94. }