Jamba C++ API  5.0.0
FObjectCx.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
20 #include <base/source/fobject.h>
21 #include <pluginterfaces/vst/vsttypes.h>
23 
24 namespace pongasoft {
25 namespace VST {
26 
27 using namespace Steinberg::Vst;
28 using namespace Steinberg;
29 
35 class FObjectCx : protected FObject
36 {
37 public:
38  // Constructor
39  explicit FObjectCx(FObject *iTarget);
40 
44  virtual void close();
45 
49  virtual void onTargetChange() {};
50 
53  inline ~FObjectCx() override { close(); }
54 
55  // disabling copy
56  FObjectCx(FObjectCx const &) = delete;
57  FObjectCx& operator=(FObjectCx const &) = delete;
58 
59 protected:
63  void PLUGIN_API update(FUnknown *iChangedUnknown, Steinberg::int32 iMessage) SMTG_OVERRIDE;
64 
65 protected:
66  FObject *fTarget;
68 };
69 
74 {
75 public:
76  using ChangeCallback = std::function<void()>;
77 
78  // Constructor
79  FObjectCxCallback(FObject *iTarget, ChangeCallback iChangeCallback);
80 
81  // close
82  void close() override;
83 
84  // onTargetChange
85  void onTargetChange() override;
86 
87  // disabling copy
88  FObjectCxCallback(FObjectCxCallback const &) = delete;
89  FObjectCxCallback& operator=(FObjectCxCallback const &) = delete;
90 
91 protected:
93 };
94 
95 }
96 }
virtual void onTargetChange()
Called when the target changes (by default does nothing)
Definition: FObjectCx.h:49
~FObjectCx() override
Automatically closes the connection and stops listening.
Definition: FObjectCx.h:53
Definition: Clock.h:22
Wrapper class which maintains a connection between the target and this object.
Definition: FObjectCx.h:35
bool fIsConnected
Definition: FObjectCx.h:67
FObject * fTarget
Definition: FObjectCx.h:66
ChangeCallback fChangeCallback
Definition: FObjectCx.h:92
std::function< void()> ChangeCallback
Definition: FObjectCx.h:76
Wrapper class which will invoke the callback when the target is changed.
Definition: FObjectCx.h:73