printing getLuaData() in console

Home Forums General Programming printing getLuaData() in console

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #5234
    msepsis
    Participant
      • Topics: 219
      • Replies: 732
      • Total: 951
      • ★★★

      myData = midiMessage:getLuaData():getRange(7,262)

      console(“my data looks like = “..myData) –doesn’t work!?

       

      Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

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

        myData is a MemoryBlock not a String you can’t just dump binary data to the console, there is no defined conversion operator for such an action.

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

          Also try to loose “Lua” try to use getData(), all those CtrlrLua and Lua prefixes etc. are deprecated.

          Think of getData() or getByte() or getRange() as a way to fetch a piece of memory, and that piece is just a set of bits. No one knows but you how to put those bits in groups. 8bits is a byte, and that can represent a ASCII character or not, it might be 16bits 32bits or whatever, you need to know what does your memory represent.

          The method toHexString() takes the bits, splits them up as bytes and prints the value of each byte in hexadecimal notation. Nothing else.

          #5247
          msepsis
          Participant
            • Topics: 219
            • Replies: 732
            • Total: 951
            • ★★★

            thanks atom. The goal here is to write the contents of  midiMessage:getLuaData():getRange(7,262) to a file.

            I’m assuming that must start with:

            myData = midiMessage:getLuaData():getRange(7,262)

            myDataHexString = toHexString(myData)

             
            I’m unclear what my next steps must be. I have the above lines on my midiMessageReceived script, I want the user to be able to press a button that allows them to dave the contents of “myData” to a filename/location they specify with a file type .data. I’m not sure how to go about coding the script for the save button that will save the contents of “myDataHexString” to a file

            I seem to recall making this work somehow a while back on a test panel but now it seems things have changed so my old code doesn’t work at all.

            any assistance would be greatly appreciated.

            Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

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

              Putting a block of data to a file should be as easy as

              data = midiMessage:getLuaData() -- or getLuaData():getRange(0,24) etc.
              file = File("c:\\myfile.syx")
              file:replaceWithData(data)
              

              that’s it the file c:\\myfile.syx should contain whatever is in the MemoryBlock (data)

              #5251
              msepsis
              Participant
                • Topics: 219
                • Replies: 732
                • Total: 951
                • ★★★

                very cool. thanks atom.

                But how do I allow the user to pick the destination and file type instead of defaulting to C:\\myfile.syx?

                Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

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

                  instead of

                  file = File("c:\\myfile.syx")
                  

                  do

                  file = utils.saveFileWindow ("Save data", File.getSpecialLocation(File.userHomeDirectory), "*.syx;*.dat", true)
                  
                  #5266
                  msepsis
                  Participant
                    • Topics: 219
                    • Replies: 732
                    • Total: 951
                    • ★★★

                    I’m almost there… can write the block to a file but the file is just a bunch of gibberish when I open it..

                    Trying to get toHexString to work but I’m just getting
                    “attempt to call global ‘toHexString’ (a nil value).

                    Where’s the API? that’d help a lot. otherwise I’m just taking shots in the dark.

                    Right now, here’s what I’ve got on my getWCT script (along with all the other code that deals with each byte – all working well)
                    WCTData = midiMessage:getData():getRange(7,262)

                    Then on my “save Wavetable” button (saves the WCTdata) I’ve got:

                    saveWavetable = function(mod, value)

                    WCTDataHexString = toHexString(WCTData, 0)

                    file = utils.saveFileWindow ("Save data", File.getSpecialLocation(File.userHomeDirectory), "*.mwt", true)
                    file:replaceWithData(WCTDataHexString)

                    end

                    If I change that last line to WCTData instead of WCTDataHexString I do get a file but it’s not how I want it – like you said I’m looking for each byte is 7 bits (00h – F7h) I want my .mwt file to contain hex values.. If I’m understanding you correctly “toHexString” should do that but I’m not getting it to work at all.

                    Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

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

                      since you want to write a String not a MemoryBlock you should propablu use http://www.rawmaterialsoftware.com/juce/api/classFile.html#ab3476536a97b787f00b5988cdb326816 use the right method for the right data type. Like i wrote i’m copying the classes from JUCE 1:1 unless told otherwise. The classes File/MemoryBlock are the same (except the MemoryBlock void * arguments that can’t be void *, instead another MEmoryBlock is used as an argument)

                    Viewing 9 posts - 1 through 9 (of 9 total)
                    • The forum ‘Programming’ is closed to new topics and replies.
                    There is currently 0 users and 71 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