Docs Show & output

SwitchTools

A companion for any Switch, Cross or multi-input operator: index by slider, menu or bind, loop or clamp, colour the live input, cook only the inputs in use and unload the rest from the GPU, plus reorder, reverse, randomize and align the inputs.

▶ Show & output ◆ Patreon · Base

Why use it

A scene setup in TouchDesigner often ends in a Switch TOP with a dozen inputs, each scene in its own component. As the project grows, so does the cost of the scenes you are not showing: their textures stay in GPU memory, and whatever inside them keeps cooking still takes frame time. Driving the switch is a small network of its own as well: a slider or a CHOP for the index, logic for what happens at the ends, and some way to see which input is live.

SwitchTools sits next to the switch and takes care of both. It drives the index, lets only the inputs in use cook and can release the memory of the rest. It also colours the live input in the network editor and rewires the inputs for you: reversed, shuffled or in the order they sit on screen.

Features

How to use it

  1. Create it from the FNS tab of the OP Create dialog, under COMP. It lands in the network you are working in.
  2. Point Switch OP at your Switch TOP, Switch CHOP, Cross CHOP, Switch POP or other multi-input operator, or dock the tool to it. SwitchTools docks to the switch, moves just above it, and binds the switch's index (Cross, on a Cross CHOP) to its own Index. It also saves the current wiring as the original, so you can always go back to it.
  3. Drive the switch from Index: drag it, bind it to a slider, or export a CHOP to it. Select picks an input by name. With Blend on, values between two inputs crossfade between them.
  4. Choose what happens when Index runs past the last input with Loop Type: clamp at the ends, loop round to the first, or zigzag back.
  5. To see which input is live, switch on Colorize. The live input takes On Color and the others Off Color.

To take the tool out of the picture without deleting it, switch off Active: the switch is unbound and left as it is.

Cooking only what is on screen

This works on inputs that are components. Wire each scene's Out TOP (or Out CHOP) into the switch, and SwitchTools works with the component around it.

  • Control Cook (COMPs) lets only the component on screen cook; the others stop cooking until they are selected. While Blend crossfades between two inputs, both cook.
  • Unload GPU also releases an input's CPU and GPU memory a few frames after it goes off screen. If you switch back before then, the unload is cancelled. With Unload Method on Progressive, the release is spread over several frames, at most Unload Budget (ms/frame) milliseconds each, so a heavy scene does not hitch the frame it leaves, and POPs are covered too. Locked operators keep their data. Immediate unloads every unlocked TOP in one frame.

Rewiring the inputs

The Inputs page rewires the switch for you. Reversing, shuffling, reordering, aligning, renaming and disconnecting are each one undo step.

  • Trying another order: Reverse Inputs flips the order and Randomize Inputs shuffles it. Restore Original goes back to the wiring saved when you set Switch OP, or the one you last saved with Save as Original.
  • Keeping the layout and the order in step: NodeY to Order (reconnect) rewires the switch so the top node is the first input. Order to NodeY (swap) does the opposite and moves the nodes to match the wiring. The toggle beside NodeY to Order rewires every time you move an input node.
  • Tidying up: Align Inputs (retoggle) lines the input nodes up beside the switch, top, centre or bottom by Alignment Mode. Re-Digitize Inputs (rename) renames them so their digits match their index, scene0, scene1 and so on, or from 1 with the toggle beside it.
  • Closing a loop: First == Last wires the first input again as the last, so a loop closes cleanly. The reorder actions leave that repeat out.
  • Starting over: Disconnect All Inputs clears the switch.

Callbacks

Pulse Create Callbacks on the Callbacks page. It makes a DAT beside the tool and points Callbacks at it. The DAT has two functions:

  • onCookingChange(cooked_comps, uncooked_comps): the input components that started and stopped cooking, with Control Cook (COMPs) on.
  • onSelectionChange(selected_ops, unselected_ops): the inputs that were selected and unselected.

Both arguments arrive as sets. For example, to restart a timer inside each scene whenever it comes back on screen:

def onCookingChange(cooked_comps, uncooked_comps):
	for comp in cooked_comps:
		timer = comp.op('timer1')
		if timer is not None:
			timer.par.start.pulse()
	return

def onSelectionChange(selected_ops, unselected_ops):
	return

Get it

This tool unlocks with Patreon. It installs through the same picker as everything else and unlocks with the Patreon Base tier or higher, connected from inside TouchDesigner. Everything else in the toolkit stays free and MIT, and the membership is what keeps that work moving.

Join on Patreon → How unlocking works →

Parameters

Custom

ControlType / defaultWhat it does
Switch OPSwitchop operatorempty The Switch, Cross or multi-input operator to drive. Dropping the tool next to it or docking it sets this too.
BindBind on / offoff Bind the switch operator's index (or Cross) to this tool's Index, so either one moves the other.
Control
IndexIndex number0 Which input is shown. With Blend on, values between inputs crossfade.
BlendBlend on / offoff Turn on the switch operator's blending between inputs, so fractional indexes crossfade.
Loop TypeType menuOff What happens when Index runs past the first or last input: off, clamp at the ends, loop round, or zigzag back.
Options: Off, Clamp, Loop, Zigzag
SelectSelect menuempty Pick an input by name; sets Index.
Current SelectCurrentselectread-only menuempty Read-only: the input currently shown.
Out IndexOutindexread-only number0 Read-only: the index actually sent to the switch operator after Loop Type.
Num InputsNuminputsread-only number0 Read-only: how many inputs the switch operator has.
Cooker
Control Cook (COMPs)Controlcook on / offoff Let only the input COMPs in use cook; the rest stop cooking until selected.
Unload GPUUnloadgpu on / offoff When an input stops being used, release its COMP's CPU/GPU memory a few frames later (cancelled if it is selected again first), paced by Unload Method and Unload Budget.
Unload MethodUnloadmethod menuProgressive (COMP.progressiveUnload) How an unused input COMP's memory is released. Progressive uses COMP.progressiveUnload() paced by Unload Budget and covers every node type including POPs. Immediate calls unload() on each unlocked TOP in one frame (the previous behaviour).
Options: Progressive (COMP.progressiveUnload), Immediate per-TOP unload
Unload Budget (ms/frame)Unloadbudget number2 Milliseconds per frame spent releasing an unused input's memory (COMP.progressiveUnload). Spreads the unload over several frames so a heavy input never hitches the frame it stops being used. 0 unloads everything in a single frame.
ColorizeColorize on / offoff Colour input nodes by state: On Color for the one in use, Off Color for the rest.
On ColorOncolor colour0 Node colour of the input in use, with Colorize on.
Off ColorOffcolor colour1 Node colour of the inputs not in use, with Colorize on.
ActiveActive on / offon Turn the tool off without removing it: the switch operator is unbound and left as it is.

Inputs

ControlType / defaultWhat it does
Reverse InputsReverseinputs button Reverse the order the inputs are wired in.
Randomize InputsRandomize button Rewire the inputs in a random order.
Order to NodeY (swap)Reorderswitchops button Move the input nodes so their vertical position follows their input order.
NodeY to Order (reconnect)Reorderswitchinputs button Rewire the inputs so their order follows the nodes' vertical position.
^(automatic)^Positiontoorder on / offoff Rewire automatically whenever an input node is moved, so the order always follows the layout.
Re-Digitize Inputs (rename)Redigitizeinputs button Change the digits of the inputs to match the select index
^1 based index^Onebasedindex on / offoff Number inputs from 1 instead of 0 when renaming them.
Align Inputs (retoggle)Aligninputs on / offoff Re-toggle to re-align
Alignment ModeAlignmentmode menuCenter How Align Inputs lines the input nodes up: top, centre or bottom.
Options: Top, Center, Bottom
Adjust Offset (X, Y, YGap)Adjust number0 Offsets used when aligning inputs: horizontal offset, vertical offset and the gap between nodes.
Save as OriginalSave button Remember the current input wiring as the original.
Restore OriginalRestore button Rewire the inputs back to the saved original.
Disconnect All InputsDisconnectall button Disconnect every input of the switch operator.
First == LastFirstlast on / offoff The last input repeats the first, so a loop closes cleanly; it is left out of reordering.

Callbacks

ControlType / defaultWhat it does
CallbacksCallbacks operatorempty The DAT holding your callbacks: onCookingChange and onSelectionChange.
Create CallbacksCreatecallbacks button Create a callbacks DAT beside the tool and point Callbacks at it.

About

ControlType / defaultWhat it does
Show Builtin PagesBuiltinpages on / offoff Show the component's built-in parameter pages.