#include "ordeviceTimeCode_device.h"
#define ORDEVICETIMECODE__CLASS ORDEVICETIMECODE__CLASSNAME
#define ORDEVICETIMECODE__NAME ORDEVICETIMECODE__CLASSSTR
#define ORDEVICETIMECODE__LABEL "OR - TimeCode Device"
#define ORDEVICETIMECODE__DESC "OR - Time code sample"
#define ORDEVICETIMECODE__PREFIX "TimeCode"
ORDEVICETIMECODE__CLASS,
ORDEVICETIMECODE__LABEL,
ORDEVICETIMECODE__DESC,
"devices_ltc.png" );
bool ORDeviceTimeCode::FBCreate()
{
SamplingPeriod = FBTime(0,0,1)/24;
mReferenceTimeIndex = mRefTime.Add("OR-TimeCode");
return true;
}
void ORDeviceTimeCode::FBDestroy()
{
mRefTime.Remove(mReferenceTimeIndex);
}
bool ORDeviceTimeCode::DeviceOperation( kDeviceOperations pOperation )
{
switch (pOperation)
{
case kOpInit: return true;
case kOpStart: return Start();
case kOpStop: return Stop();
case kOpReset: return Reset();
case kOpDone: return false;
}
return FBDevice::DeviceOperation( pOperation );
}
bool ORDeviceTimeCode::Stop()
{
FBProgress lProgress;
lProgress.Caption = "Shutting down device";
lProgress.Text = "Closing device communication";
Information = "Closing device communication";
if(! mHardware.Close() )
{
Information = "Could not close device";
}
return false;
}
bool ORDeviceTimeCode::Start()
{
FBProgress Progress;
Progress.Caption = "Setting up device";
if(! mHardware.Open() )
{
Information = "Could not open device";
return false;
}
Progress.Text = "Device found, scanning for information...";
Information = "Retrieving information";
if(!mHardware.GetSetupInfo())
{
Information = "Could not get information from device.";
return false;
}
return true;
}
bool ORDeviceTimeCode::Reset()
{
Stop();
return Start();
}
bool ORDeviceTimeCode::AnimationNodeNotify(FBAnimationNode* pAnimationNode ,FBEvaluateInfo* pEvaluateInfo)
{
if(mTimeCodeAnimNode)
{
FBTimeCode tc = mHardware.GetData();
mTimeCodeAnimNode->WriteData( (double*)&tc, pEvaluateInfo );
}
return true;
}
void ORDeviceTimeCode::DeviceIONotify( kDeviceIOs pAction,FBDeviceNotifyInfo &pDeviceNotifyInfo)
{
FBTime lEvalTime;
switch (pAction)
{
case kIOPlayModeWrite:
case kIOStopModeWrite:
{
}
break;
case kIOStopModeRead:
case kIOPlayModeRead:
{
if(mHardware.ReadTimeCode(lEvalTime))
{
DeviceRecordFrame(lEvalTime,pDeviceNotifyInfo);
AckOneSampleReceived();
}
}
break;
}
}
void ORDeviceTimeCode::DeviceRecordFrame(FBTime &pTime,FBDeviceNotifyInfo &pDeviceNotifyInfo)
{
FBTimeCode tc = mHardware.GetData();
pTime = mSystem.LocalTime;
mRefTime.SetTime(mReferenceTimeIndex,tc.GetTime(),mSystem.SystemTime);
if (mTimeCodeAnimNode)
{
FBAnimationNode* Data = mTimeCodeAnimNode->GetAnimationToRecord();
if (Data)
{
{
Data->KeyAdd(pTime, (double*)&tc);
}
}
}
}
bool ORDeviceTimeCode::FbxStore(FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat)
{
{
}
return true;
}
bool ORDeviceTimeCode::FbxRetrieve(FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat)
{
{
}
return true;
}