devices/devicereclist/ordevicereclist_device.cxx

devices/devicereclist/ordevicereclist_device.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "ordevicereclist_device.h"
//--- Registration defines
#define ORDEVICERECORDLIST__CLASS ORDEVICERECORDLIST__CLASSNAME
#define ORDEVICERECORDLIST__NAME ORDEVICERECORDLIST__CLASSSTR
#define ORDEVICERECORDLIST__LABEL "OR - Recording List"
#define ORDEVICERECORDLIST__DESC "OR - Recording List Description"
//--- FiLMBOX implementation and registration
FBDeviceImplementation ( ORDEVICERECORDLIST__CLASS );
FBRegisterDevice ( ORDEVICERECORDLIST__NAME,
ORDEVICERECORDLIST__CLASS,
ORDEVICERECORDLIST__LABEL,
ORDEVICERECORDLIST__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORDeviceRecordList::FBCreate()
{
mStandby = false;
mRecFlag = false;
mIsPlaying = false;
mCurrentTakeIndex = -1;
mSystem.OnUIIdle.Add( this,(FBCallback)&ORDeviceRecordList::OnUIIdleEvent );
return true;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORDeviceRecordList::FBDestroy()
{
mSystem.OnUIIdle.Remove( this,(FBCallback)&ORDeviceRecordList::OnUIIdleEvent );
ClearList();
}
/************************************************
* Get the start time.
************************************************/
FBTime FBPlayListEntry::GetStartTime()
{
FBTime lStart, lHin;
lHin.SetTime(0,0,mPreroll,0); // Pre-roll in seconds
lStart.SetMilliSeconds(mInTime.GetMilliSeconds() - lHin.GetMilliSeconds());
return lStart;
}
/************************************************
* Get the stop time.
************************************************/
FBTime FBPlayListEntry::GetStopTime()
{
FBTime lStop, lHout;
lHout.SetTime(0,0,mPostroll,0); // Post-roll in seconds
lStop.SetMilliSeconds( mOutTime.GetMilliSeconds() + lHout.GetMilliSeconds());
return lStop;
}
/************************************************
* I/O Function and initialisation
************************************************/
bool ORDeviceRecordList::DeviceOperation( kDeviceOperations pOperation )
{
switch (pOperation)
{
case kOpInit: return true;
case kOpStart: return true;
case kOpStop: return false;
case kOpReset: return true;
case kOpDone: return false;
}
return true;
}
/************************************************
* Real-Time Synchronous Device IO.
************************************************/
void ORDeviceRecordList::DeviceIONotify( kDeviceIOs pAction,FBDeviceNotifyInfo &pDeviceNotifyInfo)
{
switch (pAction)
{
case kIOPlayModeWrite:
case kIOStopModeWrite:
{
}
break;
case kIOStopModeRead:
case kIOPlayModeRead:
{
//OnUIIdle();
AckOneSampleReceived();
}
break;
}
return;
}
/************************************************
* Load record list file.
************************************************/
void ORDeviceRecordList::LoadFile(const char *pFileName)
{
ClearList();
FILE *fp;
FBPlayListEntry *tmp = NULL;
if( (fp = fopen( pFileName, "r" )) == NULL )
{
return;//todo: cannot open file error
}
char name[256];
int hhin, mmin, ssin,ffin;
int hhout, mmout, ssout,ffout;
int preroll,postroll;
while(11==fscanf(fp, "%s %d:%d:%d:%d %d:%d:%d:%d %d %d",
name,&hhin, &mmin, &ssin,&ffin,&hhout, &mmout, &ssout,&ffout,&preroll,&postroll))
{
tmp = new FBPlayListEntry;
tmp->mName= name;
tmp->mInTime.SetTime(hhin,mmin, ssin,ffin, 0);
tmp->mOutTime.SetTime(hhout, mmout, ssout,ffout, 0);
tmp->mPreroll = preroll;
tmp->mPostroll = postroll;
mPlayList.Add(tmp);
}
fclose(fp);
}
/************************************************
* Set current take's timespan.
************************************************/
bool ORDeviceRecordList::SetCurrentTakeTimeSpan(FBTime pStart, FBTime pStop)
{
mSystem.CurrentTake->LocalTimeSpan = FBTimeSpan( pStart,pStop ) ;
return true;
}
/************************************************
* Get play status.
************************************************/
bool ORDeviceRecordList::GetPlayStatus()
{
if( mPlayerControl.GetTransportMode() == kFBTransportPlay)
{
return true;
}
return false;
}
/************************************************
* Prepare to record.
************************************************/
bool ORDeviceRecordList::PrepareToRecord()
{
//todo
FBTime start,stop, duration, time24h;
time24h.SetTime(24,0,0,0);
start = GetListEntry(GetCurrentTakeIndex())->GetStartTime();
stop = GetListEntry(GetCurrentTakeIndex())->GetStopTime();
if(start.Get() <= stop.Get())
{
duration.Set(stop.Get() -start.Get());
}
else
{
duration.Set(time24h.Get() - (start.Get() -stop.Get()));
}
bool success;
success = mPlayerControl.Record(true, false);
mPlayerControl.LoopStart = FBTime(0);
mPlayerControl.LoopStop = duration;
//int coco = duration.GetMilliSeconds();
Cue(FBTime(0)); //todo: TB tested
return success;
}
/************************************************
* Prepare to play.
************************************************/
bool ORDeviceRecordList::PrepareToPlay()
{
//todo
FBTime start,stop, duration, time24h;
time24h.SetTime(24,0,0,0);
start = GetListEntry(GetCurrentTakeIndex())->GetStartTime();
stop = GetListEntry(GetCurrentTakeIndex())->GetStopTime();
if(start.Get() <= stop.Get())
{
duration.Set(stop.Get() -start.Get());
}
else
{
duration.Set(time24h.Get() - (start.Get() -stop.Get()));
}
mPlayerControl.LoopStart = FBTime(0);
mPlayerControl.LoopStop = duration;
Cue(FBTime(0)); //todo: TB tested
return true;
}
/************************************************
* Play button (transport controls).
************************************************/
void ORDeviceRecordList::Play()
{
mPlayerControl.Play();
}
/************************************************
* Stop button (transport controls).
************************************************/
void ORDeviceRecordList::Stop()
{
SetStandbyState(false);
mPlayerControl.Stop();
}
/************************************************
* Goto time at pStart.
************************************************/
void ORDeviceRecordList::Cue(FBTime pStart)
{
mPlayerControl.Goto(pStart );
}
/************************************************
* Get current start time.
************************************************/
FBTime ORDeviceRecordList::GetCurrentStartTime()
{
FBTime zero = 0;
if(GetCurrentTakeIndex()<0 || GetCurrentTakeIndex() >= GetListCount())
{
return zero;
}
return GetListEntry(GetCurrentTakeIndex())->GetStartTime();
}
/************************************************
* Get curretn stop time.
************************************************/
FBTime ORDeviceRecordList::GetCurrentStopTime()
{
FBTime zero = 0;
if(GetCurrentTakeIndex()<0 || GetCurrentTakeIndex() >= GetListCount()){
return zero;
}
return GetListEntry(GetCurrentTakeIndex())->GetStopTime();
}
/************************************************
* Clear list.
************************************************/
void ORDeviceRecordList::ClearList()
{
for(int i=0;i< mPlayList.GetCount();i++)
{
if(mPlayList[i])
{
delete mPlayList[i];
}
}
mPlayList.Clear();
}
/************************************************
* Get number of items in play list.
************************************************/
int ORDeviceRecordList::GetListCount()
{
return mPlayList.GetCount();
}
/************************************************
* Get a list entry.
************************************************/
FBPlayListEntry *ORDeviceRecordList::GetListEntry(int i)
{
return mPlayList[i];
}
/************************************************
* Get the reference time.
************************************************/
FBTime ORDeviceRecordList::GetReferenceTime()
{
FBTime systemTime = mSystem.SystemTime;
return mRefTime.GetTime(mRefTime.ItemIndex, systemTime);
}
/************************************************
* Create a new take.
************************************************/
bool ORDeviceRecordList::CreateNewTake(char *pName)
{
// Create a new take
FBTake* newTake;
FBString newTakeName, fbTakeName;
newTakeName = pName;
newTake = new FBTake(newTakeName);
int takeIndex=-1;
mSystem.Scene->Takes.Add(newTake);
for(int i=0;i<mSystem.Scene->Takes.GetCount();i++)
{
fbTakeName = mSystem.Scene->Takes[i]->Name;
if(fbTakeName == newTakeName)
{
takeIndex = i;
break;
}
}
if(takeIndex != -1)
{
mSystem.CurrentTake = mSystem.Scene->Takes[takeIndex];
return true;
}
return false;
}
/************************************************
* Change to take \e pName.
************************************************/
bool ORDeviceRecordList::ChangeTake(char *pName)
{
// Create a new take
FBString newTakeName,fbTakeName;
int takeIndex = -1;
newTakeName = pName;
for(int i=0;i<mSystem.Scene->Takes.GetCount();i++)
{
fbTakeName = mSystem.Scene->Takes[i]->Name;
if(fbTakeName == newTakeName)
{
takeIndex = i;
break;
}
}
if(takeIndex != -1)
{
mSystem.CurrentTake = mSystem.Scene->Takes[takeIndex];
return true;
}
return false;
}
/************************************************
* On UI idling event.
************************************************/
void ORDeviceRecordList::OnUIIdleEvent(HIRegister pSender, HKEvent pEvent)
{
if(!mStandby)
{
return;
}
FBTime refTime, startTime, stopTime;
FBTimeSpan timeSpan;
refTime.Set(GetReferenceTime().Get());
if(mCurrentTakeIndex>=0 && mCurrentTakeIndex < mPlayList.GetCount())
{
startTime.Set(mPlayList[mCurrentTakeIndex]->GetStartTime().Get());
stopTime.Set(mPlayList[mCurrentTakeIndex]->GetStopTime().Get());
}
else
{
return;
}
timeSpan.Set(startTime, stopTime);
if(timeSpan & refTime)
{
if (!GetPlayStatus())
{
Play();
}
}
}
/************************************************
* Store to FBX file.
************************************************/
bool ORDeviceRecordList::FbxStore(FBFbxObject* pFbxObject,kFbxObjectStore pStoreWhat)
{
int hhin, mmin, ssin,ffin;
int hhout, mmout, ssout,ffout;
int preroll,postroll;
int field,sec;
// todo:
// Question: FieldReadGetCount() retourne le nombre de fields qu'il y dans le block?
// Question: peut-on splitter le block?
//
if (pStoreWhat & kAttributes)
{
pFbxObject->FieldWriteI("Version",101);
if(GetRecFlag())
{
pFbxObject->FieldWriteI("RecFlag",RECLIST_RECFLAG_REC);
}
else
{
pFbxObject->FieldWriteI("RecFlag",RECLIST_RECFLAG_PLAY);
}
pFbxObject->FieldWriteBegin("PlayList");
pFbxObject->FieldWriteI(mPlayList.GetCount());
for (int i=0;i<mPlayList.GetCount();i++)
{
mPlayList[i]->mInTime.GetTime(hhin,mmin, ssin,ffin, field,sec);
mPlayList[i]->mOutTime.GetTime(hhout, mmout, ssout,ffout, field,sec);
preroll = mPlayList[i]->mPreroll;
postroll = mPlayList[i]->mPostroll;
pFbxObject->FieldWriteC( mPlayList[i]->mName );
pFbxObject->FieldWriteI( hhin );
pFbxObject->FieldWriteI( mmin );
pFbxObject->FieldWriteI( ssin );
pFbxObject->FieldWriteI( ffin );
pFbxObject->FieldWriteI( hhout );
pFbxObject->FieldWriteI( mmout );
pFbxObject->FieldWriteI( ssout );
pFbxObject->FieldWriteI( ffout );
pFbxObject->FieldWriteI( preroll );
pFbxObject->FieldWriteI( postroll );
pFbxObject->FieldWriteI( mPlayList[i]->mTakeNumber );
}
pFbxObject->FieldWriteEnd();
}
return true;
}
/************************************************
* Retrieve from FBX file.
************************************************/
bool ORDeviceRecordList::FbxRetrieve(FBFbxObject* pFbxObject,kFbxObjectStore pStoreWhat)
{
int Version,recFlag;
FBString name;
FBPlayListEntry *tmp = NULL;
int hhin, mmin, ssin,ffin;
int hhout, mmout, ssout,ffout;
int preroll,postroll, takeNum = 1;
if (pStoreWhat & kAttributes)
{
Version = pFbxObject->FieldReadI("Version");
if(Version == 100)
{
recFlag = pFbxObject->FieldReadI("RecFlag");
if(recFlag == RECLIST_RECFLAG_REC)
{
SetRecFlag(true);
}
else if(recFlag == RECLIST_RECFLAG_PLAY)
{
SetRecFlag(false);
}
else
{
SetRecFlag(true);
}
if (pFbxObject->FieldReadBegin("PlayList"))
{
ClearList();
//int entryCount = pFbxObject->FieldReadGetCount();
int entryCount = pFbxObject->FieldReadI();
for ( int i=0; i<entryCount; i++ )
{
name = pFbxObject->FieldReadC();
hhin = pFbxObject->FieldReadI();
mmin = pFbxObject->FieldReadI();
ssin = pFbxObject->FieldReadI();
ffin = pFbxObject->FieldReadI();
hhout = pFbxObject->FieldReadI();
mmout = pFbxObject->FieldReadI();
ssout = pFbxObject->FieldReadI();
ffout = pFbxObject->FieldReadI();
preroll = pFbxObject->FieldReadI();
postroll = pFbxObject->FieldReadI();
takeNum = 1969;
tmp = new FBPlayListEntry;
tmp->mName= name;
tmp->mTakeNumber= takeNum;
tmp->mInTime.SetTime(hhin,mmin, ssin,ffin, 0);
tmp->mOutTime.SetTime(hhout, mmout, ssout,ffout, 0);
tmp->mPreroll = preroll;
tmp->mPostroll = postroll;
mPlayList.Add(tmp);
}
pFbxObject->FieldReadEnd();
}
}
if(Version == 101)
{
recFlag = pFbxObject->FieldReadI("RecFlag");
if(recFlag == RECLIST_RECFLAG_REC)
{
SetRecFlag(true);
}
else if(recFlag == RECLIST_RECFLAG_PLAY)
{
SetRecFlag(false);
}
else
{
SetRecFlag(true);
}
if (pFbxObject->FieldReadBegin("PlayList"))
{
ClearList();
//int entryCount = pFbxObject->FieldReadGetCount();
int entryCount = pFbxObject->FieldReadI();
for ( int i=0; i<entryCount; i++ )
{
name = pFbxObject->FieldReadC();
hhin = pFbxObject->FieldReadI();
mmin = pFbxObject->FieldReadI();
ssin = pFbxObject->FieldReadI();
ffin = pFbxObject->FieldReadI();
hhout = pFbxObject->FieldReadI();
mmout = pFbxObject->FieldReadI();
ssout = pFbxObject->FieldReadI();
ffout = pFbxObject->FieldReadI();
preroll = pFbxObject->FieldReadI();
postroll = pFbxObject->FieldReadI();
takeNum = pFbxObject->FieldReadI();
tmp = new FBPlayListEntry;
tmp->mName= name;
tmp->mTakeNumber= takeNum;
tmp->mInTime.SetTime(hhin,mmin, ssin,ffin, 0);
tmp->mOutTime.SetTime(hhout, mmout, ssout,ffout, 0);
tmp->mPreroll = preroll;
tmp->mPostroll = postroll;
mPlayList.Add(tmp);
}
pFbxObject->FieldReadEnd();
}
}
}
return true;
}