Rename a pipe method, add docs
[carla.git] / source / backend / engine / CarlaEngineOsc.hpp
blobc6d364b08aef40a0314605b45071f73735de2c76
1 /*
2 * Carla Plugin Host
3 * Copyright (C) 2011-2020 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_ENGINE_OSC_HPP_INCLUDED
19 #define CARLA_ENGINE_OSC_HPP_INCLUDED
21 #include "CarlaDefines.h"
23 #ifdef HAVE_LIBLO
25 #include "CarlaBackend.h"
26 #include "CarlaJuceUtils.hpp"
27 #include "CarlaPluginPtr.hpp"
28 #include "CarlaOscUtils.hpp"
29 #include "CarlaString.hpp"
31 #define CARLA_ENGINE_OSC_HANDLE_ARGS const CarlaPluginPtr& plugin, \
32 const int argc, const lo_arg* const* const argv, const char* const types
34 #define CARLA_ENGINE_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
35 /* check argument count */ \
36 if (argc != argcToCompare) \
37 { \
38 carla_stderr("CarlaEngineOsc::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
39 return 1; \
40 } \
41 if (argc > 0) \
42 { \
43 /* check for nullness */ \
44 if (types == nullptr || typesToCompare == nullptr) \
45 { \
46 carla_stderr("CarlaEngineOsc::%s() - argument types are null", __FUNCTION__); \
47 return 1; \
48 } \
49 /* check argument types */ \
50 if (std::strcmp(types, typesToCompare) != 0) \
51 { \
52 carla_stderr("CarlaEngineOsc::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
53 return 1; \
54 } \
57 CARLA_BACKEND_START_NAMESPACE
59 // -----------------------------------------------------------------------
61 class CarlaEngineOsc
63 public:
64 CarlaEngineOsc(CarlaEngine* engine) noexcept;
65 ~CarlaEngineOsc() noexcept;
67 void init(const char* name, int tcpPort, int udpPort) noexcept;
68 void idle() const noexcept;
69 void close() noexcept;
71 // -------------------------------------------------------------------
73 const CarlaString& getServerPathTCP() const noexcept
75 return fServerPathTCP;
78 const CarlaString& getServerPathUDP() const noexcept
80 return fServerPathUDP;
83 // -------------------------------------------------------------------
85 bool isControlRegisteredForTCP() const noexcept
87 return fControlDataTCP.target != nullptr;
90 bool isControlRegisteredForUDP() const noexcept
92 return fControlDataUDP.target != nullptr;
95 // -------------------------------------------------------------------
96 // TCP
98 void sendCallback(EngineCallbackOpcode action, uint pluginId,
99 int value1, int value2, int value3,
100 float valuef, const char* valueStr) const noexcept;
101 void sendPluginInfo(const CarlaPluginPtr& plugin) const noexcept;
102 void sendPluginPortCount(const CarlaPluginPtr& plugin) const noexcept;
103 void sendPluginParameterInfo(const CarlaPluginPtr& plugin, uint32_t index) const noexcept;
104 void sendPluginDataCount(const CarlaPluginPtr& plugin) const noexcept;
105 void sendPluginProgramCount(const CarlaPluginPtr& plugin) const noexcept;
106 void sendPluginProgram(const CarlaPluginPtr& plugin, uint32_t index) const noexcept;
107 void sendPluginMidiProgram(const CarlaPluginPtr& plugin, uint32_t index) const noexcept;
108 void sendPluginCustomData(const CarlaPluginPtr& plugin, uint32_t index) const noexcept;
109 void sendPluginInternalParameterValues(const CarlaPluginPtr& plugin) const noexcept;
110 void sendPing() const noexcept;
111 void sendResponse(int messageId, const char* error) const noexcept;
112 void sendExit() const noexcept;
114 // -------------------------------------------------------------------
115 // UDP
117 void sendRuntimeInfo() const noexcept;
118 void sendParameterValue(uint pluginId, uint32_t index, float value) const noexcept;
119 void sendPeaks(uint pluginId, const float peaks[4]) const noexcept;
121 // -------------------------------------------------------------------
123 private:
124 CarlaEngine* const fEngine;
126 // for carla-control
127 CarlaOscData fControlDataTCP;
128 CarlaOscData fControlDataUDP;
130 CarlaString fName;
131 CarlaString fServerPathTCP;
132 CarlaString fServerPathUDP;
133 lo_server fServerTCP;
134 lo_server fServerUDP;
136 // -------------------------------------------------------------------
138 int handleMessage(bool isTCP, const char* path,
139 int argc, const lo_arg* const* argv, const char* types, lo_message msg);
141 int handleMsgRegister(bool isTCP, int argc, const lo_arg* const* argv, const char* types, lo_address source);
142 int handleMsgUnregister(bool isTCP, int argc, const lo_arg* const* argv, const char* types);
143 int handleMsgControl(const char* method,
144 int argc, const lo_arg* const* argv, const char* types);
146 // Internal methods
147 int handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS);
148 int handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS);
149 int handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS);
150 int handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS);
151 int handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS);
152 int handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS);
153 int handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS);
154 int handleMsgSetParameterMappedControlIndex(CARLA_ENGINE_OSC_HANDLE_ARGS);
155 int handleMsgSetParameterMappedRange(CARLA_ENGINE_OSC_HANDLE_ARGS);
156 int handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS);
157 int handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
158 int handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS);
159 int handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS);
160 int handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS);
162 // -----------------------------------------------------------------------
164 static void osc_error_handler_TCP(int num, const char* msg, const char* path)
166 carla_stderr("CarlaEngineOsc::osc_error_handler_TCP(%i, \"%s\", \"%s\")", num, msg, path);
169 static void osc_error_handler_UDP(int num, const char* msg, const char* path)
171 carla_stderr("CarlaEngineOsc::osc_error_handler_UDP(%i, \"%s\", \"%s\")", num, msg, path);
174 static int osc_message_handler_TCP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
176 return ((CarlaEngineOsc*)userData)->handleMessage(true, path, argc, argv, types, msg);
179 static int osc_message_handler_UDP(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* userData)
181 return ((CarlaEngineOsc*)userData)->handleMessage(false, path, argc, argv, types, msg);
184 CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineOsc)
187 // -----------------------------------------------------------------------
189 CARLA_BACKEND_END_NAMESPACE
191 #endif // HAVE_LIBLO
193 #endif // CARLA_ENGINE_OSC_HPP_INCLUDED