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.

121 lines
3.3KB

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