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.

108 lines
4.3KB

  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. #pragma once
  19. #include <lo/lo.h>
  20. namespace NSM
  21. {
  22. class Client
  23. {
  24. private:
  25. lo_server _server;
  26. lo_server_thread _st;
  27. lo_address nsm_addr;
  28. bool nsm_is_active;
  29. char *nsm_client_id;
  30. char *_session_manager_name;
  31. public:
  32. enum
  33. {
  34. ERR_OK = 0,
  35. ERR_GENERAL = -1,
  36. ERR_INCOMPATIBLE_API = -2,
  37. ERR_BLACKLISTED = -3,
  38. ERR_LAUNCH_FAILED = -4,
  39. ERR_NO_SUCH_FILE = -5,
  40. ERR_NO_SESSION_OPEN = -6,
  41. ERR_UNSAVED_CHANGES = -7,
  42. ERR_NOT_NOW = -8
  43. };
  44. Client ( );
  45. virtual ~Client ( );
  46. bool is_active ( void ) { return nsm_is_active; }
  47. const char *session_manager_name ( void ) { return _session_manager_name; }
  48. /* Client->Server methods */
  49. void is_dirty ( void );
  50. void is_clean ( void );
  51. void progress ( float f );
  52. void message( int priority, const char *msg );
  53. void announce ( const char *nsm_url, const char *appliction_name, const char *capabilities, const char *process_name );
  54. void broadcast ( lo_message msg );
  55. /* init without threading */
  56. int init ( void );
  57. /* init with threading */
  58. int init_thread ( void );
  59. /* call this periodically to check for new messages */
  60. void check ( int timeout = 0 );
  61. /* or call these to start and stop a thread (must do your own locking in handler!) */
  62. void start ( void );
  63. void stop ( void );
  64. protected:
  65. /* Server->Client methods */
  66. virtual int command_open ( const char *name, const char *display_name, const char *client_id, char **out_msg ) = 0;
  67. virtual int command_save ( char **out_msg ) = 0;
  68. virtual void command_active ( bool active ) { }
  69. virtual void command_session_is_loaded ( void ) { }
  70. /* invoked when an unrecognized message is received. Should return 0 if you handled it, -1 otherwise. */
  71. virtual int command_broadcast ( const char *path, lo_message msg ) { return -1; }
  72. private:
  73. /* osc handlers */
  74. static int osc_open ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  75. static int osc_save ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  76. static int osc_announce_reply ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  77. static int osc_error ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  78. static int osc_session_is_loaded ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  79. static int osc_broadcast ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  80. };
  81. };