This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

rewrite Python code to Lua
#1
Hi!!

I am controlling an audio software with udp.
Follwoing is the python code working on the site.

Code:
from pythonosc.udp_client import SimpleUDPClient


ip = "172.28.11.110"
to_ableton = 11000
from_ableton = 11001
client = SimpleUDPClient(ip, to_ableton)

client.send_message("/topic/of/message", [a, b, c])

I want to execute this from LM so I need to rewrite this in Lua. 
I've tried follwoing code but I got an error "invalid value (table) at index 2 in table for 'concat'".
Could you help me write this code properly? 

Code:
local socket = require("socket")
local ip = "172.28.11.110"
local to_ableton = 11000
local from_ableton = 11001
local msg = {"/topic/of/message", {a, b, c}}
local udp = socket.udp()
udp:settimeout(1)
udp:setpeername(ip, to_ableton)
udp:send(table.concat(msg, " "))

Thank you very much for your help  Smile
Reply
#2
It's not that simple. You need a library for the OSC protocol: https://github.com/davidgranstrom/losc/

Run this script once to install the library (make sure that LM has valid gateway and DNS settings):
Code:
if not io.exists('/usr/share/lua/losc/') then
  os.execute('wget -O /tmp/losc.tar.gz http://dl.openrb.com/misc/losc.tar.gz && ' ..
    'tar -xzf /tmp/losc.tar.gz -C /')
end

A slight difference from the examples is that the main library should be loaded like this:
Code:
-- instead of local losc = require'losc'
local losc = require'losc.init'
Reply
#3
Wow thank you admin!
I never thought about that.
I executed the installation script as you wrote and now I can successfully send request to Abelton.  Smile

However I am having difficulties with receiving messages from Abelton.
This is what I am trying on resident script with 0 interval but it seems like I'm not receiving anything.
Can you tell if I'm doing something wrong?  Cry

Code:
local losc = require'losc.init'
local plugin = require'losc.plugins.udp-socket'

local udp = plugin.new {
  recvAddr = '127.0.0.1',
  recvPort = 11001,
  ignore_late = true, -- ignore late bundles
}
local osc = losc.new {plugin = udp}

osc:add_handler('*', function(data)
  log(data)
end)
Reply
#4
recvAddr must be your LM IP address. 127.0.0.1 is an internal address which cannot receive anything from remote hosts.
You need to call osc:open() after osc:add_handler(...)
Reply
#5
Omg it worked!
I cannot describe how thankful I am! 
Thank you for your help even though it's about osc and abelton. 
Much appreciated  Angel
Reply


Forum Jump: