CFugue
MidiTimer.h
1 /*
2  This is part of CFugue, a C++ Runtime for MIDI Score Programming
3  Copyright (C) 2009 Gopalakrishna Palem
4 
5  For links to further information, or to contact the author,
6  see <http://cfugue.sourceforge.net/>.
7 
8  $LastChangedDate: 2014-05-10 10:56:34 +0530 (Sat, 10 May 2014) $
9  $Rev: 203 $
10  $LastChangedBy: krishnapg $
11 */
12 
13 #ifndef _MIDI_TIMER_H__D2A4A592_DAE0_46DC_ADA6_6191407F567E__
14 #define _MIDI_TIMER_H__D2A4A592_DAE0_46DC_ADA6_6191407F567E__
15 
16 #include <chrono>
17 #include <thread>
18 namespace CFugue
19 {
20  ///<Summary>Plays the role of a pseudo MIDI Timer for MIDI Sequencer</Summary>
21  class MidiTimer
22  {
23  public:
24  typedef std::chrono::steady_clock::time_point TimePoint;
25  typedef std::chrono::milliseconds Duration;
26 
27  ///<Summary>
28  /// Returns current time point for MIDI Sequencing.
29  /// It is usually measure as the time elapsed since epoch.
30  /// Taking the difference of two consequent calls of this gives the elapsed time for MIDI.
31  /// @return psuedo time tick offset that is suitable for MIDI sequencer
32  ///</Summary>
33  static TimePoint Now()
34  {
35  return std::chrono::steady_clock::now();
36  }
37 
38  ///<Summary>
39  /// Causes the calling thread to sleep
40  /// @param ms sleep duration (in milli-seconds)
41  ///</Summary>
42  static void Sleep(unsigned long ms)
43  {
44  std::this_thread::sleep_for(Duration(ms));
45  }
46  };
47 
48 } // namespace CFugue
49 
50 #endif // _MIDI_TIMER_H__D2A4A592_DAE0_46DC_ADA6_6191407F567E__
std::chrono::milliseconds Duration
Definition: MidiTimer.h:25
static TimePoint Now()
Definition: MidiTimer.h:33
Plays the role of a pseudo MIDI Timer for MIDI Sequencer
Definition: MidiTimer.h:21

CFugue, the C++ Music Programming Library © Copyright 2009 Cenacle Research India Private Limited Gopalakrishna Palem