@@ -55,6 +55,7 @@ Patch::~Patch()
5555Rectangle<int > Patch::getGraphBounds () const
5656{
5757 if (auto cnv = ptr.get <t_canvas>()) {
58+ ScopedCurrentCanvas scopedCurrent (cnv.get ());
5859 if (cnv->gl_isgraph ) {
5960 cnv->gl_pixwidth = std::max (10 , cnv->gl_pixwidth );
6061 cnv->gl_pixheight = std::max (10 , cnv->gl_pixheight );
@@ -180,19 +181,13 @@ void Patch::savePatch()
180181 });
181182}
182183
183- void Patch::setCurrent ()
184- {
185- if (auto patch = ptr.get <t_glist>()) {
186- // Ugly fix: plugdata needs gl_havewindow to always be true!
187- patch->gl_havewindow = true ;
188- canvas_create_editor (patch.get ());
189- }
190- }
191-
192184void Patch::setVisible (bool const shouldVis)
193185{
194186 if (auto patch = ptr.get <t_glist>()) {
195- patch->gl_mapped = shouldVis;
187+ t_atom vis;
188+ SETFLOAT (&vis, static_cast <float >(shouldVis));
189+ pd_typedmess (patch.cast <t_pd>(), instance->generateSymbol (" vis" ), 1 , &vis);
190+ pd_typedmess (patch.cast <t_pd>(), instance->generateSymbol (" map" ), 1 , &vis);
196191 }
197192}
198193
@@ -216,8 +211,6 @@ Connections Patch::getConnections() const
216211
217212HeapArray<pd::WeakReference> Patch::getObjects ()
218213{
219- setCurrent ();
220-
221214 HeapArray<pd::WeakReference> objects;
222215 if (auto patch = ptr.get <t_glist>()) {
223216 for (t_gobj* y = patch->gl_list ; y; y = y->g_next ) {
@@ -305,7 +298,6 @@ t_gobj* Patch::createObject(int const x, int const y, String const& name)
305298 }
306299
307300 if (auto patch = ptr.get <t_glist>()) {
308- setCurrent ();
309301 return pd::Interface::createObject (patch.get (), typesymbol, argc, argv.data ());
310302 }
311303
@@ -321,8 +313,6 @@ t_gobj* Patch::renameObject(t_object* obj, String const& name)
321313 String const newName = tokens.joinIntoString (" " );
322314
323315 if (auto patch = ptr.get <t_glist>()) {
324- setCurrent ();
325-
326316 pd::Interface::renameObject (patch.get (), &obj->te_g , newName.toRawUTF8 (), newName.getNumBytesAsUTF8 ());
327317 return pd::Interface::getNewest (patch.get ());
328318 }
@@ -446,7 +436,6 @@ void Patch::paste(Point<int> const position)
446436void Patch::duplicate (SmallArray<t_gobj*> const & objects, t_outconnect const * connection)
447437{
448438 if (auto patch = ptr.get <t_glist>()) {
449- setCurrent ();
450439 pd::Interface::duplicateSelection (patch.get (), objects, connection);
451440 }
452441}
@@ -480,15 +469,13 @@ bool Patch::canConnect(t_object* src, int const nout, t_object* sink, int const
480469void Patch::createConnection (t_object* src, int const nout, t_object* sink, int const nin)
481470{
482471 if (auto patch = ptr.get <t_glist>()) {
483- setCurrent ();
484472 pd::Interface::createConnection (patch.get (), src, nout, sink, nin);
485473 }
486474}
487475
488476t_outconnect* Patch::createAndReturnConnection (t_object* src, int const nout, t_object* sink, int const nin)
489477{
490478 if (auto patch = ptr.get <t_glist>()) {
491- setCurrent ();
492479 return pd::Interface::createConnection (patch.get (), src, nout, sink, nin);
493480 }
494481
@@ -498,15 +485,13 @@ t_outconnect* Patch::createAndReturnConnection(t_object* src, int const nout, t_
498485void Patch::removeConnection (t_object* src, int const nout, t_object* sink, int const nin, t_symbol* connectionPath)
499486{
500487 if (auto patch = ptr.get <t_glist>()) {
501- setCurrent ();
502488 pd::Interface::removeConnection (patch.get (), src, nout, sink, nin, connectionPath);
503489 }
504490}
505491
506492t_outconnect* Patch::setConnctionPath (t_object* src, int const nout, t_object* sink, int const nin, t_symbol* oldConnectionPath, t_symbol* newConnectionPath)
507493{
508494 if (auto patch = ptr.get <t_glist>()) {
509- setCurrent ();
510495 return pd::Interface::setConnectionPath (patch.get (), src, nout, sink, nin, oldConnectionPath, newConnectionPath);
511496 }
512497
@@ -516,7 +501,6 @@ t_outconnect* Patch::setConnctionPath(t_object* src, int const nout, t_object* s
516501void Patch::moveObjects (SmallArray<t_gobj*> const & objects, int const dx, int const dy)
517502{
518503 if (auto patch = ptr.get <t_glist>()) {
519- setCurrent ();
520504 pd::Interface::moveObjects (patch.get (), dx, dy, objects);
521505 }
522506}
@@ -533,15 +517,13 @@ void Patch::moveObjectTo(t_gobj* object, int const x, int const y)
533517void Patch::finishRemove ()
534518{
535519 if (auto patch = ptr.get <t_glist>()) {
536- setCurrent ();
537520 pd::Interface::finishRemove (patch.get ());
538521 }
539522}
540523
541524void Patch::removeObjects (SmallArray<t_gobj*> const & objects)
542525{
543526 if (auto patch = ptr.get <t_glist>()) {
544- setCurrent ();
545527 pd::Interface::removeObjects (patch.get (), objects);
546528 }
547529}
@@ -563,7 +545,6 @@ void Patch::endUndoSequence(String const& name)
563545void Patch::undo ()
564546{
565547 if (auto patch = ptr.get <t_glist>()) {
566- setCurrent ();
567548 auto const x = patch.get ();
568549 glist_noselect (x);
569550
@@ -574,7 +555,6 @@ void Patch::undo()
574555void Patch::redo ()
575556{
576557 if (auto patch = ptr.get <t_glist>()) {
577- setCurrent ();
578558 auto const x = patch.get ();
579559 glist_noselect (x);
580560
@@ -638,7 +618,6 @@ void Patch::setTitle(String const& newTitle)
638618 SETSYMBOL (&args[1 ], pathSym);
639619
640620 if (auto patch = ptr.get <t_glist>()) {
641- setCurrent ();
642621 pd_typedmess (patch.cast <t_pd>(), instance->generateSymbol (" rename" ), 2 , args.data ());
643622 }
644623
0 commit comments