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.4KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2012 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 "const.h"
  19. #include "debug.h"
  20. #include "Timeline.H"
  21. #include "TLE.H"
  22. #include "Project.H"
  23. #include "OSC/Endpoint.H"
  24. #include <nsm.h>
  25. #define OSC_INTERVAL 0.2f
  26. extern char *instance_name;
  27. extern Timeline *timeline;
  28. // extern NSM_Client *nsm;
  29. static int
  30. command_save ( char **out_msg, void *userdata )
  31. {
  32. if ( timeline->command_save() )
  33. return ERR_OK;
  34. else
  35. {
  36. *out_msg = strdup( "Failed to save for unknown reason");
  37. return ERR_GENERAL;
  38. }
  39. }
  40. static int
  41. command_open ( const char *name, const char *display_name, const char *client_id, char **out_msg, void *userdata )
  42. {
  43. if ( instance_name )
  44. free( instance_name );
  45. instance_name = strdup( client_id );
  46. timeline->osc->name( client_id );
  47. int r = 0;
  48. if ( Project::validate( name ) )
  49. {
  50. if ( timeline->command_load( name, display_name ) )
  51. r = ERR_OK;
  52. else
  53. {
  54. *out_msg = strdup( "Failed to load for unknown reason" );
  55. r = ERR_GENERAL;
  56. }
  57. }
  58. else
  59. {
  60. if ( timeline->command_new( name, display_name ) )
  61. r =ERR_OK;
  62. else
  63. {
  64. *out_msg = strdup( "Failed to load for unknown reason" );
  65. r = ERR_GENERAL;
  66. }
  67. }
  68. timeline->discover_peers();
  69. return r;
  70. }
  71. static void
  72. command_session_is_loaded ( void *userdata )
  73. {
  74. MESSAGE( "NSM says session is loaded." );
  75. timeline->discover_peers();
  76. }
  77. static int
  78. command_broadcast ( const char *path, lo_message msg, void *userdata )
  79. {
  80. lo_message_get_argc( msg );
  81. // lo_arg **argv = lo_message_get_argv( msg );
  82. if ( !strcmp( path, "/non/hello" ) )
  83. {
  84. timeline->reply_to_finger( msg );
  85. return 0;
  86. }
  87. else
  88. return -1;
  89. }
  90. void
  91. set_nsm_callbacks ( nsm_client_t *nsm )
  92. {
  93. nsm_set_open_callback( nsm, command_open, 0 );
  94. nsm_set_save_callback( nsm, command_save, 0 );
  95. nsm_set_broadcast_callback( nsm, command_broadcast, 0 );
  96. nsm_set_session_is_loaded_callback( nsm, command_session_is_loaded, 0 );
  97. }