OpenSoundControl (OSC) in Rev?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: OpenSoundControl (OSC) in Rev?

Post by Nicke » Sun Feb 08, 2015 7:21 pm

mweider: I tried to build my own OSC lib (did not get it to fully work, I see the messages but didn't get the formatting working) before I found yours. I'm also trying to use it with CasparCG and following your advice above I have now connected but I can not figure out how to listen to all messages the client (CasparCG) sends.

I assume I should somehow use the OSC.ReadData function but I haven't figured out how to use it. Do I need to make changes to your lib or can I access this data as it is?

Thanks in advance!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OpenSoundControl (OSC) in Rev?

Post by mwieder » Sun Feb 08, 2015 8:56 pm

Well, I don't know anything about the CasparCG server itself, so you'll have to rely on someone else if you need more detailed information about that, but the procedure for my board is to send a message and then wait for the response.

For instance to get the value of analog input 3 I would say

Code: Select all

UpdateAnalogData 3

Code: Select all

local sReadData
-- override the default handler for the listener
ON Analogin.Listener pParams
    put pParams into sReadData
END Analogin.Listener

---------------------------------------------------------------------------
-- UpdateAnalogData
--
-- Get the channel A/D value and display it
---------------------------------------------------------------------------
command UpdateAnalogData pChannel
    local tData
    
    OSC.Send "/analogin/" & pChannel & "/value"
    OSC.ReadData -- read the incoming data and leave it in sReadData
    -- convert hex to decimal
    put OSC.HexToDecimal(sReadData) into tData
    return tData
end UpdateAnalogData
But my guess is that the responses from the CasparCG server will differ from the ones returned from my board, so you may want to either add or change the switch statement in OSC.ReadData or just override it in your code (if you use the libOSC code as a backscript then your handlers of the same name will have precendence).

Code: Select all

insert script of stack 'libOSC" into back
on OSC.ReadData
  -- your code here would get executed *instead* of the library OSC.ReadData handler
end OSC.ReadData
...and bear in mind that I wrote the library in 2006 for a specifi project, and probably would do some things differently today.
I may update the library some day when time permits.

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: OpenSoundControl (OSC) in Rev?

Post by Nicke » Mon Feb 09, 2015 9:13 am

CasparCG sends realtime data and events as soon as you are connected like this:
http://casparcg.com/wiki/CasparCG_OSC_Protocol

So it seems that the best way to do it is to override your OSC.ReadData. Thanks!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OpenSoundControl (OSC) in Rev?

Post by mwieder » Mon Feb 09, 2015 8:29 pm

OK. Post back here if you have problems or an overloaded function if you get it working - I think it will help others working with CasparCG as well.
What I really should do is separate the switch statement that deals with the message payload into its own function so that just that part can be overloaded instead of having to parse the header in the overload function. Someday when I get the time.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: OpenSoundControl (OSC) in Rev?

Post by Da_Elf » Mon Feb 16, 2015 1:58 pm

Hi guys. thanks for the help. hopefully i can tackle this some time this week. Ive been so overwhelmed with other stuff i havent had a chance to play with OSC in a while

DusX
Posts: 4
Joined: Wed Mar 27, 2013 6:55 pm

Re: OpenSoundControl (OSC) in Rev?

Post by DusX » Fri Mar 30, 2018 1:48 am

Any chance OSC will become an included communication protocol in LC?
If been watching this for years, and supported the Kickstarter with this hope.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: OpenSoundControl (OSC) in Rev?

Post by sphere » Mon Apr 02, 2018 9:46 am

I created a bug request as feature request for TUIO, it's an opensource Touch protocol for all desktops mac, win, linux etc. check here http://quality.livecode.com/show_bug.cgi?id=20655
It is based on OSC, you can check here https://www.tuio.org/

on that website are API etc for almost all languages except Livecode. We can wait for LC to implement it or try to do it ourselfs with help from others with LCB.
I just tried a bit LCB a few weeks ago and have to try more, but not enough time yet.
Also probably a bit to dificult for me to use the C++ or JAVA API's and use LCB to get the grip of it, but it would be openeing another world of possibilities using that touch protocol.

But since TUIO is based on OSC, if one would work i guess the other with some minor changes will too.

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: OpenSoundControl (OSC) in Rev?

Post by gilar » Sat Nov 14, 2020 5:30 pm

mwieder wrote:
Sat Jan 10, 2015 3:29 am
That's pretty close. Here's what I do (after adding the "libOSC" stack as a substack and making any appropriate changes to the constants that define the environment)

In the card script:

Code: Select all

on openStack
    insert the script of stack "libOSC" into back
    -- now the handlers in the stack script are available to all scripts
    OSC.SetUDPMode true
    OSC.Open
end openStack

on closeStack
    OSC.Close
    remove the script of stack "libOSC" from back
end closeStack
and then in a button script you'll want something like

Code: Select all

on mouseUp
  OSC.Send "/control/mark1/play 1"
end mouseUp
Hi @mwieder ... Sorry i still no luck to follow your instruction

what i'm tring to do is
controlling Resolume via OSC by livecode apps

here what i have done
In Resolume
- set OSC Input to active, in port 7000

In Livecode:
- Create a Stack (Draco OSC)
- Copy your libOSC script into (Draco OSC) Stack
- Change ipAddress and port

Code: Select all

-- NOTE: change these for your system as appropriate
constant kOSCUSBPort = "COM3:"
constant kOSCIPAddress= "127.0.0.1"
constant kOSCUDPPort = "7000"
- Put openStack & Close stack Script in Card (Draco OSC)
- Create button script
on mouseUp
OSC.Send "/track4/connect 1"
end mouseUp

do i miss something?

This is my Livecode file
https://drive.google.com/file/d/16kPndH ... sp=sharing


Comment and help would be appreciate
Thanks
Gilar | from INDONESIA

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OpenSoundControl (OSC) in Rev?

Post by mwieder » Sun Nov 15, 2020 3:41 am

Well, it's been a dozen years now since I wrote this library and a good five years since I've looked at the code, I'll see what I can do...

first of all, it's not necessary (and maybe a bad idea) to copy the OSC library into the main stack script. You've already got it in a substack and you're putting it into play with the openStack handler, so that should be sufficient.

Next, I'm assuming you changed the network address in the library (kOSCIPAddress) to the actual ip address of the resolume device. If not then you're only sending messages to yourself, and that won't do anything useful. Are you able to ping the address of the resolume successfully?

OSC.SetUDPMode true will work in your case, but the officially supported way to call that is OSC.SetUDPMode 1 (and yes, I realize that some years ago I posted "true"). The handler for that command really should be rewritten to handle "true" and "false" as well. Someday.

Are you sure you want to be in UDP mode? I can't tell from the resolume manual. You might try OSC.SetUDPMode 0 instead.

Are you getting an error dialog after the OSC.Send command?
What platform are you on? It looks to me like I wrote the original library for OSX to be a usb connection only because I wrote this for a specific hardware board.

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: OpenSoundControl (OSC) in Rev?

Post by gilar » Sun Nov 15, 2020 2:54 pm

mwieder wrote:
Sun Nov 15, 2020 3:41 am
Well, it's been a dozen years now since I wrote this library and a good five years since I've looked at the code, I'll see what I can do...
Thank you so much for coming back again on this thread ....
Next, I'm assuming you changed the network address in the library (kOSCIPAddress) to the actual ip address of the resolume device. If not then you're only sending messages to yourself, and that won't do anything useful. Are you able to ping the address of the resolume successfully?
I use resolume on local host so i change the IP into localhost sometimes i change into 127.0.0.1
Is it really need to play with another Machine?
Because i tested with CasparCG Client which has OSC command it is ok to control resolume in local machine.
Are you sure you want to be in UDP mode? I can't tell from the resolume manual. You might try OSC.SetUDPMode 0 instead.
I read about OSC with TCP or UDP and most of it use UDP, but Actually I'm not sure about it.
for the first try, i just want it work.
Are you getting an error dialog after the OSC.Send command?
What platform are you on? It looks to me like I wrote the original library for OSX to be a usb connection only because I wrote this for a specific hardware board.
I'm using Windodws 10
No. I got no Error

Then I check if i close resolume
i got this Errror Error::7000,Error10038 on socket


I'm trying to trace my message (OSC.Send "/track3/connect 1") and put it into field "testMessage_fld"

Code: Select all

on OSC.Send pMessage
   local tParsedMessage
   local tCatMessage
   local tKeys
   local tHex
   
   if blnIsConnected then
      put OSC.format(pMessage) into tParsedMessage
      put the keys of tParsedMessage into tKeys
      repeat for each line tKey in tKeys
         put tParsedMessage[tKey] after tCatMessage
      end repeat
	put tCatMessage into field "testMessage_fld" of card "games_crd"
      if blnIsUDP then
         write tCatMessage to socket (kOSCIPAddress & ":" & kOSCUDPPort)
      else
         if the platform contains "Win" then
            write numtochar(kOSCEnd) & tCatMessage & numtochar(kOSCEnd) to driver sUSBOutput
         else
            write numtochar(kOSCEnd) & tCatMessage & numtochar(kOSCEnd) & cr to driver sUSBOutput
         end if
      end if
      if the result is not empty then
         answer "Send::" && the result
      end if
   end if
end OSC.Send
This is the result

Code: Select all

,i/track3/connect
is this ok?
Gilar | from INDONESIA

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OpenSoundControl (OSC) in Rev?

Post by mwieder » Sun Nov 15, 2020 7:42 pm

This is the result
CODE: SELECT ALL

,i/track3/connect
is this ok?
No, it should be /track3/connect,i
And then the value you're sending (in this case a 1) will be binary-encoded, so you won't see the actual value in your field without decoding it back again.
But since you're seeing the other values out of order, try inserting a sort command in the OSC.Send handler:

Code: Select all

    if blnIsConnected then
        put OSC.format(pMessage) into tParsedMessage
        put the keys of tParsedMessage into tKeys
        sort tKeys ascending numeric # this will return the keys in the proper order
        repeat for each line tKey in tKeys
            put tParsedMessage[tKey] after tCatMessage
        end repeat
and see if that gets things working.

The resolume device looks like a great piece of equipment, but I don't have one here so I'm just having to guess about code that's a dozen years old.
Here's a link to what the OSC packet format should look like:

http://opensoundcontrol.org/spec-1_0

i.e., address string comma type tag binary-encoded data
all padded out to 4-byte boundaries

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: OpenSoundControl (OSC) in Rev?

Post by gilar » Mon Nov 16, 2020 1:33 am

mwieder wrote:
Sun Nov 15, 2020 7:42 pm
No, it should be /track3/connect,i
And then the value you're sending (in this case a 1) will be binary-encoded, so you won't see the actual value in your field without decoding it back again.
Ok. now it like what suppoused to be. /track3/connect,i
and see if that gets things working.
Now it's working .... thank you very much
The resolume device looks like a great piece of equipment, but I don't have one here so I'm just having to guess about code that's a dozen years old.
Here's a link to what the OSC packet format should look like:

http://opensoundcontrol.org/spec-1_0

i.e., address string comma type tag binary-encoded data
all padded out to 4-byte boundaries
Ok. I need to learn it ...

Sorry more question ...
can we receve message from resolume after we do OSC.Send "/track3/connect 1" ?
it means if resolume received this command.

i try this /layer1/video/opacity/values (Float 0.0 - 1.0) ---> OSC.Send "/layer1/video/opacity/values 0.5"
but it's not working, it seem would be different too for string, bolean, and double.


- /layer1/video/opacity/values 0.5 ----- > /layer1/video/opacity/values,f ---- > the opacisty change to 0
- /layer1/video/opacity/values 1.0 ----- > /layer1/video/opacity/values,i ---- > nothing change in opacity




Thanks
Gilar | from INDONESIA

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OpenSoundControl (OSC) in Rev?

Post by mwieder » Wed Nov 18, 2020 1:57 am

Gilar- haven't forgotten about you here. I downloaded Resolume Avenue over the weekend :shock: and have been having too much fun playing with it. :wink:

...and in looking things over, I realize that the OSC library I wrote was very much oriented towards the board I was working with, and could easily be stripped down to the OSC routines themselves, isolating the makeboard controller functions to a separate script. That makes working with resolume a bit easier, especially because I wrote the routines to read back from an OSC source *very* specific to my board.

And like you, I can send messages to resolume but can't yet read them back.

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: OpenSoundControl (OSC) in Rev?

Post by gilar » Thu Nov 19, 2020 4:11 pm

mwieder wrote:
Wed Nov 18, 2020 1:57 am
Gilar- haven't forgotten about you here. I downloaded Resolume Avenue over the weekend :shock: and have been having too much fun playing with it. :wink:
Hi ... finally you installed Resolume ...
so it would be more exploring.

Do you think OSC could replace video file or image on a clip, like in CasparCG or vMix?
I mean ... is it possible to change the url path of the clip then play it?
Gilar | from INDONESIA

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: OpenSoundControl (OSC) in Rev?

Post by mwieder » Wed Dec 02, 2020 4:54 am

Gilar-

Give this a try... I reworked the library to keep just the pertinent routines in the stack itself and then created a sample resolume card (click the "resolume" button to go there) that hardcodes record on/off buttons, has a text field for experimenting with sending other commands, and logs the messages coming back from resolume into a scrolling text field.

Watch what you wish for though... there are a *lot* of messages coming back, especially when you're looping. You may want to filter for just the messages you're interested in.

Trying to see what resolume supports in the way of OSC messages seems to be a bit hit or miss. I haven't found detailed documentation on those. And I'm not at all sure there's support for uploading clips via OSC.
Attachments
libOSC.livecode.zip
(34.79 KiB) Downloaded 186 times

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”