Collection of tools useful for audio production
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.

132 lines
6.1KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #ifndef CARLA_OSC_H
  18. #define CARLA_OSC_H
  19. #include "carla_osc_includes.h"
  20. #include "carla_backend.h"
  21. #define CARLA_OSC_HANDLE_ARGS1 CarlaBackend::CarlaPlugin* const plugin
  22. #define CARLA_OSC_HANDLE_ARGS2 CARLA_OSC_HANDLE_ARGS1, const int argc, const lo_arg* const* const argv, const char* const types
  23. #define CARLA_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  24. /* check argument count */ \
  25. if (argc != argcToCompare) \
  26. { \
  27. qCritical("CarlaOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  28. return 1; \
  29. } \
  30. if (argc > 0) \
  31. { \
  32. /* check for nullness */ \
  33. if (! (types && typesToCompare)) \
  34. { \
  35. qCritical("CarlaOsc::%s() - argument types are null", __FUNCTION__); \
  36. return 1; \
  37. } \
  38. /* check argument types */ \
  39. if (strcmp(types, typesToCompare) != 0) \
  40. { \
  41. qCritical("CarlaOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  42. return 1; \
  43. } \
  44. }
  45. class CarlaOsc
  46. {
  47. public:
  48. CarlaOsc(CarlaBackend::CarlaEngine* const engine);
  49. ~CarlaOsc();
  50. void init(const char* const name);
  51. void close();
  52. // -------------------------------------------------------------------
  53. bool isControllerRegistered() const
  54. {
  55. return bool(m_controllerData.target);
  56. }
  57. const CarlaOscData* getControllerData() const
  58. {
  59. return &m_controllerData;
  60. }
  61. const char* getServerPath() const
  62. {
  63. return m_serverPath;
  64. }
  65. private:
  66. CarlaBackend::CarlaEngine* const engine;
  67. const char* m_serverPath;
  68. lo_server_thread m_serverThread;
  69. CarlaOscData m_controllerData;
  70. const char* m_name;
  71. size_t m_name_len;
  72. // -------------------------------------------------------------------
  73. static void osc_error_handler(const int num, const char* const msg, const char* const path)
  74. {
  75. qCritical("osc_error_handler(%i, %s, %s)", num, msg, path);
  76. }
  77. static int osc_message_handler(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg, void* const user_data)
  78. {
  79. CarlaOsc* const _this_ = (CarlaOsc*)user_data;
  80. return _this_->handleMessage(path, argc, argv, types, msg);
  81. }
  82. int handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg);
  83. int handle_register(const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source);
  84. int handle_unregister();
  85. int handle_update(CARLA_OSC_HANDLE_ARGS2, const lo_address source);
  86. int handle_configure(CARLA_OSC_HANDLE_ARGS2);
  87. int handle_control(CARLA_OSC_HANDLE_ARGS2);
  88. int handle_program(CARLA_OSC_HANDLE_ARGS2);
  89. int handle_midi(CARLA_OSC_HANDLE_ARGS2);
  90. int handle_exiting(CARLA_OSC_HANDLE_ARGS1);
  91. int handle_set_active(CARLA_OSC_HANDLE_ARGS2);
  92. int handle_set_drywet(CARLA_OSC_HANDLE_ARGS2);
  93. int handle_set_volume(CARLA_OSC_HANDLE_ARGS2);
  94. int handle_set_balance_left(CARLA_OSC_HANDLE_ARGS2);
  95. int handle_set_balance_right(CARLA_OSC_HANDLE_ARGS2);
  96. int handle_set_parameter_value(CARLA_OSC_HANDLE_ARGS2);
  97. int handle_set_parameter_midi_cc(CARLA_OSC_HANDLE_ARGS2);
  98. int handle_set_parameter_midi_channel(CARLA_OSC_HANDLE_ARGS2);
  99. int handle_set_program(CARLA_OSC_HANDLE_ARGS2);
  100. int handle_set_midi_program(CARLA_OSC_HANDLE_ARGS2);
  101. int handle_note_on(CARLA_OSC_HANDLE_ARGS2);
  102. int handle_note_off(CARLA_OSC_HANDLE_ARGS2);
  103. int handle_lv2_atom_transfer(CARLA_OSC_HANDLE_ARGS2);
  104. int handle_lv2_event_transfer(CARLA_OSC_HANDLE_ARGS2);
  105. int handle_bridge_ains_peak(CARLA_OSC_HANDLE_ARGS2);
  106. int handle_bridge_aouts_peak(CARLA_OSC_HANDLE_ARGS2);
  107. };
  108. #endif // CARLA_OSC_H