//////////////////////////////////////////////////////////////////////
// SMPTETimecode.h
//////////////////////////////////////////////////////////////////////
// Demonstration of SMPTE Timecode conversions
//
// Brooks Harris
// 2015-04-04
// http://www.edlmax.com/services.htm
//
// If this code works, I wrote it. If not, I've never heard of it.
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SMPTETIMECODE_H__20197ADB_CE61_4259_9170_56900BAD8B52__INCLUDED_)
#define AFX_SMPTETIMECODE_H__20197ADB_CE61_4259_9170_56900BAD8B52__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <stdio.h>
#include <stdlib.h> // for atol()
//#include <math.h> // for floor()

// frames to hh:mm:ss:ff algorithms will count above 23:59:59:xx to 24:00:00:00 etc.
// define this to rollover at last frame count before 24:00:00:00
#define USE_24HOUR_ROLLOVER

typedef enum SMPTETCBASERATE
{
SMPTETCBASERATE_NOT_SET = 0,
SMPTETCBASERATE_30FPS = 1, // NTSC
SMPTETCBASERATE_25FPS = 2, // PAL
SMPTETCBASERATE_24FPS = 3, // Film or 24p
} SMPTETCBASERATE;

typedef enum SMPTETCTYPE
{
SMPTETCTYPE_NOT_SET = 0,
SMPTETCTYPE_FIELD1_NON_DROP_FRAME = 1, // '.' period
SMPTETCTYPE_FIELD2_NON_DROP_FRAME = 2, // ':' colon
SMPTETCTYPE_FIELD1_DROP_FRAME = 3, // ',' comma
SMPTETCTYPE_FIELD2_DROP_FRAME = 4, // ';' semi colon
} SMPTETCTYPE;

// convert hh:mm:ss:ff to frames
int SMPTE_HMSF_To_Frames( long lHr,
long lMn,
long lSc,
long lFr,
SMPTETCBASERATE SMPTETCBASERATEx,
SMPTETCTYPE SMPTETCTYPEx,
long* plFramesResult);

// convert timecode character representation to frames
int SMPTE_TextTC_To_Frames( char* sTimecode,
SMPTETCBASERATE SMPTETCBASERATEx,
long* plFramesResult);

// convert frames to hh MM ss ff
int SMPTE_Frames_To_HMSF( long lFrames,
SMPTETCBASERATE SMPTETCBASERATEx,
SMPTETCTYPE SMPTETCTYPEx,
long* plHrResult,
long* plMnResult,
long* plScResult,
long* plFrResult);

// convert frames to timecode character representation
int SMPTE_Frames_To_TextTC( long lFrames,
SMPTETCBASERATE SMPTETCBASERATEx,
SMPTETCTYPE SMPTETCTYPEx,
char* sTimecodeResult);

#endif // !defined(AFX_SMPTETIMECODE_H__20197ADB_CE61_4259_9170_56900BAD8B52__INCLUDED_)