1 //-----------------------------------------------------------------------------
2 // Project     : VST SDK
3 //
4 // Category    : Examples
5 // Filename    : public.sdk/samples/vst/adelay/source/adelaycontroller.cpp
6 // Created by  : Steinberg, 06/2009
7 // Description :
8 //
9 //-----------------------------------------------------------------------------
10 // LICENSE
11 // (c) 2020, 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 "adelaycontroller.h"
38 #include "adelayids.h"
39 #include "pluginterfaces/base/ustring.h"
40 #include "pluginterfaces/base/ibstream.h"
41 
42 #if TARGET_OS_IPHONE
43 #include "interappaudio/iosEditor.h"
44 #endif
45 #include "base/source/fstreamer.h"
46 
47 namespace Steinberg {
48 namespace Vst {
49 
DEF_CLASS_IID(IDelayTestController)50 DEF_CLASS_IID (IDelayTestController)
51 
52 //-----------------------------------------------------------------------------
53 tresult PLUGIN_API ADelayController::initialize (FUnknown* context)
54 {
55 	tresult result = EditController::initialize (context);
56 	if (result == kResultTrue)
57 	{
58 		parameters.addParameter (STR16 ("Bypass"), nullptr, 1, 0, ParameterInfo::kCanAutomate|ParameterInfo::kIsBypass, kBypassId);
59 
60 		parameters.addParameter (STR16 ("Delay"), STR16 ("sec"), 0, 1, ParameterInfo::kCanAutomate, kDelayId);
61 	}
62 	return kResultTrue;
63 }
64 
65 #if TARGET_OS_IPHONE
66 //-----------------------------------------------------------------------------
createView(FIDString name)67 IPlugView* PLUGIN_API ADelayController::createView (FIDString name)
68 {
69 	if (FIDStringsEqual (name, ViewType::kEditor))
70 	{
71 		return new ADelayEditorForIOS (this);
72 	}
73 	return 0;
74 }
75 #endif
76 
77 //------------------------------------------------------------------------
setComponentState(IBStream * state)78 tresult PLUGIN_API ADelayController::setComponentState (IBStream* state)
79 {
80 	// we receive the current state of the component (processor part)
81 	// we read only the gain and bypass value...
82 	if (!state)
83 		return kResultFalse;
84 
85 	IBStreamer streamer (state, kLittleEndian);
86 	float savedDelay = 0.f;
87 	if (streamer.readFloat (savedDelay) == false)
88 		return kResultFalse;
89 	setParamNormalized (kDelayId, savedDelay);
90 
91 	int32 bypassState = 0;
92 	if (streamer.readInt32 (bypassState) == false)
93 	{
94 		// could be an old version, continue
95 	}
96 	setParamNormalized (kBypassId, bypassState ? 1 : 0);
97 
98 	return kResultOk;
99 }
100 
101 //------------------------------------------------------------------------
doTest()102 bool PLUGIN_API ADelayController::doTest ()
103 {
104 	// this is called when running thru the validator
105 	// we can now run our own test cases
106 	return true;
107 }
108 
109 //------------------------------------------------------------------------
110 } // namespace Vst
111 } // namespace Steinberg
112