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