Carla Backend
CarlaPlugin.hpp
Go to the documentation of this file.
1/*
2 * Carla Plugin Host
3 * Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
4 *
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.
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 doc/GPL.txt file.
16 */
17
18#ifndef CARLA_PLUGIN_HPP_INCLUDED
19#define CARLA_PLUGIN_HPP_INCLUDED
20
21#include "CarlaBackend.h"
22#include "CarlaPluginPtr.hpp"
23
24// -----------------------------------------------------------------------
25// Avoid including extra libs here
26
27typedef void* lo_message;
28typedef struct _NativePluginDescriptor NativePluginDescriptor;
29struct LADSPA_RDF_Descriptor;
30
31// -----------------------------------------------------------------------
32
33CARLA_BACKEND_START_NAMESPACE
34
35#if 0
36} /* Fix editor indentation */
37#endif
38
39// -----------------------------------------------------------------------
40
52class CarlaEngineBridge;
53struct CarlaStateSave;
54struct EngineEvent;
55
56// -----------------------------------------------------------------------
57
67class CARLA_API CarlaPlugin
68{
69protected:
76 CarlaPlugin(CarlaEngine* engine, uint id);
77
78public:
82 virtual ~CarlaPlugin();
83
84 // -------------------------------------------------------------------
85 // Information (base)
86
97 virtual PluginType getType() const noexcept = 0;
98
104 uint getId() const noexcept;
105
111 uint getHints() const noexcept;
112
118 uint getOptionsEnabled() const noexcept;
119
126 bool isEnabled() const noexcept;
127
134 const char* getName() const noexcept;
135
140 const char* getFilename() const noexcept;
141
145 const char* getIconName() const noexcept;
146
150 virtual PluginCategory getCategory() const noexcept;
151
156 virtual int64_t getUniqueId() const noexcept;
157
161 virtual uint32_t getLatencyInFrames() const noexcept;
162
163 // -------------------------------------------------------------------
164 // Information (count)
165
169 uint32_t getAudioInCount() const noexcept;
170
174 uint32_t getAudioOutCount() const noexcept;
175
179 uint32_t getCVInCount() const noexcept;
180
184 uint32_t getCVOutCount() const noexcept;
185
189 virtual uint32_t getMidiInCount() const noexcept;
190
194 virtual uint32_t getMidiOutCount() const noexcept;
195
200 uint32_t getParameterCount() const noexcept;
201
205 virtual uint32_t getParameterScalePointCount(uint32_t parameterId) const noexcept;
206
210 uint32_t getProgramCount() const noexcept;
211
215 uint32_t getMidiProgramCount() const noexcept;
216
220 uint32_t getCustomDataCount() const noexcept;
221
222 // -------------------------------------------------------------------
223 // Information (current data)
224
230 int32_t getCurrentProgram() const noexcept;
231
238 int32_t getCurrentMidiProgram() const noexcept;
239
243 virtual uint getAudioPortHints(bool isOutput, uint32_t portIndex) const noexcept;
244
248 const ParameterData& getParameterData(uint32_t parameterId) const noexcept;
249
253 const ParameterRanges& getParameterRanges(uint32_t parameterId) const noexcept;
254
258 bool isParameterOutput(uint32_t parameterId) const noexcept;
259
265 const MidiProgramData& getMidiProgramData(uint32_t index) const noexcept;
266
272 const CustomData& getCustomData(uint32_t index) const noexcept;
273
282 virtual std::size_t getChunkData(void** dataPtr) noexcept;
283
284 // -------------------------------------------------------------------
285 // Information (per-plugin data)
286
292 virtual uint getOptionsAvailable() const noexcept;
293
297 virtual float getParameterValue(uint32_t parameterId) const noexcept;
298
302 virtual float getParameterScalePointValue(uint32_t parameterId, uint32_t scalePointId) const noexcept;
303
307 __attribute__((warn_unused_result))
308 virtual bool getLabel(char* strBuf) const noexcept;
309
313 __attribute__((warn_unused_result))
314 virtual bool getMaker(char* strBuf) const noexcept;
315
319 __attribute__((warn_unused_result))
320 virtual bool getCopyright(char* strBuf) const noexcept;
321
327 __attribute__((warn_unused_result))
328 virtual bool getRealName(char* strBuf) const noexcept;
329
333 __attribute__((warn_unused_result))
334 virtual bool getParameterName(uint32_t parameterId, char* strBuf) const noexcept;
335
339 __attribute__((warn_unused_result))
340 virtual bool getParameterSymbol(uint32_t parameterId, char* strBuf) const noexcept;
341
346 __attribute__((warn_unused_result))
347 virtual bool getParameterText(uint32_t parameterId, char* strBuf) noexcept;
348
352 __attribute__((warn_unused_result))
353 virtual bool getParameterUnit(uint32_t parameterId, char* strBuf) const noexcept;
354
358 __attribute__((warn_unused_result))
359 virtual bool getParameterComment(uint32_t parameterId, char* strBuf) const noexcept;
360
365 __attribute__((warn_unused_result))
366 virtual bool getParameterGroupName(uint32_t parameterId, char* strBuf) const noexcept;
367
371 __attribute__((warn_unused_result))
372 virtual bool getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* strBuf) const noexcept;
373
379 float getInternalParameterValue(int32_t parameterId) const noexcept;
380
384 __attribute__((warn_unused_result))
385 bool getProgramName(uint32_t index, char* strBuf) const noexcept;
386
392 __attribute__((warn_unused_result))
393 bool getMidiProgramName(uint32_t index, char* strBuf) const noexcept;
394
403 void getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept;
404
405 // -------------------------------------------------------------------
406 // Set data (state)
407
413 virtual void prepareForSave(bool temporary);
414
418 virtual void resetParameters() noexcept;
419
423 virtual void randomizeParameters() noexcept;
424
431 const CarlaStateSave& getStateSave(bool callPrepareForSave = true);
432
438 void loadStateSave(const CarlaStateSave& stateSave);
439
445 bool saveStateToFile(const char* filename);
446
452 bool loadStateFromFile(const char* filename);
453
457 bool exportAsLV2(const char* lv2path);
458
459 // -------------------------------------------------------------------
460 // Set data (internal stuff)
461
468 virtual void setId(uint newId) noexcept;
469
475 virtual void setName(const char* newName);
476
482 virtual void setOption(uint option, bool yesNo, bool sendCallback);
483
490 void setEnabled(bool yesNo) noexcept;
491
498 void setActive(bool active, bool sendOsc, bool sendCallback) noexcept;
499
500#ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
508 void setDryWet(float value, bool sendOsc, bool sendCallback) noexcept;
509
517 void setVolume(float value, bool sendOsc, bool sendCallback) noexcept;
518
528 void setBalanceLeft(float value, bool sendOsc, bool sendCallback) noexcept;
529
539 void setBalanceRight(float value, bool sendOsc, bool sendCallback) noexcept;
540
550 void setPanning(float value, bool sendOsc, bool sendCallback) noexcept;
551
555 void setDryWetRT(float value, bool sendCallbackLater) noexcept;
556 void setVolumeRT(float value, bool sendCallbackLater) noexcept;
557 void setBalanceLeftRT(float value, bool sendCallbackLater) noexcept;
558 void setBalanceRightRT(float value, bool sendCallbackLater) noexcept;
559 void setPanningRT(float value, bool sendCallbackLater) noexcept;
560#endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
561
568 virtual void setCtrlChannel(int8_t channel, bool sendOsc, bool sendCallback) noexcept;
569
570 // -------------------------------------------------------------------
571 // Set data (plugin-specific stuff)
572
584 virtual void setParameterValue(uint32_t parameterId, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
585
589 virtual void setParameterValueRT(uint32_t parameterId, float value, uint32_t frameOffset, bool sendCallbackLater) noexcept;
590
602 void setParameterValueByRealIndex(int32_t rindex, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
603
608 virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept;
609
614 virtual void setParameterMappedControlIndex(uint32_t parameterId, int16_t index,
615 bool sendOsc, bool sendCallback, bool reconfigureNow) noexcept;
616
620 virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum,
621 bool sendOsc, bool sendCallback) noexcept;
622
634 virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
635
643 virtual void setChunkData(const void* data, std::size_t dataSize);
644
656 virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
657
669 virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
670
675 void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
676
680 virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
681 virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
682
683 // -------------------------------------------------------------------
684 // Plugin state
685
690 virtual void reload() = 0;
691
695 virtual void reloadPrograms(bool doInit);
696
697 // -------------------------------------------------------------------
698 // Plugin processing
699
700protected:
704 virtual void activate() noexcept;
705
709 virtual void deactivate() noexcept;
710
711public:
715 virtual void process(const float* const* audioIn, float** audioOut,
716 const float* const* cvIn, float** cvOut, uint32_t frames) = 0;
717
721 virtual void bufferSizeChanged(uint32_t newBufferSize);
722
726 virtual void sampleRateChanged(double newSampleRate);
727
731 virtual void offlineModeChanged(bool isOffline);
732
733 // -------------------------------------------------------------------
734 // Misc
735
740 virtual void idle();
741
746 bool tryLock(bool forcedOffline) noexcept;
747
751 void unlock() noexcept;
752
753 // -------------------------------------------------------------------
754 // Plugin buffers
755
759 virtual void initBuffers() const noexcept;
760
764 virtual void clearBuffers() noexcept;
765
766 // -------------------------------------------------------------------
767 // OSC stuff
768
773 virtual void handleOscMessage(const char* method,
774 int argc,
775 const void* argv,
776 const char* types,
777 lo_message msg);
778
779 // -------------------------------------------------------------------
780 // MIDI events
781
787 void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
788 bool sendGui, bool sendOsc, bool sendCallback);
789
790#ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
797#endif
798
799 // -------------------------------------------------------------------
800 // UI Stuff
801
805 virtual void setCustomUITitle(const char* title) noexcept;
806
811 virtual void showCustomUI(bool yesNo);
812
818 virtual void* embedCustomUI(void* ptr);
819
825 virtual void uiIdle();
826
831 virtual void uiParameterChange(uint32_t index, float value) noexcept;
832
837 virtual void uiProgramChange(uint32_t index) noexcept;
838
843 virtual void uiMidiProgramChange(uint32_t index) noexcept;
844
849 virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
850
855 virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
856
857 // -------------------------------------------------------------------
858 // Helper functions
859
863 CarlaEngine* getEngine() const noexcept;
864
868 CarlaEngineClient* getEngineClient() const noexcept;
869
873 CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
874
878 CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
879
883 CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
884
888 CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
889
893 CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
894
898 CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
899
900#ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
905 void checkForMidiLearn(EngineEvent& event) noexcept;
906#endif
907
912 virtual void* getNativeHandle() const noexcept;
913
918 virtual const void* getNativeDescriptor() const noexcept;
919
923 virtual uintptr_t getUiBridgeProcessId() const noexcept;
924
925 // -------------------------------------------------------------------
926
931 uint32_t getPatchbayNodeId() const noexcept;
932
937 void setPatchbayNodeId(uint32_t nodeId) noexcept;
938
939 // -------------------------------------------------------------------
940 // Plugin initializers
941
946 virtual BinaryType getBinaryType() const noexcept
947 {
948 return BINARY_NATIVE;
949 }
950
954 virtual const void* getExtraStuff() const noexcept
955 {
956 return nullptr;
957 }
958
959#ifndef DOXYGEN
960 struct Initializer {
961 CarlaEngine* const engine;
962 const uint id;
963 const char* const filename;
964 const char* const name;
965 const char* const label;
966 const int64_t uniqueId;
967 const uint options; // see PluginOptions
968 };
969
970 static CarlaPluginPtr newNative(const Initializer& init);
971 static CarlaPluginPtr newBridge(const Initializer& init,
972 BinaryType btype, PluginType ptype,
973 const char* binaryArchName, const char* bridgeBinary);
974
975 static CarlaPluginPtr newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
976 static CarlaPluginPtr newDSSI(const Initializer& init);
977 static CarlaPluginPtr newLV2(const Initializer& init);
978 static CarlaPluginPtr newVST2(const Initializer& init);
979 static CarlaPluginPtr newVST3(const Initializer& init);
980 static CarlaPluginPtr newAU(const Initializer& init);
981 static CarlaPluginPtr newJSFX(const Initializer& init);
982
983 static CarlaPluginPtr newJuce(const Initializer& init, const char* format);
984 static CarlaPluginPtr newFluidSynth(const Initializer& init, PluginType ptype, bool use16Outs);
985 static CarlaPluginPtr newSFZero(const Initializer& init);
986
987 static CarlaPluginPtr newJackApp(const Initializer& init);
988#endif
989
990 // -------------------------------------------------------------------
991
992protected:
996 struct ProtectedData;
997 ProtectedData* const pData;
998
999 // -------------------------------------------------------------------
1000 // Internal helper functions
1001
1002protected:
1006 virtual void cloneLV2Files(const CarlaPlugin& other);
1007
1013 virtual void restoreLV2State(bool temporary) noexcept;
1014
1018 virtual void prepareForDeletion() noexcept;
1019
1023 virtual void waitForBridgeSaveSignal() noexcept;
1024
1025 // -------------------------------------------------------------------
1026 // Helper classes
1027
1033 {
1034 public:
1035 ScopedDisabler(CarlaPlugin* plugin) noexcept;
1037
1038 private:
1039 CarlaPlugin* const fPlugin;
1040 bool fWasEnabled;
1041
1042 CARLA_PREVENT_HEAP_ALLOCATION
1043 CARLA_DECLARE_NON_COPYABLE(ScopedDisabler)
1044 };
1045
1052 {
1053 public:
1054 ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
1056
1057 private:
1058 CarlaPlugin* const fPlugin;
1059 const bool fBlock;
1060
1061 CARLA_PREVENT_HEAP_ALLOCATION
1062 CARLA_DECLARE_NON_COPYABLE(ScopedSingleProcessLocker)
1063 };
1064
1065 friend class CarlaEngine;
1066 friend class CarlaEngineBridge;
1067 CARLA_DECLARE_NON_COPYABLE(CarlaPlugin)
1068};
1069
1072// -----------------------------------------------------------------------
1073
1074CARLA_BACKEND_END_NAMESPACE
1075
1076#endif // CARLA_PLUGIN_HPP_INCLUDED
CARLA_BACKEND_START_NAMESPACE typedef std::shared_ptr< CarlaPlugin > CarlaPluginPtr
Definition: CarlaPluginPtr.hpp:267
void * lo_message
Definition: CarlaPlugin.hpp:27
struct _NativePluginDescriptor NativePluginDescriptor
Definition: CarlaPlugin.hpp:28
Definition: CarlaEngine.hpp:442
Definition: CarlaEngine.hpp:489
Definition: CarlaEngine.hpp:645
Definition: CarlaEngine.hpp:702
Definition: CarlaEngine.hpp:551
Definition: CarlaEngine.hpp:814
Definition: CarlaPlugin.hpp:1033
ScopedDisabler(CarlaPlugin *plugin) noexcept
Definition: CarlaPlugin.hpp:1052
ScopedSingleProcessLocker(CarlaPlugin *plugin, bool block) noexcept
Definition: CarlaPlugin.hpp:68
virtual void * embedCustomUI(void *ptr)
virtual void cloneLV2Files(const CarlaPlugin &other)
virtual void uiIdle()
void setVolume(float value, bool sendOsc, bool sendCallback) noexcept
virtual void showCustomUI(bool yesNo)
void setDryWetRT(float value, bool sendCallbackLater) noexcept
virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum, bool sendOsc, bool sendCallback) noexcept
virtual void setParameterValue(uint32_t parameterId, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept
virtual void setParameterValueRT(uint32_t parameterId, float value, uint32_t frameOffset, bool sendCallbackLater) noexcept
ProtectedData *const pData
Definition: CarlaPlugin.hpp:996
void setBalanceLeftRT(float value, bool sendCallbackLater) noexcept
CarlaPlugin(CarlaEngine *engine, uint id)
virtual void uiMidiProgramChange(uint32_t index) noexcept
void setBalanceRight(float value, bool sendOsc, bool sendCallback) noexcept
void setVolumeRT(float value, bool sendCallbackLater) noexcept
void setBalanceRightRT(float value, bool sendCallbackLater) noexcept
virtual void uiProgramChange(uint32_t index) noexcept
void checkForMidiLearn(EngineEvent &event) noexcept
virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept
CarlaEngine * getEngine() const noexcept
virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept
void setPanningRT(float value, bool sendCallbackLater) noexcept
virtual void setCustomData(const char *type, const char *key, const char *value, bool sendGui)
virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit=false) noexcept
virtual void * getNativeHandle() const noexcept
void setParameterValueByRealIndex(int32_t rindex, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept
virtual void restoreLV2State(bool temporary) noexcept
virtual void uiParameterChange(uint32_t index, float value) noexcept
void setPanning(float value, bool sendOsc, bool sendCallback) noexcept
virtual const void * getExtraStuff() const noexcept
Definition: CarlaPlugin.hpp:954
void setBalanceLeft(float value, bool sendOsc, bool sendCallback) noexcept
virtual void setParameterMappedControlIndex(uint32_t parameterId, int16_t index, bool sendOsc, bool sendCallback, bool reconfigureNow) noexcept
virtual void setCtrlChannel(int8_t channel, bool sendOsc, bool sendCallback) noexcept
void setDryWet(float value, bool sendOsc, bool sendCallback) noexcept
virtual void setCustomUITitle(const char *title) noexcept
virtual PluginType getType() const noexcept=0
void postponeRtAllNotesOff()
virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept
virtual void setChunkData(const void *data, std::size_t dataSize)
virtual ~CarlaPlugin()
virtual void prepareForDeletion() noexcept
PluginType
Definition: CarlaBackend.h:608
BinaryType
Definition: CarlaBackend.h:544
PluginCategory
Definition: CarlaBackend.h:689
CarlaEngine * newJuce(AudioApi api)
CarlaEngine * newBridge(const char *audioPoolBaseName, const char *rtClientBaseName, const char *nonRtClientBaseName, const char *nonRtServerBaseName)
Definition: CarlaPluginPtr.hpp:33
Definition: CarlaBackend.h:1918
Definition: CarlaEngine.hpp:216
Definition: CarlaBackend.h:1897
Definition: CarlaBackend.h:1708
Definition: CarlaBackend.h:1763