-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidiTimecode.h
More file actions
58 lines (43 loc) · 1.71 KB
/
MidiTimecode.h
File metadata and controls
58 lines (43 loc) · 1.71 KB
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
#ifndef MIDITIMECODE_H
#define MIDITIMECODE_H
#include <Arduino.h>
#define BUFFER_SIZE 12 //Must be at least 12 for quarter frame & SysEx messages, at least 2 for just QF messages
class MidiTimecode
//Class to parse MIDI timecode from incoming MIDI data. Uses buffer of MIDI bytes and parse both quarter frame and SysEx MTC messages
{
private:
//These variables store the current TC values
int mHour = 0;
int mMinute = 0;
int mSecond = 0;
int mFrame = 0;
int mFramerate = 0;
//Least sig. nibbles are stored as TC values are only updated on receipt of MSnibble, as MTC QF messages are little-endian
int mHourLSNibble;
int mMinuteLSNibble;
int mSecondLSNibble;
int mFrameLSNibble;
int mFramerateLSNibble;
//Current write point in buffer.
int mWritePoint = 0;
//Circular buffer of MIDI bytes, written to by writeByte().
byte mMIDIBuffer[BUFFER_SIZE];
//Processes quarter frame message after the TC number and value are parsed.
//Stores the LSnibble of each value, calculates TC value when MSnibble is received
void processQuarterFrame(int timecodeNumber, int timecodeValue);
//Checks for an MTC SysEx message, parsing the MTC values if message found.
void checkSysExTimecode();
protected:
//Returns byte value in MIDI buffer n number of bytes behind the write point
byte readByte(int n);
public:
//Writes a single MIDI byte into the buffer
//MTC messages are checked for during this function and values updated appropriately.
void writeByte(byte midiByte);
//Accessor functions
int getHours(){return mHour;};
int getMinutes(){return mMinute;};
int getSeconds(){return mSecond;};
int getFrames(){return mFrame;};
};
#endif