Traversing a patcher checking for jpatchline connections

Nov 11, 2012 at 8:55pm

Traversing a patcher checking for jpatchline connections

Hi there,

I am working within the patcher hierarchy and I am in need of getting notified when patchlines are created and deleted among any object.
I would also like to be able to distinguish the type of connection (Max, MSP or Jitter)

The code I have so far is something like:

void myobj_attach_to_patchlines_for_patcher(t_myobj *x, t_object *patcher)
{
    t_object *patchline;

    patchline = jpatcher_get_firstline(patcher);
    while (patchline) {
        object_attach_byptr_register(x, patchline, CLASS_NOBOX);
        patchline = jpatchline_get_nextline(patchline);
    }
}

t_max_err myobj_notify(t_myobj *x, t_symbol *sym, t_symbol *msg, void *sender, void *data)
{
    //if (sender == ???) {
        if (msg == gensym("free")) {

            t_object *patchline = (t_object *)sender;
            t_object *box1 = jpatchline_get_box1(patchline);
            t_object *box2 = jpatchline_get_box2(patchline);
            t_object *obj1 = jbox_get_object(box1);
            t_object *obj2 = jbox_get_object(box2);

            // if both objects are MSP objects
            if (object_getmethod(obj1, gensym("dsp")) &&
                object_getmethod(obj2, gensym("dsp"))) {
                object_post((t_object *)x, "MSP connection %p deleted", patchline);
            } else {
                object_post((t_object *)x, "Max connection %p deleted", patchline);
            }

            // no clue for Jitter connections...
        }
    //}
    return MAX_ERR_NONE;

This allows me to get notifications when patchlines are deleted, however how to get notifications when new connections/patchlines are created ?
Also, I’ve found that the way I distinguish Max from MSP connections is not always reliable.
What would be a better way? How to check for Jitter connections ?

Thanks for any help.

- Luigi

#65172
Nov 12, 2012 at 1:30pm

Hi Luigi — not sure if I can answer your question to satisfaction, but here is a try :-) …

The example I have is to look at the code from Plugtastic @ https://github.com/jamoma/Plugtastic/blob/master/implementations/MaxMSP/jcom.plug.out%E2%89%88/jcom.plug.out.cpp

This attaches to patchlines to get notifications for deletion, which looks to be approximately what you have done.

To find out about new connections…

1. This object ( jcom.plug.out≈ ) attaches to the patcher to listen for “dirty” notifications.
2. Whenever the patcher is dirtied it sets a qelem. The qelem then broadcasts a message to every object in the patcher.
3. Any object responding to the message, sends another message out its outlet(s)
4. Now the receiving objects know that there is a connection

Hope this helps!
Tim

#234907
Nov 12, 2012 at 8:22pm

Hi Tim,

thanks for your reply.

I did look at the [jcom.plug.out] object and other Jamoma objects, which also employ the same mechanism. I clearly understand the code and what it does but I am not really sure it suits my needs.

I don’t really need to broadcast messages and – above all – I don’t want to be dependent on the ability of an object to respond to a certain message in order to determine if there is a connection. The whole mechanism employed in [jcom.plug.out] might work well for Jamoma, but it seems too convoluted for what I am doing, which is certainly not as complex and deep as the Jamoma project.

What I am looking for is to simply get notified when a new connection is made.
In my notify method I would like to get a pointer to the jpatchline that was just created, in the same fashion I get a pointer to a jpatchline upon deletion. Is that possible ?

Cheers

- Luigi

#234908

You must be logged in to reply to this topic.