OSC integration DLL

Post your working scripts, libraries and tools for AHK v1.1 and older
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: OSC integration DLL

29 Apr 2021, 14:00

@Ved

On the picture attached you can see the code and the software configuration.

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) 
{
    msgbox ta aqui
    
    ; 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
Attachments
Screenshot 2021-04-29 155851.png
Screenshot 2021-04-29 155851.png (616.63 KiB) Viewed 3342 times
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: OSC integration DLL

29 Apr 2021, 14:01

WOW! IT WORKED NOW! I DON'T KNOW WHY! BUT IT WORKED!!!!
Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: OSC integration DLL

29 Apr 2021, 18:20

@foxdanger
XD congratulations
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: OSC integration DLL

01 May 2021, 15:29

Ved wrote: @foxdanger
XD congratulations
Thank you for this DLL <3
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

05 May 2021, 11:05

Oh, seems I didn't get any notifications for your posts - sorry for my absence.

@foxdanger
Glad to hear it works now!

@Ved
Ved wrote:
25 Apr 2021, 02:18
the wilcards "?" and "*" not work

the option [string] chrash ahk script
Do you still have these problems?
OSC wildcards are not tested a lot but the basics are working for me. Could you share your script and also post the OSC message(s) that should be received?
Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: OSC integration DLL

05 May 2021, 15:59

@nyquist
yes,the problems of wilcards still?

monitoring all osc mensages its the goal,,,
DllCall("OSC2AHK.dll\addListener", AStr, "/*", UInt, 0x1001, UInt, oscTypeall)
DllCall("OSC2AHK.dll\addListener", AStr, "*", UInt, 0x1001, UInt, oscTypeall)
DllCall("OSC2AHK.dll\addListener", AStr, "/?", UInt, 0x1001, UInt, oscTypeall)
DllCall("OSC2AHK.dll\addListener", AStr, "?", UInt, 0x1001, UInt, oscTypeall)

increase the varsetcapacity but dont work
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

06 May 2021, 02:54

Ah, I see the problem. According to the OSC standard, every OSC address must start with a "/".
So these lines are not valid:
Ved wrote: DllCall("OSC2AHK.dll\addListener", AStr, "*", UInt, 0x1001, UInt, oscTypeall)
[...]
DllCall("OSC2AHK.dll\addListener", AStr, "?", UInt, 0x1001, UInt, oscTypeall)
I should probably handle this error in the DLL and automatically add a / to the beginning if none is present.

Another note: Purely with wildcards you cannot listen to all addresses. According to the OSC standard, /* matches /something but not /something/else, the forward slash splits the address pattern.
To listen to many messages (all messages up to a known section count), you could do something like this:

Code: Select all

DllCall("OSC2AHK.dll\addListener", AStr, "/*", UInt, 0x1001, UInt, oscTypeall)
DllCall("OSC2AHK.dll\addListener", AStr, "/*/*", UInt, 0x1001, UInt, oscTypeall)
DllCall("OSC2AHK.dll\addListener", AStr, "/*/*/*", UInt, 0x1001, UInt, oscTypeall)
DllCall("OSC2AHK.dll\addListener", AStr, "/*/*/*/*", UInt, 0x1001, UInt, oscTypeall)
[...]
Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: OSC integration DLL

06 May 2021, 16:49

okey,,test and report
Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: OSC integration DLL

07 May 2021, 08:10

@nyquist
work fine the last examples.

Dll incorpore functions for GetStringAddress,or GetStringName?
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

07 May 2021, 08:26

Happy to hear that!

What should GetStringAddress and GetStringName do?
Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: OSC integration DLL

07 May 2021, 13:27

posibility of get addres name listened?

Image

[Mod edit: Image link fixed.]
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

09 May 2021, 11:45

Hm, with the current concept, this is not possible.
When a OSC message is received, the callback function in your AHK script (specified in OnMessage()) gets the contained datatype and value but no "ID" or something that you could use to get the address of this specific message. We also cannot just add an ID to this callback as the Windows message queue only supports two parameters which are already in use for datatype and value. That means, there is no way to specify the message for which you want to get the address.

The idea behind this concept was that the user specifies the addresses that should be received and gives them numbers. This is done with the addListener() function and the messageID parameter. So for example you could do something like this:

Code: Select all

DllCall("OSC2AHK.dll\addListener", AStr, "/volumeUp", UInt, 0x1001, UInt, oscTypeFloat)
OnMessage(0x1001, "msghandlerVolumeUp")
DllCall("OSC2AHK.dll\addListener", AStr, "/volumeDown", UInt, 0x1002, UInt, oscTypeFloat)
OnMessage(0x1002, "msghandlerVolumeDown")

msghandlerVolumeUp(oscType, data, msgID, hwnd) 
{
    ; Now we know for sure, we got a OSC message with address "/volumeUp"
}

msghandlerVolumeDown(oscType, data, msgID, hwnd) 
{
    ; Now we know for sure, we got a OSC message with address "/volumeDown"
}

This way might need more code to write but also takes away processing load from the AHK script and reduces the needed memory, as otherwise we would have to buffer every single OSC message in the DLL and then ask the DLL for address, type and value afterwards. Lots of DllCalls would be the consequences.
Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: OSC integration DLL

11 May 2021, 16:22

@nyquist
ok, thanks for your work nyquist, we will take advantage of it with gratitude, greetings
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: OSC integration DLL

16 Jun 2021, 12:17

Whe calling a function through the OnMessage, there's a way to pass a parameter?

Example:

Code: Select all

DllCall("OSC2AHK.dll\addListener", AStr, "/enterEditMode", UInt, 0x1001, UInt, oscTypeInt)
OnMessage(0x1001, "_changeMode")
DllCall("OSC2AHK.dll\addListener", AStr, "/enterCutMode", UInt, 0x1002, UInt, oscTypeInt)
OnMessage(0x1002, "_changeMode")

_changeMode(oscType, data, msgID, hwnd, I WANT ADD THE PARAMETER MODE HERE){
    Switch (mode)
        "EDIT":
        return
        "CUT":
        return
        "COLOR":
        return
}

I asked this because the software that are sending the OSC does not have a DATA field, so I can't send nothing than call the function.
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

16 Jun 2021, 13:06

Hm, I don't think that's possible, at least I don't know about something like this (it's a general AHK function, nothing about the DLL).

What you could do is call different functions for "/enterEditMode" and "/enterCutMode" and then route them from there. Something like this:

(Didn't test this, might not work out of the box, just a hint)

Code: Select all

OnMessage(0x1001, "_changeModeToEdit")
OnMessage(0x1002, "_changeModeToCut")

_changeModeToEdit(oscType, data, msgID, hwnd)
{
   _changeMode(oscType, data, msgID, hwnd, "EDIT")
}

_changeModeToCut(oscType, data, msgID, hwnd)
{
   _changeMode(oscType, data, msgID, hwnd, "CUT")
}

_changeMode(oscType, data, msgID, hwnd, mode)
{
   Switch (mode)
        "EDIT":
        return
        "CUT":
        return
        "COLOR":
        return
}
Yes, it's another routing layer and no, it's not getting easier to keep track of. But it should work :D
foxdanger
Posts: 83
Joined: 11 Jun 2019, 13:48

Re: OSC integration DLL

16 Jun 2021, 13:08

nyquist wrote:
16 Jun 2021, 13:06
Yes, it's another routing layer and no, it's not getting easier to keep track of. But it should work :D
yeah, that what I though.

The other route I already knew... And I'll have to use it so. I was just trying to figure out if we could pass more parameters because would be great :D

Anyway, thx a lot my friend!
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

16 Jun 2021, 13:19

Yes, I think that's just how it is.
I like to add lots of comments to the code (e.g. a routing explanation), so I still know what I have done if I or someone else has to look at it later ;-)
EErreErre
Posts: 2
Joined: 22 Jul 2021, 09:45

Re: OSC integration DLL

22 Jul 2021, 09:54

Hi to everyone

I've also posted this question on the DLL repository.

I'm working on a controller for ZoomOSC based on ahk.
For a particular function i need to send a single message with 2 string.

I've tried many combination for the data format in ahk but no one works.

I've created a screenshot for better explain what i mean.

I've used the program Protokol to test the function

The first line is obtained with the software Companion
As you can see the message is (STRING) "USER1" (STRING) "USER2"

The second line is from AHK and it send only 1 (STRING) message

Is possible to get the same result ?

Thanks a lot
Attachments
Protokol_Capt.PNG
Protokol_Capt.PNG (39.5 KiB) Viewed 2995 times
nyquist
Posts: 25
Joined: 25 Mar 2021, 15:44

Re: OSC integration DLL

27 Jul 2021, 04:51

Hi!
EErreErre wrote:
22 Jul 2021, 09:54
I'm working on a controller for ZoomOSC based on ahk.
For a particular function i need to send a single message with 2 string.
At the moment only one OSC argument per message is supported, so sending two strings as payload with one message is not possible.
I'll keep this as feature request, but it will take at least a few weeks until I have time to look into this in detail...
potscrubber
Posts: 36
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

Re: OSC integration DLL

15 Aug 2021, 22:28

@nyquist hey thank-you so much for this excellent oscpack implementation for AHK. This has been a long time coming and you have nailed it. I have a lot of automation controls in my studio and have been previously using a cli osc sender (based on oscpack too), and very hacky udp listener in AHK. I've just replaced all that with OSC2AHK and am enjoying much increased performance and elegant implementation.

Thank-you very much for sharing!

pot.
Last edited by potscrubber on 16 Aug 2021, 17:14, edited 1 time in total.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: tidbit and 119 guests