CairoExamplePlugin.cpp (6228B)
1 /* 2 * DISTRHO Plugin Framework (DPF) 3 * Copyright (C) 2019-2021 Jean Pierre Cimalando <jp-dev@inbox.ru> 4 * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com> 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any purpose with 7 * or without fee is hereby granted, provided that the above copyright notice and this 8 * permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD 11 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN 12 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 14 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include "DistrhoPlugin.hpp" 19 20 #include <string.h> 21 22 START_NAMESPACE_DISTRHO 23 24 class CairoExamplePlugin : public Plugin 25 { 26 float fParameters[kParameterCount]; 27 28 public: 29 CairoExamplePlugin() 30 : Plugin(kParameterCount, 0, 0) 31 { 32 std::memset(fParameters, 0, sizeof(fParameters)); 33 } 34 35 /** 36 Get the plugin label.@n 37 This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters. 38 */ 39 const char* getLabel() const override 40 { 41 return "cairo_ui"; 42 } 43 44 /** 45 Get an extensive comment/description about the plugin. 46 */ 47 const char* getDescription() const override 48 { 49 return "Cairo DPF Example"; 50 } 51 52 /** 53 Get the plugin author/maker. 54 */ 55 const char* getMaker() const override 56 { 57 return "DISTRHO"; 58 } 59 60 /** 61 Get the plugin license (a single line of text or a URL).@n 62 For commercial plugins this should return some short copyright information. 63 */ 64 const char* getLicense() const override 65 { 66 return "ISC"; 67 } 68 69 /** 70 Get the plugin version, in hexadecimal. 71 */ 72 uint32_t getVersion() const override 73 { 74 return d_version(1, 0, 0); 75 } 76 77 /** 78 Initialize the audio port @a index.@n 79 This function will be called once, shortly after the plugin is created. 80 */ 81 void initAudioPort(const bool input, const uint32_t index, AudioPort& port) override 82 { 83 // treat meter audio ports as stereo 84 port.groupId = kPortGroupMono; 85 86 // everything else is as default 87 Plugin::initAudioPort(input, index, port); 88 } 89 90 /** 91 Initialize the parameter @a index.@n 92 This function will be called once, shortly after the plugin is created. 93 */ 94 void initParameter(const uint32_t index, Parameter& parameter) override 95 { 96 /** 97 All parameters in this plugin have the same ranges. 98 */ 99 switch (index) 100 { 101 case kParameterKnob: 102 parameter.hints = kParameterIsAutomatable; 103 parameter.name = "Knob"; 104 parameter.symbol = "knob"; 105 parameter.ranges.min = 0.0f; 106 parameter.ranges.max = 1.0f; 107 parameter.ranges.def = 0.0f; 108 break; 109 case kParameterTriState: 110 parameter.hints = kParameterIsAutomatable|kParameterIsInteger; 111 parameter.name = "Color"; 112 parameter.symbol = "color"; 113 parameter.ranges.min = 0.0f; 114 parameter.ranges.max = 2.0f; 115 parameter.ranges.def = 0.0f; 116 parameter.enumValues.count = 3; 117 parameter.enumValues.restrictedMode = true; 118 { 119 ParameterEnumerationValue* const values = new ParameterEnumerationValue[3]; 120 parameter.enumValues.values = values; 121 values[0].label = "Red"; 122 values[0].value = 0; 123 values[1].label = "Green"; 124 values[1].value = 1; 125 values[2].label = "Blue"; 126 values[2].value = 2; 127 } 128 break; 129 case kParameterButton: 130 parameter.hints = kParameterIsAutomatable|kParameterIsBoolean; 131 parameter.name = "Button"; 132 parameter.symbol = "button"; 133 parameter.ranges.min = 0.0f; 134 parameter.ranges.max = 1.0f; 135 parameter.ranges.def = 0.0f; 136 parameter.enumValues.count = 2; 137 parameter.enumValues.restrictedMode = true; 138 { 139 ParameterEnumerationValue* const values = new ParameterEnumerationValue[2]; 140 parameter.enumValues.values = values; 141 values[0].label = "Off"; 142 values[0].value = 0; 143 values[1].label = "On"; 144 values[1].value = 1; 145 } 146 break; 147 } 148 } 149 150 /** 151 Get the current value of a parameter.@n 152 The host may call this function from any context, including realtime processing. 153 */ 154 float getParameterValue(const uint32_t index) const override 155 { 156 return fParameters[index]; 157 } 158 159 /** 160 Change a parameter value.@n 161 The host may call this function from any context, including realtime processing.@n 162 When a parameter is marked as automatable, you must ensure no non-realtime operations are performed. 163 @note This function will only be called for parameter inputs. 164 */ 165 void setParameterValue(const uint32_t index, const float value) override 166 { 167 fParameters[index] = value; 168 } 169 170 /** 171 Run/process function for plugins without MIDI input. 172 @note Some parameters might be null if there are no audio inputs or outputs. 173 */ 174 void run(const float** const inputs, float** const outputs, const uint32_t frames) override 175 { 176 /** 177 This plugin does nothing, it just demonstrates cairo UI usage. 178 So here we directly copy inputs over outputs, leaving the audio untouched. 179 We need to be careful in case the host re-uses the same buffer for both inputs and outputs. 180 */ 181 if (outputs[0] != inputs[0]) 182 std::memcpy(outputs[0], inputs[0], sizeof(float)*frames); 183 } 184 }; 185 186 Plugin* createPlugin() 187 { 188 return new CairoExamplePlugin; 189 } 190 191 END_NAMESPACE_DISTRHO