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
* Documentation could be improved (sending functions)
## Table of contents
- [OSC2AHK](#osc2ahk)
- [Work in progress](#work-in-progress)
- [Table of contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [General concept](#general-concept)
- [Receive functions](#receive-functions)
- [Load DLL](#load-dll)
- [Open network port](#open-network-port)
- [Close network port](#close-network-port)
- [Add listener](#add-listener)
- [Remove listener](#remove-listener)
- [Get string data](#get-string-data)
- [Send functions](#send-functions)
- [Send integer message](#send-integer-message)
- [Send float message](#send-float-message)
- [Send string message](#send-string-message)
- [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
After the DLL is loaded and a network port is opened with the [`open()`](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK#open-network-port) function, it receives all incoming OSC messages. To specify the messages that should be passed to the AutoHotkey (AHK) script, "listeners" are specified and created by the ['addListener()'](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK#add-listener) function. When a OSC message is received that matches a existing listener, a "system message" is sent to the AHK script. This happens via the Windows message queue and the system message ID is used to tell the script which OSC address was received. Therefore with [`addListener()`](https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK#add-listener) a ID has to be passed to the DLL which then uses this ID to post the system message.
### Functions
### Receive functions
These functions are the main functions used to receive OSC messages in AHK.
#### Load DLL
First the DLL should be loaded from within the AHK script by calling
Note that you may add many listeners, for any combination of the same/different OSC addresses, datatypes and system message IDs. Also, in AutoHotkey you may add multiple callback functions for the same system message ID or multiple system message IDs to the same callback function. This creates a big flexibility but to keep it less clutterd, such multiple routing paths should be avoided where possible.
For advanced usage, the address pattern passed to `addListener()` supports standard OSC wildcards, so one listener can match multiple messages that share some simliarities. These wildcards are supported by the OSC 1.0 standard:
> * '?' in the OSC Address Pattern matches any single character
> * '*' in the OSC Address Pattern matches any sequence of zero or more characters
> * A string of characters in square brackets (e.g., "[string]") in the OSC Address Pattern matches any character in the string. Inside square brackets, the minus sign (-) and exclamation point (!) have special meanings:
> * two characters separated by a minus sign indicate the range of characters between the given two in ASCII collating sequence. (A minus sign at the end of the string has no special meaning.)
> * An exclamation point at the beginning of a bracketed string negates the sense of the list, meaning that the list matches any character not in the list. (An exclamation point anywhere besides the first character after the open bracket has no special meaning.)
> * A comma-separated list of strings enclosed in curly braces (e.g., "{foo,bar}") in the OSC Address Pattern matches any of the strings in the list.
> * Any other character in an OSC Address Pattern can match only the same character.
>
> -- <cite>[http://opensoundcontrol.org/]</cite>
#### Remove listener
Of course, listeners also can be removed in a similar way:
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);