NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
tick.h
Go to the documentation of this file.
1/*
2 * NiCMidi - A C++ Class Library for MIDI
3 *
4 * Copyright (C) 2004 J.D. Koftinoff Software, Ltd.
5 * www.jdkoftinoff.com jeffk@jdkoftinoff.com
6 * Copyright (C) 2021, 2022 Nicola Cassetta
7 * https://github.com/ncassetta/NiCMidi
8 *
9 * This file is part of NiCMidi.
10 *
11 * NiCMidi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as
13 * published by the Free Software Foundation, either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * NiCMidi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with NiCMidi. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25
28
29
30#ifndef _NICMIDI_TICK_H
31#define _NICMIDI_TICK_H
32
33#include <atomic>
34#include <mutex>
35#include "timer.h"
36
39
44typedef enum {
49 PR_LAST
53
54
66 public:
73
79
80
82 virtual void Reset() = 0;
83
86 MIDITick* GetFunc() const { return tick_proc; }
88 tPriority GetPriority() const { return priority; }
92 bool IsPlaying() const { return running.load(); }
95 void SetDevOffset(tMsecs dev_offs);
101 virtual void Start();
104 virtual void Stop();
105
106
107 protected:
116 static void StaticTickProc(tMsecs sys_time, void* pt) {}
119 virtual void TickProc(tMsecs sys_time) = 0;
120
123
130 std::recursive_mutex proc_lock;
131
132 private:
133 const tPriority priority;
134 std::atomic<bool> running;
135};
136
137#endif // TICK_H_INCLUDED
A pure virtual class implementing an object which has a callback procedure to be called at every tick...
Definition: tick.h:65
std::recursive_mutex proc_lock
A mutex you can use for implementing thread safe methods.
Definition: tick.h:130
MIDITick * GetFunc() const
Returns the address of the StaticTickProc() method, which will be called by the MIDIManager at every ...
Definition: tick.h:86
virtual void Reset()=0
A pure virtual method which should reinitialize the class parameters.
tPriority GetPriority() const
Returns the priority.
Definition: tick.h:88
tMsecs sys_time_offset
The system time of the last call of Start().
Definition: tick.h:128
static void StaticTickProc(tMsecs sys_time, void *pt)
This is the static callback procedure which the MIDIManager will call at every MIDITimer tick.
Definition: tick.h:116
void SetDevOffset(tMsecs dev_offs)
Sets an user defined time offset, which will be added to every time calculation.
virtual void Start()
Sets the running status as true and starts to call the callback.
virtual void TickProc(tMsecs sys_time)=0
This is the pure virtual function you must implement in your subclass.
tMsecs GetDevOffset() const
Returns the user time offset parameter (see SetDevOffset()).
Definition: tick.h:90
bool IsPlaying() const
Returns true if the callback procedure is active.
Definition: tick.h:92
tMsecs dev_time_offset
A time offset set by the user and which you can use for your calculations.
Definition: tick.h:125
const MIDITick * tick_proc
The pointer to the static callback (set by the constructor to StaticTickProc()).
Definition: tick.h:122
virtual ~MIDITickComponent()
The destructor.
virtual void Stop()
Sets the running status as false and stops the callback.
MIDITickComponent(tPriority pr, MIDITick func)
The constructor.
tPriority
Definition: tick.h:44
unsigned long long tMsecs
The type of a variable which can hold the elapsed time in milliseconds.
Definition: timer.h:44
void() MIDITick(tMsecs, void *)
This is the typedef of the callback functions which are called at every timer tick.
Definition: timer.h:47
@ PR_FIRST
The component is inserted as first element in the queue.
Definition: tick.h:45
@ PR_POST_SEQ
The component is inserted after the sequencer.
Definition: tick.h:48
@ PR_LAST
The component is inserted as last element in the queue.
Definition: tick.h:49
@ PR_PRE_SEQ
The component is inserted before the sequencer.
Definition: tick.h:46
@ PR_SEQ
The component is the sequencer (you can insert only one in the queue)
Definition: tick.h:47
Contains the definition of the MIDITimer class and some other typedef related to MIDI timing.