CSL  6.0
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(),
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 
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) {
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 
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);
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
InOut class copies the IO port's input buffer to the output buffer, possibly with channel remap and s...
Definition: InOut.h:37
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
virtual void getParameterName(VstInt32 index, char *text)
Definition: VSTIO.cpp:89
float mFreq
Example: filter center freq.
Definition: VSTIO.h:57
#define CSL_FILTER_FREQUENCY
Definition: CSL_Types.h:283
#define kNoProc
Definition: InOut.h:25
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
Definition: CSL_Core.h:158
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
Definition: CSL_Core.cpp:1425
void open()
open/close start/stop methods
Definition: VSTIO.cpp:46
virtual bool getVendorString(char *text)
Definition: VSTIO.cpp:98
AdditiveInstrument.
static unsigned numOutChannels()
default number of output channels
Definition: CGestalt.cpp:59
virtual void processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames)
Definition: VSTIO.cpp:114
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
Definition: CSL_Core.cpp:66
bool mInterleaved
flag if IO is interleaved
Definition: CSL_Core.h:792
virtual void setProgramName(char *name)
Definition: VSTIO.cpp:56
virtual VstInt32 getVendorVersion()
Definition: VSTIO.cpp:108
void setSize(unsigned numChannels, unsigned numFrames)
Definition: CSL_Core.cpp:75
void close()
open/close start/stop methods
Definition: VSTIO.cpp:48
float nextValue()
answer the next value (dynamic or constant)
Definition: CSL_Core.h:341
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
Definition: CSL_Core.h:777
const char * what()
static unsigned blockSize()
the default block size
Definition: CGestalt.cpp:57
#define BW_BAND_PASS
Definition: Filters.h:53
VSTIO is an IO that answers the VST processReplacing() call by calling its CSL graph.
Definition: VSTIO.h:21
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
Definition: CSL_Core.h:752
static unsigned frameRate()
default frame rate
Definition: CGestalt.cpp:51
VSTIO * createEffectInstance(audioMasterCallback audioMaster)
Definition: VSTIO.cpp:12
static unsigned numInChannels()
default number of input channels
Definition: CGestalt.cpp:58
void stop()
stop the timer thread
Definition: VSTIO.cpp:52
Instrument class (abstract)
Definition: Instrument.h:56
void start()
start my timer thread
Definition: VSTIO.cpp:50
virtual void getParameterLabel(VstInt32 index, char *label)
Definition: VSTIO.cpp:81
virtual float getParameter(VstInt32 index)
Definition: VSTIO.cpp:71
virtual void getProgramName(char *name)
Definition: VSTIO.cpp:60
unsigned mNumOutChannels
outputs
Definition: CSL_Core.h:788
InOut * mInOut
the in-out object
Definition: VSTIO.h:55
virtual bool getProductString(char *text)
Definition: VSTIO.cpp:103
void checkBuffers()
allocate if not already there
Definition: CSL_Core.cpp:107
VSTIO()
Constructor.
Definition: VSTIO.cpp:17
virtual void getParameterDisplay(VstInt32 index, char *text)
Definition: VSTIO.cpp:85
void setFrequency(UnitGenerator &frequency)
set the receiver's frequency to a UGen or a float
Definition: Filters.cpp:27
Butterworth IIR (2nd order recursive) filter.
Definition: Filters.h:137
void setRoot(UnitGenerator &root)
set/clear my graph root generator
Definition: CSL_Core.cpp:1405
Buffer mOutputBuffer
the output buffer I use (passed to nextBuffer calls)
Definition: CSL_Core.h:779
virtual void setParameter(VstInt32 index, float value)
Definition: VSTIO.cpp:67
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
Definition: CSL_Core.h:778
Port * getPort(CSL_MAP_KEY name)
Definition: CSL_Core.cpp:920
virtual bool getEffectName(char *name)
Definition: VSTIO.cpp:93
Port – used to represent constant, control-rate or signal inputs and outputs in named maps; holds a ...
Definition: CSL_Core.h:312
virtual ~VSTIO()
Definition: VSTIO.cpp:42
Filter * mFilter
BPF filter.
Definition: VSTIO.h:56
Base class of CSL exceptions (written upper-case). Has a string message.