MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / LoadState

Method LoadState

Source/ModularSynth.cpp:2911–2975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2909}
2910
2911void ModularSynth::LoadState(std::string file)
2912{
2913 ofLog() << "LoadState() " << file;
2914
2915 if (!juce::File(file).existsAsFile())
2916 {
2917 LogEvent("couldn't find file " + file, kLogEventType_Error);
2918 return;
2919 }
2920
2921 if (mInitialized)
2922 TitleBar::sShowInitialHelpOverlay = false; //don't show initial help popup
2923
2924 FileStreamIn in(ofToDataPath(file));
2925
2926 if (in.Eof())
2927 {
2928 LogEvent("File is empty: " + file, kLogEventType_Error);
2929 return;
2930 }
2931
2932 mAudioThreadMutex.Lock("LoadState()");
2933 LockRender(true);
2934 mAudioPaused = true;
2935 mIsLoadingState = true;
2936 LockRender(false);
2937 mAudioThreadMutex.Unlock();
2938
2939 //TODO(Ryan) here's a little hack to allow older BSK files that were saved in 32-bit to load.
2940 //I guess this could bite me if someone ever has a very massive json. the number corresponds to a long-standing sanity check in FileStreamIn::operator>>(std::string &var), so this shouldn't break any current behavior.
2941 //this should definitely be removed if anything about the structure of the BSK format changes.
2942 uint64_t firstLength[1];
2943 in.Peek(firstLength, sizeof(uint64_t));
2944 if (firstLength[0] >= FileStreamIn::sMaxStringLength)
2945 FileStreamIn::s32BitMode = true;
2946
2947 std::string jsonString;
2948 in >> jsonString;
2949 bool layoutLoaded = LoadLayoutFromString(jsonString);
2950
2951 if (layoutLoaded)
2952 {
2953 mIsLoadingModule = true;
2954 mModuleContainer.LoadState(in);
2955 if (ModularSynth::sLastLoadedFileSaveStateRev >= 424)
2956 mUILayerModuleContainer.LoadState(in);
2957 mIsLoadingModule = false;
2958
2959 TheTransport->Reset();
2960 }
2961
2962 FileStreamIn::s32BitMode = false;
2963
2964 mCurrentSaveStatePath = file;
2965 File savePath(mCurrentSaveStatePath);
2966 std::string filename = savePath.getFileName().toStdString();
2967 mMainComponent->getTopLevelComponent()->setName("bespoke synth - " + filename);
2968

Callers 1

DuplicateModuleMethod · 0.45

Calls 7

ofLogClass · 0.85
ofToDataPathFunction · 0.85
EofMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
PeekMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected