vsthostutils.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 // Project     : VST SDK
00003 // Version     : 3.0
00004 //
00005 // Category    : Helpers
00006 // Filename    : vsthostutils.cpp
00007 // Created by  : Steinberg, 10/2005
00008 // Modified    : $Date: 2008/01/10 10:36:23 $
00009 // Description : VST Hosting Utilities
00010 //
00011 //-----------------------------------------------------------------------------
00012 // LICENSE
00013 // © 2008, Steinberg Media Technologies GmbH, All Rights Reserved
00014 //-----------------------------------------------------------------------------
00015 // This Software Development Kit may not be distributed in parts or its entirety  
00016 // without prior written agreement by Steinberg Media Technologies GmbH. 
00017 // This SDK must not be used to re-engineer or manipulate any technology used  
00018 // in any Steinberg or Third-party application or software module, 
00019 // unless permitted by law.
00020 // Neither the name of the Steinberg Media Technologies nor the names of its
00021 // contributors may be used to endorse or promote products derived from this 
00022 // software without specific prior written permission.
00023 // 
00024 // THIS SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND
00025 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00027 // IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT, 
00028 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00029 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00030 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00031 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00032 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033 // OF THE POSSIBILITY OF SUCH DAMAGE.
00034 //-----------------------------------------------------------------------------
00035 
00036 #include "vsthostutils.h"
00037 
00038 //------------------------------------------------------------------------
00039 namespace Steinberg {
00040 namespace Vst {
00041 
00042 //------------------------------------------------------------------------
00043 // HostProcessData
00044 //------------------------------------------------------------------------
00045 HostProcessData::HostProcessData ()
00046 {
00047         memset (this, 0, sizeof (ProcessData));
00048         symbolicSampleSize = kSample32;
00049 }
00050 
00051 //------------------------------------------------------------------------
00052 HostProcessData::~HostProcessData ()
00053 {
00054         unprepare ();
00055 }
00056 
00057 //------------------------------------------------------------------------
00058 bool HostProcessData::prepare (IComponent& component)
00059 {
00060         int32 newNumInputs  = component.getBusCount (kAudio, kInput);
00061         int32 newNumOutputs = component.getBusCount (kAudio, kOutput);
00062 
00063         if (inputs || outputs)
00064                 unprepare ();
00065 
00066         numInputs = newNumInputs;
00067         if (numInputs > 0)
00068         {
00069                 inputs = createBusBuffers (component, kInput, numInputs);
00070                 if (!inputs)
00071                         return false;
00072         }
00073 
00074         numOutputs = newNumOutputs;
00075         if (numOutputs > 0)
00076         {
00077                 outputs = createBusBuffers (component, kOutput, numOutputs);
00078                 if (!outputs)
00079                         return false;
00080         }
00081 
00082         return true;
00083 }
00084 
00085 //------------------------------------------------------------------------
00086 void HostProcessData::unprepare ()
00087 {
00088         if (inputs)
00089         {
00090                 destroyBusBuffers (inputs, numInputs);
00091                 inputs = 0;
00092                 numInputs = 0;
00093         }
00094 
00095         if (outputs)
00096         {
00097                 destroyBusBuffers (outputs, numOutputs);
00098                 outputs = 0;
00099                 numOutputs = 0;
00100         }
00101 }
00102 
00103 //------------------------------------------------------------------------
00104 AudioBusBuffers* HostProcessData::createBusBuffers (IComponent& component, BusDirection dir, int32 busCount)
00105 {
00106         AudioBusBuffers* buffers = new AudioBusBuffers[busCount];
00107         if (!buffers)
00108                 return 0;
00109 
00110         memset (buffers, 0, busCount * sizeof (AudioBusBuffers));
00111 
00112         for (int32 busIndex = 0; busIndex < busCount; busIndex++)
00113         {
00114                 BusInfo busInfo = {0};
00115                 tresult result = component.getBusInfo (kAudio, dir, busIndex, busInfo);
00116                 if (result != kResultOk)
00117                         continue;
00118 
00119                 int32 channelCount = busInfo.channelCount;
00120 
00121                 AudioBusBuffers& buffer = buffers[busIndex];
00122                 buffer.numChannels = channelCount;
00123                 buffer.silenceFlags = 0;
00124                 if (channelCount > 0)
00125                 {
00126                         buffer.channelBuffers32 = new Sample32*[channelCount];
00127                         if (buffer.channelBuffers32)
00128                                 memset (buffer.channelBuffers32, 0, channelCount * sizeof (Sample32*));
00129                 }
00130         }
00131 
00132         return buffers;
00133 }
00134 
00135 //------------------------------------------------------------------------
00136 void HostProcessData::destroyBusBuffers (AudioBusBuffers* buffers, int32 busCount)
00137 {
00138         for (int32 busIndex = 0; busIndex < busCount; busIndex++)
00139         {
00140                 Sample32** channelBuffers = buffers[busIndex].channelBuffers32;
00141                 if (channelBuffers)
00142                         delete [] channelBuffers;
00143         }
00144 
00145         delete [] buffers;
00146 }
00147 
00148 //------------------------------------------------------------------------
00149 }} // namespace Vst
Empty

Copyright ©2008 Steinberg Media Technologies. All Rights Reserved.