254 lines
7.9 KiB
C++
254 lines
7.9 KiB
C++
/*************************************************************************/
|
|
/* File : VideoControl.cpp */
|
|
/* */
|
|
/* Author : Leïla AIT KACI */
|
|
/* Last Modification : 28/05/03 */
|
|
/*************************************************************************/
|
|
#include "CKAll.h"
|
|
#include "CKVideo.h"
|
|
#include "CKVideoManager.h"
|
|
|
|
void RegisterVideoControlParams (CKParameterManager* pm);
|
|
void UnregisterVideoControlParams (CKParameterManager* pm);
|
|
|
|
CKObjectDeclaration* FillBehaviorVideoControlDecl ();
|
|
CKERROR CreateVideoControlProto (CKBehaviorPrototype **);
|
|
int VideoControl (const CKBehaviorContext& BehContext);
|
|
CKERROR VideoControlCB (const CKBehaviorContext& BehContext);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Defines
|
|
//////////////////////////////////////////////////////////////////////
|
|
#define BB_NAME "Video Basic Control"
|
|
#define BB_DESC "Modify a video's global controls (runtime parameters)."
|
|
#define BB_CAT "Video/Controls"
|
|
#define BB_VERSION 0x00010000
|
|
#define BB_TARGET CKCID_VIDEO
|
|
|
|
#define RETURN_IF_FAILED(index, res) \
|
|
if ( res != CK_OK ) { \
|
|
XString err = "Pin '"; \
|
|
err += beh->GetInputParameter(index)->GetName(); \
|
|
err += "': "; \
|
|
err += video->GetErrorDescrition(res); \
|
|
beh->SetOutputParameterValue(POUT_ERROR, err.Str(), err.Length() + 1 ); \
|
|
beh->ActivateOutput(OUT_ERROR); \
|
|
return CKBR_OK; \
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Enums for Parameter's Indexes
|
|
//////////////////////////////////////////////////////////////////////
|
|
enum BB_IN
|
|
{
|
|
IN_IN
|
|
};
|
|
|
|
enum BB_OUT
|
|
{
|
|
OUT_OUT,
|
|
OUT_ERROR
|
|
};
|
|
|
|
enum BB_LOC
|
|
{
|
|
CONTROLFLAGS
|
|
};
|
|
|
|
enum BB_PIN
|
|
{
|
|
PIN_LOOP,
|
|
PIN_START_TIME,
|
|
PIN_STOP_TIME,
|
|
PIN_SPEED,
|
|
PIN_GAIN,
|
|
PIN_PAN
|
|
};
|
|
|
|
enum BB_POUT
|
|
{
|
|
POUT_ERROR
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
#define CONTROL_GUID CKGUID(0xa37739,0x32557aa3)
|
|
#define CONTROL_LOOP 0x00000001
|
|
#define CONTROL_SPEED 0x00000002
|
|
#define CONTROL_START 0x00000004
|
|
#define CONTROL_GAIN 0x00000008
|
|
#define CONTROL_STOP 0x00000010
|
|
#define CONTROL_PAN 0x00000020
|
|
#define CONTROL_DEFAULT "Loop,Start Time,Stop Time,Speed,Gain,Pan"
|
|
|
|
void RegisterVideoControlParams(CKParameterManager* pm)
|
|
{
|
|
pm->RegisterNewFlags(CONTROL_GUID, "", "Loop=1,Speed=2,Start Time=4,Gain=8,Stop Time=16,Pan=32");
|
|
|
|
CKParameterTypeDesc* TypeDesc;
|
|
TypeDesc = pm->GetParameterTypeDescription(CONTROL_GUID);
|
|
TypeDesc->dwFlags |= CKPARAMETERTYPE_HIDDEN;
|
|
}
|
|
|
|
void UnregisterVideoControlParams(CKParameterManager* pm)
|
|
{
|
|
pm->UnRegisterParameterType(CONTROL_GUID);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKObjectDeclaration *FillBehaviorVideoControlDecl()
|
|
{
|
|
CKObjectDeclaration *od = CreateCKObjectDeclaration(BB_NAME);
|
|
od->SetType(CKDLL_BEHAVIORPROTOTYPE);
|
|
od->SetCompatibleClassId(BB_TARGET);
|
|
od->SetDescription(BB_DESC);
|
|
od->SetVersion(BB_VERSION);
|
|
od->SetCategory(BB_CAT);
|
|
od->SetAuthorName("Virtools");
|
|
od->SetAuthorGuid(VIRTOOLS_GUID);
|
|
od->SetGuid(CKGUID(0x71ee6816,0x25846aee));
|
|
od->SetCreationFunction(CreateVideoControlProto);
|
|
|
|
return od;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKERROR CreateVideoControlProto(CKBehaviorPrototype** pproto)
|
|
{
|
|
CKBehaviorPrototype *proto = CreateCKBehaviorPrototype(BB_NAME);
|
|
if(!proto) return CKERR_OUTOFMEMORY;
|
|
|
|
//--- Inputs declaration
|
|
proto->DeclareInput("In");
|
|
|
|
//--- Outputs declaration
|
|
proto->DeclareOutput("Out");
|
|
proto->DeclareOutput("Error");
|
|
|
|
//----- Input Parameters Declaration
|
|
proto->DeclareInParameter("Loop", CKPGUID_BOOL, "TRUE" );
|
|
proto->DeclareInParameter("Start Time", CKPGUID_TIME );
|
|
proto->DeclareInParameter("Stop Time", CKPGUID_TIME );
|
|
proto->DeclareInParameter("Speed", CKPGUID_FLOAT, "1" );
|
|
proto->DeclareInParameter("Gain", CKPGUID_PERCENTAGE, "100%" );
|
|
proto->DeclareInParameter("Pan", CKPGUID_FLOAT, "0" );
|
|
|
|
//--- Output Parameters Declaration
|
|
proto->DeclareOutParameter("Error", CKPGUID_STRING);
|
|
|
|
//---- Settings Declaration
|
|
proto->DeclareSetting("Controls", CONTROL_GUID, CONTROL_DEFAULT);
|
|
|
|
proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL);
|
|
proto->SetBehaviorFlags((CK_BEHAVIOR_FLAGS)(CKBEHAVIOR_TARGETABLE));
|
|
proto->SetFunction(VideoControl);
|
|
proto->SetBehaviorCallbackFct(VideoControlCB, CKCB_BEHAVIORSETTINGSEDITED|CKCB_BEHAVIORCREATE, NULL);
|
|
|
|
*pproto = proto;
|
|
return CK_OK;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
int VideoControl(const CKBehaviorContext& BehContext)
|
|
{
|
|
CKContext* ctx = BehContext.Context;
|
|
CKBehavior* beh = BehContext.Behavior;
|
|
|
|
beh->ActivateInput(IN_IN, FALSE);
|
|
|
|
CKVideo* video = (CKVideo*) beh->GetTarget();
|
|
if ( !video ) {
|
|
XString err = "Invalid Video";
|
|
beh->SetOutputParameterValue(POUT_ERROR, err.Str(), err.Length() + 1 );
|
|
beh->ActivateOutput(OUT_ERROR);
|
|
return CKBR_OK;
|
|
}
|
|
|
|
DWORD ControlFlags;
|
|
beh->GetLocalParameterValue(CONTROLFLAGS, &ControlFlags);
|
|
|
|
CKERROR res[6];
|
|
memset(res, 0, sizeof(res));
|
|
|
|
int Current = 0;
|
|
if ( ControlFlags & CONTROL_LOOP ) {
|
|
CKBOOL Loop = TRUE;
|
|
beh->GetInputParameterValue(PIN_LOOP, &Loop);
|
|
res[Current] = video->SetLoop(Loop);
|
|
}
|
|
Current++;
|
|
|
|
// If both time are set, we must make only one call to SetLimitTimes
|
|
// to make sure comparaison test is
|
|
if ( (ControlFlags & CONTROL_START) && (ControlFlags & CONTROL_STOP) ) {
|
|
float StartTime = 0.0f;
|
|
float StopTime = 0.0f;
|
|
beh->GetInputParameterValue(PIN_START_TIME, &StartTime);
|
|
beh->GetInputParameterValue(PIN_STOP_TIME, &StopTime);
|
|
res[Current] = res[Current+1] = video->SetLimitTimes(StartTime, StopTime);
|
|
}
|
|
else if ( ControlFlags & CONTROL_START ) {
|
|
float StartTime = 0.0f;
|
|
beh->GetInputParameterValue(PIN_START_TIME, &StartTime);
|
|
res[Current] = video->SetLimitTimes(StartTime, -1);
|
|
}
|
|
else if ( ControlFlags & CONTROL_STOP ) {
|
|
float StopTime = 0.0f;
|
|
beh->GetInputParameterValue(PIN_STOP_TIME, &StopTime);
|
|
res[Current+1] = video->SetLimitTimes(-1, StopTime);
|
|
}
|
|
Current+=2;
|
|
if ( ControlFlags & CONTROL_SPEED ) {
|
|
float Speed = 0.0f;
|
|
beh->GetInputParameterValue(PIN_SPEED, &Speed);
|
|
res[Current] = video->SetSpeed(Speed);
|
|
}
|
|
Current++;
|
|
if ( ControlFlags & CONTROL_GAIN ) {
|
|
float Gain = 0.0f;
|
|
beh->GetInputParameterValue(PIN_GAIN, &Gain);
|
|
res[Current] = video->SetVolume(Gain);
|
|
}
|
|
Current++;
|
|
if ( ControlFlags & CONTROL_PAN ) {
|
|
float Pan = 0.0f;
|
|
beh->GetInputParameterValue(PIN_PAN, &Pan);
|
|
res[Current] = video->SetBalance(Pan);
|
|
}
|
|
Current++;
|
|
|
|
// Return at the first error
|
|
for (int i=0; i<Current; i++)
|
|
RETURN_IF_FAILED(i, res[i]);
|
|
|
|
beh->SetOutputParameterValue(POUT_ERROR, "Success", 8);
|
|
beh->ActivateOutput(OUT_OUT);
|
|
return CKBR_OK;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKERROR VideoControlCB(const CKBehaviorContext& BehContext)
|
|
{
|
|
CKContext* ctx = BehContext.Context;
|
|
CKBehavior* beh = BehContext.Behavior;
|
|
|
|
// Get Setting
|
|
DWORD ControlFlags;
|
|
beh->GetLocalParameterValue(CONTROLFLAGS, &ControlFlags);
|
|
|
|
// Activate / Deactivate Pins
|
|
beh->EnableInputParameter(PIN_LOOP, ControlFlags & CONTROL_LOOP );
|
|
beh->EnableInputParameter(PIN_START_TIME, ControlFlags & CONTROL_START );
|
|
beh->EnableInputParameter(PIN_STOP_TIME, ControlFlags & CONTROL_STOP );
|
|
beh->EnableInputParameter(PIN_SPEED, ControlFlags & CONTROL_SPEED );
|
|
beh->EnableInputParameter(PIN_GAIN, ControlFlags & CONTROL_GAIN );
|
|
beh->EnableInputParameter(PIN_PAN, ControlFlags & CONTROL_PAN );
|
|
|
|
return CKBR_OK;
|
|
}
|