1 //-----------------------------------------------------------------------------
2 // Flags       : clang-format on
3 // Project     : VST SDK
4 //
5 // Category    : Examples
6 // Filename    : public.sdk/samples/vst/hostchecker/source/hostchecker.h
7 // Created by  : Steinberg, 04/2012
8 // Description :
9 //
10 //-----------------------------------------------------------------------------
11 // LICENSE
12 // (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved
13 //-----------------------------------------------------------------------------
14 // Redistribution and use in source and binary forms, with or without modification,
15 // are permitted provided that the following conditions are met:
16 //
17 //   * Redistributions of source code must retain the above copyright notice,
18 //     this list of conditions and the following disclaimer.
19 //   * Redistributions in binary form must reproduce the above copyright notice,
20 //     this list of conditions and the following disclaimer in the documentation
21 //     and/or other materials provided with the distribution.
22 //   * Neither the name of the Steinberg Media Technologies nor the names of its
23 //     contributors may be used to endorse or promote products derived from this
24 //     software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 // OF THE POSSIBILITY OF SUCH DAMAGE.
36 //-----------------------------------------------------------------------------
37 
38 #pragma once
39 
40 #include "eventlogdatabrowsersource.h"
41 #include "public.sdk/source/vst/vstaudioeffect.h"
42 #include "public.sdk/source/vst/vsteditcontroller.h"
43 
44 #include "hostcheck.h"
45 #include "logevents.h"
46 #include "vstgui/plugin-bindings/vst3editor.h"
47 #include "base/source/fstring.h"
48 #include "pluginterfaces/vst/ivstchannelcontextinfo.h"
49 #include "pluginterfaces/vst/ivstmidilearn.h"
50 #include "pluginterfaces/vst/ivstnoteexpression.h"
51 #include "pluginterfaces/vst/ivstphysicalui.h"
52 #include "pluginterfaces/vst/ivstprefetchablesupport.h"
53 #include "pluginterfaces/vst/ivstrepresentation.h"
54 
55 namespace Steinberg {
56 namespace Vst {
57 
58 enum
59 {
60 	// for Parameters
61 	kParam1Tag = 1000,
62 	kGeneratePeaksTag,
63 	kLatencyTag,
64 	kBypassTag,
65 	kCanResizeTag,
66 	kScoreTag,
67 
68 	// for Units
69 	kUnitId = 1234
70 };
71 
72 class EditorSizeController;
73 
74 //-----------------------------------------------------------------------------
75 class HostCheckerController : public EditControllerEx1,
76                               public VSTGUI::VST3EditorDelegate,
77                               public ChannelContext::IInfoListener,
78                               public IXmlRepresentationController,
79                               public IMidiMapping,
80                               public IMidiLearn,
81                               public INoteExpressionController,
82                               public INoteExpressionPhysicalUIMapping
83 {
84 public:
85 	using UTF8StringPtr = VSTGUI::UTF8StringPtr;
86 	using IController = VSTGUI::IController;
87 	using IUIDescription = VSTGUI::IUIDescription;
88 	using VST3Editor = VSTGUI::VST3Editor;
89 
90 	tresult PLUGIN_API initialize (FUnknown* context) SMTG_OVERRIDE;
91 	tresult PLUGIN_API terminate () SMTG_OVERRIDE;
92 
93 	tresult PLUGIN_API setComponentState (IBStream* state) SMTG_OVERRIDE;
94 	tresult PLUGIN_API getUnitByBus (MediaType type, BusDirection dir, int32 busIndex,
95 	                                 int32 channel, UnitID& unitId /*out*/) SMTG_OVERRIDE;
96 	tresult PLUGIN_API setComponentHandler (IComponentHandler* handler) SMTG_OVERRIDE;
97 	int32 PLUGIN_API getUnitCount () SMTG_OVERRIDE;
98 	tresult PLUGIN_API setParamNormalized (ParamID tag, ParamValue value) SMTG_OVERRIDE;
99 
100 	tresult beginEdit (ParamID tag) SMTG_OVERRIDE;
101 	tresult endEdit (ParamID tag) SMTG_OVERRIDE;
102 
103 	IPlugView* PLUGIN_API createView (FIDString name) SMTG_OVERRIDE;
104 	tresult PLUGIN_API notify (IMessage* message) SMTG_OVERRIDE;
105 	tresult PLUGIN_API connect (IConnectionPoint* other) SMTG_OVERRIDE;
106 
107 	VSTGUI::CView* createCustomView (VSTGUI::UTF8StringPtr name,
108 	                                 const VSTGUI::UIAttributes& attributes,
109 	                                 const VSTGUI::IUIDescription* description,
110 	                                 VSTGUI::VST3Editor* editor) SMTG_OVERRIDE;
111 
112 	//---from IEditController2-------
113 	tresult PLUGIN_API setKnobMode (KnobMode mode) SMTG_OVERRIDE;
114 	tresult PLUGIN_API openHelp (TBool /*onlyCheck*/) SMTG_OVERRIDE;
115 	tresult PLUGIN_API openAboutBox (TBool /*onlyCheck*/) SMTG_OVERRIDE;
116 
117 	tresult PLUGIN_API setState (IBStream* state) SMTG_OVERRIDE;
118 	tresult PLUGIN_API getState (IBStream* state) SMTG_OVERRIDE;
119 
120 	//---ChannelContext::IInfoListener-------
121 	tresult PLUGIN_API setChannelContextInfos (IAttributeList* list) SMTG_OVERRIDE;
122 
123 	//---IXmlRepresentationController--------
124 	tresult PLUGIN_API getXmlRepresentationStream (RepresentationInfo& info /*in*/,
125 	                                               IBStream* stream /*out*/) SMTG_OVERRIDE;
126 
127 	//---IMidiMapping---------------------------
128 	tresult PLUGIN_API getMidiControllerAssignment (int32 busIndex, int16 channel,
129 	                                                CtrlNumber midiControllerNumber,
130 	                                                ParamID& id /*out*/) SMTG_OVERRIDE;
131 
132 	//---IMidiLearn-----------------------------
133 	tresult PLUGIN_API onLiveMIDIControllerInput (int32 busIndex, int16 channel,
134 	                                           CtrlNumber midiCC) SMTG_OVERRIDE;
135 
136 	//---INoteExpressionController----------------------
137 	int32 PLUGIN_API getNoteExpressionCount (int32 busIndex, int16 channel) SMTG_OVERRIDE;
138 	tresult PLUGIN_API getNoteExpressionInfo (int32 busIndex, int16 channel,
139 	                                          int32 noteExpressionIndex,
140 	                                          NoteExpressionTypeInfo& info /*out*/) SMTG_OVERRIDE;
141 	tresult PLUGIN_API getNoteExpressionStringByValue (int32 busIndex, int16 channel,
142 	                                                   NoteExpressionTypeID id,
143 	                                                   NoteExpressionValue valueNormalized /*in*/,
144 	                                                   String128 string /*out*/) SMTG_OVERRIDE;
145 	tresult PLUGIN_API getNoteExpressionValueByString (
146 	    int32 busIndex, int16 channel, NoteExpressionTypeID id, const TChar* string /*in*/,
147 	    NoteExpressionValue& valueNormalized /*out*/) SMTG_OVERRIDE;
148 
149 	//---INoteExpressionPhysicalUIMapping----------------------
150 	tresult PLUGIN_API getPhysicalUIMapping (int32 busIndex, int16 channel,
151 	                                         PhysicalUIMapList& list) SMTG_OVERRIDE;
152 
153 	//--- --------------------------------------------------------------------------
154 	void editorAttached (EditorView* editor) SMTG_OVERRIDE;
155 	void editorRemoved (EditorView* editor) SMTG_OVERRIDE;
156 	void editorDestroyed (EditorView* editor) SMTG_OVERRIDE;
157 
158 	IController* createSubController (UTF8StringPtr name, const IUIDescription* description,
159 	                                  VST3Editor* editor) override;
160 
161 	tresult PLUGIN_API queryInterface (const Steinberg::TUID iid, void** obj) override;
162 
REFCOUNT_METHODS(EditControllerEx1)163 	REFCOUNT_METHODS (EditControllerEx1)
164 
165 	static FUnknown* createInstance (void*)
166 	{
167 		return (IEditController*)new HostCheckerController ();
168 	}
169 	static FUID cid;
170 
171 	void addFeatureLog (int32 iD);
getSavedSize(ViewRect & size)172 	bool getSavedSize (ViewRect& size)
173 	{
174 		if (sizeFactor <= 0)
175 			return false;
176 		ViewRect rect (0, 0, width, height);
177 		size = rect;
178 		return true;
179 	}
180 
181 protected:
182 	void extractCurrentInfo (EditorView* editor);
183 
184 	VSTGUI::SharedPointer<VSTGUI::CDataBrowser> mDataBrowser;
185 	VSTGUI::SharedPointer<VSTGUI::EventLogDataBrowserSource> mDataSource;
186 
187 	bool mLatencyInEdit = false;
188 	ParamValue mWantedLatency = 0.0;
189 
190 	using EditorVector = std::vector<Steinberg::Vst::EditorView*>;
191 	EditorVector editors;
192 
193 	using EditorMap = std::map<Steinberg::Vst::EditorView*, EditorSizeController*>;
194 	EditorMap editorsSubCtlerMap;
195 
196 	uint32 width = 0;
197 	uint32 height = 0;
198 	double sizeFactor = 0;
199 };
200 
201 //------------------------------------------------------------------------
202 } // namespace Vst
203 } // namespace Steinberg
204