RSS Twitter Facebook
g200kg > KnobMan Online Help > 15.Plugin API

KnobMan Online Help

2008/11/06

15.Plugin API



TENTATIVE SPECIFICATION

Plugins

KnobMan has a interface to plug-in modules that expand the functionality.

Plugin Type

The Plugins can be windows executable ( 'exe' files ) or some other script file, for example, '.py' file for Python. Each script extension should be registerd to the 'Option' menu with a associated script interpreter. In default, the '.py' files are registered as for Python (C:\Python26\python.exe). The plugin files should be place into the 'Plugins' folder under the 'KnobMan.exe'.

Plugin Invocation

The plugins are listed on the 'Plugins' menu automatically. If a menu item selected, the exe or the script are invoked.

  • exe file: invoked via CreateProcess() call with window handle of the KnobMan as a arg.
  • script file: the script interpreter is invoked with a script and window handle of the KnobMan as args
The script 'Monochrome.py' is invoked like followings:

>C\Python26\python.exe Monochrome.py 123456

Here the 123456 is a decimal representation of the WindowHandle (HWND) of the KnobMan

Plugin I/F

Plugins can communicate with KnobMan using just only WM_SETTEXT and WM_GETTEXT messages. If you use Python, the 'ctypes' module will help to do this. The target window handle is passed by commandline. Followings are a code fragment for getting target window handle.

C:

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow) {
	HWND hwndTarget=(HWND)atoi(lpCmdLine);

Python:

import sys
import ctypes
hwnd=int(sys.argv[1])

After get the window handle, the plugins can control KnobMan by special format WM_SETTEXT that set the text of "KnobManCtl:xxxx". For example,...

C:

char *str="KnobManCtl:SetValue Layer1.OffsetX1=0.0";
SendMessage(hwndTarget,WM_SETTEXT,0,(LPARAM)str);

Python:

import sys
import ctypes
user32=ctypes.windll.user32
WM_SETTEXT=12
user32.SendMessageA(hwnd,WM_SETTEXT,0,"KnobManCtl:SetValue Layer1.OffsetX1=0.0")
will set a value of Layer1 OffsetX1 to 0.0

Commands

  • "KnobManCtl:Exit" :Plugin should send this message when exit.
  • "KnobManCtl:LayerX.GetValue param" :Get a parameter value from KnobMan. 'X' is 1 based layer number. the return value can be retrieved by WM_GETTEXT message
  • "KnobManCtl:LayerX.SetValue param=value" :Set a value to a parameter. 'X' is 1 based layer number.
  • "KnobManCtl:SetCurrentLayer" :Set current focused layer. 1 based, 0 for preferences page.
  • "KnobManCtl:GetCurrentLayer" :Get current focused layer. 1 based, 0 for preferences page. The return value can be retrieved by WM_GETTEXT mesasge.
  • "KnobManCtl:ExportImage <filename>" :Export current Image as <filename>
  • "KnobManCtl:OpenFile <filename>" :Open .knob file
  • "KnobManCtl:SaveFile <filename>" :Save .knob file
  • "KnobManCtl:AddLayer" :Add a layer same as 'New Layer' button
  • "KnobManCtl:DupLayer" :Dup a layer same as 'Dup Layer' button
  • "KnobManCtl:DelLayer" :Delete a layer same as 'Del Layer' button

Params

Available params for GetValue / SetValue list:
Prefs. instead of LayerX.
  • "Prefs.Layers" :the number of the layers
  • "Prefs.PreviewFrames" :PreviewFrames parameter
  • "Prefs.RenderFrames" :RenderFrames parameter
  • "Prefs.OutputSizeX" :OutputSizeX parameter
  • "Prefs.OutputSizeY" :OutputSizeY parameter
  • "Prefs.Align" :Align parameter horizontal=1 vertical=0
  • "Prefs.BgColor" :Background Color
for each layers: ex) Layer1.Primitive
  • "Visible" :Layer Visiblity (0 or 1)
  • "VisibleSolo" :Layer VisibleSolo (0 or 1)
  • "Primitive" :Primitive type
  • "Color" :Color parameter for primitives
  • "Text" :Text parameter for 'Text' primitive
  • "Shape" :Shape parameter for 'Shape' primitive
  • "Font" :Font parameter for 'Text' primitive
  • "File" :Filename for 'Image' primitive
  • "FontSize" :FontSize parameter for 'Text' primitive
  • "Italic" :Italic parameter for 'Text' primitive
  • "Bold" :Bold parameter for 'Text' primitive
  • "PrimFill" :Fill parameter for 'Shape' primitive
  • "PrimGridSize" :GridSize parameter for 'Shape' primitive
  • "PrimGridVisible" :Grid Visible parameter for 'Shape' primitive
  • "PrimGridEnable" :Grid Enable parameter for 'Shape' primitive
  • "Aspect" :Aspect parameter for primitives
  • "EmbossDiffuse" :Emboss Diffuse parameter for primitives
  • "Emboss" :Emboss parameter for primitives
  • "TextureType" :Texture Type parameter for primitives
  • "Texture" :Texture parameter for primitives
  • "TexZoom" :Texture Zoom parameter for primitives
  • "Specular" :Specular parameter for primitives
  • "Diffuse" :Diffuse parameter for primitives
  • "Width" :Width prameter for primitives
  • "Ambient" :Ambient parameter for 'Sphere' primitive
  • "AngleStep" :Angle Step parameter for 'RadLine' or 'WaveCircle' primitives
  • "SpecularWidth" :Specular Width parameter for primitives
  • "Round" :Round parameter for primitives
  • "Length" :Length parameter for primitives
  • "Antialias" :Antialias parameter
  • "AnimUnfold" :Unfold parameter
  • "AnimStep" :Anim Step parameter
  • "OffsetX1" :OffsetX for first frame
  • "OffsetX2" :OffsetX for the last frame
  • "OffsetY1" :OffsetY for first frame
  • "OffsetY2" :OffsetY for the last frame
  • "OffsetXAnim" :OffsetX animation enable=1 disable=0
  • "OffsetYAnim" :OffsetY animation enable=1 disable=0
  • "OffsetXCurve" :OffsetX animation curve 0-4
  • "OffsetYCurve" :OffsetY animation curve 0-4
  • "RotCenterX" :RotCenterX parameter
  • "RotCenterY" :RotCenterY parameter
  • "Angle1" :Angle parameter for first frame
  • "Angle2" :Angle parameter for the last frame
  • "AngleAnim" :Angle animation enable=1 disable=0
  • "AngleCurve" :Angle animation curve 0-4
  • "Zoom1" :Zoom parameter for first frame
  • "Zoom2" :Zoom parameter for the last frame
  • "ZoomAnim" :Zoom animation enable=1 disable=0
  • "ZoomCurve" Zoom animation curve 0-4
  • "Alpha1" :Alpha parameter for first frame
  • "Alpha2" :Alpha parameter for the last fame
  • "AlphaAnim" :Alpha animation enable=1 disable=0
  • "AlphaCurve" :Alpha animation curve 0-4
  • "Brightness1" :Brightness parameter for first frame
  • "Brightness2" :Brightness parameter for the last frame
  • "BrightnessAnim" :Brightness animation enable=1 disable=0
  • "BrightnessCurve" :Brightness animation curve 0-4
  • "Contrast1" :Contrast parameter for first frame
  • "Contrast2" :Contrast parameter for the last frame
  • "ContrastAnim" :Contrast animation enable=1 disable=0
  • "ContrastCurve" :Constrast animation curve 0-4
  • "Saturation1" :Saturation parameter for first frame
  • "Saturation2" :Saturation parameter for the last frame
  • "SaturationAnim" :Saturation animation enable=1 disable=0
  • "SaturationCurve" :Saturation animation curve 0-4
  • "Hue1" :Hue parameter for first frame
  • "Hue2" :Hue parameter for the last frame
  • "HueAnim" :Hue animation enable=1 disable=0
  • "HueCurve" :Hue animation curve 0-4
  • "UseMask" :Use AnimMask enable=1 disable=0
  • "MaskStart1" :Mask Start parameter for first frame
  • "MaskStart2" :Mask Start parameter for the last frame
  • "MaskStartAnim" :Mask Start animation enable=1 disable=0
  • "MaskStartCurve" :Mask Start animation curve 0-4
  • "MaskStop1" :Mask Stop parameter for first frame
  • "MaskStop2" :Mask Stop paremeter for the last frame
  • "MaskStopAnim" :Mask Stop animation enable=1 disable=0
  • "MaskStopCurve" :Mask Stop animation curve 0-4
  • "MaskType" :Mask Type parameter
  • "MaskGradation" :Mask Gradation parameter
  • "MaskGradDir" :Mask Gradation Dir parameter
  • "UseFMask" :Use Frame Mask enable=1 disable=0
  • "FMaskStart" :Frame Mask Start parameter
  • "FMaskStop" :Frame Mask Stop parameter
  • "LightDir1" :Specular LightDir parameter for first frame
  • "LightDir2" :Specular LightDir parameter for the last frame
  • "LightDirAnim" :Specular LightDir animation enable=1 disable=0
  • "LightDirCurve" :Specular LightDir animation curve 0-4
  • "SpecDensity1" :Specular Density parameter for first frame
  • "SpecDensity2" :Specular Density parameter for the last frame
  • "SpecDensityAnim" :Specular Density animation enable=1 disable=0
  • "SpecDensityCurve" :Specular Density animation curve 0-4
  • "LightDirDEnable" :DropShadow LightDir Enable
  • "LightDirD1" :DropShadow LightDir parameter for the first frame
  • "LightDirD2" :DropShadow LightDir parameter for the last frame
  • "LightDirDAnim" :DropShadow LightDir animation enable=1 disable=0
  • "LightDirDCurve" :DropShadow LightDir animation curve 0-4
  • "ShadowOffset1" :DropShadow Offset1 parameter
  • "ShadowOffset2" :DropShadow Offset2 parameter
  • "ShadowOffsetAnim" :DropShadow Offset animation enable=1 disable=0
  • "ShadowOffsetCurve" :DropShadow Offset animation curve 0-4
  • "ShadowDensity" or "ShadowDensity1" :DropShadow Density parameter for the first frame
  • "ShadowDensity2" :DropShadow Density parameter for the last frame
  • "ShadowDiffuse1" :DropShadow Diffuse parameter for the first frame
  • "ShadowDiffuse2" :DropShadow Diffuse parameter for the last frame
  • "ShadowDiffuseAnim" :DropShadow Diffuse animation enable=1 disable=0
  • "ShadowDiffuseCurve" :DropShadow Diffuse animation curve 0-4
  • "LightDirIEnable" :InsideShadow LightDir enable
  • "LightDirI1" :InsideShadow LightDir parameter for the first frame
  • "LightDirI2" :InsideShadow LightDir parameter for the last frame
  • "LightDirIAnim" :InsideShadow LightDir animation enable=1 disable=0
  • "LightDirICurve" :InsideShadow LightDir animation curve 0-4
  • "IShadowOffset1" :InsideShadow Offset parameter for the first frame
  • "IShadowOffset2" :InsideShadow Offset parameter for the last frame
  • "IShadowOffsetAnim" :InsideShadow Offset animation enable=1 disable=0
  • "IShadowOffsetCurve" :InsideShadow Offset animation curve 0-4
  • "IShadowDensity1" :InsideShadow Density parameter for the first frame
  • "IShadowDensity2" :InsideShadow Density parameter for the last frame
  • "IShadowDensityAnim" :InsideShadow Density animation enable=1 disable=0
  • "IShadowDensityCurve" :InsideShadow Density animation curve 0-4
  • "IShadowDiffuse1" :InsideShadow Diffuse parameter for the first frame
  • "IShadowDiffuse2" :InsideShadow Diffuse parameter for the last frame
  • "IShadowDiffuseAnim" :InsideShadow Diffuse animation enable=1 disable=0
  • "IShadowDiffuseCurve" :InsideShadow Diffuse animation curve 0-4
  • "LightDirEEnable" :EdgeHilight LightDir Enable
  • "LightDirE1" :EdgeHighlight LightDir parameter for the first frame
  • "LightDirE2" :EdgeHighlight LightDir parameter for the last frame
  • "LightDirEAnim" :EdgeHighlight LightDir animation enable=1 disable=0
  • "LightDirECurve" :EdgeHighlight LightDir animation curve 0-4
  • "EdgeOffset1" :EdgeHighlight Offset parameter for the first frame
  • "EdgeOffset2" :EdgeHighlight Offset parameter for the last frame
  • "EdgeOffsetAnim" :EdgeHighlight Offset animation enable=1 disable=0
  • "EdgeOffsetCurve" :EdgeHighlight Offset animation curve 0-4
  • "EdgeDensity1" :EdgeHighlight Density parameter for the first frame
  • "EdgeDensity2" :EdgeHighlight Density parameter for the last frame
  • "EdgeDensityAnim" :EdgeHighlight Density animation enable=1 disable=0
  • "EdgeDensityCurave" :EdgeHighlight Density animation curve 0-4

Here is a some source-code

C source: HorzVert
// HorzVert.cpp : KnobMan Plugin
//
// Usage:
//   Place the .exe file to 'Plugins' directory
//   You can run plugin from 'Plugins' menu.
//
//    HorzVert will try convert horizontal slider <=> vertical slider
//     BY
//       OutputSizeX / OutputSizeY exchange
//       Primitive H-Lines/V-Lines change
//       Primitive Aspect change
//       OffsetX/Y exchange
//       RotCenterX/Y exchange
//		 MaskType Horizontal/Vertical change
//
//  May not work properly if you use...
//    * non-square image primitives
//    * triangle / line primitives
//    * angles / mask rotations effects
//  But probably help you if need Horizontal/Vertical Sliders

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>


float GetValue(HWND hwnd,int iLayer,char *strKey) {
	static char str[100];
	if(iLayer)
		sprintf(str,"KnobManCtl:GetValue Layer%d.%s",iLayer,strKey);
	else
		sprintf(str,"KnobManCtl:GetValue Prefs.%s",strKey);
	SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)str);
	SendMessage(hwnd,WM_GETTEXT,100,(LPARAM)str);
	return atof(str);
}
char *GetValueText(HWND hwnd,int iLayer,char *strKey) {
	static char str[100];
	if(iLayer)
		sprintf(str,"KnobManCtl:GetValue Layer%d.%s",iLayer,strKey);
	else
		sprintf(str,"KnobManCtl:GetValue Prefs.%s",strKey);
	SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)str);
	SendMessage(hwnd,WM_GETTEXT,100,(LPARAM)str);
	return str;
}
void SetValue(HWND hwnd,int iLayer,char *strKey,float fVal) {
	char str[100];
	if(iLayer)
		sprintf(str,"KnobManCtl:SetValue Layer%d.%s=%f",iLayer,strKey,fVal);
	else
		sprintf(str,"KnobManCtl:SetValue Prefs.%s=%f",strKey,fVal);
	SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)str);
}
void SetValue(HWND hwnd,int iLayer,char *strKey,char *strVal) {
	char str[256];
	if(iLayer)
		sprintf(str,"KnobManCtl:SetValue Layer%d.%s=%s",iLayer,strKey,strVal);
	else
		sprintf(str,"KnobManCtl:SetValue Prefs.%s=%s",strKey,strVal);
	SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)str);
}
void ExitPlugin(HWND hwnd) {
	SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)"KnobManCtl:Exit");
}

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow) {
	int i,iMaxLayer;
	float f,fX,fY;
	char str[100];
	char *p;
	int r;
	HWND hwndTarget=(HWND)atoi(lpCmdLine);
	r=MessageBox(NULL,"HorzVert: Horizontal/Vertical exchange for Sliders.\n\n"
		"HorzVert will try convert horizontal slider <=> vertical slider\n"
		" BY///\n"
		"  OutputSizeX / OutputSizeY exchange\n"
		"  Primitive H-Lines/V-Lines change\n"
		"  Primitive Aspect change\n"
		"  OffsetX/Y exchange\n"
		"  RotCenterX/Y exchange\n"
		"  MaskType Horizontal/Vertical change\n"
		"\n"
		"May not work properly if you use...\n"
		" * non-square image primitives\n"
		" * triangle / line primitives\n"
		" * angles / mask rotations effects\n"
		"But probably help you if need Horizontal/Vertical Sliders\n"
		,"HorzVert",MB_OKCANCEL);
	if(r==IDCANCEL) {
		ExitPlugin(hwndTarget);
		return 0;
	}
	iMaxLayer=(int)GetValue(hwndTarget,0,"Layers");
	fX=GetValue(hwndTarget,0,"OutputSizeX");
	fY=GetValue(hwndTarget,0,"OutputSizeY");
	SetValue(hwndTarget,0,"OutputSizeX",fY);
	SetValue(hwndTarget,0,"OutputSizeY",fX);
	for(i=1;i<=iMaxLayer;++i) {
		p=GetValueText(hwndTarget,i,"Primitive");
		if(strcmp(p,"H-Lines")==0)
			SetValue(hwndTarget,i,"Primitive","V-Lines");
		else if(strcmp(p,"V-Lines")==0)
			SetValue(hwndTarget,i,"Primitive","H-Lines");
		f=GetValue(hwndTarget,i,"Aspect");
		SetValue(hwndTarget,i,"Aspect",-f);
		fX=GetValue(hwndTarget,i,"OffsetX1");
		fY=GetValue(hwndTarget,i,"OffsetY1");
		SetValue(hwndTarget,i,"OffsetX1",fY);
		SetValue(hwndTarget,i,"OffsetY1",fX);
		fX=GetValue(hwndTarget,i,"OffsetX2");
		fY=GetValue(hwndTarget,i,"OffsetY2");
		SetValue(hwndTarget,i,"OffsetX2",fY);
		SetValue(hwndTarget,i,"OffsetY2",fX);
		fX=GetValue(hwndTarget,i,"OffsetXAnim");
		fY=GetValue(hwndTarget,i,"OffsetYAnim");
		SetValue(hwndTarget,i,"OffsetXAnim",fY);
		SetValue(hwndTarget,i,"OffsetYAnim",fX);
		fX=GetValue(hwndTarget,i,"RotCenterX");
		fY=GetValue(hwndTarget,i,"RotCenterY");
		SetValue(hwndTarget,i,"RotCenterX",fY);
		SetValue(hwndTarget,i,"RotCenterY",fX);
		p=GetValueText(hwndTarget,i,"MaskType");
		if(strcmp(p,"Horizontal")==0)
			SetValue(hwndTarget,i,"MaskType","Vertical");
		else if(strcmp(p,"Vertical")==0)
			SetValue(hwndTarget,i,"MaskType","Horizontal");
	}
	ExitPlugin(hwndTarget);
	MessageBox(NULL,"Finished","HorzVert",MB_OK);
	return 0;
}

Python: Monochrome
import sys
import ctypes

user32=ctypes.windll.user32
WM_SETTEXT=12

def KMSendText(hwnd,text):
  user32.SendMessageA(hwnd,WM_SETTEXT,0,text)

def KMGetText(hwnd):
  length = user32.GetWindowTextLengthA(hwnd)
  if length:
    buffer = ctypes.create_string_buffer("",length + 1)
    if user32.GetWindowTextA(hwnd, buffer, length +1):
      return buffer.value

def KMSetValue(hwnd,layer,param,value):
  s="KnobManCtl:SetValue "
  if layer==0:
    s=s+"Prefs."
  else:
    s=s+"Layer"+str(layer)+"."
  s=s+param+"="+str(value)
  KMSendText(hwnd,s)

def KMGetValue(hwnd,layer,param):
  s="KnobManCtl:GetValue "
  if layer==0:
    s=s+"Prefs."
  else:
    s=s+"Layer"+str(layer)+"."
  s=s+param
  KMSendText(hwnd,s)
  return KMGetText(hwnd)

def KMExport(hwnd,file):
  KMSendText(hwnd,"KnobManCtl:ExportImage "+file)

def KMExit(hwnd):
  KMSendText(hwnd,"KnobManCtl:Exit")


###################################################
def Main():
  hwnd=int(sys.argv[1])
  user32.MessageBoxA(0,"Change to Monochrome","Monochrome",0)
  layers=int(KMGetValue(hwnd,0,"Layers"))
  for layer in range(1,layers+1):
    KMSetValue(hwnd,layer,"Saturation1",-100)
    KMSetValue(hwnd,layer,"Saturation2",-100)
  KMExit(hwnd)
  user32.MessageBoxA(0,"Completed.","Monochrome",0)

Main()

Return


g200kg