Home › Forums › General › Programming › stateData
- This topic has 47 replies, 6 voices, and was last updated 7 years, 10 months ago by Possemo.
-
AuthorPosts
-
November 24, 2014 at 2:58 am #32730
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
November 24, 2014 at 11:13 am #32739stateData 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.
November 24, 2014 at 2:27 pm #32745Oh ok
Thank you Atom
i will try itNovember 27, 2014 at 4:18 pm #32908Hi
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 NameBytesi don’t understand the interest of var()
i followed juce classes and juce website explanations
any advice ?
November 28, 2014 at 11:00 am #32938You 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
November 28, 2014 at 6:45 pm #32944I’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
December 1, 2014 at 11:50 am #33089I’ll fix that, i think i know why that happens.
December 11, 2014 at 9:11 pm #33550Hi
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) constCTRLR :
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)endLoadglb = 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())
endend
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
December 15, 2014 at 5:24 pm #33720This 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"/>
December 18, 2014 at 2:42 am #33864hello Atom
Sorry to spend your timeI 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)December 18, 2014 at 11:54 am #33891I 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.
December 18, 2014 at 11:37 pm #33910Me too
Whatever i do i get the error
but in maschine the preset with the data is saved and loaded anywayone 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 sureDecember 19, 2014 at 2:09 am #33916After 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 methodEDIT: 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.
December 29, 2014 at 11:57 am #34457I’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?
December 29, 2014 at 12:19 pm #34463I 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.
December 29, 2014 at 1:09 pm #34464Hi
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 errorsDecember 29, 2014 at 1:29 pm #34465Ok, 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.
December 29, 2014 at 1:48 pm #34466The 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.
December 29, 2014 at 4:06 pm #34470—
— 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
endend
I get it now ! but I have 2 midi port errorswhen I load daw preset files
Attachments:
You must be logged in to view attached files.January 20, 2015 at 2:11 am #36137Hi Atom
Is it planned to add this callback in instances ?
Is it possible or it behaves too differently ?Thank you
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.