vstcomponentbase.cpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // Project     : VST SDK
00003 // Version     : 3.0
00004 //
00005 // Category    : Helpers
00006 // Filename    : vstcomponentbase.cpp
00007 // Created by  : Steinberg, 05/2005
00008 // Modified    : $Date: 2008/01/09 12:51:06 $
00009 // Description : Base class for VST Component and Edit Controller
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 "vstcomponentbase.h"
00037 
00038 namespace Steinberg {
00039 namespace Vst {
00040 
00041 //------------------------------------------------------------------------
00042 // ComponentBase
00043 //------------------------------------------------------------------------
00044 ComponentBase::ComponentBase ()
00045 : hostContext (0)
00046 , peerConnection (0)
00047 {
00048         FUNKNOWN_CTOR
00049 }
00050 
00051 //------------------------------------------------------------------------
00052 ComponentBase::~ComponentBase ()
00053 {
00054         FUNKNOWN_DTOR
00055 }
00056 
00057 //------------------------------------------------------------------------
00058 IMPLEMENT_REFCOUNT (ComponentBase)
00059 
00060 //------------------------------------------------------------------------
00061 tresult PLUGIN_API ComponentBase::queryInterface (const char* iid, void** obj)
00062 {
00063         QUERY_INTERFACE (iid, obj, IConnectionPoint::iid, IConnectionPoint)
00064         QUERY_INTERFACE (iid, obj, IPluginBase::iid, IPluginBase)
00065         QUERY_INTERFACE (iid, obj, FUnknown::iid, IPluginBase)
00066         *obj = 0;
00067         return kNoInterface;
00068 }
00069 
00070 //------------------------------------------------------------------------
00071 tresult PLUGIN_API ComponentBase::initialize (FUnknown* context)
00072 {
00073         // check if already initialized
00074         if (hostContext)
00075                 return kResultFalse;
00076 
00077         hostContext = context;
00078         if (hostContext)
00079                 hostContext->addRef ();
00080 
00081         return kResultOk;
00082 }
00083 
00084 //------------------------------------------------------------------------
00085 tresult PLUGIN_API ComponentBase::terminate ()
00086 {
00087         // release host interfaces
00088         if (hostContext)
00089         {
00090                 hostContext->release ();
00091                 hostContext = 0;
00092         }
00093 
00094         // in case host did not disconnect us, 
00095         // release peer now
00096         if (peerConnection)
00097         {
00098                 peerConnection->disconnect (this);
00099                 peerConnection->release ();
00100                 peerConnection = 0;
00101         }
00102 
00103         return kResultOk;
00104 }
00105 
00106 //------------------------------------------------------------------------
00107 tresult PLUGIN_API ComponentBase::connect (IConnectionPoint* other)
00108 {
00109         if (!other)
00110                 return kInvalidArgument;
00111         
00112         // check if already connected
00113         if (peerConnection) 
00114                 return kResultFalse;
00115 
00116         peerConnection = other;
00117         peerConnection->addRef ();
00118         return kResultOk;
00119 }
00120 
00121 //------------------------------------------------------------------------
00122 tresult PLUGIN_API ComponentBase::disconnect (IConnectionPoint* other)
00123 {
00124         if (peerConnection && other == peerConnection)
00125         {
00126                 peerConnection->release (),
00127                 peerConnection = 0;
00128                 return kResultOk;
00129         }
00130         return kResultFalse;
00131 }
00132 
00133 //------------------------------------------------------------------------
00134 tresult PLUGIN_API ComponentBase::notify (IMessage* message)
00135 {
00136         if (!message)
00137                 return kInvalidArgument;
00138 
00139         if (!strcmp (message->getMessageID (), "TextMessage"))
00140         {
00141                 TChar string[256] = {0};
00142                 if (message->getAttributes ()->getString ("Text", string, USTRINGSIZE (string)) == kResultOk)
00143                 {
00144                         char ascii[256] = {0};
00145                         UString (string, -1).toAscii (ascii, sizeof (ascii));
00146                         return receiveText (ascii);
00147                 }
00148         }
00149 
00150         return kResultFalse;
00151 }
00152 
00153 //------------------------------------------------------------------------
00154 IMessage* ComponentBase::allocateMessage ()
00155 {
00156         FUnknownPtr<IHostApplication> hostApp (hostContext);
00157         if (hostApp)
00158                 return Vst::allocateMessage (hostApp);
00159         return 0;
00160 }
00161 
00162 //------------------------------------------------------------------------
00163 tresult ComponentBase::sendMessage (IMessage* message)
00164 {
00165         if (message != 0 && getPeer () != 0)
00166                 return getPeer ()->notify (message);
00167         return kResultFalse;
00168 }
00169 
00170 //------------------------------------------------------------------------
00171 tresult ComponentBase::sendTextMessage (const char* text)
00172 {
00173         IMessage* message = allocateMessage ();
00174         if (!message)
00175                 return kResultFalse;
00176 
00177         FReleaser msgReleaser (message);
00178         message->setMessageID ("TextMessage");
00179         message->getAttributes ()->setString ("Text", USTRING (text));
00180         return sendMessage (message);
00181 }
00182 
00183 //------------------------------------------------------------------------
00184 tresult ComponentBase::receiveText (const char* text)
00185 {
00186         return kResultOk;
00187 }
00188 
00189 }} // namespace
Empty

Copyright ©2008 Steinberg Media Technologies. All Rights Reserved.