Audio plugin host https://kx.studio/carla
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.

Client.H 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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. 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) {
  48. return
  49. _session_manager_name;
  50. }
  51. /* Client->Server methods */
  52. void is_dirty(void);
  53. void is_clean(void);
  54. void progress(float f);
  55. void message(int priority, const char *msg);
  56. void announce(const char *appliction_name,
  57. const char *capabilities,
  58. const char *process_name);
  59. void broadcast(lo_message msg);
  60. /* init without threading */
  61. int init(const char *nsm_url);
  62. /* init with threading */
  63. int init_thread(const char *nsm_url);
  64. /* call this periodically to check for new messages */
  65. void check(int timeout = 0);
  66. /* or call these to start and stop a thread (must do your own locking in handler!) */
  67. void start(void);
  68. void stop(void);
  69. protected:
  70. /* Server->Client methods */
  71. virtual int command_open(const char *name,
  72. const char *display_name,
  73. const char *client_id,
  74. char **out_msg) = 0;
  75. virtual int command_save(char **out_msg) = 0;
  76. virtual void command_active(bool) { }
  77. virtual void command_session_is_loaded(void) { }
  78. /* invoked when an unrecognized message is received. Should return 0 if you handled it, -1 otherwise. */
  79. virtual int command_broadcast(const char *, lo_message) { return -1; }
  80. private:
  81. /* osc handlers */
  82. static int osc_open(const char *path,
  83. const char *types,
  84. lo_arg **argv,
  85. int argc,
  86. lo_message msg,
  87. void *user_data);
  88. static int osc_save(const char *path,
  89. const char *types,
  90. lo_arg **argv,
  91. int argc,
  92. lo_message msg,
  93. void *user_data);
  94. static int osc_announce_reply(const char *path,
  95. const char *types,
  96. lo_arg **argv,
  97. int argc,
  98. lo_message msg,
  99. void *user_data);
  100. static int osc_error(const char *path,
  101. const char *types,
  102. lo_arg **argv,
  103. int argc,
  104. lo_message msg,
  105. void *user_data);
  106. static int osc_session_is_loaded(const char *path,
  107. const char *types,
  108. lo_arg **argv,
  109. int argc,
  110. lo_message msg,
  111. void *user_data);
  112. static int osc_broadcast(const char *path,
  113. const char *types,
  114. lo_arg **argv,
  115. int argc,
  116. lo_message msg,
  117. void *user_data);
  118. };
  119. };