Norns: sending an array of numbers from lua to sclang

Hi

I figured out it’s possible to register your own OSCFunc in sc (within subclassing of CroneEngine) then in Lua script use:

osc.send_crone(path, args)

however, the args above needs to be of string type…

Can one send array of floats from lua to sc?

Thanks!

y

1 Like

trying to get the values from these sent to sc:

There may be a smarter way to do this, as I have very little experience with both languages, but my first instinct is to make your Lua script send a string containing space-separated floats and have your SC script parse that back into floats (assuming SC can do something like string.split()).

1 Like

thanks Ben.

yeah, that’d be possible but osc, by specification is able to communicate floats… so i’d like to avoid the parsing ping-pong if possible.

ok, so osc_send_crone it looks like it’s a C function call defined in:
~/norns/matron/src/osc.c

It’s a bit silly but… I did;

this.addCommand(\ping, “ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”, { |m| });

to send 64 values of float.
it works.

m.class.postln // -> Array
m[1].class.postln // -> Float

2 Likes

you can do that, but float arrays aren’t really supported r/n

you can also use “blob” type and do your own packing/unpacking

1 Like

thanks.

i did the following:
engine.ping(table.unpack(x))

how do you specify ‘blob’ type in lua exactly?
btw, i couldn’t just do unpack(x) which i guess has to do with lua’s version being not the newest?

btw, it is working. thanks to everybody;

3 Likes

oh shoot, i apologize, we didnt actually implement a blob case in osc_send.

would probably add a case here to handle tables:
[ https://github.com/monome/norns/blob/master/matron/src/weaver.c#L948 ]

but then we have to ask whether to send tables as raw byte arrays, or do some kind of packing of numbers automatically. (kind of ugly either way, hence not done i suppose.)

1 Like

right. and there is a limit to the size of what you can send via single udp packet. so i guess what we have already pretty much serves the purpose (sending relatively small data from lua to supercollider)! thanks for the clarification;)

hi,

dipping my toes into the norns ecosystem. I’m trying to create a simple implementation of DynKlang UGen. I want to play with a group of 16 harmonically related sine waves.

In my 16klangs.lua I have:

local freq_values = {55, 110, 220, 440, 880, 1760, 3520, 7040, 14080, 55, 110, 220, 440, 880, 1760, 3520}
local amp_values = {0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3}
local phase_values = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

engine.name = '16Klangs'

function init()
  print("loaded 16Klangs engine")
  engine.freqs(table.unpack(freq_vales))
  engine.amps(table.unpack(amp_values))
  engine.phases(table.unpack(phase_values))
end

I’m getting a supercollider fail, but maiden isn’t reporting any errors. is there something incorrect about how i’m passing the array into sc?

my repo is here: https://github.com/aidanreilly/16klangs

any pointers greatly appreciated :slight_smile:

EDIT: I had a typo in my sc engine which maiden didn’t report, i found the error by ssh’ing in and running /usr/bin/sclang

1 Like

in general: if you just reboot the device, you will likely miss startup errors before maiden connects.

try entering ;restart in the SC REPL tab in maiden to relaunch the supercollider process and capture startup errors.

4 Likes