playpm
August 19, 2022, 12:59pm
1
I’m using URL to open local file directly following official documents, everything works pretty well, but it can’t get called when I save and re-open the project. It seems like I saved the URL wrong by converting it to a string and save it into a property of the valuetree.
My question is is there any way to directly save the URL into valueTreeState so next time it can get recalled automatically? Thanks in advance!!!
1 Like
daniel
August 19, 2022, 1:04pm
2
Can you share the code how you set and retrieve the URL to and from the property?
This should be pretty painless and is the recommended way.
1 Like
playpm
August 19, 2022, 1:13pm
3
Ok, sorry for my ignorance. Here’s how I did it:
mFilePathURL is a URL, I put it into my valueTreeState,
mAPVTS.state.setProperty("currentFilePath", mFilePathURL.toString(true), nullptr);
then I get it in getStateInformation and recover it:
void HelloSamplerAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
juce::MemoryOutputStream mos(destData, true);
mAPVTS.state.writeToStream(mos);
}
void HelloSamplerAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
auto tree = juce::ValueTree::readFromData(data, sizeInBytes);
if( tree.isValid() )
{
mAPVTS.replaceState(tree);
auto filePath = mAPVTS.state.getProperty("currentFilePath", "").toString();
if(filePath.isNotEmpty())
{
auto filePathURL = juce::URL(filePath);
HelloSamplerAudioProcessor::loadFile (filePathURL);
}
}
}
Everything works fine on Mac and PC, only on iOS, it cannot recall properly when re-open the saved project.
daniel
August 19, 2022, 1:18pm
4
That looks good to me.
I think you can use mFilePathURL.toString(false), since for a local file get-parameters are pretty useless.
Can you check in the debugger what the string is when you read in setStateInformation?
playpm
August 19, 2022, 1:32pm
5
This is the string when I setProperty:
file:///private/var/mobile/Containers/Data/Application/214BBBE9-4839-4A2D-9E17-F304BA3F692A/Documents/songs/20201205-lofi%20test/sampler/1.wav
(I don’t know how to debug and get the setStateInformation string after kill and re-open the DAW )
daniel
August 19, 2022, 1:36pm
6
It could be related to sandboxing… not sure if the GUID is the same after a rebuild and such…
I’ll have to pass on to someone with more iOS experience, since it’s likely platform related.
The URL is there, but I don’t know if the location is there where it points to.
daniel
August 19, 2022, 1:52pm
7
Seems you got the answer in your other thread:
You can serialize it to a string. However it won’t be accessible anymore this way after the app restarted. Unfortunately JUCE made access to URL’s bookmark data private which is the thing you’d really want to serialize. See Make URL::bookmark publicly accessible
playpm
August 19, 2022, 1:53pm
8
Yeah, but not sure if it works, I’ll try it later, thanks for the help!