|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220 |
- /*
- * Carla Engine API
- * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #ifndef CARLA_ENGINE_HPP_INCLUDED
- #define CARLA_ENGINE_HPP_INCLUDED
-
- #include "CarlaBackend.h"
- #include "CarlaMIDI.h"
-
- #ifdef BUILD_BRIDGE
- struct CarlaOscData;
- #endif
-
- CARLA_BACKEND_START_NAMESPACE
-
- #if 0
- } /* Fix editor indentation */
- #endif
-
- /*!
- * @defgroup CarlaEngineAPI Carla Engine API
- *
- * The Carla Engine API.
- * @{
- */
-
- /*!
- * The type of an engine.
- */
- enum EngineType {
- /*!
- * Null engine type.
- */
- kEngineTypeNull = 0,
-
- /*!
- * JACK engine type.\n
- * Provides all processing modes.
- */
- kEngineTypeJack = 1,
-
- /*!
- * Juce engine type, used to provide Native Audio and MIDI support.
- */
- kEngineTypeJuce = 2,
-
- /*!
- * RtAudio engine type, used to provide Native Audio and MIDI support.
- */
- kEngineTypeRtAudio = 3,
-
- /*!
- * Plugin engine type, used to export the engine as a plugin.
- */
- kEngineTypePlugin = 4,
-
- /*!
- * Bridge engine type, used in BridgePlugin class.
- */
- kEngineTypeBridge = 5
- };
-
- /*!
- * The type of an engine port.
- */
- enum EnginePortType {
- /*!
- * Null port type.
- */
- kEnginePortTypeNull = 0,
-
- /*!
- * Audio port type.
- * \see CarlaEngineAudioPort
- */
- kEnginePortTypeAudio = 1,
-
- /*!
- * CV port type.
- * \see CarlaEngineCVPort
- */
- kEnginePortTypeCV = 2,
-
- /*!
- * Event port type (Control or MIDI).
- ** \see CarlaEngineEventPort
- */
- kEnginePortTypeEvent = 3
- };
-
- /*!
- * The type of an engine event.
- */
- enum EngineEventType {
- /*!
- * Null port type.
- */
- kEngineEventTypeNull = 0,
-
- /*!
- * Control event type.
- * \see EngineControlEvent
- */
- kEngineEventTypeControl = 1,
-
- /*!
- * MIDI event type.
- * \see EngineMidiEvent
- */
- kEngineEventTypeMidi = 2
- };
-
- /*!
- * The type of an engine control event.
- */
- enum EngineControlEventType {
- /*!
- * Null event type.
- */
- kEngineControlEventTypeNull = 0,
-
- /*!
- * Parameter event type.\n
- * \note Value uses a normalized range of 0.0f<->1.0f.
- */
- kEngineControlEventTypeParameter = 1,
-
- /*!
- * MIDI Bank event type.
- */
- kEngineControlEventTypeMidiBank = 2,
-
- /*!
- * MIDI Program change event type.
- */
- kEngineControlEventTypeMidiProgram = 3,
-
- /*!
- * All sound off event type.
- */
- kEngineControlEventTypeAllSoundOff = 4,
-
- /*!
- * All notes off event type.
- */
- kEngineControlEventTypeAllNotesOff = 5
- };
-
- /*!
- * Engine control event.
- */
- struct EngineControlEvent {
- EngineControlEventType type; //!< Control-Event type.
- uint16_t param; //!< Parameter Id, midi bank or midi program.
- float value; //!< Parameter value, normalized to 0.0f<->1.0f.
-
- void dumpToMidiData(const uint8_t channel, uint8_t& size, uint8_t data[3]) const noexcept;
- };
-
- /*!
- * Engine MIDI event.
- */
- struct EngineMidiEvent {
- static const uint8_t kDataSize = 4; //!< Size of internal data
-
- uint8_t port; //!< Port offset (usually 0)
- uint8_t size; //!< Number of bytes used
-
- /*!
- * MIDI data, without channel bit.
- * If size > kDataSize, dataExt is used.
- */
- uint8_t data[kDataSize];
- const uint8_t* dataExt;
- };
-
- /*!
- * Engine event.
- */
- struct EngineEvent {
- EngineEventType type; //!< Event Type; either Control or MIDI
- uint32_t time; //!< Time offset in frames
- uint8_t channel; //!< Channel, used for MIDI-related events
-
- /*!
- * Event specific data.
- */
- union {
- EngineControlEvent ctrl;
- EngineMidiEvent midi;
- };
-
- void fillFromMidiData(const uint8_t size, const uint8_t* const data);
- };
-
- /*!
- * Engine options.
- */
- struct EngineOptions {
- EngineProcessMode processMode;
- EngineTransportMode transportMode;
-
- bool forceStereo;
- bool preferPluginBridges;
- bool preferUiBridges;
- bool uisAlwaysOnTop;
-
- unsigned int maxParameters;
- unsigned int uiBridgesTimeout;
- unsigned int audioNumPeriods;
- unsigned int audioBufferSize;
- unsigned int audioSampleRate;
- const char* audioDevice;
-
- const char* binaryDir;
- const char* resourceDir;
-
- EngineOptions()
- #ifdef CARLA_OS_LINUX
- : processMode(ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS),
- transportMode(ENGINE_TRANSPORT_MODE_JACK),
- #else
- : processMode(ENGINE_PROCESS_MODE_CONTINUOUS_RACK),
- transportMode(ENGINE_TRANSPORT_MODE_INTERNAL),
- #endif
- forceStereo(false),
- preferPluginBridges(false),
- preferUiBridges(true),
- uisAlwaysOnTop(true),
- maxParameters(MAX_DEFAULT_PARAMETERS),
- uiBridgesTimeout(4000),
- audioNumPeriods(2),
- audioBufferSize(512),
- audioSampleRate(44100),
- audioDevice(nullptr),
- binaryDir(nullptr),
- resourceDir(nullptr) {}
-
- ~EngineOptions()
- {
- if (audioDevice != nullptr)
- {
- delete[] audioDevice;
- audioDevice = nullptr;
- }
-
- if (binaryDir != nullptr)
- {
- delete[] binaryDir;
- binaryDir = nullptr;
- }
-
- if (resourceDir != nullptr)
- {
- delete[] resourceDir;
- resourceDir = nullptr;
- }
- }
- };
-
- /*!
- * Engine BBT Time information.
- */
- struct EngineTimeInfoBBT {
- int32_t bar; //!< current bar
- int32_t beat; //!< current beat-within-bar
- int32_t tick; //!< current tick-within-beat
- double barStartTick;
-
- float beatsPerBar; //!< time signature "numerator"
- float beatType; //!< time signature "denominator"
-
- double ticksPerBeat;
- double beatsPerMinute;
-
- EngineTimeInfoBBT() noexcept
- : bar(0),
- beat(0),
- tick(0),
- barStartTick(0.0),
- beatsPerBar(0.0f),
- beatType(0.0f),
- ticksPerBeat(0.0),
- beatsPerMinute(0.0) {}
- };
-
- /*!
- * Engine Time information.
- */
- struct EngineTimeInfo {
- static const uint kValidBBT = 0x1;
-
- bool playing;
- uint64_t frame;
- uint64_t usecs;
- uint valid;
- EngineTimeInfoBBT bbt;
-
- EngineTimeInfo() noexcept
- : playing(false),
- frame(0),
- usecs(0),
- valid(0x0) {}
-
- void clear() noexcept
- {
- playing = false;
- frame = 0;
- usecs = 0;
- valid = 0x0;
- }
-
- // quick operator, doesn't check all values
- bool operator==(const EngineTimeInfo& timeInfo) const noexcept
- {
- if (timeInfo.playing != playing || timeInfo.frame != frame || timeInfo.valid != valid)
- return false;
- if ((valid & kValidBBT) == 0)
- return true;
- if (timeInfo.bbt.beatsPerMinute != bbt.beatsPerMinute)
- return false;
- return true;
- }
-
- bool operator!=(const EngineTimeInfo& timeInfo) const noexcept
- {
- return !operator==(timeInfo);
- }
- };
-
- // -----------------------------------------------------------------------
-
- /*!
- * Carla Engine port (Abstract).\n
- * This is the base class for all Carla Engine ports.
- */
- class CarlaEnginePort
- {
- protected:
- /*!
- * The constructor.\n
- * Param \a isInput defines wherever this is an input port or not (output otherwise).\n
- * Input/output and process mode are constant for the lifetime of the port.
- */
- CarlaEnginePort(const CarlaEngine& engine, const bool isInput);
-
- public:
- /*!
- * The destructor.
- */
- virtual ~CarlaEnginePort();
-
- /*!
- * Get the type of the port, as provided by the respective subclasses.
- */
- virtual EnginePortType getType() const noexcept = 0;
-
- /*!
- * Initialize the port's internal buffer.
- */
- virtual void initBuffer() = 0;
-
- /*!
- * Check if this port is an input.
- */
- bool isInput() const noexcept
- {
- return fIsInput;
- }
-
- #ifndef DOXYGEN
- protected:
- const CarlaEngine& fEngine;
- const bool fIsInput;
-
- CARLA_DECLARE_NON_COPY_CLASS(CarlaEnginePort)
- #endif
- };
-
- /*!
- * Carla Engine Audio port.
- */
- class CarlaEngineAudioPort : public CarlaEnginePort
- {
- public:
- /*!
- * The constructor.\n
- * All constructor parameters are constant and will never change in the lifetime of the port.
- */
- CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInput);
-
- /*!
- * The destructor.
- */
- virtual ~CarlaEngineAudioPort() override;
-
- /*!
- * Get the type of the port, in this case kEnginePortTypeAudio.
- */
- EnginePortType getType() const noexcept override
- {
- return kEnginePortTypeAudio;
- }
-
- /*!
- * Initialize the port's internal buffer.
- */
- virtual void initBuffer() override;
-
- /*!
- * Direct access to the port's audio buffer.
- */
- float* getBuffer() const noexcept
- {
- return fBuffer;
- }
-
- #ifndef DOXYGEN
- protected:
- float* fBuffer;
-
- CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineAudioPort)
- #endif
- };
-
- /*!
- * Carla Engine CV port.
- */
- class CarlaEngineCVPort : public CarlaEnginePort
- {
- public:
- /*!
- * The constructor.\n
- * All constructor parameters are constant and will never change in the lifetime of the port.
- */
- CarlaEngineCVPort(const CarlaEngine& engine, const bool isInput);
-
- /*!
- * The destructor.
- */
- virtual ~CarlaEngineCVPort() override;
-
- /*!
- * Get the type of the port, in this case kEnginePortTypeCV.
- */
- EnginePortType getType() const noexcept override
- {
- return kEnginePortTypeCV;
- }
-
- /*!
- * Initialize the port's internal buffer for \a engine.
- */
- virtual void initBuffer() override;
-
- /*!
- * Set a new buffer size.
- */
- void setBufferSize(const uint32_t bufferSize);
-
- #if 0
- // TESTING: I should remove this
- /*!
- * Write buffer back into the engine.
- */
- virtual void writeBuffer(const uint32_t frames, const uint32_t timeOffset);
-
- #endif
-
- /*!
- * Direct access to the port's buffer.
- */
- float* getBuffer() const noexcept
- {
- return fBuffer;
- }
-
- #ifndef DOXYGEN
- protected:
- float* fBuffer;
- const EngineProcessMode fProcessMode;
-
- CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort)
- #endif
- };
-
- /*!
- * Carla Engine Event port.
- */
- class CarlaEngineEventPort : public CarlaEnginePort
- {
- public:
- /*!
- * The constructor.\n
- * All constructor parameters are constant and will never change in the lifetime of the port.
- */
- CarlaEngineEventPort(const CarlaEngine& engine, const bool isInput);
-
- /*!
- * The destructor.
- */
- virtual ~CarlaEngineEventPort() override;
-
- /*!
- * Get the type of the port, in this case kEnginePortTypeEvent.
- */
- EnginePortType getType() const noexcept override
- {
- return kEnginePortTypeEvent;
- }
-
- /*!
- * Initialize the port's internal buffer for \a engine.
- */
- virtual void initBuffer() override;
-
- /*!
- * Get the number of events present in the buffer.
- * \note You must only call this for input ports.
- */
- virtual uint32_t getEventCount() const;
-
- /*!
- * Get the event at \a index.
- * \note You must only call this for input ports.
- */
- virtual const EngineEvent& getEvent(const uint32_t index);
-
- /*!
- * Get the event at \a index, faster unchecked version.
- */
- virtual const EngineEvent& getEventUnchecked(const uint32_t index);
-
- /*!
- * Write a control event into the buffer.\n
- * Arguments are the same as in the EngineControlEvent struct.
- * \note You must only call this for output ports.
- */
- virtual bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value = 0.0f);
-
- /*!
- * Write a control event into the buffer, overloaded call.
- */
- bool writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl)
- {
- return writeControlEvent(time, channel, ctrl.type, ctrl.param, ctrl.value);
- }
-
- /*!
- * Write a MIDI event into the buffer.\n
- * Arguments are the same as in the EngineMidiEvent struct.
- * \note You must only call this for output ports.
- */
- virtual bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data);
-
- /*!
- * Write a MIDI event into the buffer, overloaded call.
- */
- bool writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data)
- {
- return writeMidiEvent(time, MIDI_GET_CHANNEL_FROM_DATA(data), 0, size, data);
- }
-
- /*!
- * Write a MIDI event into the buffer, overloaded call.
- */
- bool writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi)
- {
- return writeMidiEvent(time, channel, midi.port, midi.size, midi.data);
- }
-
- #ifndef DOXYGEN
- protected:
- EngineEvent* fBuffer;
- const EngineProcessMode fProcessMode;
-
- CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineEventPort)
- #endif
- };
-
- // -----------------------------------------------------------------------
-
- /*!
- * Carla Engine client.\n
- * Each plugin requires one client from the engine (created via CarlaEngine::addClient()).\n
- * \note This is a virtual class, some engine types provide custom funtionality.
- */
- class CarlaEngineClient
- {
- public:
- /*!
- * The constructor, protected.\n
- * All constructor parameters are constant and will never change in the lifetime of the client.\n
- * Client starts in deactivated state.
- */
- CarlaEngineClient(const CarlaEngine& engine);
-
- /*!
- * The destructor.
- */
- virtual ~CarlaEngineClient();
-
- /*!
- * Activate this client.\n
- * Client must be deactivated before calling this function.
- */
- virtual void activate();
-
- /*!
- * Deactivate this client.\n
- * Client must be activated before calling this function.
- */
- virtual void deactivate();
-
- /*!
- * Check if the client is activated.
- */
- virtual bool isActive() const noexcept;
-
- /*!
- * Check if the client is ok.\n
- * Plugins will refuse to instantiate if this returns false.
- * \note This is always true in rack and patchbay processing modes.
- */
- virtual bool isOk() const noexcept;
-
- /*!
- * Get the current latency, in samples.
- */
- virtual uint32_t getLatency() const noexcept;
-
- /*!
- * Change the client's latency.
- */
- virtual void setLatency(const uint32_t samples) noexcept;
-
- /*!
- * Add a new port of type \a portType.
- * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output).
- */
- virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput);
-
- #ifndef DOXYGEN
- protected:
- const CarlaEngine& fEngine;
-
- bool fActive;
- uint32_t fLatency;
-
- CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineClient)
- #endif
- };
-
- // -----------------------------------------------------------------------
-
- /*!
- * Protected data used in CarlaEngine and subclasses.\n
- * Non-engine code MUST NEVER have direct access to this.
- */
- struct CarlaEngineProtectedData;
-
- /*!
- * Carla Engine.
- * \note This is a virtual class for all available engine types available in Carla.
- */
- class CarlaEngine
- {
- protected:
- /*!
- * The constructor, protected.\n
- * \note This only initializes engine data, it doesn't start the engine (audio).
- */
- CarlaEngine();
-
- public:
- /*!
- * The decontructor.
- * The engine must have been closed before this happens.
- */
- virtual ~CarlaEngine();
-
- // -------------------------------------------------------------------
- // Static calls
-
- /*!
- * Get the number of available engine drivers.
- */
- static unsigned int getDriverCount();
-
- /*!
- * Get the name of the engine driver at \a index.
- */
- static const char* getDriverName(const unsigned int index);
-
- /*!
- * Get the device names of driver at \a index.
- */
- static const char* const* getDriverDeviceNames(const unsigned int index);
-
- /*!
- * Get the device names of driver at \a index.
- */
- static const EngineDriverDeviceInfo* getDriverDeviceInfo(const unsigned int index, const char* const driverName);
-
- /*!
- * Create a new engine, using driver \a driverName. \n
- * Returned variable must be deleted when no longer needed.
- * \note This only initializes engine data, it doesn't initialize the engine itself.
- */
- static CarlaEngine* newDriverByName(const char* const driverName);
-
- // -------------------------------------------------------------------
- // Constant values
-
- /*!
- * Maximum client name size.
- */
- virtual unsigned int getMaxClientNameSize() const noexcept;
-
- /*!
- * Maximum port name size.
- */
- virtual unsigned int getMaxPortNameSize() const noexcept;
-
- /*!
- * Current number of plugins loaded.
- */
- unsigned int getCurrentPluginCount() const noexcept;
-
- /*!
- * Maximum number of loadable plugins allowed.
- * \note This function returns 0 if engine is not started.
- */
- unsigned int getMaxPluginNumber() const noexcept;
-
- // -------------------------------------------------------------------
- // Virtual, per-engine type calls
-
- /*!
- * Initialize engine, using \a clientName.
- */
- virtual bool init(const char* const clientName);
-
- /*!
- * Close engine.
- */
- virtual bool close();
-
- /*!
- * Idle engine.
- */
- virtual void idle();
-
- /*!
- * Check if engine is running.
- */
- virtual bool isRunning() const noexcept = 0;
-
- /*!
- * Check if engine is running offline (aka freewheel mode).
- */
- virtual bool isOffline() const noexcept = 0;
-
- /*!
- * Get engine type.
- */
- virtual EngineType getType() const noexcept = 0;
-
- /*!
- * Get the currently used driver name.
- */
- virtual const char* getCurrentDriverName() const noexcept = 0;
-
- /*!
- * Add new engine client.
- * \note This function must only be called within a plugin class.
- */
- virtual CarlaEngineClient* addClient(CarlaPlugin* const plugin);
-
- // -------------------------------------------------------------------
- // Plugin management
-
- /*!
- * Add new plugin.
- */
- bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr);
-
- /*!
- * Add new plugin, using native binary type.
- */
- bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr)
- {
- return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
- }
-
- /*!
- * Remove plugin with id \a id.
- */
- bool removePlugin(const unsigned int id);
-
- /*!
- * Remove all plugins.
- */
- bool removeAllPlugins();
-
- /*!
- * Rename plugin with id \a id to \a newName.\n
- * Returns the new name, or nullptr if the operation failed.
- */
- virtual const char* renamePlugin(const unsigned int id, const char* const newName);
-
- /*!
- * Clone plugin with id \a id.
- */
- bool clonePlugin(const unsigned int id);
-
- /*!
- * Prepare replace of plugin with id \a id.\n
- * The next call to addPlugin() will use this id, replacing the selected plugin.
- * \note This function requires addPlugin() to be called afterwards, as soon as possible.
- */
- bool replacePlugin(const unsigned int id);
-
- /*!
- * Switch plugins with id \a idA and \a idB.
- */
- bool switchPlugins(const unsigned int idA, const unsigned int idB);
-
- /*!
- * Get plugin with id \a id.
- */
- CarlaPlugin* getPlugin(const unsigned int id) const;
-
- /*!
- * Get plugin with id \a id, faster unchecked version.
- */
- CarlaPlugin* getPluginUnchecked(const unsigned int id) const noexcept;
-
- /*!
- * Get a unique plugin name within the engine.\n
- * Returned variable must be deleted if non-NULL.
- */
- const char* getUniquePluginName(const char* const name) const;
-
- // -------------------------------------------------------------------
- // Project management
-
- /*!
- * Load a file of any type.\n
- * This will try to load a generic file as a plugin,
- * either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
- */
- bool loadFile(const char* const filename);
-
- /*!
- * Load a project file.
- * @note Already loaded plugins are not removed; call removeAllPlugins() first if needed.
- */
- bool loadProject(const char* const filename);
-
- /*!
- * Save current project to a file.
- */
- bool saveProject(const char* const filename);
-
- // -------------------------------------------------------------------
- // Information (base)
-
- /*!
- * Get the current engine driver hints.
- */
- unsigned int getHints() const noexcept;
-
- /*!
- * Get the current buffer size.
- */
- uint32_t getBufferSize() const noexcept;
-
- /*!
- * Get the current sample rate.
- */
- double getSampleRate() const noexcept;
-
- /*!
- * Get the current engine name.
- */
- const char* getName() const noexcept;
-
- /*!
- * Get the current engine proccess mode.
- */
- EngineProcessMode getProccessMode() const noexcept;
-
- /*!
- * Get the current engine options (read-only).
- */
- const EngineOptions& getOptions() const noexcept;
-
- /*!
- * Get the current Time information (read-only).
- */
- const EngineTimeInfo& getTimeInfo() const noexcept;
-
- // -------------------------------------------------------------------
- // Information (peaks)
-
- /*!
- * TODO.
- * \a id must be either 1 or 2.
- */
- float getInputPeak(const unsigned int pluginId, const bool isLeft) const;
-
- /*!
- * TODO.
- * \a id must be either 1 or 2.
- */
- float getOutputPeak(const unsigned int pluginId, const bool isLeft) const;
-
- // -------------------------------------------------------------------
- // Callback
-
- /*!
- * TODO.
- */
- void callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr);
-
- /*!
- * TODO.
- */
- void setCallback(const EngineCallbackFunc func, void* const ptr);
-
- #ifndef BUILD_BRIDGE
- // -------------------------------------------------------------------
- // Patchbay
-
- /*!
- * Connect patchbay ports \a portA and \a portB.
- */
- virtual bool patchbayConnect(const int portA, const int portB);
-
- /*!
- * Disconnect patchbay connection \a connectionId.
- */
- virtual bool patchbayDisconnect(const int connectionId);
-
- /*!
- * Force the engine to resend all patchbay clients, ports and connections again.
- */
- virtual bool patchbayRefresh();
- #endif
-
- // -------------------------------------------------------------------
- // Transport
-
- /*!
- * Start playback of the engine transport.
- */
- virtual void transportPlay();
-
- /*!
- * Pause the engine transport.
- */
- virtual void transportPause();
-
- /*!
- * Relocate the engine transport to \a frames.
- */
- virtual void transportRelocate(const uint64_t frame);
-
- // -------------------------------------------------------------------
- // Error handling
-
- /*!
- * Get last error.
- */
- const char* getLastError() const noexcept;
-
- /*!
- * Set last error.
- */
- void setLastError(const char* const error) const;
-
- // -------------------------------------------------------------------
- // Misc
-
- /*!
- * Tell the engine it's about to close.\n
- * This is used to prevent the engine thread(s) from reactivating.
- */
- void setAboutToClose();
-
- // -------------------------------------------------------------------
- // Options
-
- /*!
- * Set the engine option \a option.
- */
- void setOption(const EngineOption option, const int value, const char* const valueStr);
-
- // -------------------------------------------------------------------
- // OSC Stuff
-
- #ifdef BUILD_BRIDGE
- /*!
- * Check if OSC bridge is registered.
- */
- bool isOscBridgeRegistered() const noexcept;
- #else
- /*!
- * Check if OSC controller is registered.
- */
- bool isOscControlRegistered() const noexcept;
- #endif
-
- /*!
- * Idle OSC.
- */
- void idleOsc();
-
- /*!
- * Get OSC TCP server path.
- */
- const char* getOscServerPathTCP() const noexcept;
-
- /*!
- * Get OSC UDP server path.
- */
- const char* getOscServerPathUDP() const noexcept;
-
- #ifdef BUILD_BRIDGE
- /*!
- * Set OSC bridge data.
- */
- void setOscBridgeData(const CarlaOscData* const oscData) const noexcept;
- #endif
-
- // -------------------------------------------------------------------
- // Helper functions
-
- /*!
- * Return internal data, needed for EventPorts when used in Rack and Bridge modes.
- * \note RT call
- */
- EngineEvent* getInternalEventBuffer(const bool isInput) const noexcept;
-
- /*!
- * Force register a plugin into slot \a id. \n
- * This is needed so we can receive OSC events for a plugin while it initializes.
- */
- void registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin);
-
- // -------------------------------------------------------------------
-
- protected:
- /*!
- * Internal data, for CarlaEngine subclasses only.
- */
- CarlaEngineProtectedData* const pData;
- friend struct CarlaEngineProtectedData;
-
- // -------------------------------------------------------------------
- // Internal stuff
-
- /*!
- * Report to all plugins about buffer size change.
- */
- void bufferSizeChanged(const uint32_t newBufferSize);
-
- /*!
- * Report to all plugins about sample rate change.\n
- * This is not supported on all plugin types, in which case they will have to be re-initiated.
- */
- void sampleRateChanged(const double newSampleRate);
-
- /*!
- * Report to all plugins about offline mode change.
- */
- void offlineModeChanged(const bool isOffline);
-
- /*!
- * Run any pending RT events.\n
- * Must always be called at the end of audio processing.
- * \note RT call
- */
- void runPendingRtEvents();
-
- /*!
- * Set a plugin (stereo) peak values.
- * \note RT call
- */
- void setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept;
-
- // -------------------------------------------------------------------
-
- virtual bool connectRackMidiInPort(const int) { return false; }
- virtual bool connectRackMidiOutPort(const int) { return false; }
- virtual bool disconnectRackMidiInPort(const int) { return false; }
- virtual bool disconnectRackMidiOutPort(const int) { return false; }
-
- // -------------------------------------------------------------------
-
- private:
- /*!
- * Native audio APIs.
- */
- enum AudioApi {
- AUDIO_API_NULL = 0,
- // common
- AUDIO_API_JACK = 1,
- // linux
- AUDIO_API_ALSA = 2,
- AUDIO_API_OSS = 3,
- AUDIO_API_PULSE = 4,
- // macos
- AUDIO_API_CORE = 5,
- // windows
- AUDIO_API_ASIO = 6,
- AUDIO_API_DS = 7
- };
-
- // -------------------------------------------------------------------
- // Engine initializers
-
- // jack
- static CarlaEngine* newJack();
-
- // rtaudio
- static CarlaEngine* newRtAudio(const AudioApi api);
- static unsigned int getRtAudioApiCount();
- static const char* getRtAudioApiName(const unsigned int index);
- static const char* const* getRtAudioApiDeviceNames(const unsigned int index);
- static const EngineDriverDeviceInfo* getRtAudioDeviceInfo(const unsigned int index, const char* const deviceName);
-
- // juce
- static CarlaEngine* newJuce(const AudioApi api);
- static unsigned int getJuceApiCount();
- static const char* getJuceApiName(const unsigned int index);
- static const char* const* getJuceApiDeviceNames(const unsigned int index);
- static const EngineDriverDeviceInfo* getJuceDeviceInfo(const unsigned int index, const char* const deviceName);
-
- #ifdef BUILD_BRIDGE
- public:
- static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName);
-
- // -------------------------------------------------------------------
- // Bridge/Controller OSC stuff
-
- void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const;
- void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const;
- void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const;
- void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const;
- void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const;
- void oscSend_bridge_program_count(const uint32_t count) const;
- void oscSend_bridge_midi_program_count(const uint32_t count) const;
- void oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const;
- void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const;
- void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const;
- void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const;
- void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const;
- void oscSend_bridge_parameter_value(const int32_t index, const float value) const; // may be used for internal params (< 0)
- void oscSend_bridge_default_value(const uint32_t index, const float value) const;
- void oscSend_bridge_current_program(const int32_t index) const;
- void oscSend_bridge_current_midi_program(const int32_t index) const;
- void oscSend_bridge_program_name(const uint32_t index, const char* const name) const;
- void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const;
- void oscSend_bridge_configure(const char* const key, const char* const value) const;
- void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const;
- void oscSend_bridge_set_chunk_data(const char* const chunkFile) const;
- void oscSend_bridge_set_peaks() const;
- #else
- public:
- void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const;
- void oscSend_control_add_plugin_end(const uint pluginId) const;
- void oscSend_control_remove_plugin(const uint pluginId) const;
- void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const;
- void oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const;
- void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const;
- void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const;
- void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const;
- void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const;
- void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const;
- void oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const;
- void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const;
- void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const;
- void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const;
- void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const;
- void oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const; // may be used for internal params (< 0)
- void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const;
- void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const;
- void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const;
- void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const;
- void oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const;
- void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const;
- void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const;
- void oscSend_control_set_peaks(const uint pluginId) const;
- void oscSend_control_exit() const;
- #endif
-
- CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine)
- };
-
- /**@}*/
-
- CARLA_BACKEND_END_NAMESPACE
-
- #endif // CARLA_ENGINE_HPP_INCLUDED
|