stateData

Home Forums General Programming stateData

Viewing 20 posts - 1 through 20 (of 48 total)
  • Author
    Posts
  • #32730
    zeoka
    Participant
      • Topics: 73
      • Replies: 466
      • Total: 539
      • ★★★

      Hi Atom

      I’ve well tested the feature that save extra data in DAW sound format like mxsnd (maschine 2 ) it works nice
      however i’ve an error that disable the myMethod2

      
      --
      -- Called when data needs saving
      --
      myMethod = function(stateData)
      stateData = MemoryBlock()
       for i = 0,13,1 do 
           s = panel:getComponent("SoundName"):getProperty("uiLabelText"):byte(i+1)
            if s == nil then 
               s = 32 
           end
           e = string.format("%x",s)
           d = MemoryBlock(e)
           stateData:insert(d,1,i)
       end
      stateData:append(MemoryBlock(panel:getLabelComponent("GlobalData"):getText()))
      
      console(string.format("%s",stateData:toHexString(1)))
      end
      
      --
      -- Called when data is restored
      --
      myMethod2 = function(stateData)
      
      panel:getLabelComponent("SoundName"):setText(stateData:getRange(0,14):toString())
      panel:getLabelComponent("GlobalData"):setText(stateData:getRange(14,33):toHexString(1))
      console(string.format("%s",stateData:toHexString(1)))
      end

      line6 :attempt to call method getRange (a nil value)

      the data is restored though

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

        stateData is not a MemoryBlock but a ValueTree, you now have the built in debugger, so just put pause(“break”) in the restore method to see what you are getting as parameters to the method.

        #32745
        zeoka
        Participant
          • Topics: 73
          • Replies: 466
          • Total: 539
          • ★★★

          Oh ok
          Thank you Atom
          i will try it

          #32908
          zeoka
          Participant
            • Topics: 73
            • Replies: 466
            • Total: 539
            • ★★★

            Hi
            tried to figure out how to

            
            --
            -- Called when data needs saving
            --
            myMethod = function(stateData)
            
            namevar = var(panel:getComponent("SoundName"):getProperty("uiLabelText"))
            glbvar =  var(panel:getLabelComponent("GlobalData"):getText())
            
            stateData:setProperty(NameBytes,namevar, UndoManager (30000,30))
            
            stateData:setProperty(Globalbytes,glbvar, UndoManager (30000,30))
            
            end
            --
            -- Called when data is restored
            --
            myMethod2 = function(stateData)
            
            if NameBytes:isValid() == true then 
            panel:getLabelComponent("SoundName"):setText(namevar:getProperty(NameBytes))
            end
            pause("break") 
            if Globalbytes:isValid() == true then
            panel:getLabelComponent("GlobalData"):setText(glbvar:getProperty(Globalbytes))
            end
            Is the value tree is done by Ctrlr and i chose nodes or i must add myself data and call them after ?
            
            it's seems to work  so i think this is the first theory 
            even if there a message error 
            
            end

            i miss something
            may be NameBytes() instead of NameBytes

            i don’t understand the interest of var()

            i followed juce classes and juce website explanations

            any advice ?

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

              You don’t need to wrap stuff in var, var is a container for all other value types (strings, numbers) so just pass them directly, also you don’t need to pass an UndoManager just pass nil or 0

              #32944
              zeoka
              Participant
                • Topics: 73
                • Replies: 466
                • Total: 539
                • ★★★

                I’ve done like you said and removed var() just the data is in memoryblock form
                var (const MemoryBlock &binaryData)

                This is working great !! i switch between DAW presets
                The data are in the preset file (788ko instead of 13ko )

                However i notice the data are not saved whith the DAW sound preset when Ctrlr is a restricted instance

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

                  I’ll fix that, i think i know why that happens.

                  #33550
                  zeoka
                  Participant
                    • Topics: 73
                    • Replies: 466
                    • Total: 539
                    • ★★★

                    Hi
                    It seems that getProperty and setProperty is different in Ctrlr and Juce
                    it needs something more
                    CTRLR :
                    var const& getProperty(ValueTree const& ,Identifier)
                    or
                    var getProperty(ValueTree const& ,Identifier,var const&)
                    JUCE :
                    const& var & getProperty (const Identifier name) const
                    or
                    var getProperty (const Identifier name, const var &defaultReturnValue) const

                    CTRLR :
                    ValueTree & setProperty(ValueTree &,Identifier,var const&,custom[class juce ::undoManager]*)
                    JUCE :
                    ValueTree & setProperty (const Identifier name, const var &newValue, UndoManager *undoManager)

                    last thing I’ve tried is this
                    Saveglb = function(stateData)
                    namevar = MemoryBlock(panel:getComponent(“SoundName”):getProperty(“uiLabelText”))
                    glbvar = MemoryBlock(panel:getLabelComponent(“GlobalData”):getText())
                    stateData:setProperty(“NameBytes”,namev,0)
                    stateData:setProperty(“Globalbytes”,glbv,0)end

                    Loadglb = function(stateData)
                    if stateData:hasProperty(“Globalbytes”) == true then
                    GLO = stateData:getProperty(“Globalbytes”,glbv)
                    panel:getLabelComponent(“GlobalData”):setText(MemoryBlock(GLO):toHexString(1))
                    panel:getComponent(“GlobalHandling”):repaint()
                    end
                    if stateData:hasProperty(“NameBytes”) == true then
                    PNAM = stateData:getProperty(“NameBytes”,namev)
                    panel:getLabelComponent(“SoundName”):setText(MemoryBlock(PNAM):toString())
                    end

                    end

                    I still get errors and callbacks disabling. Strangely, whatever I script

                    the data are well saved and loaded , that’s working (not instances) 5.3.26

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

                      This is how i suspect you should use the ValueTree class (works for me without errors)

                      >>> vt = ValueTree("data")
                      >>> vt:setProperty ("property1", "value")
                      ERROR: No matching overload found, candidates:
                      ValueTree& setProperty(ValueTree&,Identifier,var const&,custom [N4juce11UndoManagerE]*)
                      
                      >>> vt:setProperty ("property1", "value", nil)
                      
                      >>> vt:setProperty ("property2", 2, nil)
                      
                      >>> console (vt:toXmlString())
                      <?xml version="1.0" encoding="UTF-8"?>
                      
                      <data property1="value" property2="2"/>
                      #33864
                      zeoka
                      Participant
                        • Topics: 73
                        • Replies: 466
                        • Total: 539
                        • ★★★

                        hello Atom
                        Sorry to spend your time

                        I thought statedata was the value tree (valid or not )

                        I’ve done as you describe

                        Saveglb = function(stateData)
                        dataRcvr = ValueTree("data")
                          namev = panel:getComponent("SoundName"):getProperty("uiLabelText")
                           glbv = panel:getLabelComponent("GlobalData"):getText()
                        dataRcvr:setProperty("NameBytes",namev,nil)
                        dataRcvr:setProperty("Globalbytes",glbv,nil)

                        and

                        --if dataRcvr:hasProperty("Globalbytes") == true then 
                            GLO  = dataRcvr:getProperty("Globalbytes",glbv)
                            panel:getLabelComponent("GlobalData"):setText(MemoryBlock(GLO):toHexString(1))
                            panel:getComponent("GlobalHandling"):repaint()
                        --end
                         --if dataRcvr:hasProperty("NameBytes") == true then 
                            PNAM = dataRcvr:getProperty("NameBytes",namev)
                            panel:getLabelComponent("SoundName"):setText(MemoryBlock(PNAM):toString())
                        --end

                        it works well but when I load it doesn’t recognize dataRcvr (vt equivalent)
                        a nil value
                        the script is disabled and a midi port error occurs (not really grave)

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

                          I don’t understand, how can it work if you’re setting your properties on a localy created ValueTree, you need to work on the passed stateData ValueTree and set your properties there.

                          #33910
                          zeoka
                          Participant
                            • Topics: 73
                            • Replies: 466
                            • Total: 539
                            • ★★★

                            Me too
                            Whatever i do i get the error
                            but in maschine the preset with the data is saved and loaded anyway

                            one thing i’m sure the patch name and glb data are not saved without the method

                            Can i send you the panel may be you could diag what happens ?

                            i need to do other tests with statedata as valuetree as i have done before
                            but with other preset format
                            to be sure

                            #33916
                            zeoka
                            Participant
                              • Topics: 73
                              • Replies: 466
                              • Total: 539
                              • ★★★

                              After many tests in fxp and mnxsnd formats

                              I’ve improved the script but a really strange thing happens

                              
                                Saveglb = function(stateData)
                                namev = panel:getComponent("SoundName"):getProperty("uiLabelText")
                                 glbv = panel:getLabelComponent("GlobalData"):getText()
                              stateData:setProperty("NameBytes",namev,nil)
                              stateData:setProperty("Globalbytes",glbv,nil)
                              
                              Loadglb = function(stateData)
                               if stateData:hasProperty("Globalbytes") == true then 
                                  GLO  = MemoryBlock( stateData:getProperty("Globalbytes",glbv))
                                  if GLO ~= nil 
                                then --panel:getLabelComponent("GlobalData"):setText(string.format("%s",GLO:toHexString(1))
                                     --panel:getComponent("GlobalHandling"):repaint()
                                    
                                 end
                              end
                               if stateData:hasProperty("NameBytes") == true then 
                                     PNAM = MemoryBlock(stateData:getProperty("NameBytes",namev))
                                  if PNAM ~= nil
                                then --panel:getLabelComponent("SoundName"):setText(string.format("%s", PNAM:toString()))
                                  
                                 end
                              end
                              
                              end  
                              

                              the lines are greyed !! but it works without errors !
                              however
                              –midi ports errors still occurs
                              — instance doesn’t save/load this method

                              EDIT: tried 5.3.35

                              noticed the preset format have 7 kb added 790 vs 783
                              i have an param undefined_0 value_0 at the begining in maschine
                              i didn’t see it in modulator list
                              ..
                              Ok not a param added
                              The vstIndex 0 works :
                              panel to daw : ok
                              daw to panel : broken

                              • This reply was modified 9 years, 3 months ago by zeoka.
                              #34457
                              dasfaker
                              Keymaster
                                • Topics: 80
                                • Replies: 793
                                • Total: 873
                                • ★★★

                                I’m trying to store a memoryBlock in to the stateData value tree. I have this code:

                                --
                                -- Called when data needs saving
                                --
                                saveValueTree = function(stateData)
                                
                                	stateData:setProperty (PatchDataCurrent1:toHexString(1), 1, nil)
                                	console(stateData:getPropertyName(1))
                                end
                                --
                                -- Called when data is restored
                                --
                                loadValueTree = function(stateData)
                                
                                	console(stateData:getPropertyName(1))
                                end

                                The data is saved correctly, but I get an error (can’t parse the file content as XML) at panel loading.

                                Any clue what I’m doing wrong?

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

                                  I have no idea what you are doing here

                                  if you want to set a property you set it bu it’s name, so:

                                  stateData:setProperty (“myPropertyName”, PatchDataCurrent1:toHexString(1), nil)

                                  and when you want to read it then:
                                  stringHexData = stateData:getPropertyName(“myPropertyName”)

                                  now stringHexData contains the string of hex numbers you need to convert to real data.

                                  #34464
                                  zeoka
                                  Participant
                                    • Topics: 73
                                    • Replies: 466
                                    • Total: 539
                                    • ★★★

                                    Hi
                                    It seems my scripts are correct (I showed them in one script but they are two in fact)
                                    i thought get property returned the data but you use getPropertyName that return the index of property ??
                                    Anyway my lines are greyed and the data are recovered (??) but i have errors

                                    #34465
                                    dasfaker
                                    Keymaster
                                      • Topics: 80
                                      • Replies: 793
                                      • Total: 873
                                      • ★★★

                                      Ok, I got it working. I was doing the inverse, storing the message as identifier because I thought the value had to be a integer.

                                      Now I have a doubt. When is stateData stored in the .panel file? If I deactivate autosave in preferences, my stateData is not saved in the file when I save or close the panel. If I activate autosave in preferences I see stateData stored but when the autosave interval reaches the time assigned, not when saveing or closing the panel.

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

                                        The panel tree is not flushed to disk with every save, it’s only updated in memory, if you want to flush it to disk you do save ctrlr state (this is the equivalent of saving your project when host ctrlr as a VST). This is done for performance reasons.

                                        #34470
                                        zeoka
                                        Participant
                                          • Topics: 73
                                          • Replies: 466
                                          • Total: 539
                                          • ★★★


                                          — Called when data needs saving

                                          Saveglb = function(stateData)
                                          stateData:setProperty(“NameBytes”,panel:getComponent(“SoundName”):getProperty(“uiLabelText”),nil)
                                          stateData:setProperty(“Globalbytes”,panel:getComponent(“GlobalData”):getProperty(“uiLabelText”),nil)
                                          end
                                          —————–

                                          — Called when data is restored

                                          Loadglb = function(stateData)
                                          if stateData:hasProperty(“Globalbytes”) == true then
                                          GLO = stateData:getProperty(“Globalbytes”)
                                          if GLO ~= nil
                                          then panel:getLabelComponent(“GlobalData”):setText(GLO)
                                          end
                                          end
                                          if stateData:hasProperty(“NameBytes”) == true then
                                          PNAM = stateData:getProperty(“NameBytes”)
                                          if PNAM ~= nil
                                          then panel:getLabelComponent(“SoundName”):setText(PNAM)

                                          end
                                          end

                                          end
                                          I get it now ! but I have 2 midi port errors

                                          when I load daw preset files

                                          Attachments:
                                          You must be logged in to view attached files.
                                          #36137
                                          zeoka
                                          Participant
                                            • Topics: 73
                                            • Replies: 466
                                            • Total: 539
                                            • ★★★

                                            Hi Atom

                                            Is it planned to add this callback in instances ?
                                            Is it possible or it behaves too differently ?

                                            Thank you

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