LMMS
Loading...
Searching...
No Matches
vstcomponentbase.cpp
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// Project : VST SDK
3//
4// Category : Helpers
5// Filename : public.sdk/source/vst/vstcomponentbase.cpp
6// Created by : Steinberg, 05/2005
7// Description : Base class for VST Component and Edit Controller
8//
9//-----------------------------------------------------------------------------
10// LICENSE
11// (c) 2021, Steinberg Media Technologies GmbH, All Rights Reserved
12//-----------------------------------------------------------------------------
13// Redistribution and use in source and binary forms, with or without modification,
14// are permitted provided that the following conditions are met:
15//
16// * Redistributions of source code must retain the above copyright notice,
17// this list of conditions and the following disclaimer.
18// * Redistributions in binary form must reproduce the above copyright notice,
19// this list of conditions and the following disclaimer in the documentation
20// and/or other materials provided with the distribution.
21// * Neither the name of the Steinberg Media Technologies nor the names of its
22// contributors may be used to endorse or promote products derived from this
23// software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34// OF THE POSSIBILITY OF SUCH DAMAGE.
35//-----------------------------------------------------------------------------
36
37#include "vstcomponentbase.h"
38#include "base/source/fstring.h"
39
40namespace Steinberg {
41namespace Vst {
42
43//------------------------------------------------------------------------
44// ComponentBase Implementation
45//------------------------------------------------------------------------
49
50//------------------------------------------------------------------------
54
55//------------------------------------------------------------------------
57{
58 // check if already initialized
59 if (hostContext)
60 return kResultFalse;
61
62 hostContext = context;
63
64 return kResultOk;
65}
66
67//------------------------------------------------------------------------
69{
70 // release host interfaces
71 hostContext = nullptr;
72
73 // in case host did not disconnect us,
74 // release peer now
76 {
77 peerConnection->disconnect (this);
78 peerConnection = nullptr;
79 }
80
81 return kResultOk;
82}
83
84//------------------------------------------------------------------------
86{
87 if (!other)
88 return kInvalidArgument;
89
90 // check if already connected
92 return kResultFalse;
93
94 peerConnection = other;
95 return kResultOk;
96}
97
98//------------------------------------------------------------------------
100{
101 if (peerConnection && other == peerConnection)
102 {
103 peerConnection = nullptr;
104 return kResultOk;
105 }
106 return kResultFalse;
107}
108
109//------------------------------------------------------------------------
111{
112 if (!message)
113 return kInvalidArgument;
114
115 if (FIDStringsEqual (message->getMessageID (), "TextMessage"))
116 {
117 TChar string[256] = {0};
118 if (message->getAttributes ()->getString ("Text", string, sizeof (string)) == kResultOk)
119 {
120 String tmp (string);
121 tmp.toMultiByte (kCP_Utf8);
122 return receiveText (tmp.text8 ());
123 }
124 }
125
126 return kResultFalse;
127}
128
129//------------------------------------------------------------------------
131{
133 if (hostApp)
134 return Vst::allocateMessage (hostApp);
135 return nullptr;
136}
137
138//------------------------------------------------------------------------
140{
141 if (message != nullptr && getPeer () != nullptr)
142 return getPeer ()->notify (message);
143 return kResultFalse;
144}
145
146//------------------------------------------------------------------------
148{
149 if (auto msg = owned (allocateMessage ()))
150 {
151 msg->setMessageID ("TextMessage");
152 String tmp (text, kCP_Utf8);
153 if (tmp.length () >= 256)
154 tmp.remove (255);
155 msg->getAttributes ()->setString ("Text", tmp.text16 ());
156 return sendMessage (msg);
157 }
158 return kResultFalse;
159}
160
161//------------------------------------------------------------------------
162tresult ComponentBase::sendMessageID (const char* messageID) const
163{
164 if (auto msg = owned (allocateMessage ()))
165 {
166 msg->setMessageID (messageID);
167 return sendMessage (msg);
168 }
169 return kResultFalse;
170}
171
172//------------------------------------------------------------------------
174{
175 return kResultOk;
176}
177
178//------------------------------------------------------------------------
179} // namespace Vst
180} // namespace Steinberg
static void message(int level, const char *fmt,...)
Definition adplugdb.cpp:120
virtual int32 length() const
Return length of string.
Definition fstring.h:128
Definition funknown.h:361
Definition funknown.h:403
Definition fstring.h:308
const char8 * text8() const SMTG_OVERRIDE
Returns pointer to string of type char8.
Definition fstring.h:621
bool toMultiByte(uint32 destCodePage=kCP_Default)
Definition fstring.cpp:2225
const char16 * text16() const SMTG_OVERRIDE
Returns pointer to string of type char16.
Definition fstring.h:630
String & remove(uint32 index=0, int32 n=-1)
Remove n characters from string starting at index (n=-1: until end).
Definition fstring.cpp:3053
tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE
Definition vstcomponentbase.cpp:110
IConnectionPoint * getPeer() const
Definition vstcomponentbase.h:67
IMessage * allocateMessage() const
Definition vstcomponentbase.cpp:130
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE
Definition vstcomponentbase.cpp:56
~ComponentBase() override
Definition vstcomponentbase.cpp:51
IPtr< IConnectionPoint > peerConnection
Definition vstcomponentbase.h:105
tresult PLUGIN_API terminate() SMTG_OVERRIDE
Definition vstcomponentbase.cpp:68
IPtr< FUnknown > hostContext
Definition vstcomponentbase.h:104
tresult sendTextMessage(const char8 *text) const
Definition vstcomponentbase.cpp:147
virtual tresult receiveText(const char8 *text)
Definition vstcomponentbase.cpp:173
tresult PLUGIN_API connect(IConnectionPoint *other) SMTG_OVERRIDE
Definition vstcomponentbase.cpp:85
tresult sendMessage(IMessage *message) const
Definition vstcomponentbase.cpp:139
tresult sendMessageID(const char8 *messageID) const
Definition vstcomponentbase.cpp:162
ComponentBase()
Definition vstcomponentbase.cpp:46
tresult PLUGIN_API disconnect(IConnectionPoint *other) SMTG_OVERRIDE
Definition vstcomponentbase.cpp:99
Definition ivstmessage.h:73
virtual tresult PLUGIN_API notify(IMessage *message)=0
Definition ivstmessage.h:41
const char * msg
Definition missing_descriptor.c:20
Definition ivstattributes.h:28
char16 TChar
UTF-16 character.
Definition vsttypes.h:62
IMessage * allocateMessage(IHostApplication *host)
Definition ivsthostapplication.h:53
Definition baseiids.cpp:43
char char8
Definition ftypes.h:93
@ kResultOk
Definition funknown.h:193
@ kInvalidArgument
Definition funknown.h:196
@ kResultFalse
Definition funknown.h:195
@ kCP_Utf8
UTF8 Encoding.
Definition fstring.h:72
bool FIDStringsEqual(FIDString id1, FIDString id2)
Definition fstrdefs.h:281
int32 tresult
Definition ftypes.h:76
IPtr< I > owned(I *p)
Definition smartpointer.h:241
const char * text
Definition swell-functions.h:167