| 2909 | } |
| 2910 | |
| 2911 | void 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 |
no test coverage detected