-
Notifications
You must be signed in to change notification settings - Fork 0
/
MtcMaster_class.h
127 lines (109 loc) · 4 KB
/
MtcMaster_class.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// Stage Lab MTC Master Class header file
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#ifndef MTCMASTER_CLASS_H_INCLUDED
#define MTCMASTER_CLASS_H_INCLUDED
#include <vector>
#include <chrono>
#include <iostream>
#include <fstream>
#include <thread>
#include <sys/time.h>
#include <sys/resource.h>
#include <mutex>
#include <iomanip>
#include <cstring>
#include <pthread.h>
#include "rtmidi/RtMidi.h"
using namespace std;
enum MidiStatusCodes
{
MIDI_STATUS_UNKNOWN = 0x00,
// channel voice messages
MIDI_STATUS_NOTE_OFF = 0x80,
MIDI_STATUS_NOTE_ON = 0x90,
MIDI_STATUS_CONTROL_CHANGE = 0xB0,
MIDI_STATUS_PROGRAM_CHANGE = 0xC0,
MIDI_STATUS_PITCH_BEND = 0xE0,
MIDI_STATUS_AFTERTOUCH = 0xD0, // aka channel pressure
MIDI_STATUS_POLY_AFTERTOUCH = 0xA0, // aka key pressure
// system messages
MIDI_STATUS_SYSEX = 0xF0,
MIDI_STATUS_TIME_CODE = 0xF1,
MIDI_STATUS_SONG_POS_POINTER = 0xF2,
MIDI_STATUS_SONG_SELECT = 0xF3,
MIDI_STATUS_TUNE_REQUEST = 0xF6,
MIDI_STATUS_SYSEX_END = 0xF7,
MIDI_STATUS_TIME_CLOCK = 0xF8,
MIDI_STATUS_START = 0xFA,
MIDI_STATUS_CONTINUE = 0xFB,
MIDI_STATUS_STOP = 0xFC,
MIDI_STATUS_ACTIVE_SENSING = 0xFE,
MIDI_STATUS_SYSTEM_RESET = 0xFF
};
enum FrameRate
{
FR_24 = 24,
FR_25 = 25,
FR_29 = 29,
FR_30 = 30
}; // Frame rate constants
class MtcMaster : public RtMidiOut
{
//////////////////////////////////////////
public:
//////////////////////////////////////////
//////////////////////////////////////////
// Constructors and destructors
MtcMaster(RtMidi::Api api = LINUX_ALSA,
const string& clientName = "MtcMaster",
// const string& portName = "MTCPort",
FrameRate setUpFR = FR_25);
~MtcMaster(void);
//////////////////////////////////////////
//////////////////////////////////////////
// Member variables
vector<unsigned char> mtcTimeVector; // MTC Time char vector
static unsigned short instanceCount; // Static counter of number of instances of the class
//////////////////////////////////////////
// Member methods
void sendMtcPosition();
void play();
void pause();
void stop();
void setTime(uint64_t nanos);
uint64_t getTime(void);
void fillMtcTimeVector(uint64_t nanos);
string mtcTimeVectorString(void);
string getApiString(void);
inline bool getPlaying(void) { return playing; }
inline void setPlaying(bool status) { playing = status; }
inline FrameRate getFrameRate(void) { return currentFrameRate; }
inline void setFrameRate(FrameRate FR) { currentFrameRate = FR; }
inline uint64_t getMtcTime (void) { return mtcTime; };
void subtractNanos(const uint64_t diff);
void addNanos(const uint64_t diff);
//////////////////////////////////////////
private:
//////////////////////////////////////////
//////////////////////////////////////////
// Private variables
uint64_t mtcTime; // MTC time
FrameRate currentFrameRate; // Current Frame Rate
unsigned char currentFRBits; // Current Time code bits
static std::mutex mtx; // Mutex to lock the threaded function
static bool playing; // Flag to know if the object is playing
//////////////////////////////////////////
// Logging file
std::ofstream logFileStream;
void logTime(void);
//////////////////////////////////////////
// Private methods
void threadedMethod(void);
void setScheduling(std::thread &th, int policy, int priority);
};
#endif // MTCMASTER_CLASS_H_INCLUDED