1 /* 2 * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef __VST_HOST_H__ 7 #define __VST_HOST_H__ 8 9 #include <String.h> 10 #include <Entry.h> 11 #include <Directory.h> 12 #include <Path.h> 13 #include <List.h> 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <stdint.h> 18 #include <image.h> 19 #include <string.h> 20 #include <ctype.h> 21 22 #define VST_PARAM_TEST_COUNT 100 23 24 //error codes 25 #define VST_ERR_ALREADY_LOADED -1 26 #define VST_ERR_NOT_LOADED -2 27 #define VST_ERR_NO_MAINPROC -3 28 29 //param types 30 #define VST_PARAM_SLIDER 1 31 #define VST_PARAM_CHECKBOX 2 32 #define VST_PARAM_DROPLIST 3 33 34 //channels 35 #define VST_INPUT_CHANNELS 1 36 #define VST_OUTPUT_CHANNELS 2 37 38 //vst callback opcodes 39 #define VST_MASTER_AUTOMATE 0x00 40 #define VST_MASTER_VERSION 0x01 41 #define VST_MASTER_IDLE 0x03 42 #define VST_MASTER_VENDOR 0x20 43 #define VST_MASTER_PRODUCT 0x21 44 45 //vst actions 46 #define VST_OPEN 0x00 47 #define VST_CLOSE 0x01 48 #define VST_GET_PARAM_UNIT 0x06 49 #define VST_GET_PARAM_STR 0x07 50 #define VST_GET_PARAM_NAME 0x08 51 #define VST_SET_SAMPLE_RATE 0x0A 52 #define VST_SET_BLOCK_SIZE 0x0B 53 #define VST_STATE_CHANGED 0x0C 54 #define VST_GET_EFFECT_NAME 0x2D 55 #define VST_GET_VENDOR_STR 0x2F 56 #define VST_GET_PRODUCT_STR 0x30 57 #define VST_GET_VENDOR_VER 0x31 58 59 //vst plugin structure 60 struct VSTEffect 61 { 62 int cookie; 63 int32 (*dispatcher)(struct VSTEffect*, int32, int32, int32, void*, float); 64 void (*process)(struct VSTEffect*, float**, float**, int32); 65 void (*setParameter)(struct VSTEffect*, int32, float); 66 float (*getParameter)(struct VSTEffect*, int32); 67 int32 numPrograms; 68 int32 numParams; 69 int32 numInputs; 70 int32 numOutputs; 71 int32 flags; 72 void* _notused_pointer1; 73 void* _notused_pointer2; 74 char _notused_block1[12]; 75 float _notused_float; 76 void* _notused_pointer3; 77 void* _notused_pointer4; 78 int32 ID; 79 char _notused_block2[4]; 80 void (*processReplacing)(struct VSTEffect*, float**, float**, int); 81 }; 82 83 //typedefs 84 typedef int32 (*audioMasterCallback)(VSTEffect*, int32, int32, int32, void*, float); 85 typedef VSTEffect* (*VSTEntryProc)(audioMasterCallback audioMaster); 86 inline float round(float x) {return ceil(x-0.5);} 87 88 //structure for droplist parameters 89 struct DropListValue { 90 int Index; 91 float Value; 92 BString Name; 93 }; 94 95 class VSTPlugin; 96 //vst parameter class adapter 97 class VSTParameter { 98 public: 99 VSTParameter(VSTPlugin* plugin, int index); 100 ~VSTParameter(); 101 float Value(void); 102 void SetValue(float value); 103 const char* MinimumValue(void); 104 const char* MaximumValue(void); 105 const char* Unit(void); 106 int Index(void); 107 int Type(void); 108 const char* Name(void); 109 int ListCount(void); 110 DropListValue* ListItemAt(int index); 111 bigtime_t LastChangeTime(void); 112 private: 113 BString* ValidateValues(BString *string); 114 VSTPlugin* fPlugin; 115 VSTEffect* fEffect; 116 int fIndex; 117 int fType; 118 BString fName; 119 BString fUnit; 120 BString fMinValue; 121 BString fMaxValue; 122 BList fDropList; 123 bigtime_t fChanged; 124 float fLastValue; 125 }; 126 127 //vst plugin interface 128 class VSTPlugin { 129 public: 130 VSTPlugin(); 131 ~VSTPlugin(); 132 int LoadModule(const char *path); 133 int UnLoadModule(void); 134 int SetSampleRate(float rate); 135 float SampleRate(void); 136 int SetBlockSize(size_t size); 137 const char* Path(void); 138 size_t BlockSize(void); 139 VSTEffect* Effect(void); 140 const char* EffectName(void); 141 const char* ModuleName(void); 142 const char* Vendor(void); 143 const char* Product(void); 144 int ParametersCount(void); 145 VSTParameter* Parameter(int index); 146 int Channels(int mode); 147 int ReAllocBuffers(void); 148 void Process(float *buffer, int samples, int channels); 149 private: 150 VSTEntryProc GetMainEntry(); 151 VSTEffect* fEffect; 152 VSTEntryProc VSTMainProc; 153 bool fActive; 154 image_id fModule; 155 BPath fPath; 156 size_t fBlockSize; 157 float fSampleRate; 158 int fInputChannels; 159 int fOutputChannels; 160 BString fModuleName; 161 BString fEffectName; 162 BString fVendorString; 163 BString fProductString; 164 BList fParameters; 165 float **inputs; 166 float **outputs; 167 }; 168 169 #endif //__VST_HOST_H__ 170