Home › Forums › General › Programming › getModulatorValuesAsData strange behaviour
- This topic has 11 replies, 3 voices, and was last updated 7 years, 9 months ago by atom.
-
AuthorPosts
-
August 5, 2016 at 2:44 am #69755
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.
August 5, 2016 at 3:17 am #69757not 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.
August 5, 2016 at 4:24 am #69759next 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
August 5, 2016 at 1:23 pm #69761My 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?
August 5, 2016 at 1:37 pm #69762What 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 withsetModulatorValuesFromData
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.
August 5, 2016 at 2:10 pm #69765i 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); }
August 5, 2016 at 5:23 pm #69768Thx 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?August 5, 2016 at 10:06 pm #69770is the code above a patch you would like to add to Ctrlr ? can you explaing what’s going on there ?
August 6, 2016 at 4:56 pm #69772is 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); }
August 9, 2016 at 8:37 pm #69799Maybe 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?
August 9, 2016 at 9:32 pm #69801yes 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 ?
August 9, 2016 at 9:33 pm #69802please post this as a bug on github i’ll have that on my list
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.