this 'reset' only works after values have been changed?

Home Forums General Programming this 'reset' only works after values have been changed?

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #72307
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      i have a ‘reset’ function triggered by button with
      ‘Called when modulator value changes’ or ‘Mouse Down’-
      but on Panel load, it will initially only work after
      the values it resets have been changed.

      it is for resetting the values of envelope modulators to
      default values. i can’t see why it doesn’t work initially.
      here is an example:

      
      --called when modulator value changes
      function resetPitchEG(m,v)
      
      --This stops issues during panel bootup
      if panel:getRestoreState() or panel:getProgramState() then return end
      
      --reset envelope
      	local reset= panel:getModulator("resetPitchEG"):getValue()
      	local tabs= panel:getComponent ("tabs_Envelopes")
      	--change tab
      	tabs:setPropertyInt ("uiTabsCurrentTab", 0)
      
      	if reset~=nil then
      	--time
      		for k= 1,4 do
      		modul1=panel:getModulatorWithProperty("modulatorCustomIndex",1)
      		modul2=panel:getModulatorWithProperty("modulatorCustomIndex",2)
      		modul3=panel:getModulatorWithProperty("modulatorCustomIndex",3)
      		modul4=panel:getModulatorWithProperty("modulatorCustomIndex",4)
      
      			if tab =="tabs_Envelopes" then
      			modul1:setModulatorValue(50,false,false,false)
      			modul2:setModulatorValue(50,false,false,false)
      			modul3:setModulatorValue(50,false,false,false)
      			modul4:setModulatorValue(50,false,false,false)
      			end
      		end
      	--level
      		for k=5,9 do
      		modul5=panel:getModulatorWithProperty("modulatorCustomIndex",5)
      		modul6=panel:getModulatorWithProperty("modulatorCustomIndex",6)
      		modul7=panel:getModulatorWithProperty("modulatorCustomIndex",7)
      		modul8=panel:getModulatorWithProperty("modulatorCustomIndex",8)
      		modul9=panel:getModulatorWithProperty("modulatorCustomIndex",9)
      
      			if tab =="tabs_Envelopes" then
      			modul5:setModulatorValue(0,false,false,false)
      			modul6:setModulatorValue(0,false,false,false)
      			modul7:setModulatorValue(0,false,false,false)
      			modul8:setModulatorValue(0,false,false,false)
      			modul9:setModulatorValue(0,false,false,false)
      			end
      		end
      	end
      end

      this works fine the rest of the time. it is a bit long like this;
      if i can learn to iterate, i can improve it, but i also want access
      to individual values. i suspect i’m declaring wrong: do i need to
      initialise each modulator or something like that?
      ie: if i randomize them first, it will reset. if i just click
      ‘reset’, nothing happens.

      any thoughts?

      ps: condition ‘if reset~=nil’ here is a bit ‘meh..’, i don’t
      know if it really needs to getValue. could be something
      better here too.

      pps: this is applying values to modulators in a CustomGroup.
      i’m using index ranges to separate ‘time’ and ‘level’ modu-
      lators. they could all be addressed together really.

      #72308
      proton
      Participant
        • Topics: 19
        • Replies: 94
        • Total: 113
        • ★★

        this iterations makes no sense (why the for loop if you don’t loop there):
        ——————————————————————————-
        –time
        for k= 1,4 do
        modul1=panel:getModulatorWithProperty(“modulatorCustomIndex”,1)
        modul2=panel:getModulatorWithProperty(“modulatorCustomIndex”,2)
        modul3=panel:getModulatorWithProperty(“modulatorCustomIndex”,3)
        modul4=panel:getModulatorWithProperty(“modulatorCustomIndex”,4)
        ——————————————————————————-

        Read about the “for loop” and read about arrays/tables. This way you could store your variables in a table and do the iteration on its elements.

        modul = {}

        for k= 1,4 do modul[k]=panel:getModulatorWithProperty(“modulatorCustomIndex”,k)
        end

        this will loop thru elements 1-4 of your table. DO the same for the other variables.

        Cheers!

        #72310
        human fly
        Participant
          • Topics: 124
          • Replies: 1070
          • Total: 1194
          • ★★★★

          ah, ok. it’s true i’m still unsure about ‘for’ iterations.

          i went for it like that to try to do it in one go, – just to
          get something working! the renumbering of the ‘modul’s
          was because i needed different values for some of them,
          not all the same. it is adequate for what i need, for the
          time being.

          is there anything you can see in there that would stop it
          from operating on first-loaded values? it resets fine
          after i’ve changed any parameter.

          • This reply was modified 6 years, 11 months ago by human fly.
          • This reply was modified 6 years, 11 months ago by human fly.
          • This reply was modified 6 years, 11 months ago by human fly. Reason: abbrev
          #72312
          human fly
          Participant
            • Topics: 124
            • Replies: 1070
            • Total: 1194
            • ★★★★

            in fact, i’m still not in the habit of using tables at this stage.
            was getting to know ‘custom groups’.

            #72335
            human fly
            Participant
              • Topics: 124
              • Replies: 1070
              • Total: 1194
              • ★★★★

              *bump* re: why is reset working before values changed.
              can you see anything that is preventing that?
              maybe it would work if i declared modulators on startup.

              but how about a little ‘local’ fix for it here? just for
              argument’s sake? 🙂
              (and disregarding inelegance of the whole thing)

            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 68 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