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.

120 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. /* Actual implementation of our side of the LASH protocol */
  19. /* NOTES: Since LASH doesn't provide us with the information we
  20. * need--when we need it--we just punt and only use LASH to save and
  21. * load the path to the *real* project data. */
  22. #include "LASH.H"
  23. #include "Project.H"
  24. #include "TLE.H" // all this just for quit()
  25. #include <FL/Fl.H>
  26. extern TLE *tle;
  27. #include "const.h"
  28. #include "util/debug.h"
  29. const float lash_poll_interval = 0.2f;
  30. void
  31. LASH::timer_cb ( void *v )
  32. {
  33. ((LASH*)v)->poll();
  34. Fl::repeat_timeout( lash_poll_interval, &LASH::timer_cb, v );
  35. }
  36. LASH::LASH ( )
  37. {
  38. Fl::add_timeout( lash_poll_interval, &LASH::timer_cb, this );
  39. }
  40. LASH::~LASH ( )
  41. {
  42. Fl::remove_timeout( &LASH::timer_cb );
  43. }
  44. bool
  45. LASH::handle_save_file ( const char *path )
  46. {
  47. MESSAGE( "LASH wants us to save \"%s\"", path );
  48. char *name;
  49. asprintf( &name, "%s/project-path", path );
  50. FILE *fp;
  51. if ( ! ( fp = fopen( name, "w" ) ) )
  52. {
  53. free( name );
  54. return false;
  55. }
  56. else
  57. free( name );
  58. char project_path[ 512 ];
  59. fl_filename_absolute( project_path, sizeof( project_path ), "." );
  60. fwrite( project_path, strlen( project_path ), 1, fp );
  61. fclose( fp );
  62. return Project::save();
  63. }
  64. bool
  65. LASH::handle_restore_file ( const char *path )
  66. {
  67. MESSAGE( "LASH wants us to load \"%s\"", path );
  68. char *name;
  69. asprintf( &name, "%s/project-path", path );
  70. FILE *fp;
  71. if ( ! ( fp = fopen( name, "r" ) ) )
  72. {
  73. free( name );
  74. return false;
  75. }
  76. else
  77. free( name );
  78. char project_path[ 512 ];
  79. fgets( project_path, sizeof( project_path ), fp );
  80. fclose( fp );
  81. return Project::open( project_path ) == 0;
  82. }
  83. void
  84. LASH::handle_quit ( void )
  85. {
  86. MESSAGE( "LASH wants us to quit" );
  87. tle->quit();
  88. }