stateData

Home Forums General Programming stateData

Viewing 8 posts - 41 through 48 (of 48 total)
  • Author
    Posts
  • #69051
    goodweather
    Participant
      • Topics: 45
      • Replies: 550
      • Total: 595
      • ★★★

      Thx.

      Q1: For other data than modulators, I will create the 2 methods you indicate (and descrive very well above). As closing the panel don’t save stateData, is it somewhere an OnPanelClose method to force the saving of the stateData?
      I was planning to use methods for Reading/Writing .ini file containing different settings but I’ll try this way instead. Seems easier BUT I want to be sure to have the last values of my variables saved so they can be restored at next panel open.

      Q2: For all modulators data, is there a way to prevent restoring the modulators state (or better, to be able to control the restore or not restore of modulators state)?

      The difference of behaviour you mention above (quit Ctrlr or just close panel) is maybe in relation with my issue that all my OnChange methods are triggered (see http://ctrlr.org/forums/topic/order-of-events-when-loading-a-panel/)

      Related question: I see 2 method types in Ctrlr when adding a method. luaCtrlrRestoreState and luaPanelRestoreState (same for Save).
      What are the difference between them and which one should be used where?
      There is the setting in Preferences and there is the setting at Panel level which seems to be the same.

      #69062
      goodweather
      Participant
        • Topics: 45
        • Replies: 550
        • Total: 595
        • ★★★

        While waiting to get an answer to my questions in the previous post, I made a test panel for stateData and it works indeed exactly as dasfaker mentioned:

        • keeping the panel open and closing Ctrlr saves the stateData
        • closing the panel and re-opening it doesn’t save the stateData

        Feel free to try with attached panel. You can edit 2 labels, 1 push button and one rotary button. You can also reset the stateData values to see that they are indeed changing.

        One way to force the user to close Ctrlr is to hide the panel menu…
        Does anyone have some other suggestion?

        Attachments:
        You must be logged in to view attached files.
        #69064
        dasfaker
        Keymaster
          • Topics: 80
          • Replies: 793
          • Total: 873
          • ★★★

          While it’s easier to deal with .panel files, the final “product” should be an exported instance. With exported instances you don’t have to deal with this problem (and more), and closing the app stores the data. The .panel should be used only for developing.

          #69110
          goodweather
          Participant
            • Topics: 45
            • Replies: 550
            • Total: 595
            • ★★★

            Can someone help me with stateData and Memoryblock save/restore?
            I don’t succeed to get a memoryblock cakked LoadedProgramData to be saved and restored (always empty)…

            Is there a special way to save and restore a memoryblock in stateDate?

            In a method used to load a program I have
            LoadedProgramData = utils.unpackDsiData(Pro2PackedProgramData:getRange(6,1171))
            and it works fine; all modulatros are well initialized using the appropriate getByte methods as
            modOsc1Sync:setValue(LoadedProgramData:getByte(52), true)

            I have a SaveStateData method in “Called when Ctrlr state is saved”

            SaveStateData = function(--[[ ValueTree --]]stateData)
            
            -- Variables to be saved
            stateData:setProperty ("LastBank", LastBank, nil)
            stateData:setProperty ("LastProgram", LastProgram, nil)
            stateData:setProperty ("LoadedProgramData", LoadedProgramData, nil)
            stateData:setProperty ("CurrentOsc1Wave", iCurrentOsc1Wave, nil)
            stateData:setProperty ("CurrentOsc2Wave", iCurrentOsc2Wave, nil)
            stateData:setProperty ("CurrentOsc3Wave", iCurrentOsc3Wave, nil)
            stateData:setProperty ("CurrentOsc4Wave", iCurrentOsc4Wave, nil)
            stateData:setProperty ("Disk1FullPath", sDisk1FullPath, nil)
            stateData:setProperty ("Disk1FileName", sDisk1FileName, nil)
            
            end

            I have a ReadStateData in “Called when Ctrlr is loaded”

            ReadStateData = function(--[[ ValueTree --]] stateData)
            
            -- Variables to be read
            LastBank = stateData:getProperty("LastBank")
            LastProgram = stateData:getProperty("LastProgram")
            iCurrentOsc1Wave = stateData:getProperty("CurrentOsc1Wave")
            iCurrentOsc2Wave = stateData:getProperty("CurrentOsc2Wave")
            iCurrentOsc3Wave = stateData:getProperty("CurrentOsc3Wave")
            iCurrentOsc4Wave = stateData:getProperty("CurrentOsc4Wave")
            sDisk1FullPath = stateData:getProperty("Disk1FullPath")
            sDisk1FileName = stateData:getProperty("Disk1FileName")
            LoadedProgramData = MemoryBlock()
            LoadedProgramData = stateData:getProperty("LoadedProgramData")
            
            end

            LoadedProgramData:getSize() is giving an error “Attempt to call method ‘?’ a (nil value)” so LoadedProgramdata is probably not a memory block or is nil…

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

              MemoryBlocks have to be stored like this

              stateData:setProperty (“LoadedProgramData”, LoadedProgramData:toHexString(1), nil)

              #69115
              goodweather
              Participant
                • Topics: 45
                • Replies: 550
                • Total: 595
                • ★★★

                It is working now. Thanks dasfaker, you put me on the way 🙂

                Explanation: stateData is saving strings so you need to convert objects like memoryblock to a string but on restore also do the opposite.
                I saw this because when using toHexString on Save stateData it didn’t work and by using what(LoadedProgramData) I saw it was a string…

                So:

                • For memoryblock save, use

                  stateData:setProperty (“LoadedProgramData”, LoadedProgramData:toHexString(1), nil)

                • For memoryblock restore, use
                  LoadedProgramData = MemoryBlock()
                  LoadedProgramData:loadFromHexString(stateData:getProperty("LoadedProgramData"))

                I’ll add this in the Step by Step guide 2.0 as it is needed by panel makers…

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

                  While waiting to get an answer to my questions in the previous post, I made a test panel for stateData and it works indeed exactly as dasfaker mentioned:

                  • keeping the panel open and closing Ctrlr saves the stateData
                  • closing the panel and re-opening it doesn’t save the stateData

                  Feel free to try with attached panel. You can edit 2 labels, 1 push button and one rotary button. You can also reset the stateData values to see that they are indeed changing.

                  One way to force the user to close Ctrlr is to hide the panel menu…
                  Does anyone have some other suggestion?

                  Hi, have you found out how you can permanently save stateData? I’m just trying out and it stores the stateData when I save the panel (see screenshot). But when I close and reopen Ctrlr two times it is gone. As you said, when you close the panel within Ctrlr it is gone already. Also when you export the panel to *.bpanelz it is gone as well. Seems to be quite volatile.. :-{} or is this only meant to be used in the vst-plugin version?

                  • This reply was modified 7 years, 11 months ago by Possemo.
                  Attachments:
                  You must be logged in to view attached files.
                  #69210
                  Possemo
                  Participant
                    • Topics: 14
                    • Replies: 638
                    • Total: 652
                    • ★★★

                    It works when exporting to *.bpanelz. I don’t know why I didn’t noticed it yesterday. It is as you say goodweather, when you close the panel within Ctrlr it is gone. Moreover, when you start and close Ctrlr two times it is gone as well (all parameters zeroed). At least this is the behavior of my SuperJX panel in Ctrlr standalone ver.

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