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.

159 lines
4.7KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2010 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. //#include "util/Thread.H"
  21. #include <list>
  22. namespace OSC
  23. {
  24. class OSC_Value
  25. {
  26. protected:
  27. char _type;
  28. float f;
  29. double d;
  30. int i;
  31. const char *s;
  32. public:
  33. OSC_Value ( const OSC_Value &rhs )
  34. {
  35. _type = rhs._type;
  36. f =rhs.f;
  37. d = rhs.d;
  38. i = rhs.i;
  39. s = rhs.s;
  40. }
  41. OSC_Value ( )
  42. {
  43. _type = 0;
  44. f = 0;
  45. d = 0;
  46. i = 0;
  47. s = 0;
  48. }
  49. virtual ~OSC_Value ( ) { }
  50. virtual char type ( void ) const { return _type; }
  51. };
  52. class OSC_Float : public OSC_Value
  53. {
  54. public:
  55. float value ( void ) const { return f; }
  56. OSC_Float ( float v )
  57. {
  58. _type = 'f';
  59. f = v;
  60. }
  61. };
  62. class OSC_Int : public OSC_Value
  63. {
  64. public:
  65. int value ( void ) const { return i; }
  66. OSC_Int ( int v )
  67. {
  68. _type = 'i';
  69. i = v;
  70. }
  71. };
  72. class OSC_String : public OSC_Value
  73. {
  74. public:
  75. const char * value ( void ) const { return s; }
  76. OSC_String ( const char *v )
  77. {
  78. _type = 's';
  79. s = v;
  80. }
  81. };
  82. class Endpoint
  83. {
  84. static void error_handler(int num, const char *msg, const char *path);
  85. // Thread _thread;
  86. // lo_server_thread _st;
  87. lo_server _server;
  88. public:
  89. Endpoint ( const char *port = 0 );
  90. ~Endpoint ( );
  91. void add_method ( const char *path, const char *typespec, lo_method_handler handler, void *user_data );
  92. void del_method ( const char *path, const char *typespec );
  93. void start ( void );
  94. void stop ( void );
  95. int port ( void ) const;
  96. char * url ( void ) const;
  97. void check ( void ) const;
  98. void wait ( int timeout ) const;
  99. void run ( void ) const;
  100. int send ( lo_address to, const char *path, std::list< OSC_Value > values );
  101. /* overloads for common message formats */
  102. int send ( lo_address to, const char *path );
  103. int send ( lo_address to, const char *path, float v );
  104. int send ( lo_address to, const char *path, double v );
  105. int send ( lo_address to, const char *path, int v );
  106. int send ( lo_address to, const char *path, long v );
  107. int send ( lo_address to, const char *path, const char *v );
  108. int send ( lo_address to, const char *path, const char *v1, const char *v2 );
  109. };
  110. };
  111. /* helper macros for defining OSC handlers */
  112. #define OSC_NAME( name ) osc_ ## name
  113. #define OSC_DMSG() DMESSAGE( "Got OSC message: %s", path );
  114. #define OSC_HANDLER( name ) static int OSC_NAME( name ) ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data )
  115. #define OSC_REPLY_OK() ((Mixer*)user_data)->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, "ok" )
  116. #define OSC_REPLY( msg_str ) ((Mixer*)user_data)->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, msg_str )
  117. #define OSC_REPLY_ERR() ((Mixer*)user_data)->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, "err" )