Jamba C++ API 8.0.0
Loading...
Searching...
No Matches
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 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19#pragma once
20
21#include <base/source/timer.h>
22#include <public.sdk/source/vst/vstaudioeffect.h>
23#include <pongasoft/VST/Timer.h>
24#include <chrono>
25#include "RTState.h"
26
27namespace pongasoft::VST::RT {
28
29using namespace Steinberg;
30using namespace Steinberg::Vst;
31
37class RTProcessor : public AudioEffect, public IMessageProducer
38{
39public:
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
70protected:
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
113 template<typename Rep, typename Period>
114 void enableGUITimer(std::chrono::duration<Rep, Period> iUIFrameRate)
115 {
116 enableGUITimer(std::chrono::duration_cast<std::chrono::milliseconds>(iUIFrameRate).count());
117 }
118
122
123protected:
124 // interval for gui message timer (can be changed by subclass BEFORE calling `initialize`)
126
127public:
128 // allocateMessage
129 IPtr<IMessage> allocateMessage() override;
130
131 // sendMessage
132 tresult sendMessage(IPtr<IMessage> iMessage) override;
133
134private:
135 using RTProcessorCallback = void (RTProcessor::*)();
136
137 // wrapper class to dispatch the callback
138 class GUITimerCallback : public ITimerCallback
139 {
140 public:
141 explicit GUITimerCallback(RTProcessor *iProcessor,
142 RTProcessorCallback iCallback) : fProcessor{iProcessor}, fCallback{iCallback} {}
143
144 void onTimer(Timer *timer) override
145 {
146 (fProcessor->*fCallback)();
147 }
148 private:
151 };
152
153
154
155private:
156 // the generic gui timer (enabled with enableGUITimer)
159 std::unique_ptr<AutoReleaseTimer> fGUITimer;
160
161 // the timer that will handle sending messages (enabled when there are messages to handle)
163 std::unique_ptr<AutoReleaseTimer> fGUIMessageTimer;
164
166
167#ifdef JAMBA_DEBUG_LOGGING
168 int32 fSymbolicSampleSize = -1;
169#endif
170};
171
172}
Abstraction for allocating and sending a message.
Definition MessageProducer.h:34
void onTimer(Timer *timer) override
Definition RTProcessor.h:144
RTProcessor * fProcessor
Definition RTProcessor.h:149
GUITimerCallback(RTProcessor *iProcessor, RTProcessorCallback iCallback)
Definition RTProcessor.h:141
RTProcessorCallback fCallback
Definition RTProcessor.h:150
tresult PLUGIN_API setState(IBStream *state) override
Restore the state (ex: after loading preset or project).
Definition RTProcessor.cpp:165
tresult PLUGIN_API process(ProcessData &data) override
Here we go...the process call.
Definition RTProcessor.cpp:85
GUITimerCallback fGUIMessageTimerCallback
Definition RTProcessor.h:162
tresult PLUGIN_API initialize(FUnknown *context) override
Called at first after constructor (setup input/output).
Definition RTProcessor.cpp:189
virtual void sendPendingMessages()
Called (from a GUI timer) to send the messages to the GUI (JmbParam for the moment).
Definition RTProcessor.h:121
std::unique_ptr< AutoReleaseTimer > fGUITimer
Definition RTProcessor.h:159
bool fActive
Definition RTProcessor.h:165
tresult PLUGIN_API getState(IBStream *state) override
Called to save the state (before saving a preset or project).
Definition RTProcessor.cpp:177
std::unique_ptr< AutoReleaseTimer > fGUIMessageTimer
Definition RTProcessor.h:163
virtual RTState * getRTState()=0
Subclasses must implement this method to return the state.
virtual void onGUITimer()
Subclass will implement this method to respond to the GUI timer firing /////// WARNING !
Definition RTProcessor.h:101
tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE
Called to handle a message (coming from GUI).
Definition RTProcessor.cpp:72
uint32 fGUITimerIntervalMs
Definition RTProcessor.h:158
tresult PLUGIN_API setActive(TBool state) override
Switch the Plug-in on/off.
Definition RTProcessor.cpp:40
tresult PLUGIN_API canProcessSampleSize(int32 symbolicSampleSize) override
Asks if a given sample size is supported see SymbolicSampleSizes.
Definition RTProcessor.cpp:142
RTProcessor(Steinberg::FUID const &iControllerUID)
Definition RTProcessor.cpp:26
void enableGUITimer(std::chrono::duration< Rep, Period > iUIFrameRate)
Call this method to enable the GUI timer (onGUITimer will be called at the specified frequency) Shoul...
Definition RTProcessor.h:114
virtual tresult processInputs32Bits(ProcessData &data)
Processes inputs (step 2 always called after processing the parameters) for 32 bits.
Definition RTProcessor.h:88
virtual bool canProcess32Bits() const
Definition RTProcessor.h:73
virtual bool canProcess64Bits() const
Definition RTProcessor.h:77
virtual tresult processInputs(ProcessData &data)
Processes inputs (step 2 always called after processing the parameters) Delegate to processInputs32Bi...
Definition RTProcessor.cpp:110
void(RTProcessor::*)() RTProcessorCallback
Definition RTProcessor.h:135
~RTProcessor() override=default
IPtr< IMessage > allocateMessage() override
Allocates a message instance.
Definition RTProcessor.cpp:202
GUITimerCallback fGUITimerCallback
Definition RTProcessor.h:157
void enableGUITimer(uint32 iUIFrameRateMs)
Call this method to enable the GUI timer (onGUITimer will be called at the specified frequency) Shoul...
Definition RTProcessor.cpp:157
virtual tresult processInputs64Bits(ProcessData &data)
Processes inputs (step 2 always called after processing the parameters) for 64 bits.
Definition RTProcessor.h:93
uint32 fGUIMessageTimerIntervalMs
Definition RTProcessor.h:125
tresult sendMessage(IPtr< IMessage > iMessage) override
Sends the given message to the peer.
Definition RTProcessor.cpp:210
Manages the state used by the processor: you add all the parameters that the state manages using the ...
Definition RTState.h:45
virtual tresult sendPendingMessages(IMessageProducer *iMessageProducer)
Called (from a GUI timer) to send the messages to the GUI (JmbParam for the moment).
Definition RTState.cpp:334
Definition RTJmbInParameter.h:26