VDJPedia

Ingreso rápido:  


 Plugins_SDKv8_Example5

Back to Developer SDK

Video Transition Plugin using SDK v8 (2 Decks)



Here is an example to start developping a plugin "MyPlugin8". We use the class "CMyPlugin8" to define our object but you can use what you want. The file "Main.cpp" is the caller of your object "CMyPlugin8" and is the entry point to communicate with VirtualDJ.

For this example, you need to include the following files from the SDK v8 in your project: vdjPlugin8.h (basic common base-class for all plugins) and vdjVideo8.h (base classes for all Video plugins)
You can use other compiler but please find one example of Visual C++ project for this project on a PC. It will generate a .dll file
For the case of this example, please copy all the files in the same folder.

MyPlugin8.h:
#ifndef MYPLUGIN8_H
#define MYPLUGIN8_H

#include "vdjVideo8.h"

#if (defined(VDJ_WIN))
#define DIRECT3D_VERSION 0x9000
#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")
#elif (defined(VDJ_MAC))
#include <OpenGL/OpenGL.h> // you have to import OpenGL.framework in the XCode project
typedef unsigned long D3DCOLOR; // To use the same approach as Microsoft Direct3D
#define D3DCOLOR_RGBA(r,g,b,a) ((D3DCOLOR)(((((a)&0xFF)<<24)|(((r)&0xFF)<<16)|((g)&0xFF)<<8)|((b)&0xFF)))
#define glColorD3D(d3dcolor) glColor4ub((d3dcolor>>16)&255, (d3dcolor>>8)&255, d3dcolor&255, (d3dcolor>>24)&255 )
// Some colors
const D3DCOLOR white = D3DCOLOR_RGBA(255,255,255,255);
const D3DCOLOR black = D3DCOLOR_RGBA(0,0,0,255);
const D3DCOLOR red = D3DCOLOR_RGBA(255,0,0,255);
const D3DCOLOR green = D3DCOLOR_RGBA(0,255,0,255);
const D3DCOLOR blue = D3DCOLOR_RGBA(0,0,255,255);
const D3DCOLOR translucide_black = D3DCOLOR_RGBA(0,0,0,120);
#endif

class CMyPlugin8 : public IVdjPluginVideoTransition8
{
public:
HRESULT VDJ_API OnLoad();
HRESULT VDJ_API OnGetPluginInfo(TVdjPluginInfo8 *infos);
ULONG VDJ_API Release();
HRESULT VDJ_API OnDeviceInit();
HRESULT VDJ_API OnDeviceClose();
HRESULT VDJ_API OnDraw(float crossfader);

private:
#if (defined(VDJ_WIN))
IDirect3DDevice9 *D3DDevice;
IDirect3DTexture9 *D3DTexture;
IDirect3DSurface9* D3DSurface;

#elif (defined(VDJ_MAC))

GLuint GLTexture;

#endif
};

#endif


MyPlugin8.cpp:
#include "MyPlugin8.h"

#if (defined(VDJ_WIN))
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
#endif
#endif

//-----------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnLoad()
{
// ADD YOUR CODE HERE WHEN THE PLUGIN IS CALLED

#if (defined(VDJ_WIN))

D3DDevice = NULL;
D3DTexture = NULL;
D3DSurface = NULL;

#elif (defined(VDJ_MAC))

GLTexture = 0;

#endif

return S_OK;
}
//-----------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnGetPluginInfo(TVdjPluginInfo8 *infos)
{
infos->PluginName = "MyPlugin8";
infos->Author = "Atomix Productions";
infos->Description = "My first VirtualDJ 8 plugin";
infos->Version = "1.0";
infos->Flags = VDJFLAG_VIDEOTRANSITION_CONTINOUS;
infos->Bitmap = NULL;

return S_OK;
}
//---------------------------------------------------------------------------
ULONG VDJ_API CMyPlugin8::Release()
{
// ADD YOUR CODE HERE WHEN THE PLUGIN IS RELEASED

delete this;
return 0;
}
//---------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnDeviceInit()
{
// ADD YOUR CODE HERE
HRESULT hr;

#if (defined(VDJ_WIN))

hr = GetDevice(VdjVideoEngineDirectX9, (void**) &D3DDevice);
if(hr!=S_OK || D3DDevice == NULL) return S_FALSE;

#endif

return S_OK;
}
//---------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnDeviceClose()
{
// ADD YOUR CODE HERE

return S_OK;
}
//---------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnDraw(float crossfader)
{
// ADD YOUR CODE HERE
HRESULT hr;

int main=(crossfader<=0.5f)?1:2;
float factor = 1.0f - crossfader/0.5f;
int alpha;
TVertex *vertices;
DWORD AlphaColor;

#if (defined(VDJ_WIN))

hr = GetTexture(VdjVideoEngineDirectX9, main, (void **) &D3DTexture);
hr = D3DTexture->GetSurfaceLevel(0, &D3DSurface);

SAFE_RELEASE(D3DTexture);
SAFE_RELEASE(D3DSurface);

#elif (defined(VDJ_MAC))

hr = GetTexture(VdjVideoEngineOpenGL, (void **) &GLTexture, &vertices);

#endif

if (crossfader<=0.5f) alpha=(int)(factor* 255);
else alpha=(int)((1.0f- factor)*255);

vertices = GetVertices(main);

AlphaColor = D3DCOLOR_RGBA(255,255,255, alpha); // see MyPlugin8.h for the declaration on Mac

vertices[0].color = AlphaColor;
vertices[1].color = AlphaColor;
vertices[2].color = AlphaColor;
vertices[3].color = AlphaColor;

#if (defined(VDJ_WIN))

// D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

#elif (defined(VDJ_MAC))

// glColorD3D(AlphaColor); // see MyPlugin8.h for the declaration

#endif

hr = DrawDeck(main, vertices);

return S_OK;
}


Main.cpp:
#include "MyPlugin8.h"

HRESULT VDJ_API DllGetClassObject(const GUID &rclsid,const GUID &riid,void** ppObject)
{
if (memcmp(&rclsid,&CLSID_VdjPlugin8,sizeof(GUID))==0 && memcmp(&riid,&IID_IVdjPluginVideoTransition8,sizeof(GUID))==0)
{
*ppObject=new CMyPlugin8();
}
else
{
return CLASS_E_CLASSNOTAVAILABLE;
}

return NO_ERROR;
}





Back to Developer SDK