Home › Forums › General › Programming › midi2osc bridge with lua
- This topic has 15 replies, 4 voices, and was last updated 6 years, 10 months ago by Niki0beas.
-
AuthorPosts
-
November 28, 2016 at 7:15 am #70366
Is it possible to write a midi2osc script entirely in lua, without using any gui in panel?
I want to use Ctrlr as lua interpreter and load it inside DAW, so it would quietly make the necessary conversion between daw and midi controller. Is it’s possible, I would be glad to see an example of doing so or some documentation.
I’ve already started lua script for vstlua plugin, but is keeps crashing and Ctrlr might be a good alternative. Thanks in advance.December 4, 2016 at 9:01 am #70407I’m stuck, trying to get string value from received arguments table on receiving OSC message.
In demo OSC panel it’s set to output arguments as float numbers.
I’ve commented output to panel monitor and only trying to get the right output to console.onOSCMessage = function(path, types, arguments) console ("OSC: " .. path .. " types: " .. types) --console (string.format ("float: %.2f",arguments[0].f)) console (tostring(arguments[0].f)) -- log = panel:getLabel("oscMonitor") -- if log:getText():length() > 300 then -- log:setText("") -- end -- log:append(path):append(", "):append(types):append("\n") -- for i=0,#arguments do -- log:append(string.format(" %.2f [%d]", arguments.f, arguments.i)) -- end -- log:append("\n") end
I get normal output of values, that are numbers, but when the argument is a text (like host’s track name), I get this output to Lua console:
LUA>> OSC: /track/2/name types: s LUA>> 1.825356e+31
where second line should print “sdfsdh”, instead of 1.825356e+31.
Each time I try to access “arguments” a different way, Ctrlr crashes either when compiling script or when OSC message is received. I wonder how this arguments table is constructed and how to get a needed value out of it?December 4, 2016 at 9:46 am #70408I’ve found that “arguments” type is table and “arguments[0]” type is userdata, which is seems to be C type data.
Now I’m trying to find out how to convert userdata into string, depending of whether text (string) agrument of the OSC message was received or number (float).
Any help would be appreciated.P.S. To be clear, my goal is to make midi<>osc bridge with Ctrlr, so I could send MIDI commands from Novation SL MkII controller to Ctrlr, convert them into OSC commands and send them to Reaper. Then, OSC feedback from Reaper would be converted into MIDI commands and fed to SL MkII.
December 4, 2016 at 11:24 am #70409I can’t help you much in what you are doing, but what version of Ctrlr are you using? IMHO newest v5.4.16 is buggy, I recommend v5.4.11.
December 4, 2016 at 11:38 am #70410I’ll definetily switch to an earlier version, but current issue isn’t about the version, I think.
The problem is that DEMO-OSC panel intended to parse osc message as (path, type, arguments), where:path is osc command
(i.e. /track/1/volume),types is an argument type
(i.e. “f” aka “float” for numbers in “/play, 1”
or “s” aka “string” for text, like track name in “/track/name/, ‘Rhythm Guitar'”arguments is a table of arguments. Reaper sends only one argument for any type of command, so it’s safe to always use “arguments[0]” to access the argument’s value.
The thing is that when agrument type is a string, I get argument value as a number, like “4.545054e+30” for track name “qwerty” and can’t understand how to convert this number back in text format and store as value inside Lua script.
December 4, 2016 at 11:39 am #70411I must also mention, that values stored in “arguments” table have “userdata” type.
December 4, 2016 at 12:09 pm #70413This code shows the first character of the track’s name and I’m yet to find how to display second character, at least, and glue them together.
- This reply was modified 7 years, 4 months ago by fundorin.
December 4, 2016 at 1:28 pm #70419I feel like it somehow connected with how we’re asking for arguments[0].
For “asd” track name
arguments[0].s gives 97 (letter “a”, I suppose)
arguments[0].c gives 97
arguments[0].f gives 9.2249397685399e-039December 4, 2016 at 1:58 pm #70420It seems like only first character of the string returns by osc library.
December 5, 2016 at 7:52 am #70436Possemo, could you confirm this issue? To test it, create new control surface in Reaper’s preferences (Control Surfaces/Add/OSC).
Set everything like in this picture (use your own IP address,though):
Open Ctrlr, load this panel – https://dl.dropboxusercontent.com/u/8162257/OSC2.panel
Then, in Ctrlr, Panel/Lua editor.Select “onOscMessage” script. Restart Reaper or add any track in it and rename it.
Lua console in Ctrlr should output osc messages from Reaper. With Default.ReaperOSC, selected in Reaper’s Control Surface setting, there should be many osc commands in console, but that’s fine. You need those, which have type “s” (string).For example – LUA>> OSC: /track/name Value: 84 Type: s
The problem is that the value is a decimal representation of the ASCII table for the first character while it should be a text.
You can experiment with string 17 of the script. Changing tonumber to tostring doesn’t help, for example.
I would love to have a little help with this issue.
P.S. standalone Ctrlr 5.4.11 x64 (about shows 5.3.201), windows 10.
December 5, 2016 at 8:51 am #70437Ok, will test it when I’ve got the time, it will probably be at the end of the week (fri. or sat.). I have to say that the implementation of OSC is quite “early”. As far as I know nobody has used it until now.
December 5, 2016 at 8:57 am #70438As far as I remember, Atom finally added OSC support after I asked him about it and explained in which situation OSC could be useful in Ctrlr.
After that, I was busy and only now have some time to realise the idea that I had in mind at that time.
I realise that nearly nobody have used OSC for now, but if everything would work properly with OSC part, Ctrlr can become a Lemur/TouchOSC alternative for desktops.March 23, 2017 at 3:30 am #71725fundorin — would you allow me to see your OSC2 panel? I’m trying to understand OSC for Ctrlr (to use with Plogue Bidule).
March 23, 2017 at 3:33 am #71726OSC part isn’t ready at all, cause Ctrlr isn’t handling OSC messages right. I was waiting for a fixed version from the last year, to continue developing my panel, but it seems like atom doesn’t have enough time to add proper OSC functionality to Ctrlr.
March 23, 2017 at 6:26 am #71727Ah, that’s too bad. So much potential! Thanks for the info.
June 12, 2017 at 6:01 am #72340 -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.