Shortcut for Patching via Python!

Hi all! Merry Xmas,
Hope somebody is happy about this:
Open the attached File, select the CHops at the bottom, (or any operators!) and press shift+a,
They will be connected in series based on their location in the x direction of the network!
I’m super happy about this to be honest and hope to go a lot further with this. If anybody has anything to add or criticize(I’m not a very good python programmer) I’d be very interested!
Greetings!

(of course the shortcut shift+a can be changed easily, and I tried to keep the code tidy and documented)
(Thanks to rob for the help with selection stuff!)

EDIT:reupload, first bug is squashed :slight_smile:
EDIT: uploaded new version (new shortcut shift+q to connect two ops without selection.)
Shortcuts20.24.toe (5.93 KB)

Great script!

one comment:
Instead of putting the key function in keyEvent, simply put: shift.a
in the Shortcuts parameter, and put your code in the shortCutEvent function.
This saves you from having to check key, plus the endless combination of possible modifiers.

Cheers.
Rob

Thanks a lot Rob!
Here is a version including your suggestion. Also the old one could actually only be used within “/project1/” :unamused:
Now it works everywhere in the selected pane.
Also I added disconnecting ops (shift+s).
In the file is a demonstration of a problem with disconnecting I still have. Branching from one to many causes problems, all connections go away instead only the ones between selected ops.
(branching from many to one works fine)

On the wiki page about the connector class I find:
op(‘lag1’).outputConnectors[0].disconnect()
but disconnect takes no args. So can I only disconnect all connections from a specific connector?
Or can I also disconnect depending on where the wire leads to?

A completely different thing: This project should ultimately lead to keyboard patching.
What would be great in order to achieve this is navigating and selecting OP via keyboard. Do you think that’s possible with python? I’d need to know all coordinates of all operators in a COMP I think. But I couldn’t find a way to retrieve all OPs in a COMP for example. I’d be very interested if you think thats feasible.
Shortcuts_5.toe (5.88 KB)

I’ll have a look.

You can disconnect from the other end:
op(‘merge1’).inputConnectors[0].disconnect() for example.

Sounds interesting. There are currently a few keyboard shortcuts for navigating (up / down / enter) but none for moving between OPs. Coordinates are pretty straightforward: OP.nodeX .nodeY etc

Have you tried: OP.children() ?
Returns a (possibly empty) list of a children in a COMP.

Cheers
Rob

Hi rob!
Thanks for all of this!

Yes, but then I still have the same problem if there are more ops running into that OP(as some OPs accept multiple inputs t the same inlet like the math or merge Chop e.g.).
Right?

No, each input connector has only one source.
Something like the Merge operator has multiple input connectors.
You can disconnect them individually.
ie, change the 0 in the preceeding script to 1,2, etc
Cheers
Rob.

Thanks again Rob!
In this version all problems(that I’m aware of) are solved.
Working functions are:
Connecting OPs in series (shift+a)
Disconnecting selected OPs (shift+s)
Disconnecting all outputs of a single OP (shift+s with only one OP selected)
Moving one or multiple OPs through the network(ctrl+arrow keys)+shift for faster movement

Can one actually somehow deactivate usual functionality of the arrow keys?(timeline nudge)

Now I’ll try to implement the selection stuff but I think this is going to be a bit more work.
All the best!
Shortcuts_6.toe (5.89 KB)

Is it true that currentChild and selectedChildren would be the way to go if I want to navigate around between OPs and create selections via keyboard?
These are readonly it appears, which would render my plans nearly impossible I guess.
right?

this is awesome. it’s like the max toolbox for max/msp.
any chance of integrating this kind of thing into the core of the application, or at least including the python-based version of it in the main /ui COMP (or somewhere similar)?

:slight_smile: very happy you like it, it is of course inspired by nat’s famous max toolbox.
You can easily implement it by just opening a new TD file, putting it somewhere you like it and saving this as your startup template.
cheers!

oh, and let me reiterate my last question by this occasion:
“Is it true that currentChild and selectedChildren would be the way to go if I want to navigate around between OPs and create selections via keyboard?
These are readonly it appears, which would render my plans nearly impossible I guess.
right?”

Those are read only.
To change whether an individual OP is current or selected, change it accordingly.

op(‘wave1’).selected = True
op(‘wave1’).current = True

etc.

.

I’d have to dig deeper, but my initial answer is that these arrow keys are specifically reserved for timeline operation, if memory serves correct.

Good work on the macros!

-Rob

Thanks a lot rob! That seems promising, I hope I’ll be able to continue working on this soon and of course post results again here.
(If anybody else feels like contributing to this, you are very invited :slight_smile: )

update on this:
i’ve changed the connect in series shortcut to shift+w, but most importantly:
there is a new shortcut to connect the selected(current) OP’s input to the nearest OP to the left (shift+q). That may sound complicated, but this is what we can do with it:
You can press tab to open the op-create dialog, start typing to choose an op, press enter.
Repeat that to make another OP. Use the move OP shortcuts to place the second OP slighlty to the right of the first one. press shift+q and boom, they are connected. Just created a small chain without touching the mouse.
This might still sound complicated, but try it. super convenient.
cheers!
Shortcuts20.24.toe (5.93 KB)

1 Like

Really cool, thanks for putting this together!

with the new annotate features in 2022, your default shortcuts will need to be re thunk

1 Like