3 * Copyright (C) 2011-2022 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_HPP_INCLUDED
19 #define CARLA_ENGINE_HPP_INCLUDED
21 #include "CarlaBackend.h"
22 #include "CarlaPluginPtr.hpp"
25 class MemoryOutputStream
;
29 CARLA_BACKEND_START_NAMESPACE
31 // -----------------------------------------------------------------------
34 * @defgroup CarlaEngineAPI Carla Engine API
36 * The Carla Engine API.
41 * The type of an engine.
51 * Provides all processing modes.
56 * JUCE engine type, used to provide Native Audio and MIDI support.
61 * RtAudio engine type, used to provide Native Audio and MIDI support.
63 kEngineTypeRtAudio
= 3,
66 * SDL engine type, used to provide Native Audio support.
71 * Plugin engine type, used to export the engine as a plugin.
73 kEngineTypePlugin
= 5,
76 * Bridge engine type, used in BridgePlugin class.
78 kEngineTypeBridge
= 6,
81 * Dummy engine type, does not send audio or MIDI anywhere.
87 * The type of an engine port.
93 kEnginePortTypeNull
= 0,
97 * @see CarlaEngineAudioPort
99 kEnginePortTypeAudio
= 1,
103 * @see CarlaEngineCVPort
105 kEnginePortTypeCV
= 2,
108 * Event port type (Control or MIDI).
109 * @see CarlaEngineEventPort
111 kEnginePortTypeEvent
= 3
115 * The type of an engine event.
117 enum EngineEventType
{
121 kEngineEventTypeNull
= 0,
124 * Control event type.
125 * @see EngineControlEvent
127 kEngineEventTypeControl
= 1,
131 * @see EngineMidiEvent
133 kEngineEventTypeMidi
= 2
137 * The type of an engine control event.
139 enum EngineControlEventType
{
143 kEngineControlEventTypeNull
= 0,
146 * Parameter event type.
147 * @note Value uses a normalized range of 0.0f<->1.0f.
149 kEngineControlEventTypeParameter
= 1,
152 * MIDI Bank event type.
154 kEngineControlEventTypeMidiBank
= 2,
157 * MIDI Program change event type.
159 kEngineControlEventTypeMidiProgram
= 3,
162 * All sound off event type.
164 kEngineControlEventTypeAllSoundOff
= 4,
167 * All notes off event type.
169 kEngineControlEventTypeAllNotesOff
= 5
173 * Special value for EngineEvent channel field, indicating a non-midi parameter event.
175 static const uint8_t kEngineEventNonMidiChannel
= 0x30;
177 // -----------------------------------------------------------------------
180 * Engine control event.
182 struct CARLA_API EngineControlEvent
{
183 EngineControlEventType type
; //!< Control-Event type.
184 uint16_t param
; //!< Parameter Id, midi bank or midi program.
185 int8_t midiValue
; //!< Raw midi value, >= 0 if applicable, -1 otherwise.
186 float normalizedValue
; //!< Parameter value, normalized to 0.0f<->1.0f.
187 bool handled
; //!< Indicates that event was handled/received at least once.
190 * Convert this control event into MIDI data.
193 uint8_t convertToMidiData(uint8_t channel
, uint8_t data
[3]) const noexcept
;
199 struct CARLA_API EngineMidiEvent
{
200 static const uint8_t kDataSize
= 4; //!< Size of internal data
202 uint8_t port
; //!< Port offset (usually 0)
203 uint8_t size
; //!< Number of bytes used
206 * MIDI data, without channel bit.
207 * If size > kDataSize, dataExt is used (otherwise NULL).
209 uint8_t data
[kDataSize
];
210 const uint8_t* dataExt
;
216 struct CARLA_API EngineEvent
{
217 EngineEventType type
; //!< Event Type; either Control or MIDI
218 uint32_t time
; //!< Time offset in frames
219 uint8_t channel
; //!< Channel, used for MIDI-related events
222 * Event specific data.
225 EngineControlEvent ctrl
;
226 EngineMidiEvent midi
;
230 * Fill this event from MIDI data.
232 void fillFromMidiData(uint8_t size
, const uint8_t* data
, uint8_t midiPortOffset
) noexcept
;
235 // -----------------------------------------------------------------------
240 struct CARLA_API EngineOptions
{
241 EngineProcessMode processMode
;
242 EngineTransportMode transportMode
;
243 const char* transportExtra
;
247 bool preferPluginBridges
;
248 bool preferUiBridges
;
250 bool pluginsAreStandalone
;
256 uint uiBridgesTimeout
;
257 uint audioBufferSize
;
258 uint audioSampleRate
;
259 bool audioTripleBuffer
;
260 const char* audioDriver
;
261 const char* audioDevice
;
269 const char* pathAudio
;
270 const char* pathMIDI
;
272 const char* pathLADSPA
;
273 const char* pathDSSI
;
275 const char* pathVST2
;
276 const char* pathVST3
;
279 const char* pathJSFX
;
280 const char* pathCLAP
;
282 const char* binaryDir
;
283 const char* resourceDir
;
284 const char* clientNamePrefix
;
286 bool preventBadBehaviour
;
287 uintptr_t frontendWinId
;
291 const char* executable
;
294 const char* fallbackPrefix
;
302 CARLA_DECLARE_NON_COPYABLE(Wine
)
307 EngineOptions() noexcept
;
308 ~EngineOptions() noexcept
;
309 CARLA_DECLARE_NON_COPYABLE(EngineOptions
)
314 * Engine BBT Time information.
316 struct CARLA_API EngineTimeInfoBBT
{
319 int32_t bar
; //!< current bar
320 int32_t beat
; //!< current beat-within-bar
321 double tick
; //!< current tick-within-beat
324 float beatsPerBar
; //!< time signature "numerator"
325 float beatType
; //!< time signature "denominator"
328 double beatsPerMinute
;
333 void clear() noexcept
;
336 EngineTimeInfoBBT() noexcept
;
337 EngineTimeInfoBBT(const EngineTimeInfoBBT
&) noexcept
;
342 * Engine Time information.
344 struct CARLA_API EngineTimeInfo
{
348 EngineTimeInfoBBT bbt
;
353 void clear() noexcept
;
356 EngineTimeInfo() noexcept
;
357 EngineTimeInfo(const EngineTimeInfo
&) noexcept
;
358 EngineTimeInfo
& operator=(const EngineTimeInfo
&) noexcept
;
360 // fast comparison, doesn't check all values
361 bool compareIgnoringRollingFrames(const EngineTimeInfo
& timeInfo
, uint32_t maxFrames
) const noexcept
;
363 // quick operator, doesn't check all values
364 bool operator==(const EngineTimeInfo
& timeInfo
) const noexcept
;
365 bool operator!=(const EngineTimeInfo
& timeInfo
) const noexcept
;
369 // -----------------------------------------------------------------------
372 * Carla Engine port (Abstract).
373 * This is the base class for all Carla Engine ports.
375 class CARLA_API CarlaEnginePort
379 * The constructor, protected.
380 * All constructor parameters are constant and will never change in the lifetime of the port.
382 CarlaEnginePort(const CarlaEngineClient
& client
, bool isInputPort
, uint32_t indexOffset
) noexcept
;
388 virtual ~CarlaEnginePort() noexcept
;
391 * Get the type of the port, as provided by the respective subclasses.
393 virtual EnginePortType
getType() const noexcept
= 0;
396 * Initialize the port's internal buffer.
398 virtual void initBuffer() noexcept
= 0;
401 * Check if this port is an input.
403 inline bool isInput() const noexcept
409 * Get the index offset as passed in the constructor.
411 inline uint32_t getIndexOffset() const noexcept
417 * Get this ports' engine client.
419 inline const CarlaEngineClient
& getEngineClient() const noexcept
425 * Set a meta-data property on this port.
427 virtual void setMetaData(const char* key
, const char* value
, const char* type
);
431 const CarlaEngineClient
& kClient
;
433 const uint32_t kIndexOffset
;
435 CARLA_DECLARE_NON_COPYABLE(CarlaEnginePort
)
440 * Carla Engine Audio port.
442 class CARLA_API CarlaEngineAudioPort
: public CarlaEnginePort
447 * All constructor parameters are constant and will never change in the lifetime of the port.
449 CarlaEngineAudioPort(const CarlaEngineClient
& client
, bool isInputPort
, uint32_t indexOffset
) noexcept
;
454 ~CarlaEngineAudioPort() noexcept override
;
457 * Get the type of the port, in this case kEnginePortTypeAudio.
459 inline EnginePortType
getType() const noexcept final
461 return kEnginePortTypeAudio
;
465 * Initialize the port's internal buffer.
467 void initBuffer() noexcept override
;
470 * Direct access to the port's audio buffer.
473 inline float* getBuffer() const noexcept
482 CARLA_DECLARE_NON_COPYABLE(CarlaEngineAudioPort
)
487 * Carla Engine CV port.
489 class CARLA_API CarlaEngineCVPort
: public CarlaEnginePort
494 * All constructor parameters are constant and will never change in the lifetime of the port.
496 CarlaEngineCVPort(const CarlaEngineClient
& client
, bool isInputPort
, uint32_t indexOffset
) noexcept
;
501 ~CarlaEngineCVPort() noexcept override
;
504 * Get the type of the port, in this case kEnginePortTypeCV.
506 inline EnginePortType
getType() const noexcept final
508 return kEnginePortTypeCV
;
512 * Initialize the port's internal buffer.
514 void initBuffer() noexcept override
;
517 * Direct access to the port's CV buffer.
520 inline float* getBuffer() const noexcept
526 * Get min/max range for this CV port.
528 inline void getRange(float& min
, float& max
) const noexcept
535 * Set min/max range for this CV port.
537 void setRange(float min
, float max
) noexcept
;
542 float fMinimum
, fMaximum
;
544 CARLA_DECLARE_NON_COPYABLE(CarlaEngineCVPort
)
549 * Carla Engine Event port.
551 class CARLA_API CarlaEngineEventPort
: public CarlaEnginePort
556 * All constructor parameters are constant and will never change in the lifetime of the port.
558 CarlaEngineEventPort(const CarlaEngineClient
& client
, bool isInputPort
, uint32_t indexOffset
) noexcept
;
563 ~CarlaEngineEventPort() noexcept override
;
566 * Get the type of the port, in this case kEnginePortTypeEvent.
568 inline EnginePortType
getType() const noexcept final
570 return kEnginePortTypeEvent
;
574 * Initialize the port's internal buffer for @a engine.
576 void initBuffer() noexcept override
;
579 * Get the number of events present in the buffer.
580 * @note You must only call this for input ports.
582 virtual uint32_t getEventCount() const noexcept
;
585 * Get the event at @a index.
586 * @note You must only call this for input ports.
588 virtual EngineEvent
& getEvent(uint32_t index
) const noexcept
;
591 * Get the event at @a index, faster unchecked version.
593 virtual EngineEvent
& getEventUnchecked(uint32_t index
) const noexcept
;
596 * Write a control event into the buffer.
597 * @note You must only call this for output ports.
599 bool writeControlEvent(uint32_t time
, uint8_t channel
, const EngineControlEvent
& ctrl
) noexcept
;
602 * Write a control event into the buffer.
603 * Arguments are the same as in the EngineControlEvent struct.
604 * @note You must only call this for output ports.
606 virtual bool writeControlEvent(uint32_t time
, uint8_t channel
, EngineControlEventType type
,
607 uint16_t param
, int8_t midiValue
, float normalizedValue
) noexcept
;
610 * Write a MIDI event into the buffer.
611 * @note You must only call this for output ports.
613 bool writeMidiEvent(uint32_t time
, uint8_t size
, const uint8_t* data
) noexcept
;
616 * Write a MIDI event into the buffer.
617 * @note You must only call this for output ports.
619 bool writeMidiEvent(uint32_t time
, uint8_t channel
, const EngineMidiEvent
& midi
) noexcept
;
622 * Write a MIDI event into the buffer.
623 * Arguments are the same as in the EngineMidiEvent struct.
624 * @note You must only call this for output ports.
626 virtual bool writeMidiEvent(uint32_t time
, uint8_t channel
, uint8_t size
, const uint8_t* data
) noexcept
;
630 const EngineProcessMode kProcessMode
;
631 EngineEvent
* fBuffer
;
632 friend class CarlaPluginInstance
;
633 friend class CarlaEngineCVSourcePorts
;
635 CARLA_DECLARE_NON_COPYABLE(CarlaEngineEventPort
)
639 // -----------------------------------------------------------------------
642 * Carla Engine Meta CV Port.
643 * FIXME needs a better name...
645 class CARLA_API CarlaEngineCVSourcePorts
651 virtual ~CarlaEngineCVSourcePorts();
654 * Add a CV port as a source of events.
656 virtual bool addCVSource(CarlaEngineCVPort
* port
, uint32_t portIndexOffset
, bool reconfigureNow
);
659 * Remove a CV port as a source of events.
661 virtual bool removeCVSource(uint32_t portIndexOffset
);
664 * Get events and add them to an event port.
665 * FIXME needs a better name...
667 virtual void initPortBuffers(const float* const* buffers
, uint32_t frames
,
668 bool sampleAccurate
, CarlaEngineEventPort
* eventPort
);
671 * Set value range for a CV port.
673 bool setCVSourceRange(uint32_t portIndexOffset
, float minimum
, float maximum
);
683 struct ProtectedData
;
684 ProtectedData
* const pData
;
687 * The constructor, protected.
689 CarlaEngineCVSourcePorts();
691 CARLA_DECLARE_NON_COPYABLE(CarlaEngineCVSourcePorts
)
695 // -----------------------------------------------------------------------
698 * Carla Engine Client.
699 * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).
700 * @note This is a virtual class, some engine types provide custom functionality.
702 class CARLA_API CarlaEngineClient
708 virtual ~CarlaEngineClient() noexcept
;
711 * Activate this client.
712 * Client must be deactivated before calling this function.
714 virtual void activate() noexcept
;
717 * Deactivate this client.
718 * Client must be activated before calling this function.
720 virtual void deactivate(bool willClose
) noexcept
;
723 * Check if the client is activated.
725 virtual bool isActive() const noexcept
;
728 * Check if the client is ok.
729 * Plugins will refuse to instantiate if this returns false.
730 * @note This is always true in rack and patchbay processing modes.
732 virtual bool isOk() const noexcept
;
735 * Get the current latency, in samples.
737 virtual uint32_t getLatency() const noexcept
;
740 * Change the client's latency.
742 virtual void setLatency(uint32_t samples
) noexcept
;
745 * Add a new port of type @a portType.
746 * @note This function does nothing in rack processing mode since ports are static there.
748 virtual CarlaEnginePort
* addPort(EnginePortType portType
, const char* name
, bool isInput
, uint32_t indexOffset
);
751 * Remove a previously added port via addPort().
753 virtual bool removePort(EnginePortType portType
, const char* name
, bool isInput
);
755 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
757 * Create an instance of CV source ports.
758 * Must be called only once per client.
760 virtual CarlaEngineCVSourcePorts
* createCVSourcePorts();
764 * Get this client's engine.
766 const CarlaEngine
& getEngine() const noexcept
;
769 * Get the engine's process mode.
771 EngineProcessMode
getProcessMode() const noexcept
;
774 * Get port count for a type and mode.
776 uint
getPortCount(EnginePortType portType
, bool isInput
) const noexcept
;
779 * Get an audio port name.
781 const char* getAudioPortName(bool isInput
, uint index
) const noexcept
;
784 * Get a CV port name.
786 const char* getCVPortName(bool isInput
, uint index
) const noexcept
;
789 * Get an event port name.
791 const char* getEventPortName(bool isInput
, uint index
) const noexcept
;
796 struct ProtectedData
;
797 ProtectedData
* const pData
;
800 * The constructor, protected.
802 CarlaEngineClient(ProtectedData
* pData
);
804 CARLA_DECLARE_NON_COPYABLE(CarlaEngineClient
)
808 // -----------------------------------------------------------------------
812 * @note This is a virtual class for all available engine types available in Carla.
814 class CARLA_API CarlaEngine
818 * The constructor, protected.
819 * @note This only initializes engine data, it doesn't actually start the engine.
826 * The engine must have been closed before this happens.
828 virtual ~CarlaEngine();
830 // -------------------------------------------------------------------
834 * Get the number of available engine drivers.
836 static uint
getDriverCount();
839 * Get the name of the engine driver at @a index.
841 static const char* getDriverName(uint index
);
844 * Get the device names of the driver at @a index.
846 static const char* const* getDriverDeviceNames(uint index
);
849 * Get device information about the driver at @a index and name @a driverName.
851 static const EngineDriverDeviceInfo
* getDriverDeviceInfo(uint index
, const char* driverName
);
854 * Show a device custom control panel.
855 * @see ENGINE_DRIVER_DEVICE_HAS_CONTROL_PANEL
857 static bool showDriverDeviceControlPanel(uint index
, const char* deviceName
);
860 * Create a new engine, using driver @a driverName.
861 * Returned value must be deleted when no longer needed.
862 * @note This only initializes engine data, it doesn't actually start the engine.
864 static CarlaEngine
* newDriverByName(const char* driverName
);
866 // -------------------------------------------------------------------
870 * Maximum client name size.
872 virtual uint
getMaxClientNameSize() const noexcept
;
875 * Maximum port name size.
877 virtual uint
getMaxPortNameSize() const noexcept
;
880 * Current number of plugins loaded.
882 uint
getCurrentPluginCount() const noexcept
;
885 * Maximum number of loadable plugins allowed.
886 * This function returns 0 if engine is not started.
888 uint
getMaxPluginNumber() const noexcept
;
890 // -------------------------------------------------------------------
891 // Virtual, per-engine type calls
894 * Initialize/start the engine, using @a clientName.
895 * When the engine is initialized, you need to call idle() at regular intervals.
897 virtual bool init(const char* clientName
) = 0;
901 * This function always closes the engine even if it returns false.
902 * In other words, even when something goes wrong when closing the engine it still be closed nonetheless.
904 virtual bool close();
909 virtual void idle() noexcept
;
912 * Check if engine implementation calls idle on the main thread.
913 * Typically true unless running Carla as a plugin.
915 virtual bool hasIdleOnMainThread() const noexcept
= 0;
918 * Check if engine is running.
920 virtual bool isRunning() const noexcept
= 0;
923 * Check if engine is running offline (aka freewheel mode).
925 virtual bool isOffline() const noexcept
= 0;
928 * Check if engine runs on a constant buffer size value.
929 * Default implementation returns true.
931 virtual bool usesConstantBufferSize() const noexcept
;
936 virtual EngineType
getType() const noexcept
= 0;
939 * Get the currently used driver name.
941 virtual const char* getCurrentDriverName() const noexcept
= 0;
944 * Add new engine client.
945 * @note This function must only be called within a plugin class.
947 virtual CarlaEngineClient
* addClient(CarlaPluginPtr plugin
);
950 * Get the current CPU load estimated by the engine.
952 virtual float getDSPLoad() const noexcept
;
955 * Get the total number of xruns so far.
957 virtual uint32_t getTotalXruns() const noexcept
;
960 * Clear the xrun count.
962 virtual void clearXruns() const noexcept
;
965 * Dynamically change buffer size and/or sample rate while engine is running.
966 * @see ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE
967 * @see ENGINE_DRIVER_DEVICE_VARIABLE_SAMPLE_RATE
969 virtual bool setBufferSizeAndSampleRate(uint bufferSize
, double sampleRate
);
972 * Show the custom control panel for the current engine device.
973 * @see ENGINE_DRIVER_DEVICE_HAS_CONTROL_PANEL
975 virtual bool showDeviceControlPanel() const noexcept
;
977 // -------------------------------------------------------------------
982 * @see ENGINE_CALLBACK_PLUGIN_ADDED
984 bool addPlugin(BinaryType btype
, PluginType ptype
,
985 const char* filename
, const char* name
, const char* label
, int64_t uniqueId
,
986 const void* extra
, uint options
= PLUGIN_OPTIONS_NULL
);
989 * Add new plugin, using native binary type.
990 * @see ENGINE_CALLBACK_PLUGIN_ADDED
992 bool addPlugin(PluginType ptype
,
993 const char* filename
, const char* name
, const char* label
, int64_t uniqueId
,
997 * Remove plugin with id @a id.
998 * @see ENGINE_CALLBACK_PLUGIN_REMOVED
1000 virtual bool removePlugin(uint id
);
1003 * Remove all plugins.
1005 bool removeAllPlugins();
1007 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
1009 * Rename plugin with id @a id to @a newName.
1010 * Returns the new name, or null if the operation failed.
1011 * Returned variable must be deleted if non-null.
1012 * @see ENGINE_CALLBACK_PLUGIN_RENAMED
1014 virtual bool renamePlugin(uint id
, const char* newName
);
1017 * Clone plugin with id @a id.
1019 bool clonePlugin(uint id
);
1022 * Prepare replace of plugin with id @a id.
1023 * The next call to addPlugin() will use this id, replacing the selected plugin.
1024 * @note This function requires addPlugin() to be called afterwards, as soon as possible.
1026 bool replacePlugin(uint id
) noexcept
;
1029 * Switch plugins with id @a idA and @a idB.
1031 virtual bool switchPlugins(uint idA
, uint idB
) noexcept
;
1035 * Set a plugin's parameter in drag/touch mode.
1036 * Usually happens from a UI when the user is moving a parameter with a mouse or similar input.
1038 * @param parameterId The parameter to update
1039 * @param touch The new state for the parameter
1041 virtual void touchPluginParameter(uint id
, uint32_t parameterId
, bool touch
) noexcept
;
1044 * Get plugin with id @a id.
1046 CarlaPluginPtr
getPlugin(uint id
) const noexcept
;
1049 * Get plugin with id @a id, faster unchecked version.
1051 CarlaPluginPtr
getPluginUnchecked(uint id
) const noexcept
;
1054 * Get a unique plugin name within the engine.
1055 * Returned variable must be deleted if non-null.
1057 const char* getUniquePluginName(const char* name
) const;
1059 // -------------------------------------------------------------------
1060 // Project management
1063 * Load a file of any type.
1064 * This will try to load a generic file as a plugin,
1065 * either by direct handling (SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
1067 bool loadFile(const char* filename
);
1070 * Load a project file.
1071 * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
1073 bool loadProject(const char* filename
, bool setAsCurrentProject
);
1076 * Save current project to a file.
1078 bool saveProject(const char* filename
, bool setAsCurrentProject
);
1080 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
1082 * Get the currently set project folder.
1083 * @note Valid for both standalone and plugin versions.
1085 virtual const char* getCurrentProjectFolder() const noexcept
;
1088 * Get the currently set project filename.
1089 * @note Valid only for both standalone version.
1091 const char* getCurrentProjectFilename() const noexcept
;
1094 * Clear the currently set project filename.
1096 void clearCurrentProjectFilename() noexcept
;
1099 // -------------------------------------------------------------------
1100 // Information (base)
1103 * Get the current buffer size.
1105 uint32_t getBufferSize() const noexcept
;
1108 * Get the current sample rate.
1110 double getSampleRate() const noexcept
;
1113 * Get the current engine name.
1115 const char* getName() const noexcept
;
1118 * Get the current engine process mode.
1120 EngineProcessMode
getProccessMode() const noexcept
;
1123 * Get the current engine options (read-only).
1125 const EngineOptions
& getOptions() const noexcept
;
1128 * Get the current Time information (read-only).
1130 virtual EngineTimeInfo
getTimeInfo() const noexcept
;
1132 // -------------------------------------------------------------------
1133 // Information (peaks)
1136 * Get a plugin's peak values.
1137 * @note not thread-safe if pluginId == MAIN_CARLA_PLUGIN_ID
1139 const float* getPeaks(uint pluginId
) const noexcept
;
1142 * Get a plugin's input peak value.
1144 float getInputPeak(uint pluginId
, bool isLeft
) const noexcept
;
1147 * Get a plugin's output peak value.
1149 float getOutputPeak(uint pluginId
, bool isLeft
) const noexcept
;
1151 // -------------------------------------------------------------------
1155 * Call the main engine callback, if set.
1156 * May be called by plugins.
1158 virtual void callback(bool sendHost
, bool sendOSC
,
1159 EngineCallbackOpcode action
, uint pluginId
,
1160 int value1
, int value2
, int value3
, float valuef
, const char* valueStr
) noexcept
;
1163 * Set the main engine callback to @a func.
1165 void setCallback(EngineCallbackFunc func
, void* ptr
) noexcept
;
1167 // -------------------------------------------------------------------
1171 * Call the file callback, if set.
1172 * May be called by plugins.
1174 virtual const char* runFileCallback(FileCallbackOpcode action
,
1175 bool isDir
, const char* title
, const char* filter
) noexcept
;
1178 * Set the file callback to @a func.
1180 void setFileCallback(FileCallbackFunc func
, void* ptr
) noexcept
;
1182 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
1183 // -------------------------------------------------------------------
1187 * Connect two patchbay ports.
1189 virtual bool patchbayConnect(bool external
,
1190 uint groupA
, uint portA
,
1191 uint groupB
, uint portB
);
1194 * Remove a patchbay connection.
1196 virtual bool patchbayDisconnect(bool external
, uint connectionId
);
1199 * Set the position of a group.
1201 virtual bool patchbaySetGroupPos(bool sendHost
, bool sendOSC
, bool external
,
1202 uint groupId
, int x1
, int y1
, int x2
, int y2
);
1205 * Force the engine to resend all patchbay clients, ports and connections again.
1207 virtual bool patchbayRefresh(bool sendHost
, bool sendOSC
, bool external
);
1210 // -------------------------------------------------------------------
1214 * Start playback of the engine transport.
1216 virtual void transportPlay() noexcept
;
1219 * Pause the engine transport.
1221 virtual void transportPause() noexcept
;
1224 * Set the engine transport bpm to @a bpm.
1226 virtual void transportBPM(double bpm
) noexcept
;
1229 * Relocate the engine transport to @a frames.
1231 virtual void transportRelocate(uint64_t frame
) noexcept
;
1233 // -------------------------------------------------------------------
1239 const char* getLastError() const noexcept
;
1244 void setLastError(const char* error
) const noexcept
;
1246 // -------------------------------------------------------------------
1250 * Check if the engine is about to close.
1252 bool isAboutToClose() const noexcept
;
1255 * Tell the engine it's about to close.
1256 * This is used to prevent the engine thread(s) from reactivating.
1257 * Returns true if there's no pending engine events.
1259 bool setAboutToClose() noexcept
;
1261 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
1265 bool isLoadingProject() const noexcept
;
1269 * Tell the engine to stop the current cancelable action.
1270 * @see ENGINE_CALLBACK_CANCELABLE_ACTION
1272 void setActionCanceled(bool canceled
) noexcept
;
1275 * Check wherever the last cancelable action was indeed canceled or not.
1277 bool wasActionCanceled() const noexcept
;
1279 // -------------------------------------------------------------------
1283 * Set the engine option @a option to @a value or @a valueStr.
1285 virtual void setOption(EngineOption option
, int value
, const char* valueStr
) noexcept
;
1287 // -------------------------------------------------------------------
1290 #ifndef BUILD_BRIDGE
1292 * Check if OSC controller is registered.
1294 bool isOscControlRegistered() const noexcept
;
1297 * Get OSC TCP server path.
1299 const char* getOscServerPathTCP() const noexcept
;
1302 * Get OSC UDP server path.
1304 const char* getOscServerPathUDP() const noexcept
;
1307 // -------------------------------------------------------------------
1311 * Internal data, for CarlaEngine subclasses and friends.
1313 struct ProtectedData
;
1314 ProtectedData
* const pData
;
1317 * Some internal classes read directly from pData or call protected functions.
1319 friend class CarlaEngineEventPort
;
1320 friend class CarlaEngineOsc
;
1321 friend class CarlaEngineRunner
;
1322 friend class CarlaPluginInstance
;
1323 friend class EngineInternalGraph
;
1324 friend class PendingRtEventsRunner
;
1325 friend class ScopedActionLock
;
1326 friend class ScopedEngineEnvironmentLocker
;
1327 friend class ScopedRunnerStopper
;
1328 friend class PatchbayGraph
;
1329 friend struct ExternalGraph
;
1330 friend struct RackGraph
;
1332 // -------------------------------------------------------------------
1336 * Report to all plugins about buffer size change.
1338 void bufferSizeChanged(uint32_t newBufferSize
);
1341 * Report to all plugins about sample rate change.
1342 * This is not supported on all plugin types, in which case they will have to be re-initiated.
1344 void sampleRateChanged(double newSampleRate
);
1347 * Report to all plugins about offline mode change.
1349 void offlineModeChanged(bool isOffline
);
1352 * Set a plugin (stereo) peak values.
1355 void setPluginPeaksRT(uint pluginId
, float const inPeaks
[2], float const outPeaks
[2]) noexcept
;
1359 * Common save project function for main engine and plugin.
1361 void saveProjectInternal(water::MemoryOutputStream
& outStrm
) const;
1364 * Common load project function for main engine and plugin.
1366 bool loadProjectInternal(water::XmlDocument
& xmlDoc
, bool alwaysLoadConnections
);
1369 // -------------------------------------------------------------------
1373 * Return internal data, needed for EventPorts when used in Rack, Patchbay and Bridge modes.
1376 EngineEvent
* getInternalEventBuffer(bool isInput
) const noexcept
;
1378 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
1379 // -------------------------------------------------------------------
1383 * Virtual functions for handling patchbay state.
1384 * Do not free returned data.
1386 struct PatchbayPosition
{ const char* name
; int x1
, y1
, x2
, y2
, pluginId
; bool dealloc
; };
1387 virtual const char* const* getPatchbayConnections(bool external
) const;
1388 virtual const PatchbayPosition
* getPatchbayPositions(bool external
, uint
& count
) const;
1389 virtual void restorePatchbayConnection(bool external
, const char* sourcePort
, const char* targetPort
);
1390 // returns true if plugin name mapping found, ppos.name updated to its converted name
1391 virtual bool restorePatchbayGroupPosition(bool external
, PatchbayPosition
& ppos
);
1394 * Virtual functions for handling external graph ports.
1396 virtual bool connectExternalGraphPort(uint
, uint
, const char*);
1397 virtual bool disconnectExternalGraphPort(uint
, uint
, const char*);
1400 // -------------------------------------------------------------------
1402 CARLA_DECLARE_NON_COPYABLE(CarlaEngine
)
1407 // -----------------------------------------------------------------------
1409 CARLA_BACKEND_END_NAMESPACE
1411 #endif // CARLA_ENGINE_HPP_INCLUDED