Skip to content

Commit

Permalink
Fix subpatch issue
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 7, 2025
1 parent d6c77de commit 65648e8
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions Source/Pd/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,39 @@ void Instance::initialisePd(String& pdlua_version)
t_canvas* glist = reinterpret_cast<struct _glist*>(argv->a_w.w_gpointer);

if (auto const vis = atom_getfloat(argv + 1)) {
pd::Patch::Ptr subpatch = new pd::Patch(pd::WeakReference(glist, pd), pd, false);

File patchFile;
if (canvas_isabstraction(glist)) {
auto const path = File(String::fromUTF8(canvas_getdir(glist)->s_name)).getChildFile(String::fromUTF8(glist->gl_name->s_name)).withFileExtension("pd");
subpatch->setCurrentFile(URL(path));
patchFile = File(String::fromUTF8(canvas_getdir(glist)->s_name)).getChildFile(String::fromUTF8(glist->gl_name->s_name)).withFileExtension("pd");
}

MessageManager::callAsync([pd, subpatch] {

MessageManager::callAsync([pd, glist, patchFile] {
PluginEditor* activeEditor = nullptr;
for (auto* editor : pd->getEditors()) {
if (!editor->isActiveWindow())
continue;
editor->getTabComponent().openPatch(subpatch);
if (editor->isActiveWindow())
{
activeEditor = editor;
break;
}
}
if(!activeEditor) return;

for(auto& patch : pd->patches)
{
if(patch->getRawPointer() == glist)
{
activeEditor->getTabComponent().openPatch(patch);
return;
}
}

pd::Patch::Ptr subpatch = new pd::Patch(pd::WeakReference(glist, pd), pd, false);
if(patchFile.exists())
{
subpatch->setCurrentFile(URL(patchFile));
}
activeEditor->getTabComponent().openPatch(subpatch);

});
} else {
MessageManager::callAsync([pd, glist] {
Expand Down

0 comments on commit 65648e8

Please sign in to comment.