Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how can i communicate with other apps using OSC? - Page 2 — Gideros Forum

how can i communicate with other apps using OSC?

2

Comments

  • keszeghkeszegh Member
    i thought it needs to be added as a plugin, if it is pure lua and works as is, then i will try. thanks

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    losc
    1. attempt.
    i tmade a new gideros project, added the folder losc (from within the src folder of the github project https://github.com/davidgranstrom/losc) altogether to the project and made a main.lua where i copy-pasted contents of client.lua.

    when running, it gives the following error:
    losc/bundle.lua:36: attempt to index nil with 'gsub'

    i guess having luau instead of lua might be a problem for different ways of handlings modules etc. can you help @hgy29 or send me a working example gideros project?
  • hgy29hgy29 Maintainer
    Hi @keszegh, I am pretty sure you don’t really need my help if it is just about some lua code, in fact you have been coding in lua for more years than myself.
  • keszeghkeszegh Member
    haha, i got the nicely coated critique. you should be right, but this 'plugin' has like 10 files, all different modules etc and i never really understood how modules work especially after luau switch (e.g., i could rewrite datasaver to be a class, but doing the same with this one seems to be a non-trivial effort which i hoped that is possible to avoid).

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    in any case i appreciate your help which i completely understand to be voluntary, as always, i don't and never had any 'requests' as such.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    hi keszegh, I gave it a try because I like the idea :)

    You can replace each require something like this:
    bundle.lua:
    local relpath = "losc/"
    local Types = require(relpath.."types")
    local Message = require(relpath.."message")
    local Timetag = require(relpath.."timetag")
    types.lua:
    local relpath = "losc/"
    local Serializer = require(relpath.."serializer")
    local Timetag = require(relpath.."timetag")
    ...

    Don't forget to exclude bundle.lua, message.lua, packet.lua, ... from execution.

    You need more stuff that I don't understand like this "luv" thing https://github.com/luvit/luv/tree/master/src
    udp-libluv.lua:
    local uv = require "luv" -- XXX I am stuck here!

    Likes: keszegh

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    @MoKaLux , i appreciate your help.
    i've been working along the same lines. changed the relpath lines simply to
    local relpath = "losc"
    and in udp-socket.lua i changed require 'socket' to require 'socket.core'
    and yes i excluded everything from execution.
    and i don't remember if i changed anything else.
    in any case now i managed to run the example file to successfully send an osc message.
    so long so good, i will see later if everything works as expected.


    yes, i was also worried about that 'luv' thingy but so far it seems i did not need it.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    edited June 22
    looking at it, libuv seems to be an alternative to socket, so it won't be needed i guess if we use socket.core.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    server example freezes the player so i need to experiment more to see what's the issue.
  • MoKaLuxMoKaLux Member
    edited June 22
    Thank you I can compile the project too.

    In the example LOSC folder there are 2 files: client.lua and server.lua

    When I put those in my Gideros project and run, the Player freezes. What am I supposed to do here? Where am I supposed to read the message?

    Thank you for any help :)

    PS: I have included the Lua Socket plugin in the project


    EDIT: Player doesn't freeze if I comment this line:
    --osc:open() -- blocking call (depending on plugin used)

    Now am I supposed to have a localhost opened? how do I open/create one? Do I need a server like xamp? So many questions :p
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • keszeghkeszegh Member
    i made a main.lua and only copied the contents of client.lua there.
    that worked for me.
    you can use e.g. this app to check if the message is sent:
    https://hexler.net/protokol
    (be sure to set the same port (say 9000) in both this app and your gideros app)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    the server example freezes because of this line:
    osc:open() -- blocking call (depending on plugin used)

    what does it mean that it is a blocking call and how to make it work nevertheless?
  • MoKaLuxMoKaLux Member
    edited June 22
    That worked :o

    I excluded server.lua from execution and only execute client.lua.

    I installed Protokol and it installed the "Bonjour" apple nasty thing but that's okay :)

    I changed the port to 9000 and I can see the messages being sent/posted!

    I am amazed at what Gideros let us do!

    Viva Gideros, Viva Gideros Forum :)

    Likes: keszegh

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    great, now i just need to make the server work also.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    edited June 22
    so here is my demo project. in main.lua at the beginning one can set which example to run. the client example works fine.
    however, the server example freezes on the osc:open() "blocking call" and i don't know what should be done. (sorry for multiple posts, i could not attach the file and that was the outcome).

    demo project:
    https://www.dropbox.com/scl/fi/kalkoio8jjeosh5gfrwyg/loscdemo.zip?rlkey=70fnxkqyf60lkwf361hhpykfe&dl=0
  • MoKaLuxMoKaLux Member
    edited June 22
    for info:
    -- here we send 4 elements, first an (i)nt32, then a (f)loat, a (s)tring and some (b)lob data
    local message = losc.new_message {
    	address = '/foo/bar',
    	types = 'ifsb', -- must match*
    	123, 1.234, 'hi', 'blobdata' -- must match*
    }
    I need to read some docs and see what I can make out of this LOSC thing :p

    Thank you keszegh for opening new horizons, you are a star ;)

    EDIT: yes it seems we cannot upload zip files anymore (.txt?)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • keszeghkeszegh Member
    perhaps using threads when calling the server open call would work? it needs to be tested, i don't have any other idea in any case (and not much routine with coroutines).
  • hgy29hgy29 Maintainer

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    @hgy29 , very good find. it does work! i wonder why it was never merged.

    here is my updated example project:
    https://www.dropbox.com/scl/fi/tghw5ck3pi4ouj4tq5ftb/loscdemo-nonblocked.zip?rlkey=r04pbyyjnu8n8ne5xjap17eby&dl=0

    if you wanna try if it works, then first set it as a 'client', export it to a runnable. and then set it as a 'server', run it in the player and then when it is running in the player run the 'client' executable. then the player should receive and print the sent package.

    @MoKaLux , you surely wanna test it. and you might also want to add it on gideros wiki.
    @hgy29 , thanks again, you save hours of trial and error (perhaps coroutine would have worked too, but this way is much cleaner).

    ps: can we add zip attachments back? it would be nice for example here to attach the project so that people even a year later can download it.


    Likes: MoKaLux, pie

    +1 -1 (+2 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited June 23
    keszegh said:

    if you wanna try if it works, then first set it as a 'client', export it to a runnable. and then set it as a 'server', run it in the player and then when it is running in the player run the 'client' executable. then the player should receive and print the sent package.

    I did as per the instructions, but I don't see anything :'( . I exported the client as both winQt and win32.
    keszegh said:

    @MoKaLux , you surely wanna test it. and you might also want to add it on gideros wiki.

    With great pleasure :)
    keszegh said:

    ps: can we add zip attachments back? it would be nice for example here to attach the project so that people even a year later can download it.

    I will add your project to Gideros Wiki ;)

    EDIT: I cannot make LOSC work even in my previous working project, I don't see anything in Protokol :s
    EDIT: that works, I was running a different Player than the Gideros Studio Player. Everything is fine. Make sure to run the Player from with your Gideros Studio project :p

    Likes: keszegh

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    edited June 23
    @MoKaLux , yes, for me also client does not work with the new update.
    also the server part does not receive the call although it did an hour ago. so it needs more experimenting and tuning before we can say it is working fully.

    btw you can also try the trial version of the app https://oscpilot.com/ to send test messages to a server (remember to setup the outgoing port correctly and also to add a handler to different events, like osc:add_handler('/XFADE', function(data) ... etc.)


    EDIT: now it works for me too. it did not work when i rerun the app in the same player, had to close the player and open it again and THEN run the project (in server setup).
  • keszeghkeszegh Member
    edited June 23
    i've made some changes so that you can print out any osc message that came in (and not just the ones that are handled):
    https://www.dropbox.com/scl/fi/nslhaafb4vhjyji1fmccq/loscdemo-nonblocked-v2.zip?rlkey=uol5qp8ujlyvmfgxthgtoco6g&dl=0

    note that besides main.lua i changed one line also in the plugin in the poll function
    from
    return true, data
    to
    return data

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited June 24
    keszegh said:

    i've made some changes so that you can print out any osc message that came in (and not just the ones that are handled)

    note that besides main.lua i changed one line also in the plugin in the poll function
    from
    return true, data
    to
    return data

    I am not sure about the changes keszegh ;) , now I have some messages like this:
    losc/types.lua:149: invalid argument #2 to 'unpack' (unfinished string for format 'z')
    This spams my log (output) window in a loop! Please note this is not an error (the program works) but just an infinite loop of this message!

    I am doing some testing on my side and I try to start stop the server:
    	stage:addEventListener(Event.KEY_DOWN, function(e)
    		if e.keyCode == KeyCode.S then
    			if not isopened then
    				print("server start listening")
    				osc:open() -- non blocking call <img class="emoji" src="https://forum.gideros.rocks/resources/emoji/smile.png" title=":)" alt=":)" height="20" />
    				isopened = true
    			end
    		elseif e.keyCode == KeyCode.P then
    			if isopened then
    				print("y", osc:poll())
    				print("server stop listening (closed)")
    				isopened = false
    --				data = {}
    --				data = nil
    				osc:close()
    			end
    		end
    	end)
    The same for the client:
    --	print("client send message 1")
    --	osc:send(message)
    	stage:addEventListener(Event.KEY_DOWN, function(e)
    		if e.keyCode == KeyCode.S then
    			print("client send message")
    			osc:send(message)
    		end
    	end)
    Please let us know when your Gideros demo is matured and I will update the wiki and stuff :)
    I will play with this a little bit more but I have my other Gideros project awaiting ;)

    EDIT: can we use "blobdata" to send images, Pixel, text, ... ?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    I can capture the mouse coordinates and send them to Protokol.
    local mousex, mousey = 0, 0
    local message
    stage:addEventListener(Event.MOUSE_MOVE, function(e)
    	mousex, mousey = e.x, e.y
    	message = losc.new_message {
    		address="/foobar2",
    		types="ii",
    		mousex, mousey,
    	}
    	osc:send(message)
    end)
    stage:addEventListener(Event.MOUSE_UP, function(e)
    	mousex, mousey = e.x, e.y
    	message = losc.new_message {
    		address="/foobar2",
    		types="ii",
    		mousex, mousey,
    	}
    	osc:send(message)
    end)
    What could somebody do out of this? I am thinking like the draw together demo from ar2rsawseen demo. We have a host and clients and they all draw on the host (or something like that :p )
    I think we can build the server and several clients Gideros apps and let the server receive and draw the lines sent by the clients?

    That would be a nice demo for Gideros LOSC imho ;)

    PS: I built server and clients apps but the messages are not received by the server (clients can send data to Protokol though!)

    Likes: keszegh

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    edited June 24
    @MoKaLux ,i will look into the issue about the messages.

    OSC plugin usage: it can send/receive messages using the OSC protocol. sending pixel data would be way too slow this way, for that there are other protocols (e.g. spout, syphon, ndi - the first is supported mostly by a gideros plugin). if you send/receive data between your own apps then you can use socket directly, not much need for osc, although it can make your life easier to send various types of data. osc becomes really useful if you wanna communicate between other apps (and even hardware), as many apps support it: https://en.wikipedia.org/wiki/Open_Sound_Control

    think of it as a much more flexible alternative to the MIDI protocol:
    "The advantages of OSC over MIDI are primarily internet connectivity; data type resolution; and the comparative ease of specifying a symbolic path, as opposed to specifying all connections as seven-bit numbers with seven-bit or fourteen-bit data types. This human-readability has the disadvantage of being inefficient to transmit and more difficult to parse by embedded firmware, however." (from wikipedia)

    in my use case for example chataigne is an app that can orchestrate synchronized control of multiple apps (in a live presentation situtation: music, video, lights, etc) and then having osc controllability of my app would allow it to be part of such a setup.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • keszeghkeszegh Member
    @MoKaLux , i cannot reproduce the log spam you had.
    do you use exactly the project i attached last? if not, you can share your version so i can debug it.
Sign In or Register to comment.