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.

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