Jamba C++ API  5.0.0
Timer.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 
19 #pragma once
20 
21 #include <base/source/timer.h>
22 #include <memory>
23 
24 namespace pongasoft::VST {
25 
30 {
31 public:
32  // Constructor
33  explicit AutoReleaseTimer(Steinberg::Timer *iTimer) : fTimer{iTimer} {}
34 
35  // Destructor => auto release
37  {
38  stop();
39 
40  if(fTimer)
41  fTimer->release();
42  }
43 
44  // stops the timer
45  inline void stop()
46  {
47  if(fTimer)
48  fTimer->stop();
49  }
50 
54  static std::unique_ptr<AutoReleaseTimer> create(Steinberg::ITimerCallback* iCallback,
55  Steinberg::uint32 iIntervalMilliseconds)
56  {
57  return std::make_unique<AutoReleaseTimer>(Steinberg::Timer::create(iCallback, iIntervalMilliseconds));
58  }
59 
60  // disabling copy
61  AutoReleaseTimer(AutoReleaseTimer const &) = delete;
62  AutoReleaseTimer& operator=(AutoReleaseTimer const &) = delete;
63 
64 private:
65  Steinberg::Timer *fTimer;
66 };
67 
68 }
Simple wrapper class around Steinberg::Timer which will automatically release the timer on delete.
Definition: Timer.h:29
~AutoReleaseTimer()
Definition: Timer.h:36
void stop()
Definition: Timer.h:45
static std::unique_ptr< AutoReleaseTimer > create(Steinberg::ITimerCallback *iCallback, Steinberg::uint32 iIntervalMilliseconds)
Creates and return an auto release timer.
Definition: Timer.h:54
Definition: Clock.h:23
AutoReleaseTimer(Steinberg::Timer *iTimer)
Definition: Timer.h:33
AutoReleaseTimer & operator=(AutoReleaseTimer const &)=delete
Steinberg::Timer * fTimer
Definition: Timer.h:65