1 /* ========================================
2  *  HardVacuum - HardVacuum.h
3  *  Copyright (c) 2016 airwindows, All rights reserved
4  * ======================================== */
5 
6 #ifndef __HardVacuum_H
7 #include "HardVacuum.h"
8 #endif
9 
10 namespace HardVacuum {
11 
12 
13 // AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new HardVacuum(audioMaster);}
14 
HardVacuum(audioMasterCallback audioMaster)15 HardVacuum::HardVacuum(audioMasterCallback audioMaster) :
16     AudioEffectX(audioMaster, kNumPrograms, kNumParameters)
17 {
18 	A = 0.0;
19 	B = 0.0;
20 	C = 0.0;
21 	D = 1.0;
22 	E = 1.0;
23 	lastSampleL = 0.0;
24 	lastSampleR = 0.0;
25 	fpNShapeL = 0.0;
26 	fpNShapeR = 0.0;
27 	//this is reset: values being initialized only once. Startup values, whatever they are.
28 
29     _canDo.insert("plugAsChannelInsert"); // plug-in can be used as a channel insert effect.
30     _canDo.insert("plugAsSend"); // plug-in can be used as a send effect.
31     _canDo.insert("x2in2out");
32     setNumInputs(kNumInputs);
33     setNumOutputs(kNumOutputs);
34     setUniqueID(kUniqueId);
35     canProcessReplacing();     // supports output replacing
36     canDoubleReplacing();      // supports double precision processing
37 	programsAreChunks(true);
38     vst_strncpy (_programName, "Default", kVstMaxProgNameLen); // default program name
39 }
40 
~HardVacuum()41 HardVacuum::~HardVacuum() {}
getVendorVersion()42 VstInt32 HardVacuum::getVendorVersion () {return 1000;}
setProgramName(char * name)43 void HardVacuum::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);}
getProgramName(char * name)44 void HardVacuum::getProgramName(char *name) {vst_strncpy (name, _programName, kVstMaxProgNameLen);}
45 //airwindows likes to ignore this stuff. Make your own programs, and make a different plugin rather than
46 //trying to do versioning and preventing people from using older versions. Maybe they like the old one!
47 
pinParameter(float data)48 static float pinParameter(float data)
49 {
50 	if (data < 0.0f) return 0.0f;
51 	if (data > 1.0f) return 1.0f;
52 	return data;
53 }
54 
getChunk(void ** data,bool isPreset)55 VstInt32 HardVacuum::getChunk (void** data, bool isPreset)
56 {
57 	float *chunkData = (float *)calloc(kNumParameters, sizeof(float));
58 	chunkData[0] = A;
59 	chunkData[1] = B;
60 	chunkData[2] = C;
61 	chunkData[3] = D;
62 	chunkData[4] = E;
63 	/* Note: The way this is set up, it will break if you manage to save settings on an Intel
64 	 machine and load them on a PPC Mac. However, it's fine if you stick to the machine you
65 	 started with. */
66 
67 	*data = chunkData;
68 	return kNumParameters * sizeof(float);
69 }
70 
setChunk(void * data,VstInt32 byteSize,bool isPreset)71 VstInt32 HardVacuum::setChunk (void* data, VstInt32 byteSize, bool isPreset)
72 {
73 	float *chunkData = (float *)data;
74 	A = pinParameter(chunkData[0]);
75 	B = pinParameter(chunkData[1]);
76 	C = pinParameter(chunkData[2]);
77 	D = pinParameter(chunkData[3]);
78 	E = pinParameter(chunkData[4]);
79 	/* We're ignoring byteSize as we found it to be a filthy liar */
80 
81 	/* calculate any other fields you need here - you could copy in
82 	 code from setParameter() here. */
83 	return 0;
84 }
85 
setParameter(VstInt32 index,float value)86 void HardVacuum::setParameter(VstInt32 index, float value) {
87     switch (index) {
88         case kParamA: A = value; break;
89         case kParamB: B = value; break;
90         case kParamC: C = value; break;
91         case kParamD: D = value; break;
92         case kParamE: E = value; break;
93         default: throw; // unknown parameter, shouldn't happen!
94     }
95 }
96 
getParameter(VstInt32 index)97 float HardVacuum::getParameter(VstInt32 index) {
98     switch (index) {
99         case kParamA: return A; break;
100         case kParamB: return B; break;
101         case kParamC: return C; break;
102         case kParamD: return D; break;
103         case kParamE: return E; break;
104         default: break; // unknown parameter, shouldn't happen!
105     } return 0.0; //we only need to update the relevant name, this is simple to manage
106 }
107 
getParameterName(VstInt32 index,char * text)108 void HardVacuum::getParameterName(VstInt32 index, char *text) {
109     switch (index) {
110         case kParamA: vst_strncpy (text, "Drive", kVstMaxParamStrLen); break;
111 		case kParamB: vst_strncpy (text, "Warmth", kVstMaxParamStrLen); break;
112 		case kParamC: vst_strncpy (text, "Aura", kVstMaxParamStrLen); break;
113 		case kParamD: vst_strncpy (text, "Output", kVstMaxParamStrLen); break;
114 		case kParamE: vst_strncpy (text, "Mix", kVstMaxParamStrLen); break;
115         default: break; // unknown parameter, shouldn't happen!
116     } //this is our labels for displaying in the VST host
117 }
118 
getParameterDisplay(VstInt32 index,char * text,float extVal,bool isExternal)119 void HardVacuum::getParameterDisplay(VstInt32 index, char *text, float extVal, bool isExternal) {
120     switch (index) {
121         case kParamA: dB2string (EXTV(A) * 2.0, text, kVstMaxParamStrLen); break;
122         case kParamB: float2string (EXTV(B) * 100.0, text, kVstMaxParamStrLen); break;
123         case kParamC: float2string (EXTV(C) * 100.0, text, kVstMaxParamStrLen); break;
124         case kParamD: dB2string (EXTV(D), text, kVstMaxParamStrLen); break;
125         case kParamE: float2string (EXTV(E) * 100.0, text, kVstMaxParamStrLen); break;
126 
127         default: break; // unknown parameter, shouldn't happen!
128 	} //this displays the values and handles 'popups' where it's discrete choices
129 }
130 
parseParameterValueFromString(VstInt32 index,const char * str,float & f)131 bool HardVacuum::parseParameterValueFromString(VstInt32 index, const char* str, float& f)
132 {
133    auto v = std::atof(str);
134 
135    switch (index)
136    {
137    case kParamA:
138    {
139       f = string2dB(str, v) * 0.5;
140       break;
141    }
142    case kParamD:
143    {
144       f = string2dB(str, v);
145       break;
146    }
147    default:
148    {
149       f = v / 100.0;
150       break;
151    }
152    }
153 
154    return true;
155 }
156 
getParameterLabel(VstInt32 index,char * text)157 void HardVacuum::getParameterLabel(VstInt32 index, char *text) {
158     switch (index) {
159         case kParamA: vst_strncpy (text, "dB", kVstMaxParamStrLen); break;
160         case kParamB: vst_strncpy (text, "%", kVstMaxParamStrLen); break;
161         case kParamC: vst_strncpy (text, "%", kVstMaxParamStrLen); break;
162         case kParamD: vst_strncpy (text, "dB", kVstMaxParamStrLen); break;
163         case kParamE: vst_strncpy (text, "%", kVstMaxParamStrLen); break;
164 		default: break; // unknown parameter, shouldn't happen!
165     }
166 }
167 
canDo(char * text)168 VstInt32 HardVacuum::canDo(char *text)
169 { return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know
170 
getEffectName(char * name)171 bool HardVacuum::getEffectName(char* name) {
172     vst_strncpy(name, "HardVacuum", kVstMaxProductStrLen); return true;
173 }
174 
getPlugCategory()175 VstPlugCategory HardVacuum::getPlugCategory() {return kPlugCategEffect;}
176 
getProductString(char * text)177 bool HardVacuum::getProductString(char* text) {
178   	vst_strncpy (text, "airwindows HardVacuum", kVstMaxProductStrLen); return true;
179 }
180 
getVendorString(char * text)181 bool HardVacuum::getVendorString(char* text) {
182   	vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true;
183 }
184 
185 
186 } // end namespace HardVacuum
187 
188