Advertisement
mayae

example vst processor.

Sep 30th, 2015
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include "audioeffectx.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. class Processor : public AudioEffectX
  6. {
  7.  
  8. public:
  9.  
  10.     enum Params
  11.     {
  12.         kResonance,
  13.         kCutoff,
  14.     };
  15.  
  16.     Processor(audioMasterCallback cb)
  17.         : AudioEffectX(cb, 2, 2), stateData()
  18.     {
  19.         // move this into a .cpp file to avoid cyclical dependency, obviously.
  20.         setEditor(new GUI(this));
  21.         // experiment with this:
  22.         //programsAreChunks(true);
  23.     }
  24.  
  25.     struct Data
  26.     {
  27.         // program data:
  28.         float params[2];
  29.         // state data - not public to the host:
  30.         float curve;
  31.         int someOtherData;
  32.     } stateData;
  33.  
  34.     void setCurve(float curve)
  35.     {
  36.         stateData.curve = curve;
  37.     }
  38.  
  39.  
  40.     VstInt32 getChunk(void ** data, bool preset) override
  41.     {
  42.         // save all data, even including the non-parameters.
  43.         *data = malloc(sizeof(Data)); // can't remember where to free() this.
  44.         memcpy(*data, &stateData, sizeof(Data));
  45.         return sizeof(Data);
  46.     }
  47.  
  48.     VstInt32 setChunk(void * data, VstInt32 dataSize, bool preset) override
  49.     {
  50.         // some error checking  goes here.
  51.         memcpy(&stateData, data, sizeof(Data));
  52.     }
  53.  
  54.     void setParameter(VstInt32 index, float value) override
  55.     {
  56.         stateData.params[index] = value;
  57.     }
  58.  
  59.     float getParameter(VstInt32 index) override
  60.     {
  61.         return stateData.params[index];
  62.     }
  63.  
  64.     // rest of code, processing, etc.
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement