getModulatorValuesAsData strange behaviour

Home Forums General Programming getModulatorValuesAsData strange behaviour

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #69755
    t0f4st
    Participant
      • Topics: 5
      • Replies: 13
      • Total: 18

      Hello again!

      if i use data = panel:getModulatorValuesAsData with vstIndex there is some strange behaviour.

      the vstIndex 0 is ignored and if the vstIndex of one modulator does not correlate (0,1,2,3,4,300,301,302, ….) the modulatorValue is not available in data!!!

      reproduce: create panel add 3 slider, one button with following onClick-Method.
      change one slider vstIndex to x > 4

      --
      -- Called when a mouse is down on this component
      --
      
      checkSerializeOutput = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event)
      
      	dataToWrite = panel:getModulatorValuesAsData("vstIndex", CtrlrPanel.EncodeNormal, 1, false)
      	
      	len = dataToWrite:getSize() 
      	console(string.format("dataToWrite:getSize() == %d",len))
      	console(string.format("dataToWrite:toHexString(1) == %s",dataToWrite:toHexString(1)))
      
      	for i=1,len,1 do
      		if (dataToWrite ~= nil) then
      			console(string.format("dataToWrite[%d] = %s",i,dataToWrite))
      			--console(string.format("dataToWrite[%d] =",i))
      		else
      			console(string.format("dataToWrite[%d] = NULL",i))
      		end
      	end
      
      end
      • This topic was modified 7 years, 9 months ago by t0f4st.
      #69757
      t0f4st
      Participant
        • Topics: 5
        • Replies: 13
        • Total: 18

        not quit sure but a non-optimal workarround will be reinit vstIndex, or add an property as customIndex…

        reinit vstIndex:

        --
        -- Called when a modulator value changes
        -- @mod   http://ctrlr.org/api/class_ctrlr_modulator.html
        -- @value    new numeric value of the modulator
        --
        reInitVSTIndex = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
        
        	n = panel:getNumModulators()
        	for i=0,n-1 do
        		mod = panel:getModulatorByIndex(i)
        		mod:setPropertyInt("vstIndex",i)
        		console(string.format("mod:getProperty('vstIndex') == %d",mod:getPropertyInt("vstIndex")))
        	end
        
        end

        add an property as customIndex (serializeIndex)

        --
        -- Called when a modulator value changes
        -- @mod   http://ctrlr.org/api/class_ctrlr_modulator.html
        -- @value    new numeric value of the modulator
        --
        InitSerializeIndex = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
        
        	n = panel:getNumModulators()
        	for i=0,n-1 do
        		mod = panel:getModulatorByIndex(i)
        		mod:setPropertyInt("serializeIndex",i)
        		console(string.format("mod:getProperty('serializeIndex') == %d",mod:getPropertyInt("serializeIndex")))
        	end
        
        end
        • This reply was modified 7 years, 9 months ago by t0f4st.
        #69759
        t0f4st
        Participant
          • Topics: 5
          • Replies: 13
          • Total: 18

          next problem i have is with setModulatorValuesFromData

          i can load the modulatorValues with

          panel:setModulatorValuesFromData(fileData, "serializeIndex", CtrlrPanel.EncodeNormal, 0, 1, false)

          but the modulator with enabled MidiMessage wont send the loaded/updated values!!!

          please add a flag to panel:setModulatorValuesFromData

          panel:setModulatorValuesFromData(fileData, "serializeIndex", CtrlrPanel.EncodeNormal, 0, 1, false, true)

          with the flag enabled modulators with midiMessage will use the loaded Value and sent the midi message.

          thanks

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

            My 5 cents… What do you want to achieve? Why using the VST indexes? What are the advantages/inconvenients in comparison to basic modulator get/set values?

            #69762
            t0f4st
            Participant
              • Topics: 5
              • Replies: 13
              • Total: 18

              What do you want to achieve?

              i am serializing all modulatorValues and save it in a file. so i can load that file and all modulator values back to the saving state, and of course sending these modulatorValues also to the midi controller.

              there are atleast two ways of archiving this. first: manually looping through all mods and append it to custom structure, that can be parsed….

              but then i found the second and propably better way – because its already implemented

              serialize with: getModulatorValuesAsData
              parse with setModulatorValuesFromData

              Why using the VST indexes? What are the advantages/inconvenients in comparison to basic modulator get/set values?

              with using those panel methods i need a parameter “propertyToIndexBy”… here comes the vstIndex and its “correlate” problems….

              the main advantage of “vstIndex” is that the property vstIndex is already available and i dont have to apply a custom property on each modulator (which isnt that hard to apply but unstable to update)!

              if i change some modulators add/delete the saved data should still be usable.

              • This reply was modified 7 years, 9 months ago by t0f4st.
              • This reply was modified 7 years, 9 months ago by t0f4st.
              #69765
              t0f4st
              Participant
                • Topics: 5
                • Replies: 13
                • Total: 18

                i think with this implementation it will be possible to add/remove modulators and the data is still be usable. *i dont care about the unused memory 🙂

                LMemoryBlock CtrlrPanel::getModulatorValuesAsData(const String &propertyToSortBy, const CtrlrByteEncoding byteEncoding, const int bytesPerValue, const bool useMappedValues)
                {
                
                	int minIndex = 999999;
                	int maxIndex = 0;
                
                	for (int i=0; i<getNumModulators(); i++)
                	{
                		const int index = getModulatorByIndex(i)->getProperty(propertyToSortBy);
                
                		if (index >= 0)
                		{
                			if (index > maxIndex)
                				maxIndex = index;
                			if (index < minIndex)
                				minIndex = index;
                		}
                	}
                
                	MemoryBlock modulatorData (maxIndex * bytesPerValue, true);
                	uint32 modulatorValue;
                
                	for (int i=0; i<getNumModulators(); i++)
                	{
                		const int index = getModulatorByIndex(i)->getProperty(propertyToSortBy);
                
                		if (index >= 0)
                		{
                			if (useMappedValues)
                				modulatorValue = getModulatorByIndex(i)->getValueMapped();
                			else
                				modulatorValue = getModulatorByIndex(i)->getValueNonMapped();
                
                			modulatorData.setBitRange (index * (bytesPerValue * 8), bytesPerValue * 8, modulatorValue);
                		}
                	}
                
                	return (modulatorData);
                }
                • This reply was modified 7 years, 9 months ago by t0f4st.
                • This reply was modified 7 years, 9 months ago by t0f4st.
                #69768
                goodweather
                Participant
                  • Topics: 45
                  • Replies: 550
                  • Total: 595
                  • ★★★

                  Thx for the explanation!
                  I didn’t know this serializing/parsing of all modulators. Can indeed be useful.
                  On my side, I rely on the sysex dumps from the synth manufacturer and I load/save based on their structure.
                  Maybe that, as a workaround, you can read the vstindex and value of each modulator and set them one by one with the simple setValue?

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

                    is the code above a patch you would like to add to Ctrlr ? can you explaing what’s going on there ?

                    #69772
                    t0f4st
                    Participant
                      • Topics: 5
                      • Replies: 13
                      • Total: 18

                      is the code above a patch you would like to add to Ctrlr ? can you explaing what’s going on there ?

                      current usecase:

                      you have a panel with some modulators. during panel designing you delete and add some new modulators. this will lead to vstIndex’s which aren’t continously (0,1,2,3,4,5,6) rath discontinuity (0,1,2,5,6,100,102,..).

                      with this panel design scenario in mind data = panel:getModulatorValuesAsData("vstIndex", CtrlrPanel.EncodeNormal, 1, false) will not result valid data !!!

                      problem is the current getModulatorValuesAsData implementation! the method is expecting and requiring that the propertyToIndexBy is continously!

                      with the following getModulatorValuesAsData implementation the method call data = panel:getModulatorValuesAsData("vstIndex", CtrlrPanel.EncodeNormal, 1, false) will result in valid data, althought it has alot of unused space – which i dont mind.

                      first it gets the maximum vstIndex of all modulators used in panel.
                      with that info it creates an memoryblock with the size equal to the maximum vstIndex.

                      then the loop starts to iterate through all modulators in panel.
                      read the moduatorValues and store it in the memoryblock at the position defined by the vstIndex of the modulator.

                      i think with this implementation it will be possible to add/remove modulators and the data is still be usable. *i dont care about the unused memory ?

                      LMemoryBlock CtrlrPanel::getModulatorValuesAsData(const String &propertyToSortBy, const CtrlrByteEncoding byteEncoding, const int bytesPerValue, const bool useMappedValues)
                      {
                      
                      	int minIndex = 999999;
                      	int maxIndex = 0;
                      
                      	for (int i=0; i<getNumModulators(); i++)
                      	{
                      		const int index = getModulatorByIndex(i)->getProperty(propertyToSortBy);
                      
                      		if (index >= 0)
                      		{
                      			if (index > maxIndex)
                      				maxIndex = index;
                      			if (index < minIndex)
                      				minIndex = index;
                      		}
                      	}
                      
                      	MemoryBlock modulatorData (maxIndex * bytesPerValue, true);
                      	uint32 modulatorValue;
                      
                      	for (int i=0; i<getNumModulators(); i++)
                      	{
                      		const int index = getModulatorByIndex(i)->getProperty(propertyToSortBy);
                      
                      		if (index >= 0)
                      		{
                      			if (useMappedValues)
                      				modulatorValue = getModulatorByIndex(i)->getValueMapped();
                      			else
                      				modulatorValue = getModulatorByIndex(i)->getValueNonMapped();
                      
                      			modulatorData.setBitRange (index * (bytesPerValue * 8), bytesPerValue * 8, modulatorValue);
                      		}
                      	}
                      
                      	return (modulatorData);
                      }
                      • This reply was modified 7 years, 9 months ago by t0f4st.
                      • This reply was modified 7 years, 9 months ago by t0f4st.
                      #69799
                      t0f4st
                      Participant
                        • Topics: 5
                        • Replies: 13
                        • Total: 18

                        Maybe that, as a workaround, you can read the vstindex and value of each modulator and set them one by one with the simple setValue?

                        yeah, i already though about that manual looping and parsing but it is very slow!

                        is the code above a patch you would like to add to Ctrlr ? can you explaing what’s going on there ?

                        will you implement it in the next built?

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

                          yes i’ll just do it a bit better, i’ll iterate till the end and just NOT return those modulators that are currently NULL, the modulator table just has “holes” in it, but i’ll skip over the holes and return all the modulators that have the vstIndex smaller then the passed in largest index. will that be ok ?

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

                            please post this as a bug on github i’ll have that on my list

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