Incoming midi parsing efficiency question.

Home Forums General Programming Incoming midi parsing efficiency question.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9772
    Hecticcc
    Participant
      • Topics: 25
      • Replies: 160
      • Total: 185
      • ★★

      Until now i’ve been grabbing entire messages + seperate values from the incoming midi data like this:

      if midi:getSize() ~= nil then l = midi:getSize() end
      
      msg = midi:getData():getRange(0,l)
      
      EOF= midi:getLuaData():getByte(5)
      CMD = midi:getLuaData():getByte(6)
      ID = midi:getLuaData():getByte(7)
      LS = midi:getLuaData():getByte(9)
      MS = midi:getLuaData():getByte(10)

      But i wonder if doing it like this would be better or worse regarding efficiency?

      if midi:getSize() ~= nil then l = midi:getSize() end
      
      msg = midi:getData():getRange(0,l)
      
      EOF = msg:getByte(5)
      CMD = msg:getByte(6)
      ID = msg:getByte(7)
      LS = msg:getByte(9)
      MS = msg:getByte(10)
      #9773
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        Well that won’t work

        msg = midi:getData():getRange(0,l)
        
        EOF = msg:getByte(5)
        CMD = msg:getByte(6)
        ID = msg:getByte(7)
        LS = msg:getByte(9)
        MS = msg:getByte(10)
        

        there will be no byte 2 or highger in “msg” since it’s range 0,1, if you do getRange(0,10) then it will work. Will it be more efficient, perhaps a little there will be less data copying. But with data size of byte/kilobytes you won’t see the difference, megabytes – maybe.

        But you should try to make your code as efficient as possible, it will make you write better code in the future.

        #9780
        Hecticcc
        Participant
          • Topics: 25
          • Replies: 160
          • Total: 185
          • ★★

          It’s a letter l inthere, the variable from the first line. It’s how i grab entire messages 😉

          Thanks for the info!
          I wondered because as i am learning to code bit by bit i am starting to wonder about stuff like this as i learn more & more; but about some things (like this) i am still nearly clueless.

          #9805
          atom
          Keymaster
            • Topics: 159
            • Replies: 2945
            • Total: 3104
            • ★★★★★

            A good way is too use Lua tables, they are a flexible way of accessing data, for example:

            mb = MemoryBlock ({0x31, 0x12, 0x08, 0x04})
            mb:toLuaTable (t)
            
            console ("1:"..t[1])
            console ("2:"..t[2])
            console ("3:"..t[3])
            console ("4:"..t[4])
            

            now mb, can be mb= midi:getData():getRange(0,128), and you can access each byte by accessing the “t” table t[1] – t[128] (tables in lua are indexed from 1 not zero). I had to add the toLuaTable() it will be in the latest nightly, i forgot about it.

            #9822
            Hecticcc
            Participant
              • Topics: 25
              • Replies: 160
              • Total: 185
              • ★★

              I use tables alot , been using loops to fill tables with data coming from memoryblocks for specific dumps/functions until now, this new call will make things less cluttered in some places 🙂

              • This reply was modified 10 years, 10 months ago by Hecticcc.
            Viewing 5 posts - 1 through 5 (of 5 total)
            • The forum ‘Programming’ is closed to new topics and replies.
            There is currently 0 users and 81 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