7 Commits
0.3 ... master

5 changed files with 111 additions and 19 deletions
Split View
  1. +4
    -4
      OSC2AHK/OSC2AHK.rc
  2. +60
    -4
      OSC2AHK/dllmain.cpp
  3. +3
    -0
      OSC2AHK/dllmain.h
  4. +5
    -6
      README.md
  5. +39
    -5
      msgtest.ahk

+ 4
- 4
OSC2AHK/OSC2AHK.rc View File

@ -51,8 +51,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,3,0,0
PRODUCTVERSION 0,3,0,0
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Eleton Audio"
VALUE "FileDescription", "AutoHotkey OSC integration"
VALUE "FileVersion", "0.3.0.0"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "OSC2AHK.dll"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "OSC2AHK.dll"
VALUE "ProductName", "OSC2AHK"
VALUE "ProductVersion", "0.3.0.0"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"


+ 60
- 4
OSC2AHK/dllmain.cpp View File

@ -22,6 +22,7 @@ protected:
handleOscMsg(m);
}
catch (osc::Exception& e) {
(void)e;
// any parsing errors such as unexpected argument types, or
// missing arguments get thrown as exceptions.
OutputDebugString(L"ProcessMessage: Error while parsing message: ...");
@ -84,12 +85,16 @@ BOOL APIENTRY DllMain( HMODULE hModule,
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
OutputDebugString(L"DLL_PROCESS_ATTACH\r\n");
break;
case DLL_THREAD_ATTACH:
OutputDebugString(L"DLL_THREAD_ATTACH\r\n");
break;
case DLL_THREAD_DETACH:
OutputDebugString(L"DLL_THREAD_DETACH\r\n");
break;
case DLL_PROCESS_DETACH:
OutputDebugString(L"DLL_THREAD_DETACH\r\n");
close();
break;
}
@ -104,6 +109,20 @@ DLLEXPORT int open(HWND targetWindowHandle, unsigned int port)
if (!port) OutputDebugString(L"open: port!!\r\n");
return 1;
}
//Check if sock is currently free to use
if (sock)
{
if (sock->IsBound()) //Sock is currently opened. User should call close() first!
{
OutputDebugString(L"open: seems to be opened already!\r\n");
return 3;
}
else //Probably something went wrong in UDP socket, just try closing and reopening it...
{
close(0);
}
}
unsigned int timeout = 500; //timout for port opening, in ms
@ -133,7 +152,9 @@ DLLEXPORT int close(unsigned int clearListeners)
{
sock->AsynchronousBreak();
}
oscThread->join();
if(oscThread) oscThread->join();
delete sock;
sock = nullptr;
oscThread = NULL;
hwnd = NULL;
if (clearListeners) listeners.clear();
@ -143,10 +164,15 @@ DLLEXPORT int close(unsigned int clearListeners)
DLLEXPORT int addListener(LPCSTR address_, unsigned int messageID_, unsigned int dataType_)
{
std::string addrStr(address_);
//All OSC addresses have to start with a '/'
if (addrStr[0] != '/') addrStr.insert(0, "/");
OutputDebugString(L"addListener: address=");
OutputDebugStringA(address_);
OutputDebugStringA(addrStr.c_str());
OutputDebugString(L"\r\n");
listeners.push_back(Listener{ std::string(address_), dataType_, messageID_ });
listeners.push_back(Listener{ addrStr, dataType_, messageID_ });
return 0;
}
@ -198,6 +224,16 @@ DLLEXPORT void sendOscMessageInt(char* ip, unsigned int port, char* address, int
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageInt2(char* ip, unsigned int port, char* address, int payload1, int payload2)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
char buffer[1024];
osc::OutboundPacketStream p(buffer, 1024);
p << osc::BeginMessage(address) << payload1 << payload2 << osc::EndMessage;
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageFloat(char* ip, unsigned int port, char* address, float payload)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
@ -208,6 +244,16 @@ DLLEXPORT void sendOscMessageFloat(char* ip, unsigned int port, char* address, f
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageFloat2(char* ip, unsigned int port, char* address, float payload1, float payload2)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
char buffer[1024];
osc::OutboundPacketStream p(buffer, 1024);
p << osc::BeginMessage(address) << payload1 << payload2 << osc::EndMessage;
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageString(char* ip, unsigned int port, char* address, char* payload)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
@ -218,6 +264,16 @@ DLLEXPORT void sendOscMessageString(char* ip, unsigned int port, char* address,
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageString2(char* ip, unsigned int port, char* address, char* payload1, char* payload2)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
char buffer[1024];
osc::OutboundPacketStream p(buffer, 1024);
p << osc::BeginMessage(address) << payload1 << payload2 << osc::EndMessage;
transmitSocket.Send(p.Data(), p.Size());
}
void removeStoredString(int stringId)
{
for (UINT i = 0; i < storedStrings.size(); i++)
@ -497,7 +553,7 @@ int handleOscMsg(const osc::ReceivedMessage& m)
/* Debugging function to test messaging. Probably will be removed later. */
DLLEXPORT int testMsg(HWND windowHandle, unsigned int messageID)
{
float theFloat = 1.01;
float theFloat = (float)1.01;
int lParam = reinterpret_cast<int&>(theFloat);
PostMessage(hwnd, 0x1002, 0, lParam); //post to message queue


+ 3
- 0
OSC2AHK/dllmain.h View File

@ -25,8 +25,11 @@ extern "C" DLLEXPORT int addListener(LPCSTR address, unsigned int messageID, uns
extern "C" DLLEXPORT int removeListener(LPCSTR address);
extern "C" DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsigned int StringID);
extern "C" DLLEXPORT void sendOscMessageInt(char* ip, unsigned int port, char* address, int payload);
extern "C" DLLEXPORT void sendOscMessageInt2(char* ip, unsigned int port, char* address, int payload1, int payload2);
extern "C" DLLEXPORT void sendOscMessageFloat(char* ip, unsigned int port, char* address, float payload);
extern "C" DLLEXPORT void sendOscMessageFloat2(char* ip, unsigned int port, char* address, float payload1, float payload2);
extern "C" DLLEXPORT void sendOscMessageString(char* ip, unsigned int port, char* address, char* payload);
extern "C" DLLEXPORT void sendOscMessageString2(char* ip, unsigned int port, char* address, char* payload1, char* payload2);
int handleOscMsg(const osc::ReceivedMessage& m);
bool isMatchingOscType(unsigned int msgType, unsigned int listenerTypeField);
bool isMatchingOSCAddress(const char* address, const char* pattern);


+ 5
- 6
README.md View File

@ -2,10 +2,6 @@
This is a DLL extension for [AutoHotkey](https://www.autohotkey.com/) that enables support for OSC (Open Sound Control).
## Work in progress
While most functions should already work as intended, there may still be some bugs. If you encounter some possibly wrong behaviour, please let us know!
* OSC address wildcards are supported now but probably need some testing
## Table of contents
- [OSC2AHK](#osc2ahk)
@ -28,7 +24,7 @@ While most functions should already work as intended, there may still be some bu
- [Credits](#credits)
## Installation
Just download the latest version of OSC2AHK.dll from the [releases page](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK/releases) and place it in the same directory as your AutoHotkey scripts. Maybe you also want to check out the provided [usage examples](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK/src/branch/master/examples).
Just download the latest version of OSC2AHK.dll from the [releases page](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK/releases) and place it in the same directory as your AutoHotkey scripts. The DLL provided in the Releases section at the moment only works on 64 bit systems, Windows 10 or Windows 11. Other systems are not supported right now. Maybe you also want to check out the provided [usage examples](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK/src/branch/master/examples).
## Usage
### General concept
@ -167,11 +163,12 @@ msghandlerString(oscType, data, msgID, hwnd)
```
### Send functions
The DLL also can be used to transmit OSC messages from AutoHotkey by using the following functions:
The DLL also can be used to transmit OSC messages from AutoHotkey by using the following functions. Usually there is only one argument (payload) per message, but the functions ending in "...2" allow the sending of two arguments in one message. Only two arguments of the same type are supported at the moment.
#### Send integer message
```cpp
void sendOscMessageInt(char* ip, unsigned int port, char* address, int payload);
void sendOscMessageInt2(char* ip, unsigned int port, char* address, int payload1, int payload2);
```
Example call from AHK:
```
@ -185,6 +182,7 @@ DllCall("OSC2AHK.dll\sendOscMessageInt", AStr, ip, UInt, port, AStr, addr, Int,
#### Send float message
```cpp
void sendOscMessageFloat(char* ip, unsigned int port, char* address, float payload);
void sendOscMessageFloat2(char* ip, unsigned int port, char* address, float payload1, float payload2);
```
Example call from AHK:
```
@ -198,6 +196,7 @@ DllCall("OSC2AHK.dll\sendOscMessageFloat", AStr, ip, UInt, port, AStr, addr, Flo
#### Send string message
```cpp
void sendOscMessageString(char* ip, unsigned int port, char* address, char* payload);
void sendOscMessageString2(char* ip, unsigned int port, char* address, char* payload1, char* payload2);
```
Example call from AHK:
```


+ 39
- 5
msgtest.ahk View File

@ -21,7 +21,9 @@ DllCall("LoadLibrary", "Str", "x64\Debug\OSC2AHK.dll", "Ptr")
OnMessage(0x1002, "msghandlerFloat")
DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7002)
success := DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7003)
if (success != 0)
msgbox, Failed to open port!
DllCall("OSC2AHK.dll\addListener", AStr, "/test1", UInt, 0x1001, UInt, oscTypeInt)
OnMessage(0x1001, "msghandlerInt")
@ -122,10 +124,42 @@ do_exit:
Esc::
ExitApp
^a::
VarSetCapacity(theStr, 10)
theStr := DllCall("OSC2AHK.dll\getStringData", AStr, theStr, UInt, 10, UInt, 0, "Cdecl AStr")
msgbox,%theStr%
+a::
;ret := DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7002)
;MsgBox, %ret%
ip := "127.0.0.1"
port := 8002
addr := "/testmsg"
data := 42
data2 := 43
DllCall("OSC2AHK.dll\sendOscMessageInt", AStr, ip, UInt, port, AStr, addr, Int, data)
return
+s::
ip := "127.0.0.1"
port := 8002
addr := "/float/msg"
data := 42.3
data2 := 54.4
DllCall("OSC2AHK.dll\sendOscMessageFloat2", AStr, ip, UInt, port, AStr, addr, Float, data, Float, data2)
return
+d::
ip := "127.0.0.1"
port := 8002
addr := "/msg/string"
data := "This is the string"
data2:= "Second string"
DllCall("OSC2AHK.dll\sendOscMessageString2", AStr, ip, UInt, port, AStr, addr, AStr, data, AStr, data2)
return
+f::
ip := "127.0.0.1"
port := 8002
addr := "/msg/string"
data := "This is the string"
DllCall("OSC2AHK.dll\sendOscMessageString", AStr, ip, UInt, port, AStr, addr, AStr, data)
return
; DllCall("OSC2AHK.dll\close", UInt, 0)
;msgbox,esc
; DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7001)

Loading…
Cancel
Save