Jamba C++ API  4.1.0
RTProcessor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 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/timer.h>
21 #include <public.sdk/source/vst/vstaudioeffect.h>
22 #include <pongasoft/VST/Timer.h>
23 #include "RTState.h"
24 
25 namespace pongasoft {
26 namespace VST {
27 namespace RT {
28 
29 using namespace Steinberg;
30 using namespace Steinberg::Vst;
31 
37 class RTProcessor : public AudioEffect, public IMessageProducer
38 {
39 public:
40  explicit RTProcessor(Steinberg::FUID const &iControllerUID);
41 
42  ~RTProcessor() override = default;
43 
47  virtual RTState *getRTState() = 0;
48 
50  tresult PLUGIN_API initialize(FUnknown *context) override;
51 
53  tresult PLUGIN_API setActive(TBool state) override;
54 
56  tresult PLUGIN_API process(ProcessData &data) override;
57 
59  tresult PLUGIN_API canProcessSampleSize(int32 symbolicSampleSize) override;
60 
62  tresult PLUGIN_API setState(IBStream *state) override;
63 
65  tresult PLUGIN_API getState(IBStream *state) override;
66 
68  tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE;
69 
70 protected:
73  virtual bool canProcess32Bits() const { return true; }
74 
77  virtual bool canProcess64Bits() const { return true; }
78 
83  virtual tresult processInputs(ProcessData &data);
84 
88  virtual tresult processInputs32Bits(ProcessData &data) { return kResultOk; }
89 
93  virtual tresult processInputs64Bits(ProcessData &data) { return kResultOk; }
94 
101  virtual void onGUITimer() {}
102 
107  void enableGUITimer(uint32 iUIFrameRateMs);
108 
111  virtual void sendPendingMessages() { getRTState()->sendPendingMessages(this); }
112 
113 protected:
114  // interval for gui message timer (can be changed by subclass BEFORE calling initialize)
116 
117 public:
118  // allocateMessage
119  IPtr<IMessage> allocateMessage() override;
120 
121  // sendMessage
122  tresult sendMessage(IPtr<IMessage> iMessage) override;
123 
124 private:
125  using RTProcessorCallback = void (RTProcessor::*)();
126 
127  // wrapper class to dispatch the callback
128  class GUITimerCallback : public ITimerCallback
129  {
130  public:
131  explicit GUITimerCallback(RTProcessor *iProcessor,
132  RTProcessorCallback iCallback) : fProcessor{iProcessor}, fCallback{iCallback} {}
133 
134  void onTimer(Timer *timer) override
135  {
136  (fProcessor->*fCallback)();
137  }
138  private:
141  };
142 
143 
144 
145 private:
146  // the generic gui timer (enabled with enableGUITimer)
147  GUITimerCallback fGUITimerCallback{this, &RTProcessor::onGUITimer};
149  std::unique_ptr<AutoReleaseTimer> fGUITimer;
150 
151  // the timer that will handle sending messages (enabled when there are messages to handle)
152  GUITimerCallback fGUIMessageTimerCallback{this, &RTProcessor::sendPendingMessages};
153  std::unique_ptr<AutoReleaseTimer> fGUIMessageTimer;
154 
155  bool fActive;
156 
157 #ifdef JAMBA_DEBUG_LOGGING
158  int32 fSymbolicSampleSize = -1;
159 #endif
160 };
161 
162 }
163 }
164 }
std::unique_ptr< AutoReleaseTimer > fGUIMessageTimer
Definition: RTProcessor.h:153
void(RTProcessor::*)() RTProcessorCallback
Definition: RTProcessor.h:125
void onTimer(Timer *timer) override
Definition: RTProcessor.h:134
Abstraction for allocating and sending a message.
Definition: MessageProducer.h:33
virtual tresult processInputs32Bits(ProcessData &data)
Processes inputs (step 2 always called after processing the parameters) for 32 bits.
Definition: RTProcessor.h:88
Base class from which the actual processor inherits from.
Definition: RTProcessor.h:37
virtual bool canProcess32Bits() const
Definition: RTProcessor.h:73
uint32 fGUITimerIntervalMs
Definition: RTProcessor.h:148
Definition: Clock.h:22
bool fActive
Definition: RTProcessor.h:155
Manages the state used by the processor: you add all the parameters that the state manages using the ...
Definition: RTState.h:43
virtual void onGUITimer()
Subclass will implement this method to respond to the GUI timer firing /////// WARNING !...
Definition: RTProcessor.h:101
std::unique_ptr< AutoReleaseTimer > fGUITimer
Definition: RTProcessor.h:149
RTProcessorCallback fCallback
Definition: RTProcessor.h:140
virtual tresult processInputs64Bits(ProcessData &data)
Processes inputs (step 2 always called after processing the parameters) for 64 bits.
Definition: RTProcessor.h:93
RTProcessor * fProcessor
Definition: RTProcessor.h:139
virtual void sendPendingMessages()
Called (from a GUI timer) to send the messages to the GUI (JmbParam for the moment)
Definition: RTProcessor.h:111
uint32 fGUIMessageTimerIntervalMs
Definition: RTProcessor.h:115
virtual bool canProcess64Bits() const
Definition: RTProcessor.h:77
GUITimerCallback(RTProcessor *iProcessor, RTProcessorCallback iCallback)
Definition: RTProcessor.h:131