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