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

Method DuplicateModule

Source/ModularSynth.cpp:2757–2792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2755}
2756
2757IDrawableModule* ModularSynth::DuplicateModule(IDrawableModule* module)
2758{
2759 juce::MemoryBlock block;
2760 {
2761 FileStreamOut out(block);
2762 module->SaveState(out);
2763 }
2764
2765 ofxJSONElement layoutData;
2766 module->SaveLayoutBase(layoutData);
2767 std::vector<IDrawableModule*> modules = mModuleContainer.GetModules();
2768 std::string newName = GetUniqueName(layoutData["name"].asString(), modules);
2769 layoutData["name"] = newName;
2770
2771 IDrawableModule* newModule = CreateModule(layoutData);
2772 mModuleContainer.AddModule(newModule);
2773 SetUpModule(newModule, layoutData);
2774 newModule->Init();
2775
2776 assert(newModule);
2777
2778 newModule->SetName(module->Name()); //temporarily rename to the same as what we duplicated, so we can load state properly
2779
2780 {
2781 FileStreamIn in(block);
2782 mIsLoadingModule = true;
2783 mIsDuplicatingModule = true;
2784 newModule->LoadState(in, newModule->LoadModuleSaveStateRev(in));
2785 mIsDuplicatingModule = false;
2786 mIsLoadingModule = false;
2787 }
2788
2789 newModule->SetName(newName.c_str());
2790
2791 return newModule;
2792}
2793
2794ofxJSONElement ModularSynth::GetLayout()
2795{

Callers

nothing calls this directly

Calls 9

GetUniqueNameFunction · 0.85
SaveLayoutBaseMethod · 0.80
AddModuleMethod · 0.80
SaveStateMethod · 0.45
InitMethod · 0.45
SetNameMethod · 0.45
NameMethod · 0.45
LoadStateMethod · 0.45

Tested by

no test coverage detected