Carla Backend
CarlaPlugin.hpp
Go to the documentation of this file.
1 /*
2  * Carla Plugin Host
3  * Copyright (C) 2011-2020 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 
27 typedef void* lo_message;
28 typedef struct _NativePluginDescriptor NativePluginDescriptor;
29 struct LADSPA_RDF_Descriptor;
30 
31 // -----------------------------------------------------------------------
32 
33 CARLA_BACKEND_START_NAMESPACE
34 
35 #if 0
36 } /* Fix editor indentation */
37 #endif
38 
39 // -----------------------------------------------------------------------
40 
49 class CarlaEngineCVPort;
52 class CarlaEngineBridge;
53 struct CarlaStateSave;
54 struct EngineEvent;
55 
56 // -----------------------------------------------------------------------
57 
67 class CARLA_API CarlaPlugin
68 {
69 protected:
76  CarlaPlugin(CarlaEngine* engine, uint id);
77 
78 public:
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  const ParameterData& getParameterData(uint32_t parameterId) const noexcept;
244 
248  const ParameterRanges& getParameterRanges(uint32_t parameterId) const noexcept;
249 
253  bool isParameterOutput(uint32_t parameterId) const noexcept;
254 
260  const MidiProgramData& getMidiProgramData(uint32_t index) const noexcept;
261 
267  const CustomData& getCustomData(uint32_t index) const noexcept;
268 
277  virtual std::size_t getChunkData(void** dataPtr) noexcept;
278 
279  // -------------------------------------------------------------------
280  // Information (per-plugin data)
281 
287  virtual uint getOptionsAvailable() const noexcept;
288 
292  virtual float getParameterValue(uint32_t parameterId) const noexcept;
293 
297  virtual float getParameterScalePointValue(uint32_t parameterId, uint32_t scalePointId) const noexcept;
298 
302  __attribute__((warn_unused_result))
303  virtual bool getLabel(char* strBuf) const noexcept;
304 
308  __attribute__((warn_unused_result))
309  virtual bool getMaker(char* strBuf) const noexcept;
310 
314  __attribute__((warn_unused_result))
315  virtual bool getCopyright(char* strBuf) const noexcept;
316 
322  __attribute__((warn_unused_result))
323  virtual bool getRealName(char* strBuf) const noexcept;
324 
328  __attribute__((warn_unused_result))
329  virtual bool getParameterName(uint32_t parameterId, char* strBuf) const noexcept;
330 
334  __attribute__((warn_unused_result))
335  virtual bool getParameterSymbol(uint32_t parameterId, char* strBuf) const noexcept;
336 
341  __attribute__((warn_unused_result))
342  virtual bool getParameterText(uint32_t parameterId, char* strBuf) noexcept;
343 
347  __attribute__((warn_unused_result))
348  virtual bool getParameterUnit(uint32_t parameterId, char* strBuf) const noexcept;
349 
353  __attribute__((warn_unused_result))
354  virtual bool getParameterComment(uint32_t parameterId, char* strBuf) const noexcept;
355 
360  __attribute__((warn_unused_result))
361  virtual bool getParameterGroupName(uint32_t parameterId, char* strBuf) const noexcept;
362 
366  __attribute__((warn_unused_result))
367  virtual bool getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* strBuf) const noexcept;
368 
374  float getInternalParameterValue(int32_t parameterId) const noexcept;
375 
379  __attribute__((warn_unused_result))
380  bool getProgramName(uint32_t index, char* strBuf) const noexcept;
381 
387  __attribute__((warn_unused_result))
388  bool getMidiProgramName(uint32_t index, char* strBuf) const noexcept;
389 
398  void getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept;
399 
400  // -------------------------------------------------------------------
401  // Set data (state)
402 
408  virtual void prepareForSave(bool temporary);
409 
413  virtual void resetParameters() noexcept;
414 
418  virtual void randomizeParameters() noexcept;
419 
426  const CarlaStateSave& getStateSave(bool callPrepareForSave = true);
427 
433  void loadStateSave(const CarlaStateSave& stateSave);
434 
440  bool saveStateToFile(const char* filename);
441 
447  bool loadStateFromFile(const char* filename);
448 
452  bool exportAsLV2(const char* lv2path);
453 
454  // -------------------------------------------------------------------
455  // Set data (internal stuff)
456 
463  virtual void setId(uint newId) noexcept;
464 
470  virtual void setName(const char* newName);
471 
477  virtual void setOption(uint option, bool yesNo, bool sendCallback);
478 
485  void setEnabled(bool yesNo) noexcept;
486 
493  void setActive(bool active, bool sendOsc, bool sendCallback) noexcept;
494 
495 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
496 
503  void setDryWet(float value, bool sendOsc, bool sendCallback) noexcept;
504 
512  void setVolume(float value, bool sendOsc, bool sendCallback) noexcept;
513 
523  void setBalanceLeft(float value, bool sendOsc, bool sendCallback) noexcept;
524 
534  void setBalanceRight(float value, bool sendOsc, bool sendCallback) noexcept;
535 
545  void setPanning(float value, bool sendOsc, bool sendCallback) noexcept;
546 
550  void setDryWetRT(float value, bool sendCallbackLater) noexcept;
551  void setVolumeRT(float value, bool sendCallbackLater) noexcept;
552  void setBalanceLeftRT(float value, bool sendCallbackLater) noexcept;
553  void setBalanceRightRT(float value, bool sendCallbackLater) noexcept;
554  void setPanningRT(float value, bool sendCallbackLater) noexcept;
555 #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
556 
563  virtual void setCtrlChannel(int8_t channel, bool sendOsc, bool sendCallback) noexcept;
564 
565  // -------------------------------------------------------------------
566  // Set data (plugin-specific stuff)
567 
579  virtual void setParameterValue(uint32_t parameterId, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
580 
584  virtual void setParameterValueRT(uint32_t parameterId, float value, bool sendCallbackLater) noexcept;
585 
597  void setParameterValueByRealIndex(int32_t rindex, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
598 
603  virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept;
604 
609  virtual void setParameterMappedControlIndex(uint32_t parameterId, int16_t index,
610  bool sendOsc, bool sendCallback, bool reconfigureNow) noexcept;
611 
615  virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum,
616  bool sendOsc, bool sendCallback) noexcept;
617 
629  virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
630 
638  virtual void setChunkData(const void* data, std::size_t dataSize);
639 
651  virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
652 
664  virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
665 
670  void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
671 
675  virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
676  virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
677 
678  // -------------------------------------------------------------------
679  // Plugin state
680 
685  virtual void reload() = 0;
686 
690  virtual void reloadPrograms(bool doInit);
691 
692  // -------------------------------------------------------------------
693  // Plugin processing
694 
695 protected:
699  virtual void activate() noexcept;
700 
704  virtual void deactivate() noexcept;
705 
706 public:
710  virtual void process(const float* const* audioIn, float** audioOut,
711  const float* const* cvIn, float** cvOut, uint32_t frames) = 0;
712 
716  virtual void bufferSizeChanged(uint32_t newBufferSize);
717 
721  virtual void sampleRateChanged(double newSampleRate);
722 
726  virtual void offlineModeChanged(bool isOffline);
727 
728  // -------------------------------------------------------------------
729  // Misc
730 
735  virtual void idle();
736 
741  bool tryLock(bool forcedOffline) noexcept;
742 
746  void unlock() noexcept;
747 
748  // -------------------------------------------------------------------
749  // Plugin buffers
750 
754  virtual void initBuffers() const noexcept;
755 
759  virtual void clearBuffers() noexcept;
760 
761  // -------------------------------------------------------------------
762  // OSC stuff
763 
768  virtual void handleOscMessage(const char* method,
769  int argc,
770  const void* argv,
771  const char* types,
772  lo_message msg);
773 
774  // -------------------------------------------------------------------
775  // MIDI events
776 
782  void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
783  bool sendGui, bool sendOsc, bool sendCallback);
784 
785 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
786 
791  void postponeRtAllNotesOff();
792 #endif
793 
794  // -------------------------------------------------------------------
795  // UI Stuff
796 
800  virtual void setCustomUITitle(const char* title) noexcept;
801 
806  virtual void showCustomUI(bool yesNo);
807 
813  virtual void* embedCustomUI(void* ptr);
814 
820  virtual void uiIdle();
821 
826  virtual void uiParameterChange(uint32_t index, float value) noexcept;
827 
832  virtual void uiProgramChange(uint32_t index) noexcept;
833 
838  virtual void uiMidiProgramChange(uint32_t index) noexcept;
839 
844  virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
845 
850  virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
851 
852  // -------------------------------------------------------------------
853  // Helper functions
854 
858  CarlaEngine* getEngine() const noexcept;
859 
863  CarlaEngineClient* getEngineClient() const noexcept;
864 
868  CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
869 
873  CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
874 
878  CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
879 
883  CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
884 
888  CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
889 
893  CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
894 
895 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
896 
900  void checkForMidiLearn(EngineEvent& event) noexcept;
901 #endif
902 
907  virtual void* getNativeHandle() const noexcept;
908 
913  virtual const void* getNativeDescriptor() const noexcept;
914 
918  virtual uintptr_t getUiBridgeProcessId() const noexcept;
919 
920  // -------------------------------------------------------------------
921 
926  uint32_t getPatchbayNodeId() const noexcept;
927 
932  void setPatchbayNodeId(uint32_t nodeId) noexcept;
933 
934  // -------------------------------------------------------------------
935  // Plugin initializers
936 
941  virtual BinaryType getBinaryType() const noexcept
942  {
943  return BINARY_NATIVE;
944  }
945 
949  virtual const void* getExtraStuff() const noexcept
950  {
951  return nullptr;
952  }
953 
954 #ifndef DOXYGEN
955  struct Initializer {
956  CarlaEngine* const engine;
957  const uint id;
958  const char* const filename;
959  const char* const name;
960  const char* const label;
961  const int64_t uniqueId;
962  const uint options; // see PluginOptions
963  };
964 
965  static CarlaPluginPtr newNative(const Initializer& init);
966  static CarlaPluginPtr newBridge(const Initializer& init,
967  BinaryType btype, PluginType ptype,
968  const char* binaryArchName, const char* bridgeBinary);
969 
970  static CarlaPluginPtr newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
971  static CarlaPluginPtr newDSSI(const Initializer& init);
972  static CarlaPluginPtr newLV2(const Initializer& init);
973  static CarlaPluginPtr newVST2(const Initializer& init);
974  static CarlaPluginPtr newVST3(const Initializer& init);
975  static CarlaPluginPtr newAU(const Initializer& init);
976 
977  static CarlaPluginPtr newJuce(const Initializer& init, const char* format);
978  static CarlaPluginPtr newFluidSynth(const Initializer& init, PluginType ptype, bool use16Outs);
979  static CarlaPluginPtr newSFZero(const Initializer& init);
980 
981  static CarlaPluginPtr newJackApp(const Initializer& init);
982 #endif
983 
984  // -------------------------------------------------------------------
985 
986 protected:
990  struct ProtectedData;
991  ProtectedData* const pData;
992 
993  // -------------------------------------------------------------------
994  // Internal helper functions
995 
996 protected:
1000  virtual void cloneLV2Files(const CarlaPlugin& other);
1001 
1007  virtual void restoreLV2State(bool temporary) noexcept;
1008 
1012  virtual void prepareForDeletion() noexcept;
1013 
1017  virtual void waitForBridgeSaveSignal() noexcept;
1018 
1019  // -------------------------------------------------------------------
1020  // Helper classes
1021 
1027  {
1028  public:
1029  ScopedDisabler(CarlaPlugin* plugin) noexcept;
1030  ~ScopedDisabler() noexcept;
1031 
1032  private:
1033  CarlaPlugin* const fPlugin;
1034  bool fWasEnabled;
1035 
1036  CARLA_PREVENT_HEAP_ALLOCATION
1037  CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
1038  };
1039 
1046  {
1047  public:
1048  ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
1049  ~ScopedSingleProcessLocker() noexcept;
1050 
1051  private:
1052  CarlaPlugin* const fPlugin;
1053  const bool fBlock;
1054 
1055  CARLA_PREVENT_HEAP_ALLOCATION
1056  CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
1057  };
1058 
1059  friend class CarlaEngine;
1060  friend class CarlaEngineBridge;
1061  CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
1062 };
1063 
1066 // -----------------------------------------------------------------------
1067 
1068 CARLA_BACKEND_END_NAMESPACE
1069 
1070 #endif // CARLA_PLUGIN_HPP_INCLUDED
CarlaEngineClient
Definition: CarlaEngine.hpp:694
CarlaPluginPtr.hpp
CarlaBackend.h
CarlaPlugin::getExtraStuff
virtual const void * getExtraStuff() const noexcept
Definition: CarlaPlugin.hpp:949
CarlaEngine
Definition: CarlaEngine.hpp:806
CarlaPlugin::ScopedSingleProcessLocker
Definition: CarlaPlugin.hpp:1045
CarlaEngineCVPort
Definition: CarlaEngine.hpp:481
CarlaEngineCVSourcePorts
Definition: CarlaEngine.hpp:637
MidiProgramData
Definition: CarlaBackend.h:1847
CarlaEngineAudioPort
Definition: CarlaEngine.hpp:434
EngineInit::newJuce
CarlaEngine * newJuce(AudioApi api)
CarlaEngineEventPort
Definition: CarlaEngine.hpp:543
ParameterData
Definition: CarlaBackend.h:1658
EngineInit::newBridge
CarlaEngine * newBridge(const char *audioPoolBaseName, const char *rtClientBaseName, const char *nonRtClientBaseName, const char *nonRtServerBaseName)
NativePluginDescriptor
struct _NativePluginDescriptor NativePluginDescriptor
Definition: CarlaPlugin.hpp:28
CarlaPluginPtr
CARLA_BACKEND_START_NAMESPACE typedef std::shared_ptr< CarlaPlugin > CarlaPluginPtr
Definition: CarlaPluginPtr.hpp:267
CarlaPlugin::ScopedDisabler
Definition: CarlaPlugin.hpp:1026
CustomData
Definition: CarlaBackend.h:1868
BinaryType
BinaryType
Definition: CarlaBackend.h:509
CarlaPlugin
Definition: CarlaPlugin.hpp:67
CarlaPlugin::pData
ProtectedData *const pData
Definition: CarlaPlugin.hpp:990
lo_message
void * lo_message
Definition: CarlaPlugin.hpp:27
PluginCategory
PluginCategory
Definition: CarlaBackend.h:649
PluginType
PluginType
Definition: CarlaBackend.h:573
EngineEvent
Definition: CarlaEngine.hpp:211