DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

EmbedExternalExamplePlugin.cpp (7245B)


      1 /*
      2  * DISTRHO Plugin Framework (DPF)
      3  * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
      4  *
      5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
      6  * or without fee is hereby granted, provided that the above copyright notice and this
      7  * permission notice appear in all copies.
      8  *
      9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
     10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
     11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
     12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
     13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
     14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 #include "DistrhoPlugin.hpp"
     18 
     19 START_NAMESPACE_DISTRHO
     20 
     21 // -----------------------------------------------------------------------------------------------------------
     22 
     23 /**
     24   Plugin to show how to get some basic information sent to the UI.
     25  */
     26 class EmbedExternalExamplePlugin : public Plugin
     27 {
     28 public:
     29     EmbedExternalExamplePlugin()
     30         : Plugin(kParameterCount, 0, 0),
     31           fWidth(512.0f),
     32           fHeight(256.0f)
     33     {
     34     }
     35 
     36 protected:
     37    /* --------------------------------------------------------------------------------------------------------
     38     * Information */
     39 
     40    /**
     41       Get the plugin label.
     42       This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
     43     */
     44     const char* getLabel() const override
     45     {
     46         return "EmbedExternalUI";
     47     }
     48 
     49    /**
     50       Get an extensive comment/description about the plugin.
     51     */
     52     const char* getDescription() const override
     53     {
     54         return "Plugin to show how to use an embedable dpf-external UI.";
     55     }
     56 
     57    /**
     58       Get the plugin author/maker.
     59     */
     60     const char* getMaker() const override
     61     {
     62         return "DISTRHO";
     63     }
     64 
     65    /**
     66       Get the plugin homepage.
     67     */
     68     const char* getHomePage() const override
     69     {
     70         return "https://github.com/DISTRHO/DPF";
     71     }
     72 
     73    /**
     74       Get the plugin license name (a single line of text).
     75       For commercial plugins this should return some short copyright information.
     76     */
     77     const char* getLicense() const override
     78     {
     79         return "ISC";
     80     }
     81 
     82    /**
     83       Get the plugin version, in hexadecimal.
     84     */
     85     uint32_t getVersion() const override
     86     {
     87         return d_version(1, 0, 0);
     88     }
     89 
     90    /**
     91       Get the plugin unique Id.
     92       This value is used by LADSPA, DSSI and VST plugin formats.
     93     */
     94     int64_t getUniqueId() const override
     95     {
     96         return d_cconst('d', 'b', 'x', 't');
     97     }
     98 
     99    /* --------------------------------------------------------------------------------------------------------
    100     * Init */
    101 
    102    /**
    103       Initialize the audio port @a index.@n
    104       This function will be called once, shortly after the plugin is created.
    105     */
    106     void initAudioPort(bool input, uint32_t index, AudioPort& port) override
    107     {
    108         // treat meter audio ports as stereo
    109         port.groupId = kPortGroupStereo;
    110 
    111         // everything else is as default
    112         Plugin::initAudioPort(input, index, port);
    113     }
    114 
    115    /**
    116       Initialize the parameter @a index.
    117       This function will be called once, shortly after the plugin is created.
    118     */
    119     void initParameter(uint32_t index, Parameter& parameter) override
    120     {
    121         switch (index)
    122         {
    123         case kParameterWidth:
    124             parameter.hints      = kParameterIsAutomatable|kParameterIsInteger;
    125             parameter.ranges.def = 512.0f;
    126             parameter.ranges.min = 256.0f;
    127             parameter.ranges.max = 4096.0f;
    128             parameter.name   = "Width";
    129             parameter.symbol = "width";
    130             parameter.unit   = "px";
    131             break;
    132         case kParameterHeight:
    133             parameter.hints      = kParameterIsAutomatable|kParameterIsInteger;
    134             parameter.ranges.def = 256.0f;
    135             parameter.ranges.min = 256.0f;
    136             parameter.ranges.max = 4096.0f;
    137             parameter.name   = "Height";
    138             parameter.symbol = "height";
    139             parameter.unit   = "px";
    140             break;
    141         }
    142     }
    143 
    144    /* --------------------------------------------------------------------------------------------------------
    145     * Internal data */
    146 
    147    /**
    148       Get the current value of a parameter.
    149       The host may call this function from any context, including realtime processing.
    150     */
    151     float getParameterValue(uint32_t index) const override
    152     {
    153         switch (index)
    154         {
    155         case kParameterWidth:
    156             return fWidth;
    157         case kParameterHeight:
    158             return fHeight;
    159         }
    160 
    161         return 0.0f;
    162 
    163     }
    164 
    165    /**
    166       Change a parameter value.
    167       The host may call this function from any context, including realtime processing.
    168       When a parameter is marked as automatable, you must ensure no non-realtime operations are performed.
    169       @note This function will only be called for parameter inputs.
    170     */
    171     void setParameterValue(uint32_t index, float value) override
    172     {
    173         switch (index)
    174         {
    175         case kParameterWidth:
    176             fWidth = value;
    177             break;
    178         case kParameterHeight:
    179             fHeight = value;
    180             break;
    181         }
    182     }
    183 
    184    /* --------------------------------------------------------------------------------------------------------
    185     * Audio/MIDI Processing */
    186 
    187    /**
    188       Run/process function for plugins without MIDI input.
    189       @note Some parameters might be null if there are no audio inputs or outputs.
    190     */
    191     void run(const float** inputs, float** outputs, uint32_t frames) override
    192     {
    193        /**
    194           This plugin does nothing, it just demonstrates information usage.
    195           So here we directly copy inputs over outputs, leaving the audio untouched.
    196           We need to be careful in case the host re-uses the same buffer for both inputs and outputs.
    197         */
    198         if (outputs[0] != inputs[0])
    199             std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
    200         if (outputs[1] != inputs[1])
    201             std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
    202     }
    203 
    204     // -------------------------------------------------------------------------------------------------------
    205 
    206 private:
    207     // Parameters
    208     float fWidth, fHeight;
    209 
    210    /**
    211       Set our plugin class as non-copyable and add a leak detector just in case.
    212     */
    213     DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EmbedExternalExamplePlugin)
    214 };
    215 
    216 /* ------------------------------------------------------------------------------------------------------------
    217  * Plugin entry point, called by DPF to create a new plugin instance. */
    218 
    219 Plugin* createPlugin()
    220 {
    221     return new EmbedExternalExamplePlugin();
    222 }
    223 
    224 // -----------------------------------------------------------------------------------------------------------
    225 
    226 END_NAMESPACE_DISTRHO