CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

VSTIO.cpp
Go to the documentation of this file.
1 //
2 // VSTIO.cpp -- DAC IO using VST
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5
6 #include "VSTIO.h"
7
8 using namespace csl;
9
10 // Constructors
11
12 VSTIO * createEffectInstance (audioMasterCallback audioMaster) {
13 return new VSTIO (audioMaster, CGestalt::frameRate(), CGestalt::blockSize(),
14 CGestalt::numInChannels(), CGestalt::numOutChannels());
15 }
16
17 VSTIO::VSTIO() : IO(), AudioEffectX (audioMaster, 1, 1) { }
18
19 VSTIO:: VSTIO(audioMasterCallback audioMaster,
20 unsigned s_rate, unsigned b_size,
21 unsigned in_chans, unsigned out_chans)
22 : IO(s_rate, b_size, 0, 0, in_chans, out_chans),
23 AudioEffectX (audioMaster, 1, 1) { // 1 program, 1 parameter only
24 setNumInputs(in_chans); // stereo in
25 setNumOutputs(out_chans); // stereo out
26 setUniqueID ('CSL_BP_Filter'); // identify
27 canProcessReplacing (); // supports replacing output
28 mInterleaved = false; // non-interleaved
29
30 // set up InOut UGen to copy input to effect
31 mInOut = new InOut(this, 2, 2, kNoProc, 1, 2); // stereo i/o
32 // create effect: a BPF filter
33 mFilter = new Butter(*mInOut, BW_BAND_PASS, 1000.f, 200.f);
34 // set its name
35 mFilter->setName("CSL B-P Filter");
36 // set it as the IO's root
37 this->setRoot(*mFilter);
38 }
39
40 // Destructor
41
42 VSTIO::~VSTIO() { }
43
44 // open/close start/stop methods
45
46 void VSTIO::open() throw(CException) { }
47
48 void VSTIO::close() throw(CException) { }
49
50 void VSTIO::start() throw(CException) { } ///< start my timer thread
51
52 void VSTIO::stop() throw(CException) { } ///< stop the timer thread
53
54 // Program
55
56 void VSTIO::setProgramName (char * name) {
57 vst_strncpy ((char *)mGraph->name()->c_str(), name, kVstMaxProgNameLen);
58 }
59
60 void VSTIO::getProgramName (char * name) {
61 vst_strncpy (name, "CSL B-P Filter", kVstMaxProgNameLen);
62 // vst_strncpy (name, (char *)mGraph->name()->c_str(), kVstMaxProgNameLen);
63 }
64
65 // Parameters
66
67 void VSTIO::setParameter (VstInt32 index, float value) {
68 mFilter->setFrequency(value);
69 }
70
71 float VSTIO::getParameter (VstInt32 index) {
72 Port * thePort = mFilter->getPort(CSL_FILTER_FREQUENCY);
73 if (thePort)
74 return thePort->nextValue();
75 else
76 return(0);
77 }
78
79 // Get a label from the Instrument
80
81 void VSTIO::getParameterLabel (VstInt32 index, char* label) {
82 vst_strncpy(label, "Hz", kVstMaxParamStrLen);
83 }
84
85 void VSTIO::getParameterDisplay (VstInt32 index, char* text) {
86 Hz2string(mFreq, text, kVstMaxParamStrLen);
87 }
88
89 void VSTIO::getParameterName (VstInt32 index, char* text) {
90 vst_strncpy(text, "Freq", kVstMaxParamStrLen);
91 }
92
93 bool VSTIO::getEffectName (char * name) {
94 vst_strncpy(name, "CSL B-P Filter", kVstMaxEffectNameLen);
95 return true;
96 }
97
98 bool VSTIO::getVendorString (char * text) {
99 vst_strncpy(text, "CREATE / UCSB", kVstMaxVendorStrLen);
100 return true;
101 }
102
103 bool VSTIO::getProductString (char * text) {
104 vst_strncpy(text, "CSL B-P Filter", kVstMaxProductStrLen);
105 return true;
106 }
107
108 VstInt32 VSTIO::getVendorVersion () {
109 return 1000;
110 }
111
112 // Processing
113
114 void VSTIO::processReplacing (float ** inputs, float ** outputs, VstInt32 sampleFrames) {
115 // float* in1 = inputs[0];
116 // float* in2 = inputs[1];
117 // float* out1 = outputs[0];
118 // float* out2 = outputs[1];
119
120 if (mGraph) {
121 mInputBuffer.setSize(mNumOutChannels, sampleFrames);
122 mInputBuffer.checkBuffers();
123 // copy data to mInputBuffer for the in-out
124 for (unsigned i = 0; i < mNumOutChannels; i++)
125 memcpy(mInputBuffer.buffer(i), inputs[i], sampleFrames * sizeof(VstInt32));
126 // set up outbuf
127 mOutputBuffer.setSize(mNumOutChannels, sampleFrames);
128 // mOutputBuffer.checkBuffers();
129 // copy JUCE data ptrs
130 for (unsigned i = 0; i < mNumOutChannels; i++)
131 mOutputBuffer.setBuffer(i, outputs[i]);
132 try { // Tell the IO to call its graph
133 this->pullInput(mOutputBuffer);
134 } catch (csl::CException e) {
135 logMsg(kLogError, "Error running CSL: graph: %s\n", e.what());
136 }
137 }
138 }
139
140 ///////////////////////////////////////////////////////////////////////////
141 //
142 // VSTInst
143
144 #if 0
145
146 #include "Instrument.h"
147 #include "BasicFMInstrument.h"
148 #include "AdditiveInstrument.h"
149
150 // Constructors
151
152 VSTInst * createEffectInstance (audioMasterCallback audioMaster) {
153 Instrument * inst = new AdditiveInstrument;
154 return new VSTInst (audioMaster, inst);
155 }
156
157 VSTInst::VSTInst() IO(), AudioEffectX (audioMaster, 1, 1) { }
158
159 VSTInst:: VSTInst(audioMasterCallback audioMaster, Instrument * theInstrument,
160 unsigned s_rate, unsigned b_size,
161 unsigned in_chans, unsigned out_chans)
162 : IO(s_rate, b_size, 0, 0, in_chans, out_chans),
163 AudioEffectX (audioMaster, 1, 1) { // 1 program, 1 parameter only
164 setNumInputs (in_chans); // stereo in
165 setNumOutputs (out_chans); // stereo out
166 setUniqueID ('Gain'); // identify
167 canProcessReplacing (); // supports replacing output
168 }
169
170 VSTInst::~VSTInst() { }
171
172 void VSTInst::open() throw(CException) { } ///< open/close start/stop methods
173
174 void VSTInst::close() throw(CException) { }
175
176 void VSTInst::start() throw(CException) { } ///< start my timer thread
177
178 void VSTInst::stop() throw(CException) { } ///< stop the timer thread
179
180 // Program
181
182 void VSTInst::setProgramName (char* name) {
183 vst_strncpy (mInstrument->mName, name, kVstMaxProgNameLen);
184 }
185
186 void VSTInst::getProgramName (char* name) {
187 vst_strncpy (name, mInstrument->mName, kVstMaxProgNameLen);
188 }
189
190 // Parameters
191
192 void VSTInst::setParameter (VstInt32 index, float value) {
193
194 }
195
196 float VSTInst::getParameter (VstInt32 index) {
197
198 }
199
200 // Get a label form the Instrument
201
202 void VSTInst::getParameterLabel (VstInt32 index, char* label) {
203 vst_strncpy (label, "dB", kVstMaxParamStrLen);
204 }
205
206 void VSTInst::getParameterDisplay (VstInt32 index, char* text) {
207 dB2string (fGain, text, kVstMaxParamStrLen);
208 }
209
210 void VSTInst::getParameterName (VstInt32 index, char* text) {
211 vst_strncpy (label, "Gain", kVstMaxParamStrLen);
212 }
213
214 bool VSTInst::getEffectName (char* name) {
215 vst_strncpy (name, "Gain", kVstMaxEffectNameLen);
216 return true;
217 }
218
219 bool VSTInst::getVendorString (char* text) {
220 vst_strncpy (text, "CREATE / UCSB", kVstMaxVendorStrLen);
221 return true;
222 }
223
224 bool VSTInst::getProductString (char* text) {
225 vst_strncpy (text, "Gain", kVstMaxProductStrLen);
226 return true;
227 }
228
229 VSTInst::VstInt32 getVendorVersion () {
230 return 1000;
231 }
232
233 // Processing
234
235 void VSTInst::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames) {
236 float* in1 = inputs[0];
237 float* in2 = inputs[1];
238 float* out1 = outputs[0];
239 float* out2 = outputs[1];
240
241 while (--sampleFrames >= 0) {
242 (*out1++) = (*in1++) * fGain;
243 (*out2++) = (*in2++) * fGain;
244 }
245 }
246
247 #endif