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