midi2osc bridge with lua

Home Forums General Programming midi2osc bridge with lua

Tagged: , , ,

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #70366
    fundorin
    Participant
      • Topics: 8
      • Replies: 66
      • Total: 74

      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.

      #70407
      fundorin
      Participant
        • Topics: 8
        • Replies: 66
        • Total: 74

        I’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?

        #70408
        fundorin
        Participant
          • Topics: 8
          • Replies: 66
          • Total: 74

          I’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.

          #70409
          Possemo
          Participant
            • Topics: 14
            • Replies: 638
            • Total: 652
            • ★★★

            I 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.

            #70410
            fundorin
            Participant
              • Topics: 8
              • Replies: 66
              • Total: 74

              I’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.

              #70411
              fundorin
              Participant
                • Topics: 8
                • Replies: 66
                • Total: 74

                I must also mention, that values stored in “arguments” table have “userdata” type.

                #70413
                fundorin
                Participant
                  • Topics: 8
                  • Replies: 66
                  • Total: 74

                  This 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.
                  #70419
                  fundorin
                  Participant
                    • Topics: 8
                    • Replies: 66
                    • Total: 74

                    I 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-039

                    #70420
                    fundorin
                    Participant
                      • Topics: 8
                      • Replies: 66
                      • Total: 74

                      It seems like only first character of the string returns by osc library.

                      #70436
                      fundorin
                      Participant
                        • Topics: 8
                        • Replies: 66
                        • Total: 74

                        Possemo, 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.

                        #70437
                        Possemo
                        Participant
                          • Topics: 14
                          • Replies: 638
                          • Total: 652
                          • ★★★

                          Ok, 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.

                          #70438
                          fundorin
                          Participant
                            • Topics: 8
                            • Replies: 66
                            • Total: 74

                            As 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.

                            #71725
                            jersmi
                            Participant
                              • Topics: 0
                              • Replies: 9
                              • Total: 9

                              fundorin — would you allow me to see your OSC2 panel? I’m trying to understand OSC for Ctrlr (to use with Plogue Bidule).

                              #71726
                              fundorin
                              Participant
                                • Topics: 8
                                • Replies: 66
                                • Total: 74

                                OSC 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.

                                #71727
                                jersmi
                                Participant
                                  • Topics: 0
                                  • Replies: 9
                                  • Total: 9

                                  Ah, that’s too bad. So much potential! Thanks for the info.

                                  #72340
                                  Niki0beas
                                  Participant
                                    • Topics: 0
                                    • Replies: 1
                                    • Total: 1

                                    I’d like to help you. But I am not good at solving it.

                                    • This reply was modified 6 years, 7 months ago by Niki0beas.
                                    • This reply was modified 6 years, 7 months ago by Niki0beas.
                                  Viewing 16 posts - 1 through 16 (of 16 total)
                                  • The forum ‘Programming’ is closed to new topics and replies.
                                  There is currently 0 users and 62 guests online
                                  No users are currently active
                                  Forum Statistics
                                  Threads: 2,495, Posts: 17,374, Members: 77,605
                                  Most users ever online was 12 on January 22, 2019 3:47 pm
                                  Ctrlr