JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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) 2023, 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//------------------------------------------------------------------------
46ComponentBase::ComponentBase ()
47{
48}
49
50//------------------------------------------------------------------------
51ComponentBase::~ComponentBase ()
52{
53}
54
55//------------------------------------------------------------------------
56tresult PLUGIN_API ComponentBase::initialize (FUnknown* context)
57{
58 // check if already initialized
59 if (hostContext)
60 return kResultFalse;
61
62 hostContext = context;
63
64 return kResultOk;
65}
66
67//------------------------------------------------------------------------
68tresult PLUGIN_API ComponentBase::terminate ()
69{
70 // release host interfaces
71 hostContext = nullptr;
72
73 // in case host did not disconnect us,
74 // release peer now
75 if (peerConnection)
76 {
77 peerConnection->disconnect (this);
78 peerConnection = nullptr;
79 }
80
81 return kResultOk;
82}
83
84//------------------------------------------------------------------------
85tresult PLUGIN_API ComponentBase::connect (IConnectionPoint* other)
86{
87 if (!other)
88 return kInvalidArgument;
89
90 // check if already connected
91 if (peerConnection)
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//------------------------------------------------------------------------
110tresult PLUGIN_API ComponentBase::notify (IMessage* message)
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{
132 FUnknownPtr<IHostApplication> hostApp (hostContext);
133 if (hostApp)
134 return Vst::allocateMessage (hostApp);
135 return nullptr;
136}
137
138//------------------------------------------------------------------------
139tresult ComponentBase::sendMessage (IMessage* message) const
140{
141 if (message != nullptr && getPeer () != nullptr)
142 return getPeer ()->notify (message);
143 return kResultFalse;
144}
145
146//------------------------------------------------------------------------
147tresult ComponentBase::sendTextMessage (const char8* text) const
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 char8* 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//------------------------------------------------------------------------
173tresult ComponentBase::receiveText (const char8* /*text*/)
174{
175 return kResultOk;
176}
177
178//------------------------------------------------------------------------
179} // namespace Vst
180} // namespace Steinberg
virtual int32 length() const
Return length of string.
Definition fstring.h:128
FUnknownPtr - automatic interface conversion and smart pointer in one.
Definition funknown.h:417
The basic interface of all interfaces.
Definition funknown.h:375
const char8 * text8() const SMTG_OVERRIDE
Returns pointer to string of type char8.
Definition fstring.h:640
const char16 * text16() const SMTG_OVERRIDE
Returns pointer to string of type char16.
Definition fstring.h:649
String & remove(uint32 index=0, int32 n=-1)
Remove n characters from string starting at index (n=-1: until end)
Definition fstring.cpp:3035
tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE
Called when a message has been sent from the connection point to this.
IConnectionPoint * getPeer() const
Returns the peer for the messaging communication (you can only use IConnectionPoint::notify for commu...
IMessage * allocateMessage() const
Allocates a message instance (do not forget to release it).
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE
The host passes a number of interfaces as context to initialize the plug-in class.
tresult PLUGIN_API terminate() SMTG_OVERRIDE
This function is called before the plug-in is unloaded and can be used for cleanups.
tresult sendTextMessage(const char8 *text) const
Sends a simple text message to the peer (max 255 characters).
virtual tresult receiveText(const char8 *text)
Receives a simple text message from the peer (max 255 characters).
tresult PLUGIN_API connect(IConnectionPoint *other) SMTG_OVERRIDE
Connects this instance with another connection point.
tresult sendMessage(IMessage *message) const
Sends the given message to the peer.
tresult sendMessageID(const char8 *messageID) const
Sends a message with a given ID without any other payload.
tresult PLUGIN_API disconnect(IConnectionPoint *other) SMTG_OVERRIDE
Disconnects a given connection point from this.
virtual tresult PLUGIN_API getString(AttrID id, TChar *string, uint32 sizeInBytes)=0
Gets string value (UTF16).
Connect a component with another one: Vst::IConnectionPoint.
Definition ivstmessage.h:73
virtual tresult PLUGIN_API notify(IMessage *message)=0
Called when a message has been sent from the connection point to this.
Private plug-in message: Vst::IMessage.
Definition ivstmessage.h:41
virtual IAttributeList *PLUGIN_API getAttributes()=0
Returns the attribute list associated to the message.
virtual FIDString PLUGIN_API getMessageID()=0
Returns the message ID (for example "TextMessage").
@ kCP_Utf8
UTF8 Encoding.
Definition fstring.h:72
char16 TChar
UTF-16 character.
Definition vsttypes.h:68
IMessage * allocateMessage(IHostApplication *host)
Helper to allocate a message.
IPtr< I > owned(I *p)
Assigning newly created object to an IPtr.