Page 1 of 3

OSC integration DLL

Posted: 21 Apr 2021, 08:00
by nyquist
I've written a library to integrate OSC (Open Sound Control) messages in Autohotkey.
It can receive and transmit OSC messages, including support for OSC wildcards, integer, float and (somehow) string payloads.
You can get the DLL, documentation and some examples here:https://files.eleton-audio.de/gitea/Ludwig/OSC2AHK (@mods: feel free to repair the link, nothing dangerous over there ;-) - Thanks!)

Disclaimer: I am not an experienced AHK user but was convinced to do this, so maybe it is not perfect in every way :D
Also this is not necessarily totally finished yet, feedback is welcome!

A short usage example on receiving OSC messages:

Code: Select all

#NoEnv
; #Warn
SendMode Input
SetWorkingDir %A_ScriptDir%  ; Until here, this is the default script template
; Get handle to this running script instance
Gui +LastFound
hWnd := WinExist()

; just for convenience, you also could use the "magic numbers" directly
global oscTypeNone := 1
global oscTypeInt := 2
global oscTypeFloat := 4
global oscTypeString := 8
global oscTypeAll := 0xffffffff

; Load DLL and open network port for OSC (7001)
DllCall("LoadLibrary", "Str", "OSC2AHK.dll", "Ptr")
DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7001)

; Tell the DLL to post a system message with ID 0x1001 when a OSC message with address "/test1" and type Integer or Float is received.
DllCall("OSC2AHK.dll\addListener", AStr, "/test1", UInt, 0x1001, UInt, oscTypeInt+oscTypeFloat)
; Tell AHK to invoke the function msghandlerTest1 when a windows message with ID 0x1001 is received
OnMessage(0x1001, "msghandlerTest1")

; This function effectively is called for each OSC message as specified above
msghandlerTest1(oscType, data, msgID, hwnd) 
{
    ; Check which datatype we received (above we accepted Float and Int)
    if (oscType = oscTypeInt) 
    {
        ; Integers can be used "as is"
        msgbox,Got Integer: %data%
    }
    if (oscType = oscTypeFloat) 
    {
        ; Floats have to be "reinterpreted"
        VarSetCapacity(buf, 4, 0)
        NumPut(data, buf)
        theFloat := NumGet(buf, "Float")

        msgbox,Got Float: %theFloat%
    }
}

; Shutdown the script with Shift+ESC
+Esc::
ExitApp

Re: OSC integration DLL

Posted: 21 Apr 2021, 09:13
by iseahound
Hi! Could you explain what Open Sound Control does? I see it integrates with Max... but it's better than MIDI? Could you share a video of your setup + demo? Curious to see how AHK integrates with a music production environment.

Re: OSC integration DLL

Posted: 21 Apr 2021, 09:53
by nyquist
Hi!

Well, I like to title OSC as a "modern alternative" to MIDI. Main differences are that OSC is network based and that there is no real standard which message means what. OSC is just very flexible and allows you to send a lot more data between many devices/software over a standard network (LAN/WLAN).

As said, it is not specified what a message "means", a OSC message just contains an "address" (for example "/channel/1/volume") and some payload (for example "0.5") but how these look is up to the software that sends/receives these messages and often is user configurable.
There are several software controllers out there that you can use to generate for example a touchscreen interface, TouchOSC and OpenStageControl are just two examples.
On the other side, your application has to support OSC too. I haven't used Max (MSP?) but a little bit of PureData where you can basically do whatever you want with OSC. For example you could send out control messages to make something react to your music (beat, volume, whatever) or receive messages and control, lets's say an oscillator.

I don't really have an Autohotkey setup that I can share - as said I don't use it much (yet?). I use OSC mainly to control Reaper and RME Totalmix from a tablet with TouchOSC, but I also have done bigger stuff where lighting consoles and -software were tightly integrated. This would have been a real pain with MIDI... Also I use a lot of OSC for connecting Reaper to big Lawo mixing consoles and also a VST plugin server.

Hopefully that's a useful answer to your question and gives you an idea of what is possible ;-)

Re: OSC integration DLL

Posted: 22 Apr 2021, 14:38
by foxdanger
I'm very intersted in your project. My project use a mapping system that now can use OSC. So this can be a life changer to me. Just need to understand better how this works.

As far I could understand, the mapping software will send a OSC message with a value to my software on AHK and I can use that as a trigger? THis will be AMAZING.

I'm trying here and on my software I have this:

https://ibb.co/PNRK37Q

So, I run the simple_example.ahk and than I run my controller... When I press the button, it should recognize it??? Because nothing happened :/

What I should do?

Re: OSC integration DLL

Posted: 23 Apr 2021, 03:32
by nyquist
foxdanger wrote: As far I could understand, the mapping software will send a OSC message with a value to my software on AHK and I can use that as a trigger? THis will be AMAZING.
Yes, that's how it should work. You can receive OSC messages with your AHK script and then do "whatever you want" in AHK. The OSC message contains (simplified) an "address" and a "payload value".

foxdanger wrote: I'm trying here and on my software I have this:

https ibb.co /PNRK37Q Broken Link for safety

So, I run the simple_example.ahk and than I run my controller... When I press the button, it should recognize it??? Because nothing happened :/
The first error I see is, that you typed "/teste1", but the simple_example only listens for "/test1", that's why nothing happens.

The rest looks good, but you also have to tell your software (what exactly is it?) to which IP to send the OSC messages, can't see that on the screenshot. If both programs are on the same PC, use 127.0.0.1 which is the "loopback" address, if not, use the IP address of the other PC.

In my screenshot you can see the settings I used for testing the simple_example.

Re: OSC integration DLL

Posted: 23 Apr 2021, 09:23
by foxdanger
Thx for your answer.

The software for now is your example. I got your example and I'm trying to send the message from the Tangent Mapper to your simple_example.ahk.

If it works, I'll put it on my software :D

Re: OSC integration DLL

Posted: 23 Apr 2021, 09:30
by foxdanger

Code: Select all

#NoEnv
; #Warn
SendMode Input
SetWorkingDir %A_ScriptDir%  ; Until here, this is the default script template
; Get handle to this running script instance
;Gui +LastFound
Gui, Color, Black
Gui, +AlwaysOnTop -Caption +ToolWindow
Gui, Show, x100 y100 w200 h75
hWnd := WinExist()

; just for convenience, you also could use the "magic numbers" directly
global oscTypeNone := 1
global oscTypeInt := 2
global oscTypeFloat := 4
global oscTypeString := 8
global oscTypeAll := 0xffffffff

; Load DLL and open network port for OSC (7001)
DllCall("LoadLibrary", "Str", "OSC2AHK.dll", "Ptr")
DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7001)

; Tell the DLL to post a system message with ID 0x1001 when a OSC message with address "/test1" and type string is received.
DllCall("OSC2AHK.dll\addListener", AStr, "/test1", UInt, 0x1001, UInt, oscTypeString)
; Tell AHK to invoke the function msghandlerTest1 when a windows message with ID 0x1001 is received
OnMessage(0x1001, "msghandlerTest1")

; This function effectively is called for each OSC message as specified above
msghandlerTest1(oscType, data, msgID, hwnd) 
{
    ; Check that we really received a string message (kind of redundant for this example)
    if (oscType = oscTypeString) 
    {
        ; String cannot be passed via system messages,
        ; so the string is buffered in the DLL and we only get a unique identifier in the "data" variable.
        ; To get the actual string, we use the getStringData() DLL-call

        VarSetCapacity(theString, 20) ; prepare variable to store string in with sufficient size
        theString := DllCall("OSC2AHK.dll\getStringData", str, theString, UInt, 20, UInt, data, AStr)

        msgbox,Got string: %theString%
    }
}

; Shutdown the script with Shift+ESC
+Esc::
ExitApp
And here the image of Tangent Mapper

https://ibb.co/ngDTKC6



Then I run the script, press the button and nothing happens.

Re: OSC integration DLL

Posted: 23 Apr 2021, 09:34
by foxdanger
Tangent Mapper doesn't has a field to put the IP, so I assume that is 127... as default.

Re: OSC integration DLL

Posted: 23 Apr 2021, 09:41
by foxdanger
Using the TCPView the port 7001 doesn't appear as opened when I run the script.

Re: OSC integration DLL

Posted: 23 Apr 2021, 09:42
by foxdanger
As you can see on attach image, the tangent hub use these ports on tcpview... I don't know if I should use them instead 7001.

Re: OSC integration DLL

Posted: 23 Apr 2021, 09:56
by foxdanger
I tried it on my code too, using a simple msg just to check if everything is working and I do not got the msgbox with "door open"

Code: Select all

;Add the start controller button
Gui Add, Button, x10 y10 w1110 h30 gStartButton, Start DR Tangent Wave Booster

;Add each button for config each tools position on the screen
For index, object in _positionsArray {
    name := object.name
    varName := object.var
    Gui Add, Button, x%_counterButtonX% y%_counterButtonY% w130 h30 v%varName% gGenericButton, %name%
    
    _counterButtonY := _counterButtonY + 30
    if (index == 30){
        _counterButtonY := _startPositionButtonsY
        _counterButtonX := _counterButtonX + 140
    }Else if (index == 60 or index == 90 or index == 120 or index == 150 or index == 180 or index == 210){
        _counterButtonY := _startPositionButtonsY
        _counterButtonX := _counterButtonX + 140
    }
}

Gui Add, Button, x10 y980 w1110 h30 gSaveFileButton, Save new positions
    
Gui Show, w1130 h1020, Tangent Wave Booster Ver. 1.3 Beta
return

Gui +LastFound
hWnd := WinExist()

GuiEscape:
GuiClose:
    ExitApp

DllCall("LoadLibrary", "Str", "OSC2AHK.dll", "Ptr")
success := DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7001)
if (success == 0)
    msgbox, DOOR IS OPEN!

Re: OSC integration DLL

Posted: 23 Apr 2021, 11:14
by nyquist
This looks like port 7001 for some reason cannot be opened at your system. I can't run your code (something about "label does not exist"), but I have some suggestions:

  • Try using a different port, maybe some other application is already using it? Are you sure "Tangent Mapper" is not listening on this port?
  • Make sure your firewall does not block something here, maybe (being offline) disable it temporarily and try again!
  • Make sure you placed the DLL in the same directory as your script.
This gives a "port opened" for me:

Code: Select all

Gui +LastFound
hWnd := WinExist()

success1 :=DllCall("LoadLibrary", "Str", "OSC2AHK.dll", "Ptr")
success2 := DllCall("OSC2AHK.dll\open", UInt, hWnd, UInt, 7001)
if (success1 == 0)
    msgbox, couldnt load DLL!
if (success2 == 0)
    msgbox, port opened!
else
    msgbox, couldnt open port!

Re: OSC integration DLL

Posted: 23 Apr 2021, 12:33
by foxdanger
This is just a piece of my code, that's why u can't run.

I'll see what is happening and how to make all this work :D

Re: OSC integration DLL

Posted: 25 Apr 2021, 01:21
by Ved
osc function ok alll

one question, possibility of receive all messages? or comodin messages? in one function/onmessage(DllCall/addListener)

examples:

normal monitor simplemessage;;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/name",UInt,0x1036,UInt,oscTypeAll)

my question;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/*****",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/******",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"all",UInt,0x1036,UInt,oscTypeAll)

alternatives?


UPDATE:
okey read the electon source info,,,

the wilcards "?" and "*" not work

the option [string] chrash ahk script

Re: OSC integration DLL

Posted: 25 Apr 2021, 02:18
by Ved
okey read the electon source info,,,

the wilcards "?" and "*" not work

the option [string] chrash ahk script

Re: OSC integration DLL

Posted: 27 Apr 2021, 10:27
by foxdanger
Ved wrote:
25 Apr 2021, 01:21
osc function ok alll

one question, possibility of receive all messages? or comodin messages? in one function/onmessage(DllCall/addListener)

examples:

normal monitor simplemessage;;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/name",UInt,0x1036,UInt,oscTypeAll)

my question;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/*****",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/******",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"all",UInt,0x1036,UInt,oscTypeAll)

alternatives?


UPDATE:
okey read the electon source info,,,

the wilcards "?" and "*" not work

the option [string] chrash ahk script
Can you send me a private message in facebook or anywhere else to help me how you did to make your software listen the OSC commands?

Re: OSC integration DLL

Posted: 28 Apr 2021, 05:39
by Ved
foxdanger wrote:
27 Apr 2021, 10:27
Ved wrote:
25 Apr 2021, 01:21
osc function ok alll

one question, possibility of receive all messages? or comodin messages? in one function/onmessage(DllCall/addListener)

examples:

normal monitor simplemessage;;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/name",UInt,0x1036,UInt,oscTypeAll)

my question;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/*****",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/******",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"all",UInt,0x1036,UInt,oscTypeAll)

alternatives?


UPDATE:
okey read the electon source info,,,

the wilcards "?" and "*" not work

the option [string] chrash ahk script
Can you send me a private message in facebook or anywhere else to help me how you did to make your software listen the OSC commands?
sorry im not used twitter,facebook or any another censorship comunist app or web.

explain here your problem for helping

Re: OSC integration DLL

Posted: 28 Apr 2021, 13:23
by foxdanger
Ved wrote:
28 Apr 2021, 05:39
foxdanger wrote:
27 Apr 2021, 10:27
Ved wrote:
25 Apr 2021, 01:21
osc function ok alll

one question, possibility of receive all messages? or comodin messages? in one function/onmessage(DllCall/addListener)

examples:

normal monitor simplemessage;;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/name",UInt,0x1036,UInt,oscTypeAll)

my question;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/*****",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/******",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"all",UInt,0x1036,UInt,oscTypeAll)

alternatives?


UPDATE:
okey read the electon source info,,,

the wilcards "?" and "*" not work

the option [string] chrash ahk script
Can you send me a private message in facebook or anywhere else to help me how you did to make your software listen the OSC commands?
sorry im not used twitter,facebook or any another censorship comunist app or web.

explain here your problem for helping

The software of I'm using send OSC through 127.0.0.1 and any port that I want... And I got this DLL and run their example scripts, and none of them could listen the commands... Tried different ports and nothing... :/

Re: OSC integration DLL

Posted: 28 Apr 2021, 13:42
by Ved
foxdanger wrote:
28 Apr 2021, 13:23
Ved wrote:
28 Apr 2021, 05:39
foxdanger wrote:
27 Apr 2021, 10:27
Ved wrote:
25 Apr 2021, 01:21
osc function ok alll

one question, possibility of receive all messages? or comodin messages? in one function/onmessage(DllCall/addListener)

examples:

normal monitor simplemessage;;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/name",UInt,0x1036,UInt,oscTypeAll)

my question;;;
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/*****",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/******",UInt,0x1036,UInt,oscTypeAll)
or
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"all",UInt,0x1036,UInt,oscTypeAll)

alternatives?


UPDATE:
okey read the electon source info,,,

the wilcards "?" and "*" not work

the option [string] chrash ahk script
Can you send me a private message in facebook or anywhere else to help me how you did to make your software listen the OSC commands?
sorry im not used twitter,facebook or any another censorship comunist app or web.

explain here your problem for helping

The software of I'm using send OSC through 127.0.0.1 and any port that I want... And I got this DLL and run their example scripts, and none of them could listen the commands... Tried different ports and nothing... :/
okey

are you config the message test "name" receive?
DllCall("C:\Users\vv\Desktop\osc2ahk\OSC2AHK.dll\addListener",AStr,"/lastmarker/name",UInt,0x1036,UInt,oscTypeAll)
this ==== "/lastmarker/name" === part

Re: OSC integration DLL

Posted: 28 Apr 2021, 13:47
by gregster
Guys, please use quotes only when it makes sense. Quote selectively, if there is context, and please don't replicate half of the topic in each quote. Thank you!
(Scrolling through this (not only on a mobile device) can get really annoying.)

btw, instead of quoting someone it is also possible to just mention them... see the @ button.