Added datatype handling to ahk script (float!, closes #2). Refined OSC message handling in dll, added datatypes with constant byte width.
This commit is contained in:
parent
678b0d09a4
commit
606230d1b6
@ -137,9 +137,30 @@ DLLEXPORT int removeListener(LPCSTR address_)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int getOscType(osc::ReceivedMessage::const_iterator arg)
|
||||||
|
{
|
||||||
|
if (arg->IsBlob()) return OSC_TYPE_BLOB;
|
||||||
|
if (arg->IsBool()) return OSC_TYPE_BOOL;
|
||||||
|
if (arg->IsChar()) return OSC_TYPE_CHAR;
|
||||||
|
if (arg->IsDouble()) return OSC_TYPE_FLOAT64;
|
||||||
|
if (arg->IsFloat()) return OSC_TYPE_FLOAT;
|
||||||
|
if (arg->IsInt32()) return OSC_TYPE_INT;
|
||||||
|
if (arg->IsInt64()) return OSC_TYPE_INT64;
|
||||||
|
if (arg->IsRgbaColor()) return OSC_TYPE_COLOR;
|
||||||
|
if (arg->IsString()) return OSC_TYPE_STRING;
|
||||||
|
if (arg->IsTimeTag()) return OSC_TYPE_TIMETAG;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMatchingOscType(unsigned int msgType, unsigned int listenerTypeField)
|
||||||
|
{
|
||||||
|
return (listenerTypeField & msgType);
|
||||||
|
}
|
||||||
|
|
||||||
DLLEXPORT int handleOscMsg(const osc::ReceivedMessage& m)
|
DLLEXPORT int handleOscMsg(const osc::ReceivedMessage& m)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
unsigned int msgType = 0;
|
||||||
|
|
||||||
OutputDebugString(L"handleOscMsg: Address=");
|
OutputDebugString(L"handleOscMsg: Address=");
|
||||||
OutputDebugStringA(m.AddressPattern());
|
OutputDebugStringA(m.AddressPattern());
|
||||||
@ -155,31 +176,65 @@ DLLEXPORT int handleOscMsg(const osc::ReceivedMessage& m)
|
|||||||
for (UINT i = 0; i < listeners.size(); i++)
|
for (UINT i = 0; i < listeners.size(); i++)
|
||||||
{
|
{
|
||||||
//Check if incoming OSC address matches current listener entry
|
//Check if incoming OSC address matches current listener entry
|
||||||
if (listeners[i].address.compare(m.AddressPattern()) == 0)
|
if (listeners[i].address.compare(m.AddressPattern()) == 0) //TODO: Implement OSC Pattern Wildcards
|
||||||
{
|
{
|
||||||
//No payload
|
//Check payload type
|
||||||
if (m.ArgumentCount() == 0) {
|
if (m.ArgumentCount() == 0) {
|
||||||
if (listeners[i].dataType == OSC_TYPE_NONE || listeners[i].dataType == OSC_TYPE_ALL) {
|
msgType = OSC_TYPE_NONE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msgType = getOscType(m.ArgumentsBegin());
|
||||||
|
}
|
||||||
|
if (!msgType) return -1; //Something went wrong
|
||||||
|
|
||||||
|
//Check if listener is valid for received datatype
|
||||||
|
if (isMatchingOscType(msgType, listeners[i].dataType))
|
||||||
|
{
|
||||||
|
//Post message depending on message datatype
|
||||||
|
if (msgType == OSC_TYPE_NONE) {
|
||||||
PostMessage(hwnd, listeners[i].message, OSC_TYPE_NONE, 0);
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_NONE, 0);
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
}
|
else if (msgType == OSC_TYPE_INT) {
|
||||||
else //Some paylad, only check first one
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_INT, m.ArgumentsBegin()->AsInt32());
|
||||||
{
|
ret++;
|
||||||
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
|
||||||
if (arg->IsInt32()) { //Got Int, check if listener is valid for Int or All
|
|
||||||
if (listeners[i].dataType == OSC_TYPE_ALL || listeners[i].dataType == OSC_TYPE_INT) {
|
|
||||||
PostMessage(hwnd, listeners[i].message, OSC_TYPE_INT, arg->AsInt32()); //post to message queue
|
|
||||||
ret++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (arg->IsFloat()) { //Got Float, check if listener is valid for Float or All
|
else if (msgType == OSC_TYPE_FLOAT) {
|
||||||
if (listeners[i].dataType == OSC_TYPE_ALL || listeners[i].dataType == OSC_TYPE_FLOAT) {
|
float floatarg = m.ArgumentsBegin()->AsFloat();
|
||||||
float floatarg = arg->AsFloat();
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, reinterpret_cast<int&>(floatarg));
|
||||||
LPARAM lParam = *(LPARAM*)&floatarg;
|
ret++;
|
||||||
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, lParam); //post to message queue
|
}
|
||||||
ret++;
|
else if (msgType == OSC_TYPE_INT64) {
|
||||||
}
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_INT, m.ArgumentsBegin()->AsInt64());
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_FLOAT64) {
|
||||||
|
double doublearg = m.ArgumentsBegin()->AsDouble();
|
||||||
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, reinterpret_cast<int&>(doublearg));
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_BOOL) {
|
||||||
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, m.ArgumentsBegin()->AsBool());
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_CHAR) {
|
||||||
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, m.ArgumentsBegin()->AsChar());
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_COLOR) {
|
||||||
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, m.ArgumentsBegin()->AsRgbaColor());
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_TIMETAG) {
|
||||||
|
uint64_t timearg = m.ArgumentsBegin()->AsTimeTag();
|
||||||
|
PostMessage(hwnd, listeners[i].message, OSC_TYPE_FLOAT, reinterpret_cast<int&>(timearg));
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_STRING) {
|
||||||
|
OutputDebugString(L"handleOScMsg: String not implemented yet"); //TODO
|
||||||
|
}
|
||||||
|
else if (msgType == OSC_TYPE_BLOB) {
|
||||||
|
OutputDebugString(L"handleOScMsg: Blob not implemented yet"); //TODO
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
OutputDebugString(L"handleOscMsg: Unknown datatype\r\n");
|
OutputDebugString(L"handleOscMsg: Unknown datatype\r\n");
|
||||||
@ -195,16 +250,10 @@ DLLEXPORT int handleOscMsg(const osc::ReceivedMessage& m)
|
|||||||
/* Debugging function to test messaging. Probably will be removed later. */
|
/* Debugging function to test messaging. Probably will be removed later. */
|
||||||
DLLEXPORT int testMsg(HWND windowHandle, unsigned int messageID)
|
DLLEXPORT int testMsg(HWND windowHandle, unsigned int messageID)
|
||||||
{
|
{
|
||||||
OutputDebugString(L"testMsg()\r\n");
|
float theFloat = 1.01;
|
||||||
if (!windowHandle)
|
int lParam = reinterpret_cast<int&>(theFloat);
|
||||||
{
|
|
||||||
OutputDebugString(L"testMsg: windowHandle!!\r\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PostMessage(windowHandle, messageID, 42, 43))
|
PostMessage(hwnd, 0x1002, 0, lParam); //post to message queue
|
||||||
return 0;
|
return reinterpret_cast<int&>(theFloat);
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,18 @@
|
|||||||
|
|
||||||
#define DLLEXPORT __declspec(dllexport)
|
#define DLLEXPORT __declspec(dllexport)
|
||||||
|
|
||||||
#define OSC_TYPE_NONE 0
|
#define OSC_TYPE_NONE 1
|
||||||
#define OSC_TYPE_INT 1
|
#define OSC_TYPE_INT 2
|
||||||
#define OSC_TYPE_FLOAT 2
|
#define OSC_TYPE_FLOAT 4
|
||||||
#define OSC_TYPE_STRING 3
|
#define OSC_TYPE_STRING 8
|
||||||
#define OSC_TYPE_ALL 255
|
#define OSC_TYPE_BLOB 16
|
||||||
|
#define OSC_TYPE_INT64 32
|
||||||
|
#define OSC_TYPE_FLOAT64 64
|
||||||
|
#define OSC_TYPE_BOOL 128
|
||||||
|
#define OSC_TYPE_CHAR 256
|
||||||
|
#define OSC_TYPE_TIMETAG 512
|
||||||
|
#define OSC_TYPE_COLOR 1024
|
||||||
|
#define OSC_TYPE_ALL UINT_MAX
|
||||||
|
|
||||||
extern "C" DLLEXPORT int open(HWND targetWindowHandle, unsigned int port);
|
extern "C" DLLEXPORT int open(HWND targetWindowHandle, unsigned int port);
|
||||||
extern "C" DLLEXPORT int close();
|
extern "C" DLLEXPORT int close();
|
||||||
@ -18,3 +25,5 @@ extern "C" DLLEXPORT int addListener(LPCSTR address, unsigned int messageID, uns
|
|||||||
extern "C" DLLEXPORT int removeListener(LPCSTR address);
|
extern "C" DLLEXPORT int removeListener(LPCSTR address);
|
||||||
extern "C" DLLEXPORT int handleOscMsg(const osc::ReceivedMessage & m);
|
extern "C" DLLEXPORT int handleOscMsg(const osc::ReceivedMessage & m);
|
||||||
extern "C" DLLEXPORT int testMsg(HWND windowHandle, unsigned int messageID);
|
extern "C" DLLEXPORT int testMsg(HWND windowHandle, unsigned int messageID);
|
||||||
|
bool isMatchingOscType(unsigned int msgType, unsigned int listenerTypeField);
|
||||||
|
unsigned int getOscType(osc::ReceivedMessage::const_iterator arg);
|
||||||
|
123
msgtest.ahk
123
msgtest.ahk
@ -4,82 +4,89 @@ SetWorkingDir, %A_ScriptDir%
|
|||||||
Gui +LastFound
|
Gui +LastFound
|
||||||
hWnd := WinExist()
|
hWnd := WinExist()
|
||||||
|
|
||||||
|
; OSC datatypes. Just for better readability,
|
||||||
|
; you also just could use the numbers
|
||||||
|
global oscTypeNone := 1
|
||||||
|
global oscTypeInt := 2
|
||||||
|
global oscTypeFloat := 4
|
||||||
|
global oscTypeAll := 0xffffffff
|
||||||
|
|
||||||
stdout := FileOpen("tmp.log", "w")
|
stdout := FileOpen("tmp.log", "w")
|
||||||
stdout.WriteLine("START")
|
stdout.WriteLine("START")
|
||||||
|
|
||||||
retOnMsg := OnMessage(0x1000, "msghandler")
|
|
||||||
stdout.Write("OnMessage: ")
|
|
||||||
stdout.WriteLine(retOnMsg)
|
|
||||||
OnExit("exithandler")
|
OnExit("exithandler")
|
||||||
|
|
||||||
hModule := DllCall("LoadLibrary", "Str", "x64\Debug\OSC2AHK.dll", "Ptr") ; Avoids the need for DllCall() in the loop to load the library.
|
DllCall("LoadLibrary", "Str", "x64\Debug\OSC2AHK.dll", "Ptr")
|
||||||
stdout.Write("DLL handle: ")
|
; ret := DllCall("OSC2AHK.dll\testMsg", UInt,hWnd, UInt,0x1000, int)
|
||||||
stdout.WriteLine(hModule)
|
|
||||||
|
|
||||||
; ret := DllCall("OSC2AHK.dll\testMsg", UInt,hWnd, UInt,0x1000)
|
OnMessage(0x1002, "msghandlerFloat")
|
||||||
; stdout.WriteLine("DLL call:")
|
|
||||||
; stdout.WriteLine(ret)
|
|
||||||
|
|
||||||
ret3 := DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7002)
|
DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7002)
|
||||||
stdout.Write("DLL open: ")
|
|
||||||
stdout.WriteLine(ret3)
|
|
||||||
|
|
||||||
ret2 := DllCall("OSC2AHK.dll\addListener", AStr, "/test", UInt, 0x1001, UInt, 1)
|
DllCall("OSC2AHK.dll\addListener", AStr, "/test1", UInt, 0x1001, UInt, oscTypeInt)
|
||||||
retOnMsg := OnMessage(0x1001, "msghandler")
|
OnMessage(0x1001, "msghandlerInt")
|
||||||
stdout.Write("DLL addListener: ")
|
|
||||||
stdout.WriteLine(ret2)
|
|
||||||
|
|
||||||
;ret3 := DllCall("OSC2AHK.dll\close")
|
DllCall("OSC2AHK.dll\addListener", AStr, "/test2", UInt, 0x1002, UInt, oscTypeFloat)
|
||||||
;stdout.Write("DLL close: ")
|
OnMessage(0x1002, "msghandlerFloat")
|
||||||
;stdout.WriteLine(ret3)
|
|
||||||
|
|
||||||
; ret3 := DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7002)
|
DllCall("OSC2AHK.dll\addListener", AStr, "/test3", UInt, 0x1003, UInt, oscTypeInt+oscTypeFloat)
|
||||||
; stdout.Write("DLL open: ")
|
OnMessage(0x1003, "msghandlerTest3")
|
||||||
; stdout.WriteLine(ret3)
|
|
||||||
|
|
||||||
DllCall("OSC2AHK.dll\addListener", AStr, "/test2", UInt, 0x1001, UInt, 1)
|
|
||||||
DllCall("OSC2AHK.dll\addListener", AStr, "/test3", UInt, 0x1002, UInt, 255)
|
|
||||||
OnMessage(0x1002, "msghandlerfloat")
|
|
||||||
DllCall("OSC2AHK.dll\removeListener", AStr, "/test2")
|
|
||||||
; retOnMsg := OnMessage(0x1001, "msghandler")
|
|
||||||
; stdout.Write("DLL addListener: ")
|
|
||||||
; stdout.WriteLine(ret2)
|
|
||||||
|
|
||||||
stdout.Close()
|
stdout.Close()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
msghandler(wParam, lParam, msg, hwnd) {
|
msghandlerTest3(wParam, lParam, msg, hwnd) {
|
||||||
stdout := FileOpen("tmp.log", "a")
|
stdout := FileOpen("tmp.log", "a")
|
||||||
stdout.Write("Received MSG: ")
|
stdout.Write("Got /test3 with ")
|
||||||
|
if (wParam = oscTypeInt)
|
||||||
|
{
|
||||||
|
stdout.Write("Int")
|
||||||
|
stdout.Write(" ")
|
||||||
|
stdout.WriteLine(lParam)
|
||||||
|
}
|
||||||
|
if (wParam = oscTypeFloat)
|
||||||
|
{
|
||||||
|
stdout.Write("Float")
|
||||||
|
stdout.Write(" ")
|
||||||
|
; Retrieve float from the lParam
|
||||||
|
VarSetCapacity(buf, 8, 0)
|
||||||
|
NumPut(lParam, buf)
|
||||||
|
theFloat := NumGet(buf, "Float")
|
||||||
|
stdout.WriteLine(theFloat)
|
||||||
|
}
|
||||||
|
stdout.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
msghandlerInt(wParam, lParam, msg, hwnd) {
|
||||||
|
; Check if we actually got a Integer
|
||||||
|
if (wParam != 2)
|
||||||
|
return
|
||||||
|
|
||||||
|
; Log to the logfile
|
||||||
|
stdout := FileOpen("tmp.log", "a")
|
||||||
|
stdout.Write("Got Int: ")
|
||||||
stdout.Write(msg)
|
stdout.Write(msg)
|
||||||
stdout.write(" ")
|
stdout.Write(" ")
|
||||||
stdout.Write(wParam)
|
|
||||||
stdout.write(" ")
|
|
||||||
stdout.WriteLine(lParam)
|
stdout.WriteLine(lParam)
|
||||||
stdout.Close()
|
stdout.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
msghandlerfloat(wParam, lParam, msg, hwnd) {
|
msghandlerFloat(wParam, lParam, msg, hwnd) {
|
||||||
|
; Check if we actually got a float
|
||||||
|
if (wParam != 4)
|
||||||
|
return
|
||||||
|
|
||||||
|
; Retrieve float from the lParam
|
||||||
|
VarSetCapacity(buf, 8, 0)
|
||||||
|
NumPut(lParam, buf)
|
||||||
|
theFloat := NumGet(buf, "Float")
|
||||||
|
|
||||||
|
; Log to the logfile
|
||||||
stdout := FileOpen("tmp.log", "a")
|
stdout := FileOpen("tmp.log", "a")
|
||||||
thefloat := NumGet(lParam, 0, "Float")
|
stdout.Write("Got Float: ")
|
||||||
stdout.WriteLine(thefloat)
|
stdout.Write(msg)
|
||||||
thefloat := NumGet(lParam, 1, "Float")
|
stdout.Write(" ")
|
||||||
stdout.WriteLine(thefloat)
|
stdout.WriteLine(theFloat)
|
||||||
thefloat := NumGet(lParam, 2, "Float")
|
stdout.Close()
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
thefloat := NumGet(lParam, 3, "Float")
|
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
thefloat := NumGet(lParam, 4, "Float")
|
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
thefloat := NumGet(lParam, 5, "Float")
|
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
thefloat := NumGet(lParam, 6, "Float")
|
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
thefloat := NumGet(lParam, 7, "Float")
|
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
thefloat := NumGet(lParam, 8, "Float")
|
|
||||||
stdout.WriteLine(thefloat)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exithandler() {
|
exithandler() {
|
||||||
@ -89,7 +96,7 @@ exithandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do_exit:
|
do_exit:
|
||||||
ExitApp
|
ExitApp
|
||||||
return ; unnecessary redundancy?
|
return
|
||||||
|
|
||||||
Esc::GoSub, do_exit
|
Esc::GoSub, do_exit
|
Loading…
x
Reference in New Issue
Block a user