Initialize Start

From Derivative
Revision as of 22:56, 12 May 2021 by Greg (talk | contribs)
Jump to navigation Jump to search

Initialize Start is an approach in TouchDesigner to prepare and run timed processes. It applies to any system in TouchDesigner where there first needs be an initialization, like files read, server queried or data prepared until the system is ready, putting it in a "ready" state, and then it is signalled to start. For example, before starting a show, you may want to initialize all your generative components at their first frame.

Initialization often takes more than one frame to complete, so there is usually provision to initialize over several frames without substantially stalling TouchDesigner.

Examples of parts of TouchDesigner where the Initialize Start approach is used are:

There is a component in the palette called initalizeStart that you can use to convert any of your components to use the same mechanism.

Initialize Start follows the model of the Timer CHOP.

Control Parameters[edit]

  • Initialize (pulse) - prepares all data, in initializing state
  • Start (pulse) - starts all the timers, puts in running state
  • Play (toggle) - used to pause while playing
  • Speed (float) - speed or slows the timer or simulation clock while running.
  • Cue (toggle), Cue Pulse (pulse), Cue Point (float with menu % index, frames, seconds) - allows you to put/scrub system at specified time
  • Length (float) - if behavior is fixed-length, length is sometimes pre-determined like a movie file, sometimes user-set.
  • Pre-Roll (float) - if behavior is a procedural simulation, at initialization, it may run the sim a few seconds to get it going.
  • Initialize Time (float) - for fixed-length systems, where implemented, this initializes part-way into its internal timeline.
  • Go to Done (pulse) - stops all the timers, possibly goes to an end-state, puts in done state.

Info Channels[edit]

This is often achieved by attaching an Info CHOP to the operator. It is the actual output in the Timer CHOP and the initializeStart palette COMP.

States -

  • initializing (0 if operator currently initializes in the same-frame)
  • ready (after Initialize complete and before Start pressed)
  • running goes on after Start, stays on until Done or Initialize
  • done where applicable

Counters - used to drive animations, index lookups, etc

  • timer_fraction (where applicable), zero for infinite sims and length not known
  • timer_seconds (seconds) which is affected by Speed. If the length is known and you loop, your timer_seconds goes back to 0. It’s really your calculated index / (end - start) / (file_sample_rate)
  • timer_frames (where available)
  • cumulative_seconds (seconds) counts from 0 when you Start, affected by speed and play
  • playing_seconds (seconds) - counts from 0 when you Start, affected by play but not speed
  • running_seconds (seconds) - keeps counting up after Start and not affected by speed or play
  • length_seconds for operators with known length
  • cycles (where applicable)

Behavior[edit]

Fixed-length vs infinite (unknown) length. An example of infinite length would be a particle simulation. There are two flavors of fixed-length - user-specified length or media-determined length (like an audio file).

Callbacks[edit]

In some cases, like the Timer CHOP, there are callbacks where you can run python code when events occur, such as the end of initialization, or the end of a fixed-length behavior. The common ones are:

  • onInitialize() called when the Initialize is pulsed, and is called every frame thereafter until you return 0, in order for multi-frame initializations to occur.
  • onReady() is called when initialization is complete
  • onStart() is called when Start is pressed.
  • onDone() is called when fixed-length systems complete, and when Go to Done is pulsed.

Errors and Warnings[edit]

In some cases, the operator reports errors or warnings, like failure to initialize.